All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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:

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. More...
 
#define TF_DEFINE_PUBLIC_TOKENS(key, seq)
 Macro to define public tokens. More...
 
#define TF_DEFINE_PRIVATE_TOKENS(key, seq)
 Macro to define private tokens. More...
 
#define _TF_TOKENS_STRUCT_NAME_PRIVATE(key)   BOOST_PP_CAT(key, _PrivateStaticTokenType)
 
#define _TF_TOKENS_STRUCT_NAME(key)   BOOST_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(BOOST_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)   BOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_APPEND_MEMBER, ~, seq)
 
#define _TF_TOKENS_INITIALIZE_SEQ(seq)   BOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_DEFINE_MEMBER, ~, seq)
 
#define _TF_TOKENS_ASSIGN_ARRAY_SEQ(seq)   BOOST_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)   BOOST_PP_NOT(_TF_TOKENS_IS_ARRAY(s, data, elem))
 
#define _TF_TOKENS_APPEND_ARRAY_ELEMENTS(r, data, elem)   BOOST_PP_TUPLE_ELEM(1, 0, BOOST_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_TOKENS2 (   key,
  seq 
)
Value:
_TF_DECLARE_TOKENS2(key, seq) \
Create or return a previously created object instance of global data.
Definition: staticData.h:113

Definition at line 108 of file staticTokens.h.

#define _TF_DECLARE_PUBLIC_TOKENS3 (   key,
  eiapi,
  seq 
)
Value:
_TF_DECLARE_TOKENS3(key, seq, eiapi) \
Create or return a previously created object instance of global data.
Definition: staticData.h:113

Definition at line 105 of file staticTokens.h.

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

Definition at line 195 of file staticTokens.h.

#define _TF_DEFINE_TOKENS (   key,
  seq 
)
Value:
_TF_TOKENS_STRUCT_NAME(key)::~_TF_TOKENS_STRUCT_NAME(key)() = default; \
_TF_TOKENS_STRUCT_NAME(key)::_TF_TOKENS_STRUCT_NAME(key)() : \
_TF_TOKENS_INITIALIZE_SEQ( \
BOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_NOT_ARRAY, ~, seq) \
_TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)) \
{ \
_TF_TOKENS_ASSIGN_ARRAY_SEQ( \
BOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_ARRAY, ~, seq)) \
_TF_TOKENS_BUILD_ALLTOKENS_VECTOR( \
BOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_NOT_ARRAY, ~, seq) \
_TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)) \
}

Definition at line 282 of file staticTokens.h.

#define _TF_TOKENS_APPEND_MEMBER (   r,
  data,
  i,
  elem 
)
Value:
BOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
_TF_TOKENS_APPEND_MEMBER_BODY(~, ~, \
BOOST_PP_TUPLE_ELEM(2, 0, elem)), \
_TF_TOKENS_APPEND_MEMBER_BODY(~, ~, elem))
#define TF_PP_IS_TUPLE(arg)
Exapnds to 1 if the argument is a tuple, and 0 otherwise.

Definition at line 233 of file staticTokens.h.

#define _TF_TOKENS_DECLARE_MEMBER (   r,
  data,
  elem 
)
Value:
TfToken BOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
BOOST_PP_TUPLE_ELEM(2, 0, elem), elem) \
BOOST_PP_EXPR_IIF(TF_PP_IS_TUPLE(BOOST_PP_TUPLE_ELEM(2, 1, elem)), \
[BOOST_PP_SEQ_SIZE(BOOST_PP_TUPLE_ELEM(1, 0, \
BOOST_PP_TUPLE_ELEM(2, 1, elem)))]);
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
#define TF_PP_IS_TUPLE(arg)
Exapnds to 1 if the argument is a tuple, and 0 otherwise.

Definition at line 171 of file staticTokens.h.

#define _TF_TOKENS_DECLARE_MEMBERS (   seq)
Value:
BOOST_PP_SEQ_FOR_EACH(_TF_TOKENS_DECLARE_MEMBER, ~, \
seq _TF_TOKENS_EXPAND_ARRAY_ELEMENTS(seq)) \
std::vector<TfToken> allTokens;

Definition at line 180 of file staticTokens.h.

#define _TF_TOKENS_DEFINE_ARRAY_MEMBER (   r,
  data,
  i,
  elem 
)
Value:
data[i] = BOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
BOOST_PP_TUPLE_ELEM(2, 0, elem), elem);
#define TF_PP_IS_TUPLE(arg)
Exapnds to 1 if the argument is a tuple, and 0 otherwise.

Definition at line 227 of file staticTokens.h.

#define _TF_TOKENS_DEFINE_ARRAY_MEMBERS (   r,
  data,
  elem 
)
Value:
BOOST_PP_SEQ_FOR_EACH_I(_TF_TOKENS_DEFINE_ARRAY_MEMBER, \
BOOST_PP_TUPLE_ELEM(2, 0, elem), \
BOOST_PP_TUPLE_ELEM(1, 0, BOOST_PP_TUPLE_ELEM(2, 1, elem)))

Definition at line 253 of file staticTokens.h.

#define _TF_TOKENS_DEFINE_MEMBER (   r,
  data,
  i,
  elem 
)
Value:
BOOST_PP_COMMA_IF(i) \
BOOST_PP_TUPLE_ELEM(1, 0, BOOST_PP_IIF(TF_PP_IS_TUPLE(elem), \
(_TF_TOKENS_INITIALIZE_MEMBER_TUPLE(elem)), \
(_TF_TOKENS_INITIALIZE_MEMBER(elem))))
#define TF_PP_IS_TUPLE(arg)
Exapnds to 1 if the argument is a tuple, and 0 otherwise.

Definition at line 214 of file staticTokens.h.

#define _TF_TOKENS_EXPAND_ARRAY_ELEMENTS (   seq)
Value:
BOOST_PP_SEQ_FOR_EACH(_TF_TOKENS_APPEND_ARRAY_ELEMENTS, \
~, \
BOOST_PP_SEQ_FILTER(_TF_TOKENS_IS_ARRAY, ~, seq)) \

Definition at line 188 of file staticTokens.h.

#define _TF_TOKENS_INITIALIZE_MEMBER_TUPLE (   elem)
Value:
BOOST_PP_TUPLE_ELEM(2, 0, elem)(BOOST_PP_TUPLE_ELEM(2, 1, elem), \
TfToken::Immortal) \

Definition at line 220 of file staticTokens.h.

#define _TF_TOKENS_IS_ARRAY (   s,
  data,
  elem 
)
Value:
BOOST_PP_AND(TF_PP_IS_TUPLE(elem), \
TF_PP_IS_TUPLE(BOOST_PP_TUPLE_ELEM(2, 1, elem)))
#define TF_PP_IS_TUPLE(arg)
Exapnds to 1 if the argument is a tuple, and 0 otherwise.

Definition at line 261 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.