OGRE-Next  3.0.0
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  Double
 
struct  Float
 

Public Member Functions

 LwString (char *inStr, size_t maxLength)
 
LwStringa (const char *a0)
 
LwStringa (const LwString &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)
 
LwStringa (double a0)
 
LwStringa (Double a0)
 
LwStringa (float a0)
 
LwStringa (Float a0)
 
LwStringa (int32 a0)
 
LwStringa (int64 a0)
 
LwStringa (uint32 a0)
 
LwStringa (uint64 a0)
 
LwStringaChar (char a0)
 
char * begin ()
 
const char * begin () const
 Make every begin & end method from LwConstString available. More...
 
size_t capacity () const
 
void clear ()
 
char * end ()
 
const char * end () const
 
LwStringoperator+= (const char *pOther)
 
LwStringoperator+= (const LwString &other)
 
LwStringoperator= (const char *pOther)
 
LwStringoperator= (const LwConstString &other)
 
void resize (size_t newSize)
 Resizes the string. More...
 
void setToSubstr (const LwConstString &source, char *_start, char *_end)
 
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...
 
size_t size () const
 
- Public Member Functions inherited from Ogre::LwConstString
 LwConstString (const char *inStr, size_t maxLength)
 
 LwConstString (const LwConstString &other)=default
 
const char * begin () const
 
const char * c_str () const
 
size_t capacity () const
 
const char * end () const
 
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=static_cast< size_t >(-1)) const
 
bool operator!= (const char *other) const
 
bool operator!= (const LwConstString &other) const
 
bool operator< (const char *other) const
 
bool operator< (const LwConstString &other) const
 
LwConstStringoperator= (const LwConstString &other)=delete
 
bool operator== (const char *other) const
 
bool operator== (const LwConstString &other) const
 
bool operator> (const char *other) const
 
bool operator> (const LwConstString &other) const
 
size_t size () const
 

Static Public Member Functions

static LwString FromEmptyPointer (char *cStr, size_t maxLength)
 
- Static Public Member Functions inherited from Ogre::LwConstString
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

Member Function Documentation

◆ a() [1/17]

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

◆ a() [2/17]

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

◆ a() [3/17]

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

References a().

◆ a() [4/17]

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

References a().

◆ a() [5/17]

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() [6/17]

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() [7/17]

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() [8/17]

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() [9/17]

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().

◆ a() [10/17]

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

References a().

◆ a() [11/17]

◆ a() [12/17]

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

◆ a() [13/17]

◆ a() [14/17]

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

References _snprintf.

◆ a() [15/17]

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

References _snprintf.

◆ a() [16/17]

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

References _snprintf.

◆ a() [17/17]

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

References _snprintf.

◆ aChar()

LwString& Ogre::LwString::aChar ( char  a0)
inline

◆ begin() [1/2]

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

◆ begin() [2/2]

const char* Ogre::LwConstString::begin
inline

Make every begin & end method from LwConstString available.

See also
https://isocpp.org/wiki/faq/strange-inheritance#overload-derived

◆ capacity()

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

◆ clear()

void Ogre::LwString::clear ( )
inline

◆ end() [1/2]

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

◆ end() [2/2]

const char* Ogre::LwConstString::end
inline

◆ FromEmptyPointer()

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

◆ operator+=() [1/2]

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

References a().

◆ operator+=() [2/2]

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

References a().

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ 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,
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().

◆ setToSubstr() [2/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 size().

Referenced by setToSubstr().

◆ size()

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

Referenced by setToSubstr().


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