VTK  9.3.0
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
vtkStringToken Class Reference

Represent a string by its integer hash. More...

#include <vtkStringToken.h>

Collaboration diagram for vtkStringToken:
[legend]

Public Types

using Hash = std::uint32_t
 

Public Member Functions

 vtkStringToken (const char *data=nullptr, std::size_t size=std::string::npos)
 Construct a token from a string literal.
 
 vtkStringToken (const std::string &data)
 Construct a token from a std::string.
 
constexpr vtkStringToken (Hash tokenId) noexcept
 Construct a token given its hash value.
 
Hash GetId () 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 vtkStringToken &other) const
 Fast equality comparison (compares hashes, not strings).
 
bool operator!= (const vtkStringToken &other) const
 Fast inequality comparison (compares hashes, not strings).
 
bool operator< (const vtkStringToken &other) const
 Slow, but unsurprising string comparison (preserves lexical string ordering).
 
bool operator> (const vtkStringToken &other) const
 
bool operator<= (const vtkStringToken &other) const
 
bool operator>= (const vtkStringToken &other) const
 

Static Public Member Functions

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 const vtkStringManagerGetManager ()
 Return the database of strings and their tokens (hashes).
 

Static Protected Member Functions

static vtkStringManagerGetManagerInternal ()
 
static constexpr uint32_t hash_32_fnv1a_const (const char *const str, std::size_t size, const uint32_t value=hash32a_const) noexcept
 

Protected Attributes

Hash Id
 

Static Protected Attributes

static vtkSmartPointer< vtkStringManagerManager
 
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
 

Detailed Description

Represent a string by its integer hash.

This class does not inherit vtkObject; it is a lightweight object for representing a string as a 32-bit integer token. Tokens can be constructed at compile-time (via the ""_token string-literal operator below) or run-time (via the constructor).

Equality comparisons are simple integer tests, while inequality operators attempt to locate the original source strings and compare them alphanumerically to preserve lexicographic ordering.

This class can be used inside ordered and unordered STL containers.

Tests:
vtkStringToken (Tests)

Definition at line 33 of file vtkStringToken.h.

Member Typedef Documentation

◆ Hash

using vtkStringToken::Hash = std::uint32_t

Definition at line 36 of file vtkStringToken.h.

Constructor & Destructor Documentation

◆ vtkStringToken() [1/3]

vtkStringToken::vtkStringToken ( const char *  data = nullptr,
std::size_t  size = std::string::npos 
)

Construct a token from a string literal.

◆ vtkStringToken() [2/3]

vtkStringToken::vtkStringToken ( const std::string &  data)

Construct a token from a std::string.

◆ vtkStringToken() [3/3]

constexpr vtkStringToken::vtkStringToken ( Hash  tokenId)
inlineconstexprnoexcept

Construct a token given its hash value.

NOTE: This will NOT insert a string into the manager as other constructors do.

Definition at line 44 of file vtkStringToken.h.

Member Function Documentation

◆ GetId()

Hash vtkStringToken::GetId ( ) const
inline

Return the token's ID (usually its hash but possibly not in the case of collisions).

Definition at line 50 of file vtkStringToken.h.

◆ Data()

const std::string & vtkStringToken::Data ( ) const

Return the string corresponding to the token.

◆ operator==()

bool vtkStringToken::operator== ( const vtkStringToken other) const

Fast equality comparison (compares hashes, not strings).

◆ operator!=()

bool vtkStringToken::operator!= ( const vtkStringToken other) const

Fast inequality comparison (compares hashes, not strings).

◆ operator<()

bool vtkStringToken::operator< ( const vtkStringToken other) const

Slow, but unsurprising string comparison (preserves lexical string ordering).

◆ operator>()

bool vtkStringToken::operator> ( const vtkStringToken other) const

◆ operator<=()

bool vtkStringToken::operator<= ( const vtkStringToken other) const

◆ operator>=()

bool vtkStringToken::operator>= ( const vtkStringToken other) const

◆ StringHash()

static constexpr Hash vtkStringToken::StringHash ( const char *  data,
std::size_t  size 
)
inlinestaticconstexprnoexcept

Return the hash of a string This is used internally but also by the ""_token() literal operator.

Definition at line 67 of file vtkStringToken.h.

◆ GetManager()

static const vtkStringManager * vtkStringToken::GetManager ( )
static

Return the database of strings and their tokens (hashes).

◆ GetManagerInternal()

static vtkStringManager * vtkStringToken::GetManagerInternal ( )
staticprotected

◆ hash_32_fnv1a_const()

static constexpr uint32_t vtkStringToken::hash_32_fnv1a_const ( const char *const  str,
std::size_t  size,
const uint32_t  value = hash32a_const 
)
inlinestaticconstexprprotectednoexcept

Definition at line 92 of file vtkStringToken.h.

Member Data Documentation

◆ Id

Hash vtkStringToken::Id
protected

Definition at line 76 of file vtkStringToken.h.

◆ Manager

vtkSmartPointer<vtkStringManager> vtkStringToken::Manager
staticprotected

Definition at line 77 of file vtkStringToken.h.

◆ hash32a_const

constexpr uint32_t vtkStringToken::hash32a_const = 0x811c9dc5
staticconstexprprotected

Definition at line 84 of file vtkStringToken.h.

◆ hash32b_const

constexpr uint32_t vtkStringToken::hash32b_const = 0x1000193
staticconstexprprotected

Definition at line 85 of file vtkStringToken.h.

◆ hash64a_const

constexpr uint64_t vtkStringToken::hash64a_const = 0xcbf29ce484222325
staticconstexprprotected

Definition at line 86 of file vtkStringToken.h.

◆ hash64b_const

constexpr uint64_t vtkStringToken::hash64b_const = 0x100000001b3
staticconstexprprotected

Definition at line 87 of file vtkStringToken.h.


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