HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
instantiateType.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 /*
8  * This header is not meant to be included in a .h file.
9  * Complain if we see this header twice through.
10  */
11 
12 #ifdef PXR_BASE_TF_INSTANTIATE_TYPE_H
13 #error This file should only be included once in any given source (.cpp) file.
14 #endif
15 
16 #define PXR_BASE_TF_INSTANTIATE_TYPE_H
17 
18 #include "pxr/pxr.h"
20 #include "pxr/base/tf/type.h"
21 #include "pxr/base/tf/refPtr.h"
22 
24 
25 template <typename T, bool AS_REF_PTR>
27  struct FactoryType : public TfType::FactoryBase {
28  TfRefPtr<T> New() { return T::New(); }
29  };
30 };
31 template <class T>
33 };
34 
35 template <typename T>
36 struct Tf_TypeFactoryType<T, false> {
37  struct FactoryType : public TfType::FactoryBase {
38  T* New() { return new T; }
39  };
40 };
41 
42 // Make the type actually manufacturable.
43 template <typename T, bool MANUFACTURABLE>
45  static void Doit(TfType t) {
47  t.SetFactory<FT>();
48  }
49 };
50 
51 // Don't make it manufacturable.
52 template <typename T>
53 struct Tf_MakeTypeManufacturable<T, false> {
54  static void Doit(TfType) {
55  }
56 };
57 
58 #define _TF_REMOVE_PARENS_HELPER(...) __VA_ARGS__
59 #define _TF_REMOVE_PARENS(parens) _TF_REMOVE_PARENS_HELPER parens
60 
61 #define TF_NO_PARENT() (TfType::Bases<>)
62 #define TF_1_PARENT(p1) (TfType::Bases<p1 >)
63 #define TF_2_PARENT(p1,p2) (TfType::Bases<p1, p2 >)
64 #define TF_INSTANTIATE_TYPE(Type, flags, Bases) \
65  TF_REGISTRY_DEFINE_WITH_TYPE(TfType, Type) { \
66  TfType t1 = TfType::Define<Type, _TF_REMOVE_PARENS(Bases) >(); \
67  Tf_MakeTypeManufacturable<Type, (flags&TfType::MANUFACTURABLE)!=0 >::Doit(t1); \
68  }
69 
Base class of all factory types.
Definition: type.h:56
static void Doit(TfType t)
GLdouble t
Definition: glad.h:2397
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
TF_API void SetFactory(std::unique_ptr< FactoryBase > &&factory) const