SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
A string token identified by an integer. More...
#include <Token.h>
Public Member Functions | |
Token (const char *data=nullptr, std::size_t size=std::string::npos) | |
Construct a token from a string literal. | |
Token (const std::string &data) | |
Construct a token from a std::string. | |
constexpr | Token (Hash tokenId) noexcept |
Construct a token given its hash value. More... | |
Hash | id () const |
Return the token's ID (usually its hash but possibly not in the case of collisions). | |
const std::string & | data () const |
Return the string corresponding to the token. | |
bool | hasData () const |
Return true if a string corresponding to the token exists. | |
bool | valid () const |
Return true if the token's ID has been set (false if not). | |
bool | operator== (const Token &other) const |
Fast equality comparison (compares hashes, not strings). | |
bool | operator!= (const Token &other) const |
Fast inequality comparison (compares hashes, not strings). | |
bool | operator< (const Token &other) const |
Slow, but unsurprising string comparison (preserves lexical string ordering). | |
bool | operator> (const Token &other) const |
bool | operator<= (const Token &other) const |
bool | operator>= (const Token &other) const |
Static Public Member Functions | |
static Manager & | manager () |
Return the database of strings and their tokens (hashes). | |
static constexpr Hash | stringHash (const char *data, std::size_t size) noexcept |
Return the hash of a string This is used internally but also by the ""_token() literal operator. | |
static Token | fromHash (Hash h) |
Construct a token given only its hash. More... | |
Static Public Attributes | |
static constexpr Hash | Invalid = Manager::Invalid |
An invalid hash, used with the constructor above to make an invalid token. | |
Protected Attributes | |
Hash | m_id |
Static Protected Attributes | |
static constexpr uint32_t | hash32a_const = 0x811c9dc5 |
static constexpr uint32_t | hash32b_const = 0x1000193 |
static constexpr uint64_t | hash64a_const = 0xcbf29ce484222325 |
static constexpr uint64_t | hash64b_const = 0x100000001b3 |
static std::shared_ptr< Manager > | s_manager |
A string token identified by an integer.
Often, it is useful for a common, variable-length string to be referenced indirectly rather than storing copies of the string. This class has a static database of hashes; each instance of the class holds only a fixed-size hash value. The string value can be produced in O(1) time by looking the hash up from the static database.
|
inlineconstexprnoexcept |
Construct a token given its hash value.
NOTE: This will NOT insert a string into the manager as other constructors do.
Construct a token given only its hash.
This variant checks that the string manager holds data for the hash and will throw an exception if it does not.