24 #ifndef PXR_BASE_TF_TOKEN_H
25 #define PXR_BASE_TF_TOKEN_H
93 constexpr
TfToken() noexcept = default;
163 inline size_t Hash()
const;
183 typedef std::set<TfToken, TfTokenFastArbitraryLessThan>
Set;
187 _Rep
const *rep = _rep.
Get();
188 return rep ? rep->_str.size() : 0;
197 _Rep
const *rep = _rep.
Get();
198 return rep ? rep->_str.c_str() :
"";
208 _Rep
const *rep = _rep.
Get();
209 return rep ? rep->_str : _GetEmptyString();
220 return _rep.
Get() == o._rep.
Get();
225 return !(*
this == o);
249 return !(*
this == o);
260 return !(*
this == o);
279 auto lrep = _rep.
Get(), rrep = r._rep.
Get();
280 uint64_t lcc = lrep->_compareCode, rcc = rrep->_compareCode;
281 return lcc < rcc || (lcc == rcc && lrep->_str < rrep->_str);
312 if (!_rep.
BitsAs<
bool>()) {
317 bool immortal = !(_rep->_refCount.load(std::memory_order_relaxed) & 1);
329 template <
class HashState>
332 h.Append(token._rep.
Get());
341 void _AddRef()
const {
342 if (!_rep.
BitsAs<
bool>()) {
347 if (!_rep->IncrementAndCheckCounted()) {
353 void _RemoveRef()
const {
354 if (!_rep.
BitsAs<
bool>()) {
367 uint64_t compareCode)
369 , _compareCode(compareCode)
370 , _str(std::move(str))
371 , _cstr(_str.c_str()) {}
375 uint64_t compareCode)
376 : _Rep(std::
string(str), setNum, compareCode) {}
378 explicit _Rep(
char const *str,
380 uint64_t compareCode)
381 : _Rep(std::
string(str), setNum, compareCode) {}
388 _Rep(_Rep
const &rhs)
389 : _refCount(rhs._refCount.load(std::memory_order_relaxed))
390 , _setNum(rhs._setNum)
391 , _compareCode(rhs._compareCode)
393 , _cstr(rhs._str.c_str() == rhs._cstr ? _str.c_str() : rhs._cstr) {}
396 _refCount = rhs._refCount.load(std::memory_order_relaxed);
397 _setNum = rhs._setNum;
398 _compareCode = rhs._compareCode;
400 _cstr = (rhs._str.c_str() == rhs._cstr ? _str.c_str() : rhs._cstr);
404 inline bool IncrementAndCheckCounted()
const {
407 return _refCount.fetch_add(2, std::memory_order_relaxed) & 1;
410 inline void Decrement()
const {
413 _refCount.fetch_sub(2, std::memory_order_release);
416 mutable std::atomic_uint _refCount;
418 uint64_t _compareCode;
441 return lhs._rep.
Get() < rhs._rep.
Get();
446 TF_API std::vector<TfToken>
450 TF_API std::vector<std::string>
461 #endif // PXR_BASE_TF_TOKEN_H
friend void TfHashAppend(HashState &h, TfToken const &token)
TfHash support.
void Swap(TfToken &other)
Swap this token with another.
friend TF_API std::ostream & operator<<(std::ostream &stream, TfToken const &)
Stream insertion.
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
void SetBits(Integral val) noexcept
Set the stored bits. No static range checking is performed.
GLsizei const GLchar *const * string
std::string const & GetString() const
Return the string that this token represents.
Functor to use for hash maps from tokens to other things.
TF_API std::vector< TfToken > TfToTokenVector(const std::vector< std::string > &sv)
Convert the vector of strings sv into a vector of TfToken.
TfToken & operator=(TfToken const &rhs) noexcept
Copy assignment.
friend bool operator!=(std::string const &o, TfToken const &t)
bool operator()(TfToken const &lhs, TfToken const &rhs) const
size_t size() const
Return the size of the string that this token represents.
constexpr T * Get() const noexcept
Retrieve the pointer.
TfHashSet< TfToken, TfToken::HashFunctor > HashSet
bool operator<=(TfToken const &o) const
bool operator!=(char const *o) const
constexpr uintptr_t GetLiteral() const noexcept
size_t operator()(TfToken const &token) const
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
TfToken(TfToken &&rhs) noexcept
Move constructor.
char const * data() const
Synonym for GetText().
friend void swap(TfToken &lhs, TfToken &rhs)
constexpr Integral BitsAs() const noexcept
Retrieve the stored bits as the integral type Integral.
bool operator>(TfToken const &o) const
Greater-than operator that compares tokenized strings lexicographically.
std::vector< TfToken > TfTokenVector
Convenience types.
friend bool operator==(std::string const &o, TfToken const &t)
friend bool operator!=(char const *o, TfToken const &t)
char const * GetText() const
bool operator!=(std::string const &o) const
GLfloat GLfloat GLfloat GLfloat h
bool operator!=(TfToken const &o) const
Equality operator.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
static TF_API TfToken Find(std::string const &s)
Find the token for the given string, if one exists.
TF_API std::vector< std::string > TfToStringVector(const std::vector< TfToken > &tv)
Convert the vector of TfToken tv into a vector of strings.
#define PXR_NAMESPACE_CLOSE_SCOPE
friend struct Tf_TokenRegistry
constexpr TfToken() noexcept=default
Create the empty token, containing the empty string.
bool operator==(TfToken const &o) const
Equality operator.
bool operator<(TfToken const &r) const
friend bool operator==(const char *o, TfToken const &t)
size_t Hash() const
Return a size_t hash for this token.
bool operator>=(TfToken const &o) const
std::set< TfToken, TfTokenFastArbitraryLessThan > Set
bool IsEmpty() const
Returns true iff this token contains the empty string "".