All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parserPlugin.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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 
25 #ifndef NDR_PARSERPLUGIN_H
26 #define NDR_PARSERPLUGIN_H
27 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/ndr/api.h"
32 #include "pxr/base/tf/type.h"
33 #include "pxr/base/tf/weakBase.h"
34 #include "pxr/base/tf/weakPtr.h"
35 #include "pxr/usd/ndr/declare.h"
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
39 // Forward declarations
41 
43 #define NDR_REGISTER_PARSER_PLUGIN(ParserPluginClass) \
44 TF_REGISTRY_FUNCTION(TfType) \
45 { \
46  TfType::Define<ParserPluginClass, TfType::Bases<NdrParserPlugin>>() \
47  .SetFactory<NdrParserPluginFactory<ParserPluginClass>>(); \
48 }
49 
126 {
127 public:
128  NDR_API
129  NdrParserPlugin();
130  NDR_API
131  virtual ~NdrParserPlugin();
132 
136  NDR_API
137  virtual NdrNodeUniquePtr Parse(
138  const NdrNodeDiscoveryResult& discoveryResult) = 0;
139 
147  NDR_API
148  virtual const NdrTokenVec& GetDiscoveryTypes() const = 0;
149 
156  NDR_API
157  virtual const TfToken& GetSourceType() const = 0;
158 
162  NDR_API
163  static NdrNodeUniquePtr GetInvalidNode(const NdrNodeDiscoveryResult& dr);
164 };
165 
166 
169 
170 class NdrParserPluginFactoryBase : public TfType::FactoryBase
171 {
172 public:
173  virtual NdrParserPlugin* New() const = 0;
174 };
175 
176 template <class T>
177 class NdrParserPluginFactory : public NdrParserPluginFactoryBase
178 {
179 public:
180  virtual NdrParserPlugin* New() const
181  {
182  return new T;
183  }
184 };
185 
187 
188 PXR_NAMESPACE_CLOSE_SCOPE
189 
190 #endif // NDR_PARSERPLUGIN_H
virtual NDR_API const TfToken & GetSourceType() const =0
Returns the source type that this parser operates on.
Interface for parser plugins.
Definition: parserPlugin.h:125
Base class of all factory types.
Definition: type.h:79
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual NDR_API NdrNodeUniquePtr Parse(const NdrNodeDiscoveryResult &discoveryResult)=0
Takes the specified NdrNodeDiscoveryResult instance, which was a result of the discovery process...
Represents the raw data of a node, and some other bits of metadata, that were determined via a NdrDis...
static NDR_API NdrNodeUniquePtr GetInvalidNode(const NdrNodeDiscoveryResult &dr)
Gets an invalid node based on the discovery result provided.
virtual NDR_API const NdrTokenVec & GetDiscoveryTypes() const =0
Returns the types of nodes that this plugin can parse.
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142