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>
44#ifdef VTK_COMPILER_GCC
45#if VTK_COMPILER_GCC_VERSION <= 40805
46#define VTK_STRING_TOKEN_SPACE_BEFORE_SUFFIX 1
48#define VTK_STRING_TOKEN_SPACE_BEFORE_SUFFIX 0
51#define VTK_STRING_TOKEN_SPACE_BEFORE_SUFFIX 0
54VTK_ABI_NAMESPACE_BEGIN
59 using Hash = std::uint32_t;
75 unsigned int GetHash()
const {
return static_cast<unsigned int>(this->Id); }
77 const std::string&
Data()
const;
99 inline static constexpr Hash StringHash(
const char* data, std::size_t size)
noexcept
101 return token_NAMESPACE::Token::stringHash(data, size);
128 std::unordered_set<vtkStringToken>
Children(
bool recursive =
true);
144 if (jj.is_number_integer())
148 else if (jj.is_string())
150 tt = jj.get<std::string>();
154 throw std::runtime_error(
"String tokens must be JSON integers or strings.");
180VTK_ABI_NAMESPACE_BEGIN
202#if VTK_STRING_TOKEN_SPACE_BEFORE_SUFFIX
204 const char* data, std::size_t size)
207 const char* data, std::size_t size)
222#if VTK_STRING_TOKEN_SPACE_BEFORE_SUFFIX
223inline constexpr VTKCOMMONCORE_EXPORT
vtkStringToken operator"" _token(
224 const char* data, std::size_t size)
227 const char* data, std::size_t size)
237VTK_ABI_NAMESPACE_BEGIN
278#undef VTK_STRING_TOKEN_SPACE_BEFORE_SUFFIX
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.