HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
staticTokens.h File Reference
#include "pxr/pxr.h"
#include "pxr/base/tf/preprocessorUtils.h"
#include "pxr/base/tf/preprocessorUtilsLite.h"
#include "pxr/base/tf/staticData.h"
#include "pxr/base/tf/token.h"
#include <vector>
#include <hboost/preprocessor/cat.hpp>
#include <hboost/preprocessor/control/iif.hpp>
#include <hboost/preprocessor/control/expr_iif.hpp>
#include <hboost/preprocessor/logical/and.hpp>
#include <hboost/preprocessor/logical/not.hpp>
#include <hboost/preprocessor/punctuation/comma_if.hpp>
#include <hboost/preprocessor/seq/filter.hpp>
#include <hboost/preprocessor/seq/for_each.hpp>
#include <hboost/preprocessor/seq/for_each_i.hpp>
#include <hboost/preprocessor/seq/size.hpp>
#include <hboost/preprocessor/tuple/elem.hpp>
+ Include dependency graph for staticTokens.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _TF_DECLARE_PUBLIC_TOKENS3(key, eiapi, seq)
 
#define _TF_DECLARE_PUBLIC_TOKENS2(key, seq)
 
#define _TF_DECLARE_PUBLIC_TOKENS(N)   _TF_DECLARE_PUBLIC_TOKENS##N
 
#define _TF_DECLARE_PUBLIC_TOKENS_EVAL(N)   _TF_DECLARE_PUBLIC_TOKENS(N)
 
#define _TF_DECLARE_PUBLIC_TOKENS_EXPAND(x)   x
 
#define TF_DECLARE_PUBLIC_TOKENS(...)
 
#define TF_DEFINE_PUBLIC_TOKENS(key, seq)
 
#define TF_DEFINE_PRIVATE_TOKENS(key, seq)
 
#define _TF_TOKENS_STRUCT_NAME_PRIVATE(key)   HBOOST_PP_CAT(key, _PrivateStaticTokenType)
 
#define _TF_TOKENS_STRUCT_NAME(key)   HBOOST_PP_CAT(key, _StaticTokenType)
 
#define _TF_TOKENS_DECLARE_MEMBER(r, data, elem)
 
#define _TF_TOKENS_DECLARE_MEMBERS(seq)
 
#define _TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)
 
#define _TF_DECLARE_TOKENS3(key, seq, eiapi)
 
#define _TF_DECLARE_TOKENS2(key, seq)
 
#define _TF_TOKENS_DEFINE_MEMBER(r, data, i, elem)
 
#define _TF_TOKENS_INITIALIZE_MEMBER_TUPLE(elem)
 
#define _TF_TOKENS_INITIALIZE_MEMBER(elem)   elem(TF_PP_STRINGIZE(elem), TfToken::Immortal)
 
#define _TF_TOKENS_DEFINE_ARRAY_MEMBER(r, data, i, elem)
 
#define _TF_TOKENS_APPEND_MEMBER(r, data, i, elem)
 
#define _TF_TOKENS_APPEND_MEMBER_BODY(r, data, elem)   allTokens.push_back(elem);
 
#define _TF_TOKENS_BUILD_ALLTOKENS_VECTOR(seq)   HBOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_APPEND_MEMBER, ~, seq)
 
#define _TF_TOKENS_INITIALIZE_SEQ(seq)   HBOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_DEFINE_MEMBER, ~, seq)
 
#define _TF_TOKENS_ASSIGN_ARRAY_SEQ(seq)   HBOOST_PP_SEQ_FOR_EACH(_TF_TOKENS_DEFINE_ARRAY_MEMBERS, ~, seq)
 
#define _TF_TOKENS_DEFINE_ARRAY_MEMBERS(r, data, elem)
 
#define _TF_TOKENS_IS_ARRAY(s, data, elem)
 
#define _TF_TOKENS_IS_NOT_ARRAY(s, data, elem)   HBOOST_PP_NOT(_TF_TOKENS_IS_ARRAY(s, data, elem))
 
#define _TF_TOKENS_APPEND_ARRAY_ELEMENTS(r, data, elem)   HBOOST_PP_TUPLE_ELEM(1, 0, HBOOST_PP_TUPLE_ELEM(2, 1, elem))
 
#define _TF_DEFINE_TOKENS(key, seq)
 

Detailed Description

This file defines some macros that are useful for declaring and using static TfTokens. Typically, using static TfTokens is either cumbersome, unsafe, or slow. These macros aim to solve many of the common problems.

The following is an example of how they can be used.

In header file:

#define MF_TOKENS \. <--- please ignore '.'
(transform) \.
(moves) \.
// Syntax when string name differs from symbol.
((foo, "bar"))
// Syntax when defining an array of tokens. Note that the tokens can
// be used either with amountTs[i] or directly as tx, ty, tz.
((amountTs, ( (tx) (ty) (tz) )))
TF_DECLARE_PUBLIC_TOKENS(MfTokens, MF_TOKENS);

In cpp file:

TF_DEFINE_PUBLIC_TOKENS(MfTokens, MF_TOKENS);

Access the token by using the key as though it were a pointer, like this:

MfTokens->transform;

An additional member, allTokens, is a std::vector<TfToken> populated with all of the generated token members.

There are PUBLIC and PRIVATE versions of the macros. The PRIVATE ones are intended to be used when the tokens will only be used in a single .cpp file, in which case they can be made file static. In the case of the PRIVATE, you only need to use the DEFINE macro.

Definition in file staticTokens.h.

Macro Definition Documentation

#define _TF_DECLARE_PUBLIC_TOKENS (   N)    _TF_DECLARE_PUBLIC_TOKENS##N

Definition at line 110 of file staticTokens.h.

#define _TF_DECLARE_PUBLIC_TOKENS2 (   key,
  seq 
)
Value:
#define _TF_DECLARE_TOKENS2(key, seq)
Definition: staticTokens.h:201

Definition at line 107 of file staticTokens.h.

#define _TF_DECLARE_PUBLIC_TOKENS3 (   key,
  eiapi,
  seq 
)
Value:
_TF_DECLARE_TOKENS3(key, seq, eiapi) \
#define _TF_DECLARE_TOKENS3(key, seq, eiapi)
Definition: staticTokens.h:194

Definition at line 104 of file staticTokens.h.

#define _TF_DECLARE_PUBLIC_TOKENS_EVAL (   N)    _TF_DECLARE_PUBLIC_TOKENS(N)

Definition at line 111 of file staticTokens.h.

#define _TF_DECLARE_PUBLIC_TOKENS_EXPAND (   x)    x

Definition at line 112 of file staticTokens.h.

#define _TF_DECLARE_TOKENS2 (   key,
  seq 
)
Value:
struct _TF_TOKENS_STRUCT_NAME(key) { \
~_TF_TOKENS_STRUCT_NAME(key)(); \
};
#define _TF_TOKENS_STRUCT_NAME(key)
Definition: staticTokens.h:161
#define _TF_TOKENS_DECLARE_MEMBERS(seq)
Definition: staticTokens.h:179

Definition at line 201 of file staticTokens.h.

#define _TF_DECLARE_TOKENS3 (   key,
  seq,
  eiapi 
)
Value:
struct _TF_TOKENS_STRUCT_NAME(key) { \
eiapi _TF_TOKENS_STRUCT_NAME(key)(); \
eiapi ~_TF_TOKENS_STRUCT_NAME(key)(); \
};
#define _TF_TOKENS_STRUCT_NAME(key)
Definition: staticTokens.h:161
#define _TF_TOKENS_DECLARE_MEMBERS(seq)
Definition: staticTokens.h:179

Definition at line 194 of file staticTokens.h.

#define _TF_DEFINE_TOKENS (   key,
  seq 
)
Value:
HBOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_NOT_ARRAY, ~, seq) \
{ \
HBOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_ARRAY, ~, seq)) \
HBOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_NOT_ARRAY, ~, seq) \
}
#define _TF_TOKENS_STRUCT_NAME(key)
Definition: staticTokens.h:161
#define _TF_TOKENS_IS_NOT_ARRAY(s, data, elem)
Definition: staticTokens.h:264
#define _TF_TOKENS_IS_ARRAY(s, data, elem)
Definition: staticTokens.h:260
#define _TF_TOKENS_ASSIGN_ARRAY_SEQ(seq)
Definition: staticTokens.h:249
#define _TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)
Definition: staticTokens.h:187
#define _TF_TOKENS_BUILD_ALLTOKENS_VECTOR(seq)
Definition: staticTokens.h:241
#define _TF_TOKENS_INITIALIZE_SEQ(seq)
Definition: staticTokens.h:246

Definition at line 281 of file staticTokens.h.

#define _TF_TOKENS_APPEND_ARRAY_ELEMENTS (   r,
  data,
  elem 
)    HBOOST_PP_TUPLE_ELEM(1, 0, HBOOST_PP_TUPLE_ELEM(2, 1, elem))

Definition at line 269 of file staticTokens.h.

#define _TF_TOKENS_APPEND_MEMBER (   r,
  data,
  i,
  elem 
)
Value:
HBOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
HBOOST_PP_TUPLE_ELEM(2, 0, elem)), \
#define _TF_TOKENS_APPEND_MEMBER_BODY(r, data, elem)
Definition: staticTokens.h:238
#define TF_PP_IS_TUPLE(arg)

Definition at line 232 of file staticTokens.h.

#define _TF_TOKENS_APPEND_MEMBER_BODY (   r,
  data,
  elem 
)    allTokens.push_back(elem);

Definition at line 238 of file staticTokens.h.

#define _TF_TOKENS_ASSIGN_ARRAY_SEQ (   seq)    HBOOST_PP_SEQ_FOR_EACH(_TF_TOKENS_DEFINE_ARRAY_MEMBERS, ~, seq)

Definition at line 249 of file staticTokens.h.

#define _TF_TOKENS_BUILD_ALLTOKENS_VECTOR (   seq)    HBOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_APPEND_MEMBER, ~, seq)

Definition at line 241 of file staticTokens.h.

#define _TF_TOKENS_DECLARE_MEMBER (   r,
  data,
  elem 
)
Value:
TfToken HBOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
HBOOST_PP_TUPLE_ELEM(2, 0, elem), elem) \
HBOOST_PP_EXPR_IIF(TF_PP_IS_TUPLE(HBOOST_PP_TUPLE_ELEM(2, 1, elem)), \
[HBOOST_PP_SEQ_SIZE(HBOOST_PP_TUPLE_ELEM(1, 0, \
HBOOST_PP_TUPLE_ELEM(2, 1, elem)))]);
Definition: token.h:87
#define TF_PP_IS_TUPLE(arg)

Definition at line 170 of file staticTokens.h.

#define _TF_TOKENS_DECLARE_MEMBERS (   seq)
Value:
std::vector<TfToken> allTokens;
#define _TF_TOKENS_DECLARE_MEMBER(r, data, elem)
Definition: staticTokens.h:170
#define _TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)
Definition: staticTokens.h:187
HBOOST_PP_SEQ_FOR_EACH(_VT_DECLARE_ZERO_VALUE_FACTORY, unused, VT_VEC_VALUE_TYPES VT_MATRIX_VALUE_TYPES VT_QUATERNION_VALUE_TYPES VT_DUALQUATERNION_VALUE_TYPES) template<> inline const VtValue &VtValue
Definition: value.h:1517

Definition at line 179 of file staticTokens.h.

#define _TF_TOKENS_DEFINE_ARRAY_MEMBER (   r,
  data,
  i,
  elem 
)
Value:
data[i] = HBOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
HBOOST_PP_TUPLE_ELEM(2, 0, elem), elem);
#define TF_PP_IS_TUPLE(arg)
Definition: format.h:895

Definition at line 226 of file staticTokens.h.

#define _TF_TOKENS_DEFINE_ARRAY_MEMBERS (   r,
  data,
  elem 
)
Value:
HBOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_DEFINE_ARRAY_MEMBER, \
HBOOST_PP_TUPLE_ELEM(2, 0, elem), \
HBOOST_PP_TUPLE_ELEM(1, 0, HBOOST_PP_TUPLE_ELEM(2, 1, elem)))
#define _TF_TOKENS_DEFINE_ARRAY_MEMBER(r, data, i, elem)
Definition: staticTokens.h:226

Definition at line 252 of file staticTokens.h.

#define _TF_TOKENS_DEFINE_MEMBER (   r,
  data,
  i,
  elem 
)
Value:
HBOOST_PP_COMMA_IF(i) \
HBOOST_PP_TUPLE_ELEM(1, 0, HBOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
#define _TF_TOKENS_INITIALIZE_MEMBER_TUPLE(elem)
Definition: staticTokens.h:219
#define TF_PP_IS_TUPLE(arg)
#define _TF_TOKENS_INITIALIZE_MEMBER(elem)
Definition: staticTokens.h:223

Definition at line 213 of file staticTokens.h.

#define _TF_TOKENS_EXPAND_ARRAY_ELEMENTS (   seq)
Value:
~, \
HBOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_ARRAY, ~, seq)) \
#define _TF_TOKENS_IS_ARRAY(s, data, elem)
Definition: staticTokens.h:260
#define _TF_TOKENS_APPEND_ARRAY_ELEMENTS(r, data, elem)
Definition: staticTokens.h:269
HBOOST_PP_SEQ_FOR_EACH(_VT_DECLARE_ZERO_VALUE_FACTORY, unused, VT_VEC_VALUE_TYPES VT_MATRIX_VALUE_TYPES VT_QUATERNION_VALUE_TYPES VT_DUALQUATERNION_VALUE_TYPES) template<> inline const VtValue &VtValue
Definition: value.h:1517

Definition at line 187 of file staticTokens.h.

#define _TF_TOKENS_INITIALIZE_MEMBER (   elem)    elem(TF_PP_STRINGIZE(elem), TfToken::Immortal)

Definition at line 223 of file staticTokens.h.

#define _TF_TOKENS_INITIALIZE_MEMBER_TUPLE (   elem)
Value:
HBOOST_PP_TUPLE_ELEM(2, 0, elem)(HBOOST_PP_TUPLE_ELEM(2, 1, elem), \

Definition at line 219 of file staticTokens.h.

#define _TF_TOKENS_INITIALIZE_SEQ (   seq)    HBOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_DEFINE_MEMBER, ~, seq)

Definition at line 246 of file staticTokens.h.

#define _TF_TOKENS_IS_ARRAY (   s,
  data,
  elem 
)
Value:
HBOOST_PP_AND(TF_PP_IS_TUPLE(elem), \
TF_PP_IS_TUPLE(HBOOST_PP_TUPLE_ELEM(2, 1, elem)))
#define TF_PP_IS_TUPLE(arg)

Definition at line 260 of file staticTokens.h.

#define _TF_TOKENS_IS_NOT_ARRAY (   s,
  data,
  elem 
)    HBOOST_PP_NOT(_TF_TOKENS_IS_ARRAY(s, data, elem))

Definition at line 264 of file staticTokens.h.

#define _TF_TOKENS_STRUCT_NAME (   key)    HBOOST_PP_CAT(key, _StaticTokenType)

Definition at line 161 of file staticTokens.h.

#define _TF_TOKENS_STRUCT_NAME_PRIVATE (   key)    HBOOST_PP_CAT(key, _PrivateStaticTokenType)

Definition at line 154 of file staticTokens.h.

#define TF_DECLARE_PUBLIC_TOKENS (   ...)

Macro to define public tokens. This declares a list of tokens that can be used globally. Use in conjunction with TF_DEFINE_PUBLIC_TOKENS.

Definition at line 117 of file staticTokens.h.

#define TF_DEFINE_PRIVATE_TOKENS (   key,
  seq 
)

Macro to define private tokens.

Definition at line 128 of file staticTokens.h.

#define TF_DEFINE_PUBLIC_TOKENS (   key,
  seq 
)

Macro to define public tokens. Use in conjunction with TF_DECLARE_PUBLIC_TOKENS.

Definition at line 122 of file staticTokens.h.