Loading...
Searching...
No Matches
staticTokens.h
Go to the documentation of this file.
1
//
2
// Copyright 2016 Pixar
3
//
4
// Licensed under the terms set forth in the LICENSE.txt file available at
5
// https://openusd.org/license.
6
//
7
//todo: cleanup: TF_DEFINE_PRIVATE_TOKENS, should use the public versions
8
//todo: cleanup: document each macro extensively
9
//todo: cleanup: order macros, so that it is easier to see the structure
10
11
#ifndef PXR_BASE_TF_STATIC_TOKENS_H
12
#define PXR_BASE_TF_STATIC_TOKENS_H
13
59
60
#include "
pxr/pxr.h
"
61
#include "pxr/base/arch/defines.h"
62
#include "pxr/base/tf/preprocessorUtilsLite.h"
63
#include "
pxr/base/tf/staticData.h
"
64
#include "
pxr/base/tf/token.h
"
65
66
#include <vector>
67
68
PXR_NAMESPACE_OPEN_SCOPE
69
70
// TF_DECLARE_PUBLIC_TOKENS use these macros to handle two or three arguments.
71
// The three argument version takes an export/import macro (e.g. TF_API)
72
// while the two argument version does not export the tokens.
73
74
#define _TF_DECLARE_PUBLIC_TOKENS3(key, eiapi, seq) \
75
_TF_DECLARE_TOKENS3(key, seq, eiapi) \
76
extern eiapi TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key
77
#define _TF_DECLARE_PUBLIC_TOKENS2(key, seq) \
78
_TF_DECLARE_TOKENS2(key, seq) \
79
extern TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key
80
#define _TF_DECLARE_PUBLIC_TOKENS(N) _TF_DECLARE_PUBLIC_TOKENS##N
81
#define _TF_DECLARE_PUBLIC_TOKENS_EVAL(N) _TF_DECLARE_PUBLIC_TOKENS(N)
82
#define _TF_DECLARE_PUBLIC_TOKENS_EXPAND(x) x
83
87
// This macro expansion is disabled for Intellisense to avoid severe
88
// slowdowns when using MSVC's non-conforming preprocessor.
89
#if defined(ARCH_PREPROCESSOR_MSVC_TRADITIONAL) && defined(__INTELLISENSE__)
90
#define TF_DECLARE_PUBLIC_TOKENS(...)
91
#else
92
#define TF_DECLARE_PUBLIC_TOKENS(...) _TF_DECLARE_PUBLIC_TOKENS_EXPAND( _TF_DECLARE_PUBLIC_TOKENS_EVAL(_TF_DECLARE_PUBLIC_TOKENS_EXPAND( TF_PP_VARIADIC_SIZE(__VA_ARGS__) ))(__VA_ARGS__) )
93
#endif
94
98
#define TF_DEFINE_PUBLIC_TOKENS(key, seq) \
99
_TF_DEFINE_TOKENS(key) \
100
TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key
101
104
#define TF_DEFINE_PRIVATE_TOKENS(key, seq) \
105
namespace { \
106
struct _TF_TOKENS_STRUCT_NAME_PRIVATE(key) { \
107
_TF_TOKENS_STRUCT_NAME_PRIVATE(key)() = default; \
108
_TF_TOKENS_DECLARE_MEMBERS(seq) \
109
}; \
110
} \
111
static TfStaticData<_TF_TOKENS_STRUCT_NAME_PRIVATE(key)> key
112
114
// Private Macros
115
116
// Private macro to generate struct name from key.
117
//
118
// Note that this needs to be a unique struct name for each translation unit.
119
//
120
#define _TF_TOKENS_STRUCT_NAME_PRIVATE(key) \
121
TF_PP_CAT(key, _PrivateStaticTokenType)
122
123
// Private macro to generate struct name from key. This version is used
124
// by the public token declarations, and so key must be unique for the entire
125
// namespace.
126
//
127
#define _TF_TOKENS_STRUCT_NAME(key) \
128
TF_PP_CAT(key, _StaticTokenType)
129
131
// Declaration Macros
132
133
// Private macro used to generate TfToken member variables. elem can either
134
// be a tuple on the form (name, value) or just a name.
135
//
136
#define _TF_TOKENS_DECLARE_MEMBER(unused, elem) \
137
TfToken _TF_PP_IFF(TF_PP_IS_TUPLE(elem), \
138
TF_PP_TUPLE_ELEM(0, elem), elem){ \
139
_TF_PP_IFF(TF_PP_IS_TUPLE(elem), \
140
TF_PP_TUPLE_ELEM(1, elem), TF_PP_STRINGIZE(elem)), \
141
TfToken::Immortal};
142
#define _TF_TOKENS_DECLARE_TOKEN_MEMBERS(seq) \
143
TF_PP_SEQ_FOR_EACH(_TF_TOKENS_DECLARE_MEMBER, ~, seq)
144
145
#define _TF_TOKENS_FORWARD_TOKEN(unused, elem) TF_PP_TUPLE_ELEM(0, elem),
146
#define _TF_TOKENS_DECLARE_ALL_TOKENS(seq) \
147
std::vector<TfToken> allTokens = \
148
{TF_PP_SEQ_FOR_EACH(_TF_TOKENS_FORWARD_TOKEN, ~, seq)};
149
150
// Private macro used to declare the list of members as TfTokens
151
//
152
#define _TF_TOKENS_DECLARE_MEMBERS(seq) \
153
_TF_TOKENS_DECLARE_TOKEN_MEMBERS(seq) \
154
_TF_TOKENS_DECLARE_ALL_TOKENS(seq) \
155
156
// Private macro used to generate a struct of TfTokens.
157
//
158
#define _TF_DECLARE_TOKENS3(key, seq, eiapi) \
159
struct _TF_TOKENS_STRUCT_NAME(key) { \
160
eiapi _TF_TOKENS_STRUCT_NAME(key)(); \
161
eiapi ~_TF_TOKENS_STRUCT_NAME(key)(); \
162
_TF_TOKENS_DECLARE_MEMBERS(seq) \
163
};
164
165
#define _TF_DECLARE_TOKENS2(key, seq) \
166
struct _TF_TOKENS_STRUCT_NAME(key) { \
167
_TF_TOKENS_STRUCT_NAME(key)(); \
168
~_TF_TOKENS_STRUCT_NAME(key)(); \
169
_TF_TOKENS_DECLARE_MEMBERS(seq) \
170
};
171
173
// Definition Macros
174
175
// Private macro to define the struct of tokens.
176
//
177
#define _TF_DEFINE_TOKENS(key) \
178
_TF_TOKENS_STRUCT_NAME(key)::~_TF_TOKENS_STRUCT_NAME(key)() = default; \
179
_TF_TOKENS_STRUCT_NAME(key)::_TF_TOKENS_STRUCT_NAME(key)() = default; \
180
181
PXR_NAMESPACE_CLOSE_SCOPE
182
183
#endif
// PXR_BASE_TF_STATIC_TOKENS_H
pxr.h
staticData.h
token.h
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
pxr
base
tf
staticTokens.h
© Copyright 2025, Pixar Animation Studios. |
Terms of Use
| Generated on Tue Nov 18 2025 10:36:06 by
1.9.6