TrueReality  v0.1.1912
trUtil::RefStr Class Reference

A string wrapper that will make sure that all of the strings with the same value will point to the same memory. More...

#include <RefStr.h>

Public Member Functions

 RefStr (const std::string &value="")
 Constructor. More...
 
 RefStr (const char *value)
 Constructor. More...
 
 RefStr (const RefStr &toCopy)
 Copy constructor. More...
 
 ~RefStr ()
 Destructor. More...
 
 operator const std::string & () const
 Implicit conversion operator from RefStr to std::string;. More...
 
trUtil::RefStroperator= (const std::string &value)
 Assignment operator that takes a string. More...
 
trUtil::RefStroperator= (const trUtil::RefStr &value)
 Assignment operator that takes a Ref String. More...
 
RefStr operator+ (const std::string &string) const
 
RefStr operator+ (const RefStr &RefStr) const
 
RefStr operator+ (const char *str) const
 
const std::string * operator-> () const
 
std::string::value_type operator[] (int index) const
 
const char * c_str () const
 Gets the string. More...
 
bool operator< (const trUtil::RefStr &toCompare) const
 
bool operator== (const trUtil::RefStr &toCompare) const
 
bool operator!= (const trUtil::RefStr &toCompare) const
 
bool operator== (const std::string &toCompare) const
 
bool operator== (const char *toCompare) const
 
bool operator!= (const char *toCompare) const
 
bool operator!= (const std::string &toCompare) const
 
const std::string & Get () const
 

Static Public Member Functions

static size_t GetSharedStringCount ()
 Gets shared string count. More...
 

Private Member Functions

void Intern (const std::string &value)
 

Private Attributes

const std::string * mString
 

Detailed Description

A string wrapper that will make sure that all of the strings with the same value will point to the same memory.

The strings are only accessible as const, but a new string may be assigned to the reference string.

Author
Maxim Serebrennik

Definition at line 50 of file RefStr.h.

Constructor & Destructor Documentation

◆ RefStr() [1/3]

trUtil::RefStr::RefStr ( const std::string &  value = "")

Constructor.

Parameters
value(Optional) The value.

Definition at line 72 of file RefStr.cpp.

References Intern().

Referenced by operator+().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RefStr() [2/3]

trUtil::RefStr::RefStr ( const char *  value)

Constructor.

Parameters
valueThe value.

Definition at line 78 of file RefStr.cpp.

References Intern().

Here is the call graph for this function:

◆ RefStr() [3/3]

trUtil::RefStr::RefStr ( const RefStr toCopy)

Copy constructor.

Parameters
toCopyto copy.

Definition at line 84 of file RefStr.cpp.

References Intern(), and mString.

Here is the call graph for this function:

◆ ~RefStr()

trUtil::RefStr::~RefStr ( )

Destructor.

Definition at line 95 of file RefStr.cpp.

References mString, and trUtil::StringCount.

Member Function Documentation

◆ c_str()

const char * trUtil::RefStr::c_str ( ) const
inline

Gets the string.

Returns
Null if it fails, else a pointer to a const char.

Definition at line 141 of file RefStr.h.

◆ Get()

const std::string& trUtil::RefStr::Get ( ) const
inline

Definition at line 178 of file RefStr.h.

Referenced by trUtil::operator+(), operator<(), trUtil::operator<<(), and operator==().

Here is the caller graph for this function:

◆ GetSharedStringCount()

size_t trUtil::RefStr::GetSharedStringCount ( )
static

Gets shared string count.

Returns
the number of shared strings.

Definition at line 66 of file RefStr.cpp.

References trUtil::StringCount.

◆ Intern()

void trUtil::RefStr::Intern ( const std::string &  value)
private

Definition at line 143 of file RefStr.cpp.

References mString, and trUtil::StringCount.

Referenced by operator=(), and RefStr().

Here is the caller graph for this function:

◆ operator const std::string &()

trUtil::RefStr::operator const std::string & ( ) const
inline

Implicit conversion operator from RefStr to std::string;.

Returns
A const.

Definition at line 104 of file RefStr.h.

References trUtil::operator+().

Here is the call graph for this function:

◆ operator!=() [1/3]

bool trUtil::RefStr::operator!= ( const trUtil::RefStr toCompare) const
inline

Definition at line 153 of file RefStr.h.

◆ operator!=() [2/3]

bool trUtil::RefStr::operator!= ( const char *  toCompare) const
inline

Definition at line 168 of file RefStr.h.

◆ operator!=() [3/3]

bool trUtil::RefStr::operator!= ( const std::string &  toCompare) const
inline

Definition at line 173 of file RefStr.h.

◆ operator+() [1/3]

RefStr trUtil::RefStr::operator+ ( const std::string &  string) const

Definition at line 104 of file RefStr.cpp.

References mString, and RefStr().

Here is the call graph for this function:

◆ operator+() [2/3]

RefStr trUtil::RefStr::operator+ ( const RefStr RefStr) const

Definition at line 110 of file RefStr.cpp.

References mString, and RefStr().

Here is the call graph for this function:

◆ operator+() [3/3]

RefStr trUtil::RefStr::operator+ ( const char *  str) const

Definition at line 116 of file RefStr.cpp.

References mString, and RefStr().

Here is the call graph for this function:

◆ operator->()

const std::string* trUtil::RefStr::operator-> ( ) const
inline

Definition at line 131 of file RefStr.h.

◆ operator<()

bool trUtil::RefStr::operator< ( const trUtil::RefStr toCompare) const
inline

Definition at line 143 of file RefStr.h.

References Get().

Here is the call graph for this function:

◆ operator=() [1/2]

trUtil::RefStr & trUtil::RefStr::operator= ( const std::string &  value)

Assignment operator that takes a string.

Parameters
valueThe value.
Returns
A shallow copy of this object.

Definition at line 122 of file RefStr.cpp.

References Intern().

Here is the call graph for this function:

◆ operator=() [2/2]

trUtil::RefStr & trUtil::RefStr::operator= ( const trUtil::RefStr value)

Assignment operator that takes a Ref String.

Parameters
valueThe value.
Returns
A shallow copy of this object.

Definition at line 129 of file RefStr.cpp.

References Intern(), and mString.

Here is the call graph for this function:

◆ operator==() [1/3]

bool trUtil::RefStr::operator== ( const trUtil::RefStr toCompare) const
inline

Definition at line 148 of file RefStr.h.

References Get().

Here is the call graph for this function:

◆ operator==() [2/3]

bool trUtil::RefStr::operator== ( const std::string &  toCompare) const
inline

Definition at line 158 of file RefStr.h.

◆ operator==() [3/3]

bool trUtil::RefStr::operator== ( const char *  toCompare) const
inline

Definition at line 163 of file RefStr.h.

◆ operator[]()

std::string::value_type trUtil::RefStr::operator[] ( int  index) const
inline

Definition at line 132 of file RefStr.h.

Member Data Documentation

◆ mString

const std::string* trUtil::RefStr::mString
private

Definition at line 181 of file RefStr.h.

Referenced by Intern(), operator+(), operator=(), RefStr(), and ~RefStr().


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