CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::StringID Class Reference

The string identifier class. More...

#include <CeresEngine/Foundation/StringID.hpp>

Public Types

enum class  Status { Collision , NewString , OldString }
 The status of an insert operation. More...
 
using Hash = UInt64
 The type of a hashed string.
 
using CollisionHandler = void(*)(StringID::Hash hash, StringView a, StringView b)
 The type of the collision handler.
 

Public Member Functions

 StringID ()=default
 Constructs a new empty StringID.
 
 StringID (StringView string)
 Creates a new id by hashing a given string.
 
 StringID (StringDatabase &database, StringView string)
 Creates a new id by hashing a given string.
 
 StringID (const StringID &prefix, StringView string)
 Creates a new id with a given prefix.
 
 StringID (StringDatabase &database, StringView string, Status &status)
 Same as other constructors versions but instead of calling the CollisionHandler, they set the output parameter to the appropriate status.
 
 StringID (const StringID &prefix, StringView string, Status &status)
 Same as other constructors versions but instead of calling the CollisionHandler, they set the output parameter to the appropriate status.
 
StringID::Hash getHashCode () const noexcept
 
StringView getString () const noexcept
 

Static Public Member Functions

static CollisionHandler setCollisionHandler (CollisionHandler h)
 Exchanges the CollisionHandler.
 
static CollisionHandler getCollisionHandler ()
 Returns the current CollisionHandler.
 

Private Attributes

Hash mID = 0
 
StringDatabasemDatabase = nullptr
 

Friends

bool operator== (const StringID a, const StringID b) noexcept
 Compares string ids with another or hashed values.
 
bool operator== (const StringID::Hash a, const StringID &b) noexcept
 
bool operator== (const StringID &a, const StringID::Hash b) noexcept
 
bool operator!= (const StringID &a, const StringID &b) noexcept
 
bool operator!= (const StringID::Hash a, const StringID &b) noexcept
 
bool operator!= (const StringID &a, const StringID::Hash b) noexcept
 

Detailed Description

The string identifier class.

This is a lightweight class to store strings. It only stores a hash of the string allowing fast copying and comparisons.

Member Typedef Documentation

◆ CollisionHandler

The type of the collision handler.

Note
It will be called when a string hashing results in a collision giving it the two strings collided. The default handler throws an exception of type CollisionError.

◆ Hash

The type of a hashed string.

Member Enumeration Documentation

◆ Status

The status of an insert operation.

Enumerator
Collision 

Two different strings collide on the same value.

NewString 

A new string was inserted.

OldString 

The string already existed inside the database.

Constructor & Destructor Documentation

◆ StringID() [1/6]

CeresEngine::StringID::StringID ( )
default

Constructs a new empty StringID.

The value will be comparable true only to other empty string IDs.

◆ StringID() [2/6]

CeresEngine::StringID::StringID ( StringView  string)
explicit

Creates a new id by hashing a given string.

Note
It will insert the string into the default Database which will copy it. If it encounters a collision, the CollisionHandler will be called.

◆ StringID() [3/6]

CeresEngine::StringID::StringID ( StringDatabase database,
StringView  string 
)

Creates a new id by hashing a given string.

Note
It will insert the string into the given Database which will copy it. If it encounters a collision, the CollisionHandler will be called.

◆ StringID() [4/6]

CeresEngine::StringID::StringID ( const StringID prefix,
StringView  string 
)

Creates a new id with a given prefix.

Note
The new id will be inserted into the same database as the prefix. Otherwise the same as other constructors.

◆ StringID() [5/6]

CeresEngine::StringID::StringID ( StringDatabase database,
StringView  string,
Status status 
)

Same as other constructors versions but instead of calling the CollisionHandler, they set the output parameter to the appropriate status.

Note
This also allows information whether or not the string was already stored inside the database.

◆ StringID() [6/6]

CeresEngine::StringID::StringID ( const StringID prefix,
StringView  string,
Status status 
)

Same as other constructors versions but instead of calling the CollisionHandler, they set the output parameter to the appropriate status.

Note
This also allows information whether or not the string was already stored inside the database.

Member Function Documentation

◆ getCollisionHandler()

static CollisionHandler CeresEngine::StringID::getCollisionHandler ( )
static

Returns the current CollisionHandler.

◆ getHashCode()

StringID::Hash CeresEngine::StringID::getHashCode ( ) const
inlinenoexcept
Returns
the hashed value of the string.

◆ getString()

StringView CeresEngine::StringID::getString ( ) const
noexcept
Returns
the string value itself.

◆ setCollisionHandler()

static CollisionHandler CeresEngine::StringID::setCollisionHandler ( CollisionHandler  h)
static

Exchanges the CollisionHandler.

Friends And Related Symbol Documentation

◆ operator!= [1/3]

bool operator!= ( const StringID a,
const StringID b 
)
friend

◆ operator!= [2/3]

bool operator!= ( const StringID a,
const StringID::Hash  b 
)
friend

◆ operator!= [3/3]

bool operator!= ( const StringID::Hash  a,
const StringID b 
)
friend

◆ operator== [1/3]

bool operator== ( const StringID a,
const StringID::Hash  b 
)
friend

◆ operator== [2/3]

bool operator== ( const StringID  a,
const StringID  b 
)
friend

Compares string ids with another or hashed values.

Note
Two string ids are equal if they are from the same database and they have the same value. A hashed value is equal to a string id if it is the same value.

◆ operator== [3/3]

bool operator== ( const StringID::Hash  a,
const StringID b 
)
friend

Member Data Documentation

◆ mDatabase

StringDatabase* CeresEngine::StringID::mDatabase = nullptr
private

◆ mID

Hash CeresEngine::StringID::mID = 0
private

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