Loading...
Searching...
No Matches
staticTokens.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24//todo: cleanup: TF_DEFINE_PRIVATE_TOKENS, should use the public versions
25//todo: cleanup: document each macro extensively
26//todo: cleanup: order macros, so that it is easier to see the structure
27
28#ifndef PXR_BASE_TF_STATIC_TOKENS_H
29#define PXR_BASE_TF_STATIC_TOKENS_H
30
71
72#include "pxr/pxr.h"
73#include "pxr/base/tf/preprocessorUtilsLite.h"
75#include "pxr/base/tf/token.h"
76
77#include <vector>
78
79PXR_NAMESPACE_OPEN_SCOPE
80
81// TF_DECLARE_PUBLIC_TOKENS use these macros to handle two or three arguments.
82// The three argument version takes an export/import macro (e.g. TF_API)
83// while the two argument version does not export the tokens.
84
85#define _TF_DECLARE_PUBLIC_TOKENS3(key, eiapi, seq) \
86 _TF_DECLARE_TOKENS3(key, seq, eiapi) \
87 extern eiapi TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key
88#define _TF_DECLARE_PUBLIC_TOKENS2(key, seq) \
89 _TF_DECLARE_TOKENS2(key, seq) \
90 extern TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key
91#define _TF_DECLARE_PUBLIC_TOKENS(N) _TF_DECLARE_PUBLIC_TOKENS##N
92#define _TF_DECLARE_PUBLIC_TOKENS_EVAL(N) _TF_DECLARE_PUBLIC_TOKENS(N)
93#define _TF_DECLARE_PUBLIC_TOKENS_EXPAND(x) x
94
98#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__) )
99
103#define TF_DEFINE_PUBLIC_TOKENS(key, seq) \
104 _TF_DEFINE_TOKENS(key) \
105 TfStaticData<_TF_TOKENS_STRUCT_NAME(key)> key
106
109#define TF_DEFINE_PRIVATE_TOKENS(key, seq) \
110 namespace { \
111 struct _TF_TOKENS_STRUCT_NAME_PRIVATE(key) { \
112 _TF_TOKENS_STRUCT_NAME_PRIVATE(key)() = default; \
113 _TF_TOKENS_DECLARE_MEMBERS(seq) \
114 }; \
115 } \
116 static TfStaticData<_TF_TOKENS_STRUCT_NAME_PRIVATE(key)> key
117
119// Private Macros
120
121// Private macro to generate struct name from key.
122//
123// Note that this needs to be a unique struct name for each translation unit.
124//
125#define _TF_TOKENS_STRUCT_NAME_PRIVATE(key) \
126 TF_PP_CAT(key, _PrivateStaticTokenType)
127
128// Private macro to generate struct name from key. This version is used
129// by the public token declarations, and so key must be unique for the entire
130// namespace.
131//
132#define _TF_TOKENS_STRUCT_NAME(key) \
133 TF_PP_CAT(key, _StaticTokenType)
134
136// Declaration Macros
137
138// Private macro used to generate TfToken member variables. elem can either
139// be a tuple on the form (name, value) or just a name.
140//
141#define _TF_TOKENS_DECLARE_MEMBER(unused, elem) \
142 TfToken _TF_PP_IFF(TF_PP_IS_TUPLE(elem), \
143 TF_PP_TUPLE_ELEM(0, elem), elem){ \
144 _TF_PP_IFF(TF_PP_IS_TUPLE(elem), \
145 TF_PP_TUPLE_ELEM(1, elem), TF_PP_STRINGIZE(elem)), \
146 TfToken::Immortal};
147#define _TF_TOKENS_DECLARE_TOKEN_MEMBERS(seq) \
148 TF_PP_SEQ_FOR_EACH(_TF_TOKENS_DECLARE_MEMBER, ~, seq)
149
150#define _TF_TOKENS_FORWARD_TOKEN(unused, elem) TF_PP_TUPLE_ELEM(0, elem),
151#define _TF_TOKENS_DECLARE_ALL_TOKENS(seq) \
152 std::vector<TfToken> allTokens = \
153 {TF_PP_SEQ_FOR_EACH(_TF_TOKENS_FORWARD_TOKEN, ~, seq)};
154
155// Private macro used to declare the list of members as TfTokens
156//
157#define _TF_TOKENS_DECLARE_MEMBERS(seq) \
158 _TF_TOKENS_DECLARE_TOKEN_MEMBERS(seq) \
159 _TF_TOKENS_DECLARE_ALL_TOKENS(seq) \
160
161// Private macro used to generate a struct of TfTokens.
162//
163#define _TF_DECLARE_TOKENS3(key, seq, eiapi) \
164 struct _TF_TOKENS_STRUCT_NAME(key) { \
165 eiapi _TF_TOKENS_STRUCT_NAME(key)(); \
166 eiapi ~_TF_TOKENS_STRUCT_NAME(key)(); \
167 _TF_TOKENS_DECLARE_MEMBERS(seq) \
168 };
169
170#define _TF_DECLARE_TOKENS2(key, seq) \
171 struct _TF_TOKENS_STRUCT_NAME(key) { \
172 _TF_TOKENS_STRUCT_NAME(key)(); \
173 ~_TF_TOKENS_STRUCT_NAME(key)(); \
174 _TF_TOKENS_DECLARE_MEMBERS(seq) \
175 };
176
178// Definition Macros
179
180// Private macro to define the struct of tokens.
181//
182#define _TF_DEFINE_TOKENS(key) \
183 _TF_TOKENS_STRUCT_NAME(key)::~_TF_TOKENS_STRUCT_NAME(key)() = default; \
184 _TF_TOKENS_STRUCT_NAME(key)::_TF_TOKENS_STRUCT_NAME(key)() = default; \
185
186PXR_NAMESPACE_CLOSE_SCOPE
187
188#endif // PXR_BASE_TF_STATIC_TOKENS_H
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...