OGRE-Next: Ogre::LwString Class Reference

| OGRE-Next 3.0.0 Object-Oriented Graphics Rendering Engine

Loading...
Searching...
No Matches
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:
[legend]

## Classes
struct | Double
struct | Float

## Public Member Functions
| LwString (char *inStr, size_t maxLength)
LwString & | a (const char *a0)
LwString & | a (const LwString &a0)
template<typename M, typename N>
LwString & | a (const M &a0, const N &a1)
template<typename M, typename N, typename O>
LwString & | a (const M &a0, const N &a1, const O &a2)
template<typename M, typename N, typename O, typename P>
LwString & | a (const M &a0, const N &a1, const O &a2, const P &a3)
template<typename M, typename N, typename O, typename P, typename Q>
LwString & | a (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>
LwString & | a (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>
LwString & | a (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>
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)
LwString & | a (Double a0)
LwString & | a (double a0)
LwString & | a (Float a0)
LwString & | a (float a0)
LwString & | a (int32 a0)
LwString & | a (int64 a0)
LwString & | a (uint32 a0)
LwString & | a (uint64 a0)
LwString & | aChar (char a0)
char * | begin ()
const char * | begin () const
| Make every begin & end method from LwConstString available.
size_t | capacity () const
void | clear ()
char * | end ()
const char * | end () const
LwString & | operator+= (const char *pOther)
LwString & | operator+= (const LwString &other)
LwString & | operator= (const char *pOther)
LwString & | operator= (const LwConstString &other)
void | resize (size_t newSize)
| Resizes the string.
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.
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
LwConstString & | operator= (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

References Ogre::LwConstString::LwConstString().

Referenced by a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), a(), aChar(), FromEmptyPointer(), operator+=(), operator+=(), operator=(), and operator=().

## Member Function Documentation

## ◆ a() [1/17]

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

References LwString().

## ◆ a() [2/17]

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

References LwString().

Referenced by a(), a(), a(), a(), a(), a(), a(), a(), a(), Ogre::any_cast(), operator+=(), operator+=(), and Ogre::DriverVersion::toString().

## ◆ a() [3/17]

template<typename M, typename N>

LwString & Ogre::LwString::a | ( | const M & | a0,
|  | const N & | a1 )
| inline

References LwString(), and 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 LwString(), and 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 LwString(), and 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 LwString(), and 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 LwString(), and 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 LwString(), and 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 LwString(), and a().

## ◆ a() [10/17]

LwString & Ogre::LwString::a | ( | Double | a0 | ) |
| inline

References LwString(), _snprintf, Ogre::LwString::Double::mMinWidth, Ogre::LwString::Double::mPrecision, and Ogre::LwString::Double::mValue.

## ◆ a() [11/17]

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

References LwString(), and a().

## ◆ a() [12/17]

LwString & Ogre::LwString::a | ( | Float | a0 | ) |
| inline

References LwString(), _snprintf, Ogre::LwString::Float::mMinWidth, Ogre::LwString::Float::mPrecision, and Ogre::LwString::Float::mValue.

## ◆ a() [13/17]

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

References LwString(), and a().

## ◆ a() [14/17]

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

References LwString(), and _snprintf.

## ◆ a() [15/17]

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

References LwString(), _snprintf, and PRIi64.

## ◆ a() [16/17]

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

References LwString(), and _snprintf.

## ◆ a() [17/17]

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

References LwString(), _snprintf, and PRIu64.

## ◆ aChar()

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

References LwString().

## ◆ begin() [1/2]

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

## ◆ begin() [2/2]

const char * Ogre::LwConstString::begin | ( |  | ) | const
| 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 | ( |  | ) | const
| inline

## ◆ FromEmptyPointer()

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

References LwString(), and Ogre::LwConstString::LwString.

Referenced by Ogre::any_cast(), and Ogre::DriverVersion::toString().

## ◆ operator+=() [1/2]

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

References LwString(), and a().

## ◆ operator+=() [2/2]

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

References LwString(), and a().

## ◆ operator=() [1/2]

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

References LwString().

## ◆ operator=() [2/2]

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

References Ogre::LwConstString::LwConstString(), and LwString().

## ◆ 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::LwConstString(), 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 Ogre::LwConstString::LwConstString(), and 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:

- OgreLwString.h