All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primReaderRegistry.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 #ifndef PXRUSDMAYA_PRIMREADERREGISTRY_H
25 #define PXRUSDMAYA_PRIMREADERREGISTRY_H
26 
28 
29 #include "usdMaya/api.h"
30 #include "usdMaya/primReader.h"
31 #include "usdMaya/primReaderArgs.h"
33 
34 #include "pxr/pxr.h"
35 
36 #include "pxr/base/tf/registryManager.h"
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 
63 {
66  typedef std::function< UsdMayaPrimReaderSharedPtr (
68 
72  typedef std::function< bool (
73  const UsdMayaPrimReaderArgs&,
75 
77  PXRUSDMAYA_API
78  static void Register(const TfType& type, ReaderFactoryFn fn);
79 
93  template <typename T>
94  static void Register(ReaderFactoryFn fn)
95  {
96  if (TfType t = TfType::Find<T>()) {
97  Register(t, fn);
98  }
99  else {
100  TF_CODING_ERROR("Cannot register unknown TfType: %s.",
101  ArchGetDemangled<T>().c_str());
102  }
103  }
104 
109  PXRUSDMAYA_API
110  static void RegisterRaw(const TfType& type, ReaderFn fn);
111 
116  template <typename T>
117  static void RegisterRaw(ReaderFn fn)
118  {
119  if (TfType t = TfType::Find<T>()) {
120  RegisterRaw(t, fn);
121  }
122  else {
123  TF_CODING_ERROR("Cannot register unknown TfType: %s.",
124  ArchGetDemangled<T>().c_str());
125  }
126  }
127 
128  // takes a usdType (i.e. prim.GetTypeName())
135  PXRUSDMAYA_API
136  static ReaderFactoryFn Find(
137  const TfToken& usdTypeName);
138 
142  PXRUSDMAYA_API
143  static ReaderFactoryFn FindOrFallback(const TfToken& usdTypeName);
144 };
145 
146 #define PXRUSDMAYA_DEFINE_READER(T, argsVarName, ctxVarName)\
147 static bool UsdMaya_PrimReader_##T(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderContext*); \
148 TF_REGISTRY_FUNCTION_WITH_TAG(UsdMayaPrimReaderRegistry, T) \
149 {\
150  UsdMayaPrimReaderRegistry::RegisterRaw<T>(UsdMaya_PrimReader_##T);\
151 }\
152 bool UsdMaya_PrimReader_##T(const UsdMayaPrimReaderArgs& argsVarName, UsdMayaPrimReaderContext* ctxVarName)
153 
154 
155 PXR_NAMESPACE_CLOSE_SCOPE
156 
157 #endif
Provides functionality to register and lookup usd Maya reader plugins.
static PXRUSDMAYA_API void RegisterRaw(const TfType &type, ReaderFn fn)
Wraps fn in a ReaderFactoryFn and registers that factory function as a reader provider for T...
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:87
std::function< bool(const UsdMayaPrimReaderArgs &, UsdMayaPrimReaderContext *) > ReaderFn
Reader function, i.e.
static void Register(ReaderFactoryFn fn)
Register fn as a reader provider for T.
static void RegisterRaw(ReaderFn fn)
Wraps fn in a ReaderFactoryFn and registers that factory function as a reader provider for T...
static PXRUSDMAYA_API ReaderFactoryFn Find(const TfToken &usdTypeName)
Finds a reader factory if one exists for usdTypeName.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
This class holds read-only arguments that are passed into reader plugins for the usdMaya library...
std::function< UsdMayaPrimReaderSharedPtr(const UsdMayaPrimReaderArgs &) > ReaderFactoryFn
Reader factory function, i.e.
static PXRUSDMAYA_API ReaderFactoryFn FindOrFallback(const TfToken &usdTypeName)
Similar to Find(), but returns a &quot;fallback&quot; prim reader factory if none can be found for usdTypeName...
static PXRUSDMAYA_API void Register(const TfType &type, ReaderFactoryFn fn)
Register fn as a reader provider for type.
TfType represents a dynamic runtime type.
Definition: type.h:70
This class provides an interface for reader plugins to communicate state back to the core usd maya lo...