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/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/seq/push_back.hpp>
#include <hboost/preprocessor/stringize.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(HBOOST_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 111 of file staticTokens.h.

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

Definition at line 108 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:195

Definition at line 105 of file staticTokens.h.

#define _TF_DECLARE_PUBLIC_TOKENS_EVAL (   N)    _TF_DECLARE_PUBLIC_TOKENS(N)

Definition at line 112 of file staticTokens.h.

#define _TF_DECLARE_PUBLIC_TOKENS_EXPAND (   x)    x

Definition at line 113 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:162
#define _TF_TOKENS_DECLARE_MEMBERS(seq)
Definition: staticTokens.h:180

Definition at line 202 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:162
#define _TF_TOKENS_DECLARE_MEMBERS(seq)
Definition: staticTokens.h:180

Definition at line 195 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:162
#define _TF_TOKENS_IS_NOT_ARRAY(s, data, elem)
Definition: staticTokens.h:265
#define _TF_TOKENS_IS_ARRAY(s, data, elem)
Definition: staticTokens.h:261
#define _TF_TOKENS_ASSIGN_ARRAY_SEQ(seq)
Definition: staticTokens.h:250
#define _TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)
Definition: staticTokens.h:188
#define _TF_TOKENS_BUILD_ALLTOKENS_VECTOR(seq)
Definition: staticTokens.h:242
#define _TF_TOKENS_INITIALIZE_SEQ(seq)
Definition: staticTokens.h:247

Definition at line 282 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 270 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:239
#define TF_PP_IS_TUPLE(arg)

Definition at line 233 of file staticTokens.h.

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

Definition at line 239 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 250 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 242 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:89
#define TF_PP_IS_TUPLE(arg)

Definition at line 171 of file staticTokens.h.

#define _TF_TOKENS_DECLARE_MEMBERS (   seq)
Value:
std::vector<TfToken> allTokens;
HBOOST_PP_SEQ_FOR_EACH(SDF_DECLARE_VALUE_TYPE_TRAITS,~, SDF_VALUE_TYPES)
#define _TF_TOKENS_DECLARE_MEMBER(r, data, elem)
Definition: staticTokens.h:171
#define _TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)
Definition: staticTokens.h:188

Definition at line 180 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);
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
#define TF_PP_IS_TUPLE(arg)

Definition at line 227 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:227

Definition at line 253 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:220
#define TF_PP_IS_TUPLE(arg)
#define _TF_TOKENS_INITIALIZE_MEMBER(elem)
Definition: staticTokens.h:224

Definition at line 214 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:261
HBOOST_PP_SEQ_FOR_EACH(SDF_DECLARE_VALUE_TYPE_TRAITS,~, SDF_VALUE_TYPES)
#define _TF_TOKENS_APPEND_ARRAY_ELEMENTS(r, data, elem)
Definition: staticTokens.h:270

Definition at line 188 of file staticTokens.h.

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

Definition at line 224 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 220 of file staticTokens.h.

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

Definition at line 247 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 261 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 265 of file staticTokens.h.

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

Definition at line 162 of file staticTokens.h.

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

Definition at line 155 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 118 of file staticTokens.h.

#define TF_DEFINE_PRIVATE_TOKENS (   key,
  seq 
)

Macro to define private tokens.

Definition at line 129 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 123 of file staticTokens.h.