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
[legend]

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

CStrInternInternalsm
 

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::CStrIntern ( )
CStrIntern::CStrIntern ( const char *  str)
explicit
CStrIntern::CStrIntern ( const std::string &  str)
explicit

Member Function Documentation

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.

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

Compare with some arbitrary total order.

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

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

String equality.

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

Returns as std::string.

Member Data Documentation

CStrInternInternals* CStrIntern::m
private

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