CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::ThreadSafeStringDatabase< Parent, MutexType > Class Template Reference

A thread-safe database adapter. More...

#include <CeresEngine/Foundation/StringID.hpp>

Inheritance diagram for CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >:

Public Member Functions

template<typename... Args>
 ThreadSafeStringDatabase (Args &&... args)
 
StringID::Status insert (StringID::Hash hash, StringView string) override
 Inserts a new hash-string-pair with prefix (optional) into the internal database.
 
StringID::Status insertPrefix (StringID::Hash hash, StringID::Hash prefix, StringView string) override
 Inserts a hash-string-pair with given prefix into the internal database.
 
StringView lookup (StringID::Hash hash) const noexcept override
 Returns the string stored with a given hash.
 

Private Types

using super = Parent
 

Private Attributes

MutexType mMutex
 

Detailed Description

template<class Parent, typename MutexType = Mutex>
class CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >

A thread-safe database adapter.

Note
It derives from any database type and synchronizes access via Mutex.

Member Typedef Documentation

◆ super

template<class Parent , typename MutexType = Mutex>
using CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >::super = Parent
private

Constructor & Destructor Documentation

◆ ThreadSafeStringDatabase()

template<class Parent , typename MutexType = Mutex>
template<typename... Args>
CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >::ThreadSafeStringDatabase ( Args &&...  args)
inlineexplicit

Member Function Documentation

◆ insert()

template<class Parent , typename MutexType = Mutex>
StringID::Status CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >::insert ( StringID::Hash  hash,
StringView  string 
)
inlineoverride

Inserts a new hash-string-pair with prefix (optional) into the internal database.

Note
The string must be copied prior to storing, it may not stay valid.
Parameters
hashThe hash of the string.
stringThe string which does not need to be null-terminated.
Returns
The status of the insertion.

◆ insertPrefix()

template<class Parent , typename MutexType = Mutex>
StringID::Status CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >::insertPrefix ( StringID::Hash  hash,
StringID::Hash  prefix,
StringView  string 
)
inlineoverride

Inserts a hash-string-pair with given prefix into the internal database.

Note
The default implementation performs a lookup of the prefix string and appends it, then it calls insert. Override it if you can do it more efficiently.
Parameters
hashThe hash of the string plus prefix.
prefixThe hash of the prefix-string.
stringThe suffix which does not need to be null-terminated.
Returns
The status of the insertion.

◆ lookup()

template<class Parent , typename MutexType = Mutex>
StringView CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >::lookup ( StringID::Hash  hash) const
inlineoverridenoexcept

Returns the string stored with a given hash.

Note
It is guaranteed that the hash value has been inserted before.
Returns
A null-terminated string belonging to the hash code or an error message if the database does not store anything. The return value must stay valid as long as the database exists.

Member Data Documentation

◆ mMutex

template<class Parent , typename MutexType = Mutex>
MutexType CeresEngine::ThreadSafeStringDatabase< Parent, MutexType >::mMutex
mutableprivate

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