Tramway SDK
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
tram::UID Struct Reference

Interned string type. More...

#include <framework/uid.h>

Public Member Functions

 UID ()
 
 UID (const UID &value)
 
 ~UID ()
 
 UID (const std::string &value)
 
 UID (const char *value)
 Interns a string. More...
 
UIDoperator= (const UID &value)
 
bool operator== (const UID &other) const
 
bool operator== (const char *other) const
 
 operator bool ()
 
 operator std::string () const
 
 operator char const * () const
 

Static Public Member Functions

static bool no_quote (const char *)
 Checks whether the name will need quotes. More...
 
static bool is_empty (const char *)
 Checks whether a string consists of only whitespace. More...
 
static bool is_valid (const UID &)
 Checks whether the name is valid. More...
 

Public Attributes

uint32_t key = 0
 

Detailed Description

Interned string type.

Should intern strings in O(1) as long as the total number of interned strings is lower than UID_LIMIT. In either case, interned string comparison will always be O(1). If you are converting a lot of strings, it is best to do so early, because the internment process, altough nearly constant time, does, in fact, take some time.

See also
https://racenis.github.io/tram-sdk/documentation/framework/uid.html

Constructor & Destructor Documentation

◆ UID() [1/4]

tram::UID::UID ( )
inline

◆ UID() [2/4]

tram::UID::UID ( const UID value)
inline

◆ ~UID()

tram::UID::~UID ( )
inline

◆ UID() [3/4]

tram::UID::UID ( const std::string &  value)

◆ UID() [4/4]

tram::UID::UID ( const char *  value)

Interns a string.

This will intern the string and return a little UID that you can put in your little pockets and take away with you. For best results I recommend using the no_quotes() and is_empty() functions to first check whether a given string will also be a good name. A string that isn't empty and doesn't need quotes is a good name.

Parameters
valueThe string which will be interned.
Note
Empty strings and

Member Function Documentation

◆ is_empty()

bool tram::UID::is_empty ( const char *  str)
static

Checks whether a string consists of only whitespace.

Returns
True, if string contains at least a single non-whitespace character.

◆ is_valid()

bool tram::UID::is_valid ( const UID value)
static

Checks whether the name is valid.

Due to bad memory handling practices, it is possible to create a name with such a key, that when this name's string is looked up from the string table and dereferenced, a segfault occurs. This function checks whether a segfault is likely to occur when given a name to check. This is done by a simple bounds check on the string table.

Returns
True, if using a name is safe.

◆ no_quote()

bool tram::UID::no_quote ( const char *  str)
static

Checks whether the name will need quotes.

When parsing a name from a text file, if a name has spaces in it, then it will require quotes around it to be parsed in correctly. This function checks whether a certain string will be able to be parsed as a name correctly, without quotes.

Returns
True, if the string won't need quotes.

◆ operator bool()

tram::UID::operator bool ( )
inlineexplicit

◆ operator char const *()

tram::UID::operator char const * ( ) const

◆ operator std::string()

tram::UID::operator std::string ( ) const

◆ operator=()

UID & tram::UID::operator= ( const UID value)
inline

◆ operator==() [1/2]

bool tram::UID::operator== ( const char *  other) const
inline

◆ operator==() [2/2]

bool tram::UID::operator== ( const UID other) const
inline

Member Data Documentation

◆ key

uint32_t tram::UID::key = 0

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