/*****************************************************************************
 * $LastChangedDate: 2009-12-28 02:30:09 -0500 (Mon, 28 Dec 2009) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   StringBuf class.
 *//*
 * LEGAL:   COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef BASE_STRINGBUF_HH
#define BASE_STRINGBUF_HH 1

namespace base {

////////////////////////////////////////////////////////////////////////////////
/// @brief Basic string buffer class.
///
/// One purpose is to wrap a C++ string for sharing it.
/// For speed/convenience, to directly manipulate the C++ string and to avoid copying,
/// mBuf is exposed.  But the methods should be used whenever possible.
///
class StringBuf
{
public:
                    StringBuf( void ) { }
                    ~StringBuf() { }
    void            Set( const char* buf )           { mBuf.assign( buf ); }
    void            Set( const char* buf, int len )  { mBuf.assign( buf, len ); }
    void            Set( const uchar* buf, int len ) { mBuf.assign( reinterpret_cast<const char*>(buf), len ); }
    void            Erase( void )           { mBuf.erase(); }
    bool            IfEmpty( void )   const { return mBuf.size() == 0; }
    int             Size( void )      const { return mBuf.size(); }
    const string*   GetString( void ) const { return &mBuf; }
    const char*     GetChars( void )  const { return mBuf.c_str(); }
    const uchar*    GetUchars( void ) const { return reinterpret_cast<const uchar*>(mBuf.c_str()); }

public:
    string      mBuf;   ///< public for speed/convenience but use methods if appropriate
};

} // namespace base

#endif // BASE_STRINGBUF_HH
