All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primWriterRegistry.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_PRIM_WRITER_REGISTRY_H
25 #define PXRUSDMAYA_PRIM_WRITER_REGISTRY_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "usdMaya/api.h"
31 
32 #include "usdMaya/primWriter.h"
33 #include "usdMaya/primWriterArgs.h"
35 
36 #include "pxr/usd/sdf/path.h"
37 
38 #include <maya/MFnDependencyNode.h>
39 
40 #include <functional>
41 #include <string>
42 
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 
79 {
82  typedef std::function< UsdMayaPrimWriterSharedPtr (
83  const MFnDependencyNode&,
84  const SdfPath&,
86 
90  typedef std::function< bool (
91  const UsdMayaPrimWriterArgs&,
92  UsdMayaPrimWriterContext*) > WriterFn;
93 
112  PXRUSDMAYA_API
113  static void Register(const std::string& mayaType, WriterFactoryFn fn);
114 
119  PXRUSDMAYA_API
120  static void RegisterRaw(const std::string& mayaType, WriterFn fn);
121 
125  PXRUSDMAYA_API
126  static WriterFactoryFn Find(const std::string& mayaTypeName);
127 };
128 
129 // Note, TF_REGISTRY_FUNCTION_WITH_TAG needs a type to register with so we
130 // create a dummy struct in the macro.
131 
143 #define PXRUSDMAYA_DEFINE_WRITER(mayaTypeName, argsVarName, ctxVarName) \
144 struct UsdMayaWriterDummy_##mayaTypeName { }; \
145 static \
146 bool \
147 UsdMaya_PrimWriter_##mayaTypeName( \
148  const UsdMayaPrimWriterArgs&, \
149  UsdMayaPrimWriterContext*); \
150 TF_REGISTRY_FUNCTION_WITH_TAG( \
151  UsdMayaPrimWriterRegistry, \
152  UsdMayaWriterDummy_##mayaTypeName) \
153 { \
154  UsdMayaPrimWriterRegistry::RegisterRaw( \
155  #mayaTypeName, \
156  UsdMaya_PrimWriter_##mayaTypeName); \
157 } \
158 bool \
159 UsdMaya_PrimWriter_##mayaTypeName( \
160  const UsdMayaPrimWriterArgs& argsVarName, \
161  UsdMayaPrimWriterContext* ctxVarName)
162 
180 #define PXRUSDMAYA_REGISTER_WRITER(mayaTypeName, writerClass) \
181 TF_REGISTRY_FUNCTION_WITH_TAG( \
182  UsdMayaPrimWriterRegistry, \
183  mayaTypeName##_##writerClass) \
184 { \
185  UsdMayaPrimWriterRegistry::Register( \
186  #mayaTypeName, \
187  []( \
188  const MFnDependencyNode& depNodeFn, \
189  const SdfPath& usdPath, \
190  UsdMayaWriteJobContext& jobCtx) { \
191  return std::make_shared<writerClass>(depNodeFn, usdPath, jobCtx); \
192  }); \
193 }
194 
195 
196 PXR_NAMESPACE_CLOSE_SCOPE
197 
198 
199 #endif
static PXRUSDMAYA_API WriterFactoryFn Find(const std::string &mayaTypeName)
Finds a writer if one exists for mayaTypeName.
Provides basic functionality and access to shared data for UsdMayaPrimWriters.
Provides functionality to register and lookup USD writer plugins for Maya nodes.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
This class holds read-only arguments that are passed into the writer plugins for the usdMaya library...
std::function< bool(const UsdMayaPrimWriterArgs &, UsdMayaPrimWriterContext *) > WriterFn
Writer function, i.e.
std::function< UsdMayaPrimWriterSharedPtr(const MFnDependencyNode &, const SdfPath &, UsdMayaWriteJobContext &) > WriterFactoryFn
Writer factory function, i.e.
static PXRUSDMAYA_API void RegisterRaw(const std::string &mayaType, WriterFn fn)
Wraps fn in a WriterFactoryFn and registers the wrapped function as a prim writer provider...
static PXRUSDMAYA_API void Register(const std::string &mayaType, WriterFactoryFn fn)
Register fn as a factory function providing a UsdMayaPrimWriter subclass that can be used to write ma...