OGRE  2.2.4
Object-Oriented Graphics Rendering Engine
Ogre::LwString Class Reference

This is a Light-weight string wrapper around the C string interface. More...

#include <OgreLwString.h>

+ Inheritance diagram for Ogre::LwString:

Classes

struct  Float
 

Public Member Functions

 LwString (char *inStr, size_t maxLength)
 
LwStringa (const LwString &a0)
 
LwStringa (const char *a0)
 
LwStringa (int32 a0)
 
LwStringa (uint32 a0)
 
LwStringa (int64 a0)
 
LwStringa (uint64 a0)
 
LwStringa (float a0)
 
LwStringa (Float a0)
 
template<typename M , typename N >
LwStringa (const M &a0, const N &a1)
 
template<typename M , typename N , typename O >
LwStringa (const M &a0, const N &a1, const O &a2)
 
template<typename M , typename N , typename O , typename P >
LwStringa (const M &a0, const N &a1, const O &a2, const P &a3)
 
template<typename M , typename N , typename O , typename P , typename Q >
LwStringa (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4)
 
template<typename M , typename N , typename O , typename P , typename Q , typename R >
LwStringa (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4, const R &a5)
 
template<typename M , typename N , typename O , typename P , typename Q , typename R , typename S >
LwStringa (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4, const R &a5, const S &a6)
 
template<typename M , typename N , typename O , typename P , typename Q , typename R , typename S , typename T >
LwStringa (const M &a0, const N &a1, const O &a2, const P &a3, const Q &a4, const R &a5, const S &a6, const S &a7)
 
const char * begin () const
 
char * begin ()
 
const char * c_str () const
 
size_t capacity () const
 
void clear ()
 
const char * end () const
 
char * end ()
 
size_t find (const char *val, size_t pos=0) const
 
size_t find (const LwConstString *val, size_t pos=0) const
 
size_t find_first_of (char c, size_t pos=0) const
 
size_t find_first_of (const char *val, size_t pos=0) const
 
size_t find_last_of (char c, size_t pos=~0) const
 
bool operator!= (const LwConstString &other) const
 
bool operator!= (const char *other) const
 
LwStringoperator+= (const LwString &other)
 
LwStringoperator+= (const char *pOther)
 
bool operator< (const LwConstString &other) const
 
bool operator< (const char *other) const
 
LwStringoperator= (const LwConstString &other)
 
LwStringoperator= (const char *pOther)
 
bool operator== (const LwConstString &other) const
 
bool operator== (const char *other) const
 
bool operator> (const LwConstString &other) const
 
bool operator> (const char *other) const
 
void resize (size_t newSize)
 Resizes the string. More...
 
void setToSubstr (const LwConstString &source, size_t _start, size_t size)
 Takes a subset from source in the range [_start; _start + size), and copies it to our string. More...
 
void setToSubstr (const LwConstString &source, char *_start, char *_end)
 
size_t size () const
 

Static Public Member Functions

static LwString FromEmptyPointer (char *cStr, size_t maxLength)
 
static LwConstString FromUnsafeCStr (const char *cStr)
 

Detailed Description

This is a Light-weight string wrapper around the C string interface.

This class is heavily influenced by Tom Forsyth's article "A sprintf that isn't as ugly" https://home.comcast.net/~tom_forsyth/blog.wiki.html#[[A%20sprintf%20that%20isn%27t%20as%20ugly]]

The goals are: No dynamic allocation. Easier to read and control than sprintf() Type-safe (in as much as C can ever be type-safe - bloody auto-converts). Overflow-safe (i.e. it will refuse to scribble, and will assert in debug mode).

LwString needs to be fed a pointer and a maximum length size. The pointer's preexisting contents will be preserved. For example: char buf[1024]; buf[0] = '\0'; LwString myStr( buf, 1024 );

{ char *buf = new char[1024]; LwString myStr( buf, 1024 ); delete buf; //This class will never deallocate the pointer. }

char buf[512]; buf[0] = 'H'; buf[1] = 'i'; buf[2] = '!'; buf[3] = '\0'; LwString myStr( buf, 512 ); printf( myStr.c_str() ) //Hi!

In order to concatenate strings, you need to use the a() function. Concatenations are appended to the current string. You can concatenate strings, integers, raw char strings, and floats. Examples: Example 1: myStr.a( "Hello", " ", "World!" ); //Hello World!

Example 2: myStr.a( "Hello", " " ); myStr.a( "World!" ); //Hello World!

Example 3: char myZero = 0; myStr.a( "One", " + ", 1, " equals ", myZero ); //One + 1 equals 0

Example 4: myStr.a( 1.5f, " + ", 1.5f, " = ", 1.5f + 1.5f ); //1.5 + 1.5 = 3.0

The += operator only works with strings.

Additionally, there are a few STL-like interfaces: begin (iterator), end (iterator), find, find_first_of The input arguments, behavior and return values are the same as std::string.

Users can specify the precision of floats using LwString::Float myStr.a( LwString::Float( 3.5f, precision, minWidth ) );

Remarks
The following code will fail to compile: myStr.a( 4294967295 ); The compiler doesn't know whether the literal means 4294967295 (unsigned), or -1 (signed). To fix the compile error, perform an explicit cast: myStr.a( (uint32)4294967295 ); //Prints 4294967295 myStr.a( (int32)4294967295 ); //Prints -1

Constructor & Destructor Documentation

◆ LwString()

Ogre::LwString::LwString ( char *  inStr,
size_t  maxLength 
)
inline

Referenced by FromEmptyPointer().

Member Function Documentation

◆ a() [1/15]

LwString& Ogre::LwString::a ( const LwString a0)
inline

◆ a() [2/15]

LwString& Ogre::LwString::a ( const char *  a0)
inline

References Ogre::min().

◆ a() [3/15]

LwString& Ogre::LwString::a ( int32  a0)
inline

References _snprintf, and Ogre::max().

◆ a() [4/15]

LwString& Ogre::LwString::a ( uint32  a0)
inline

References _snprintf, and Ogre::max().

◆ a() [5/15]

LwString& Ogre::LwString::a ( int64  a0)
inline

References _snprintf, and Ogre::max().

◆ a() [6/15]

LwString& Ogre::LwString::a ( uint64  a0)
inline

References _snprintf, and Ogre::max().

◆ a() [7/15]

LwString& Ogre::LwString::a ( float  a0)
inline

◆ a() [8/15]

◆ a() [9/15]

template<typename M , typename N >
LwString& Ogre::LwString::a ( const M &  a0,
const N &  a1 
)
inline

References a().

◆ a() [10/15]

template<typename M , typename N , typename O >
LwString& Ogre::LwString::a ( const M &  a0,
const N &  a1,
const O &  a2 
)
inline

References a().

◆ a() [11/15]

template<typename M , typename N , typename O , typename P >
LwString& Ogre::LwString::a ( const M &  a0,
const N &  a1,
const O &  a2,
const P &  a3 
)
inline

References a().

◆ a() [12/15]

template<typename M , typename N , typename O , typename P , typename Q >
LwString& Ogre::LwString::a ( const M &  a0,
const N &  a1,
const O &  a2,
const P &  a3,
const Q &  a4 
)
inline

References a().

◆ a() [13/15]

template<typename M , typename N , typename O , typename P , typename Q , typename R >
LwString& Ogre::LwString::a ( const M &  a0,
const N &  a1,
const O &  a2,
const P &  a3,
const Q &  a4,
const R &  a5 
)
inline

References a().

◆ a() [14/15]

template<typename M , typename N , typename O , typename P , typename Q , typename R , typename S >
LwString& Ogre::LwString::a ( const M &  a0,
const N &  a1,
const O &  a2,
const P &  a3,
const Q &  a4,
const R &  a5,
const S &  a6 
)
inline

References a().

◆ a() [15/15]

template<typename M , typename N , typename O , typename P , typename Q , typename R , typename S , typename T >
LwString& Ogre::LwString::a ( const M &  a0,
const N &  a1,
const O &  a2,
const P &  a3,
const Q &  a4,
const R &  a5,
const S &  a6,
const S &  a7 
)
inline

References a().

◆ begin() [1/2]

const char* Ogre::LwConstString::begin ( ) const
inlineinherited

Referenced by end(), and setToSubstr().

◆ begin() [2/2]

char* Ogre::LwString::begin ( )
inline

◆ c_str()

const char* Ogre::LwConstString::c_str ( ) const
inlineinherited

◆ capacity()

size_t Ogre::LwString::capacity ( ) const
inline

◆ clear()

void Ogre::LwString::clear ( void  )
inline

◆ end() [1/2]

const char* Ogre::LwConstString::end ( ) const
inlineinherited

Referenced by end(), and setToSubstr().

◆ end() [2/2]

char* Ogre::LwString::end ( )
inline

◆ find() [1/2]

size_t Ogre::LwConstString::find ( const char *  val,
size_t  pos = 0 
) const
inlineinherited

References Ogre::min().

◆ find() [2/2]

size_t Ogre::LwConstString::find ( const LwConstString val,
size_t  pos = 0 
) const
inlineinherited

◆ find_first_of() [1/2]

size_t Ogre::LwConstString::find_first_of ( char  c,
size_t  pos = 0 
) const
inlineinherited

References Ogre::min().

◆ find_first_of() [2/2]

size_t Ogre::LwConstString::find_first_of ( const char *  val,
size_t  pos = 0 
) const
inlineinherited

References Ogre::min().

◆ find_last_of()

size_t Ogre::LwConstString::find_last_of ( char  c,
size_t  pos = ~0 
) const
inlineinherited

◆ FromEmptyPointer()

static LwString Ogre::LwString::FromEmptyPointer ( char *  cStr,
size_t  maxLength 
)
inlinestatic

◆ FromUnsafeCStr()

static LwConstString Ogre::LwConstString::FromUnsafeCStr ( const char *  cStr)
inlinestaticinherited

◆ operator!=() [1/2]

bool Ogre::LwConstString::operator!= ( const LwConstString other) const
inlineinherited

◆ operator!=() [2/2]

bool Ogre::LwConstString::operator!= ( const char *  other) const
inlineinherited

◆ operator+=() [1/2]

LwString& Ogre::LwString::operator+= ( const LwString other)
inline

References a().

◆ operator+=() [2/2]

LwString& Ogre::LwString::operator+= ( const char *  pOther)
inline

References a().

◆ operator<() [1/2]

bool Ogre::LwConstString::operator< ( const LwConstString other) const
inlineinherited

◆ operator<() [2/2]

bool Ogre::LwConstString::operator< ( const char *  other) const
inlineinherited

◆ operator=() [1/2]

LwString& Ogre::LwString::operator= ( const LwConstString other)
inline

References Ogre::min().

◆ operator=() [2/2]

LwString& Ogre::LwString::operator= ( const char *  pOther)
inline

References Ogre::min().

◆ operator==() [1/2]

bool Ogre::LwConstString::operator== ( const LwConstString other) const
inlineinherited

◆ operator==() [2/2]

bool Ogre::LwConstString::operator== ( const char *  other) const
inlineinherited

◆ operator>() [1/2]

bool Ogre::LwConstString::operator> ( const LwConstString other) const
inlineinherited

◆ operator>() [2/2]

bool Ogre::LwConstString::operator> ( const char *  other) const
inlineinherited

◆ resize()

void Ogre::LwString::resize ( size_t  newSize)
inline

Resizes the string.

Unlike std::string, the new size MUST be lower or equal than current size. (i.e. we can only shrink)

◆ setToSubstr() [1/2]

void Ogre::LwString::setToSubstr ( const LwConstString source,
size_t  _start,
size_t  size 
)
inline

Takes a subset from source in the range [_start; _start + size), and copies it to our string.

References Ogre::min(), and size().

Referenced by setToSubstr().

◆ setToSubstr() [2/2]

void Ogre::LwString::setToSubstr ( const LwConstString source,
char *  _start,
char *  _end 
)
inline
See also
setToSubstr overload. This method takes iterators to the source string. That is, both _start & _end are in range [source.begin(), source.end()]

References Ogre::LwConstString::begin(), Ogre::LwConstString::end(), and setToSubstr().

◆ size()

size_t Ogre::LwString::size ( void  ) const
inline

Referenced by setToSubstr().


The documentation for this class was generated from the following file: