VTK
9.4.20241221
|
Represent a string by its integer hash. More...
#include <vtkStringToken.h>
Public Types | |
using | Hash = std::uint32_t |
Public Member Functions | |
VTK_WRAPEXCLUDE | 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). | |
unsigned int | GetHash () const |
A Python-wrappable (but less strongly typed) alternative to GetId() | |
const std::string & | Data () const |
Return the string corresponding to the token. | |
bool | IsValid () const |
Return whether the token is valid or not. | |
bool | HasData () const |
Return whether a string is available for the token's hash ID. | |
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 Hash | InvalidHash () |
Return the hash code used to indicate an invalid (empty) token. | |
Protected Attributes | |
Hash | Id |
bool | AddChild (vtkStringToken member) |
Methods to manage groups of tokens underneath a parent. | |
bool | RemoveChild (vtkStringToken member) |
Remove a member from this token's children. | |
std::unordered_set< vtkStringToken > | Children (bool recursive=true) |
Return all the children of this token. | |
static std::unordered_set< vtkStringToken > | AllGroups () |
Return all the tokens that have children. | |
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.
Definition at line 56 of file vtkStringToken.h.
using vtkStringToken::Hash = std::uint32_t |
Definition at line 59 of file vtkStringToken.h.
VTK_WRAPEXCLUDE vtkStringToken::vtkStringToken | ( | const char * | data = nullptr , |
std::size_t | size = std::string::npos |
||
) |
Construct a token from a string literal.
vtkStringToken::vtkStringToken | ( | const std::string & | data | ) |
Construct a token from a std::string.
|
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 67 of file vtkStringToken.h.
|
inline |
Return the token's ID (usually its hash but possibly not in the case of collisions).
Definition at line 73 of file vtkStringToken.h.
|
inline |
A Python-wrappable (but less strongly typed) alternative to GetId()
Definition at line 75 of file vtkStringToken.h.
const std::string & vtkStringToken::Data | ( | ) | const |
Return the string corresponding to the token.
bool vtkStringToken::IsValid | ( | ) | const |
Return whether the token is valid or not.
Valid tokens are those whose hash is not equal to the hash of an empty string.
bool vtkStringToken::HasData | ( | ) | const |
Return whether a string is available for the token's hash ID.
bool vtkStringToken::operator== | ( | const vtkStringToken & | other | ) | const |
Fast equality comparison (compares hashes, not strings).
bool vtkStringToken::operator!= | ( | const vtkStringToken & | other | ) | const |
Fast inequality comparison (compares hashes, not strings).
bool vtkStringToken::operator< | ( | const vtkStringToken & | other | ) | const |
Slow, but unsurprising string comparison (preserves lexical string ordering).
bool vtkStringToken::operator> | ( | const vtkStringToken & | other | ) | const |
bool vtkStringToken::operator<= | ( | const vtkStringToken & | other | ) | const |
bool vtkStringToken::operator>= | ( | const vtkStringToken & | other | ) | const |
|
inlinestaticconstexprnoexcept |
Return the hash of a string This is used internally but also by the ""_token() literal operator.
Definition at line 99 of file vtkStringToken.h.
|
static |
Return the hash code used to indicate an invalid (empty) token.
bool vtkStringToken::AddChild | ( | vtkStringToken | member | ) |
Methods to manage groups of tokens underneath a parent.
Grouping tokens provides applications a way to create and discover dynamic enumerations or sets of strings. For example, you might tokenize car
and add tokens for car parts such body
, motor
, and wheels
as children of car
. Another library might then add more children such as windshield
and hood
; the application can present all of these children by asking for all the children of car
.
Add member as a child of this token.
If true is returned, the member was added. If false is returned, the member was already part of the group or one of the tokens (this token or member) was invalid.
bool vtkStringToken::RemoveChild | ( | vtkStringToken | member | ) |
Remove a member from this token's children.
If this returns false, member was not a child of this token.
std::unordered_set< vtkStringToken > vtkStringToken::Children | ( | bool | recursive = true | ) |
Return all the children of this token.
|
static |
Return all the tokens that have children.
|
protected |
Definition at line 134 of file vtkStringToken.h.