SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
smtk::string::Token Class Reference

A string token identified by an integer. More...

#include <Token.h>

Collaboration diagram for smtk::string::Token:
[legend]

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.
 
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 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 Managermanager ()
 Return the database of strings and their tokens (hashes).
 
static Token fromHash (Hash h)
 Construct a token from a hash value. More...
 

Protected Attributes

Hash m_id
 

Static Protected Attributes

static std::shared_ptr< Managers_manager
 

Detailed Description

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.

Member Function Documentation

◆ fromHash()

Token smtk::string::Token::fromHash ( Hash  h)
static

Construct a token from a hash value.

This method exists for deserialization. You should avoid using it in other circumstances. It will throw an exception if the hash does not exist in the manager.


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