This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
staticTokens.h File Reference

This file defines some macros that are useful for declaring and using static TfTokens. More...

+ 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(...)
 Macro to define public tokens.
 
#define TF_DEFINE_PUBLIC_TOKENS(key, seq)
 Macro to define public tokens.
 
#define TF_DEFINE_PRIVATE_TOKENS(key, seq)
 Macro to define private tokens.
 
#define _TF_TOKENS_STRUCT_NAME_PRIVATE(key)    TF_PP_CAT(key, _PrivateStaticTokenType)
 
#define _TF_TOKENS_STRUCT_NAME(key)    TF_PP_CAT(key, _StaticTokenType)
 
#define _TF_TOKENS_DECLARE_MEMBER(unused, elem)
 
#define _TF_TOKENS_DECLARE_TOKEN_MEMBERS(seq)    TF_PP_SEQ_FOR_EACH(_TF_TOKENS_DECLARE_MEMBER, ~, seq)
 
#define _TF_TOKENS_FORWARD_TOKEN(unused, elem)   TF_PP_TUPLE_ELEM(0, elem),
 
#define _TF_TOKENS_DECLARE_ALL_TOKENS(seq)
 
#define _TF_TOKENS_DECLARE_MEMBERS(seq)
 
#define _TF_DECLARE_TOKENS3(key, seq, eiapi)
 
#define _TF_DECLARE_TOKENS2(key, seq)
 
#define _TF_DEFINE_TOKENS(key)
 

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"))
TF_DECLARE_PUBLIC_TOKENS(MfTokens, MF_TOKENS);
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:81

In cpp file:

TF_DEFINE_PUBLIC_TOKENS(MfTokens, MF_TOKENS);
#define TF_DEFINE_PUBLIC_TOKENS(key, seq)
Macro to define public tokens.
Definition: staticTokens.h:86

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

◆ _TF_DECLARE_PUBLIC_TOKENS

#define _TF_DECLARE_PUBLIC_TOKENS (   N)    _TF_DECLARE_PUBLIC_TOKENS##N

Definition at line 74 of file staticTokens.h.

◆ _TF_DECLARE_PUBLIC_TOKENS2

#define _TF_DECLARE_PUBLIC_TOKENS2 (   key,
  seq 
)
Value:
_TF_DECLARE_TOKENS2(key, seq) \
extern TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key
Create or return a previously created object instance of global data.
Definition: staticData.h:96

Definition at line 71 of file staticTokens.h.

◆ _TF_DECLARE_PUBLIC_TOKENS3

#define _TF_DECLARE_PUBLIC_TOKENS3 (   key,
  eiapi,
  seq 
)
Value:
_TF_DECLARE_TOKENS3(key, seq, eiapi) \
extern eiapi TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key

Definition at line 68 of file staticTokens.h.

◆ _TF_DECLARE_PUBLIC_TOKENS_EVAL

#define _TF_DECLARE_PUBLIC_TOKENS_EVAL (   N)    _TF_DECLARE_PUBLIC_TOKENS(N)

Definition at line 75 of file staticTokens.h.

◆ _TF_DECLARE_PUBLIC_TOKENS_EXPAND

#define _TF_DECLARE_PUBLIC_TOKENS_EXPAND (   x)    x

Definition at line 76 of file staticTokens.h.

◆ _TF_DECLARE_TOKENS2

#define _TF_DECLARE_TOKENS2 (   key,
  seq 
)
Value:
struct _TF_TOKENS_STRUCT_NAME(key) { \
_TF_TOKENS_STRUCT_NAME(key)(); \
~_TF_TOKENS_STRUCT_NAME(key)(); \
_TF_TOKENS_DECLARE_MEMBERS(seq) \
};

Definition at line 153 of file staticTokens.h.

◆ _TF_DECLARE_TOKENS3

#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)(); \
_TF_TOKENS_DECLARE_MEMBERS(seq) \
};

Definition at line 146 of file staticTokens.h.

◆ _TF_DEFINE_TOKENS

#define _TF_DEFINE_TOKENS (   key)
Value:
_TF_TOKENS_STRUCT_NAME(key)::~_TF_TOKENS_STRUCT_NAME(key)() = default; \
_TF_TOKENS_STRUCT_NAME(key)::_TF_TOKENS_STRUCT_NAME(key)() = default; \

Definition at line 165 of file staticTokens.h.

◆ _TF_TOKENS_DECLARE_ALL_TOKENS

#define _TF_TOKENS_DECLARE_ALL_TOKENS (   seq)
Value:
std::vector<TfToken> allTokens = \
{TF_PP_SEQ_FOR_EACH(_TF_TOKENS_FORWARD_TOKEN, ~, seq)};

Definition at line 134 of file staticTokens.h.

◆ _TF_TOKENS_DECLARE_MEMBER

#define _TF_TOKENS_DECLARE_MEMBER (   unused,
  elem 
)
Value:
TfToken _TF_PP_IFF(TF_PP_IS_TUPLE(elem), \
TF_PP_TUPLE_ELEM(0, elem), elem){ \
_TF_PP_IFF(TF_PP_IS_TUPLE(elem), \
TF_PP_TUPLE_ELEM(1, elem), TF_PP_STRINGIZE(elem)), \
TfToken::Immortal};
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
#define TF_PP_IS_TUPLE(arg)
Exapnds to 1 if the argument is a tuple, and 0 otherwise.

Definition at line 124 of file staticTokens.h.

◆ _TF_TOKENS_DECLARE_MEMBERS

#define _TF_TOKENS_DECLARE_MEMBERS (   seq)
Value:
_TF_TOKENS_DECLARE_TOKEN_MEMBERS(seq) \
_TF_TOKENS_DECLARE_ALL_TOKENS(seq) \

Definition at line 140 of file staticTokens.h.

◆ _TF_TOKENS_DECLARE_TOKEN_MEMBERS

#define _TF_TOKENS_DECLARE_TOKEN_MEMBERS (   seq)     TF_PP_SEQ_FOR_EACH(_TF_TOKENS_DECLARE_MEMBER, ~, seq)

Definition at line 130 of file staticTokens.h.

◆ _TF_TOKENS_FORWARD_TOKEN

#define _TF_TOKENS_FORWARD_TOKEN (   unused,
  elem 
)    TF_PP_TUPLE_ELEM(0, elem),

Definition at line 133 of file staticTokens.h.

◆ _TF_TOKENS_STRUCT_NAME

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

Definition at line 115 of file staticTokens.h.

◆ _TF_TOKENS_STRUCT_NAME_PRIVATE

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

Definition at line 108 of file staticTokens.h.

◆ TF_DECLARE_PUBLIC_TOKENS

#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 81 of file staticTokens.h.

◆ TF_DEFINE_PRIVATE_TOKENS

#define TF_DEFINE_PRIVATE_TOKENS (   key,
  seq 
)

Macro to define private tokens.

Definition at line 92 of file staticTokens.h.

◆ TF_DEFINE_PUBLIC_TOKENS

#define TF_DEFINE_PUBLIC_TOKENS (   key,
  seq 
)

Macro to define public tokens.

Use in conjunction with TF_DECLARE_PUBLIC_TOKENS.

Definition at line 86 of file staticTokens.h.