3#ifndef vtkStringToken_h
4#define vtkStringToken_h
29#include <token/Token.h>
35#include <vtk_nlohmannjson.h>
36#include VTK_NLOHMANN_JSON(json.hpp)
40#include <unordered_set>
42VTK_ABI_NAMESPACE_BEGIN
47 using Hash = std::uint32_t;
63 unsigned int GetHash()
const {
return static_cast<unsigned int>(this->Id); }
65 const std::string&
Data()
const;
87 static constexpr Hash StringHash(
const char* data, std::size_t size)
noexcept
89 return token_NAMESPACE::Token::stringHash(data, size);
116 std::unordered_set<vtkStringToken>
Children(
bool recursive =
true);
132 if (jj.is_number_integer())
136 else if (jj.is_string())
138 tt = jj.get<std::string>();
142 throw std::runtime_error(
"String tokens must be JSON integers or strings.");
168VTK_ABI_NAMESPACE_BEGIN
191 const char* data, std::size_t size)
205constexpr VTKCOMMONCORE_EXPORT
vtkStringToken operator""_token(
const char* data, std::size_t size)
214VTK_ABI_NAMESPACE_BEGIN
Represent a string by its integer hash.
bool operator<=(const vtkStringToken &other) const
bool operator<(const vtkStringToken &other) const
Slow, but unsurprising string comparison (preserves lexical string ordering).
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.
constexpr vtkStringToken(Hash tokenId) noexcept
Construct a token given its hash value.
VTK_WRAPEXCLUDE vtkStringToken(const char *data=nullptr, std::size_t size=std::string::npos)
Construct a token from a string literal.
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 inequality comparison (compares hashes, not strings).
bool AddChild(vtkStringToken member)
Methods to manage groups of tokens underneath a parent.
const std::string & Data() const
Return the string corresponding to the token.
bool operator>=(const vtkStringToken &other) const
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.
vtkStringToken(const std::string &data)
Construct a token from a std::string.
Hash GetId() const
Return the token's ID (usually its hash but possibly not in the case of collisions).
bool operator>(const vtkStringToken &other) const
bool operator==(const vtkStringToken &other) const
Fast equality comparison (compares hashes, not strings).
unsigned int GetHash() const
A Python-wrappable (but less strongly typed) alternative to GetId()
static Hash InvalidHash()
Return the hash code used to indicate an invalid (empty) token.
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
std::size_t operator()(const vtkStringToken &t) const
void VTKCOMMONCORE_EXPORT to_json(nlohmann::json &jj, const vtkStringToken &tt)
Convert a string token into a JSON value.
bool VTKCOMMONCORE_EXPORT operator>=(const std::string &a, const vtkStringToken &b)
bool VTKCOMMONCORE_EXPORT operator==(const std::string &a, const vtkStringToken &b)
bool VTKCOMMONCORE_EXPORT operator>(const std::string &a, const vtkStringToken &b)
bool VTKCOMMONCORE_EXPORT operator<=(const std::string &a, const vtkStringToken &b)
bool VTKCOMMONCORE_EXPORT operator<(const std::string &a, const vtkStringToken &b)
bool VTKCOMMONCORE_EXPORT operator!=(const std::string &a, const vtkStringToken &b)
void VTKCOMMONCORE_EXPORT from_json(const nlohmann::json &jj, vtkStringToken &tt)
Convert a JSON value into a string token.