Pyrogenesis  trunk
Public Member Functions | Private Attributes | List of all members
CStrIntern Class Reference

Interned 8-bit strings. More...

#include <CStrIntern.h>

Collaboration diagram for CStrIntern:
Collaboration graph

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


Detailed Description

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.

Constructor & Destructor Documentation

◆ CStrIntern() [1/3]

CStrIntern::CStrIntern ( )

◆ CStrIntern() [2/3]

CStrIntern::CStrIntern ( const char *  str)

◆ CStrIntern() [3/3]

CStrIntern::CStrIntern ( const std::string &  str)

Member Function Documentation

◆ c_str()

const char * CStrIntern::c_str ( ) const

Returns null-terminated string.

◆ empty()

bool CStrIntern::empty ( ) const

◆ GetHash()

u32 CStrIntern::GetHash ( ) const

Returns cached FNV1-A hash of the string.

◆ length()

size_t CStrIntern::length ( ) const

Returns length of string in bytes.

◆ operator!=()

bool CStrIntern::operator!= ( const CStrIntern b) const

◆ operator<()

bool CStrIntern::operator< ( const CStrIntern b) const

Compare with some arbitrary total order.

(In particular, this is not alphabetic order, and is not consistent between runs of the game.)

◆ operator==()

bool CStrIntern::operator== ( const CStrIntern b) const

String equality.

◆ string()

const std::string & CStrIntern::string ( ) const

Returns as std::string.

Member Data Documentation

◆ m

CStrInternInternals* CStrIntern::m

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