Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Interned 8-bit strings. More...
#include <CStrIntern.h>
Public Member Functions | |
CStrIntern () | |
CStrIntern (const char *str) | |
CStrIntern (const std::string &str) | |
u32 | GetHash () const |
Returns cached FNV1-A hash of the string. More... | |
const char * | c_str () const |
Returns null-terminated string. More... | |
size_t | length () const |
Returns length of string in bytes. More... | |
bool | empty () const |
const std::string & | string () const |
Returns as std::string. More... | |
bool | operator== (const CStrIntern &b) const |
String equality. More... | |
bool | operator!= (const CStrIntern &b) const |
bool | operator< (const CStrIntern &b) const |
Compare with some arbitrary total order. More... | |
Private Attributes | |
CStrInternInternals * | m |
Interned 8-bit strings.
Each instance with the same string content is a pointer to the same piece of memory, allowing very fast string comparisons.
Since a CStrIntern is just a dumb pointer, copying is very fast, and pass-by-value should be preferred over pass-by-reference.
Memory allocated for strings will never be freed, so don't use this for unbounded numbers of strings (e.g. text rendered by gameplay scripts) - it's intended for a small number of short frequently-used strings.
Not thread-safe - only allocate these strings from the main thread.
CStrIntern::CStrIntern | ( | ) |
|
explicit |
|
explicit |
const char * CStrIntern::c_str | ( | ) | const |
Returns null-terminated string.
bool CStrIntern::empty | ( | ) | const |
u32 CStrIntern::GetHash | ( | ) | const |
Returns cached FNV1-A hash of the string.
size_t CStrIntern::length | ( | ) | const |
Returns length of string in bytes.
|
inline |
|
inline |
Compare with some arbitrary total order.
(In particular, this is not alphabetic order, and is not consistent between runs of the game.)
|
inline |
String equality.
const std::string & CStrIntern::string | ( | ) | const |
Returns as std::string.
|
private |