24 #ifndef PXR_BASE_TF_STATIC_DATA_H 25 #define PXR_BASE_TF_STATIC_DATA_H 33 #include "pxr/base/tf/preprocessorUtilsLite.h" 36 #include <type_traits> 38 PXR_NAMESPACE_OPEN_SCOPE
109 struct Tf_StaticDataDefaultFactory {
110 static T *New() {
return new T; }
113 template <
class T,
class Factory = Tf_StaticDataDefaultFactory<T> >
128 return ARCH_LIKELY(p) ? p : _TryToCreateData();
136 T *_TryToCreateData()
const {
138 T *tmp = Factory::New();
142 if (ARCH_LIKELY(_data.compare_exchange_strong(n, tmp)))
150 mutable std::atomic<T *> _data;
199 #define TF_MAKE_STATIC_DATA(Type, Name) \ 200 static void TF_PP_CAT(Name,_Tf_StaticDataFactoryImpl)( \ 201 std::remove_const_t<TF_PP_EAT_PARENS(Type)> *); \ 203 struct TF_PP_CAT(Name,_Tf_StaticDataFactory) { \ 204 static TF_PP_EAT_PARENS(Type) *New() { \ 205 auto *p = new std::remove_const_t<TF_PP_EAT_PARENS(Type)>; \ 206 TF_PP_CAT(Name,_Tf_StaticDataFactoryImpl)(p); \ 211 static TfStaticData< \ 212 TF_PP_EAT_PARENS(Type), TF_PP_CAT(Name,_Tf_StaticDataFactory)> Name; \ 213 static void TF_PP_CAT(Name,_Tf_StaticDataFactoryImpl)( \ 214 std::remove_const_t<TF_PP_EAT_PARENS(Type)> *Name) 216 PXR_NAMESPACE_CLOSE_SCOPE
bool IsInitialized() const
Return true if the underlying data object is created and initialized.
T * Get() const
Return a pointer to the underlying object, creating and initializing it if necessary.
Create or return a previously created object instance of global data.
T * operator->() const
Return a pointer to the underlying data object.
T & operator *() const
Member lookup.