HDK
 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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_NDR_PARSER_PLUGIN_H
9 #define PXR_USD_NDR_PARSER_PLUGIN_H
10 
11 /// \file ndr/parserPlugin.h
12 ///
13 /// \deprecated
14 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
15 /// in sdr/parserPlugin.h
16 
17 #include "pxr/pxr.h"
18 #include "pxr/usd/ndr/api.h"
19 #include "pxr/base/tf/type.h"
20 #include "pxr/base/tf/weakBase.h"
21 #include "pxr/base/tf/weakPtr.h"
22 #include "pxr/usd/ndr/declare.h"
23 
25 
26 // Forward declarations
28 
29 /// Register a parser plugin with the plugin system.
30 ///
31 /// \deprecated
32 /// Deprecated in favor of SDR_REGISTER_PARSER_PLUGIN
33 #define NDR_REGISTER_PARSER_PLUGIN(ParserPluginClass) \
34 TF_REGISTRY_FUNCTION(TfType) \
35 { \
36  TfType::Define<ParserPluginClass, TfType::Bases<NdrParserPlugin>>() \
37  .SetFactory<NdrParserPluginFactory<ParserPluginClass>>(); \
38 }
39 
40 /// \class NdrParserPlugin
41 ///
42 /// Interface for parser plugins.
43 ///
44 /// Parser plugins take a `NdrNodeDiscoveryResult` from the discovery process
45 /// and creates a full `NdrNode` instance (or, in the case of a real-world
46 /// scenario, a specialized node that derives from `NdrNode`). The parser that
47 /// is selected to run is ultimately decided by the registry, and depends on the
48 /// `NdrNodeDiscoveryResult`'s `discoveryType` member. A parser plugin's
49 /// `GetDiscoveryTypes()` method is how this link is made. If a discovery result
50 /// has a `discoveryType` of 'foo', and `SomeParserPlugin` has 'foo' included
51 /// in its `GetDiscoveryTypes()` return value, `SomeParserPlugin` will parse
52 /// that discovery result.
53 ///
54 /// Another kind of 'type' within the parser plugin is the 'source type'. The
55 /// discovery type simply acts as a way to link a discovery result to a parser
56 /// plugin. On the other hand, a 'source type' acts as an umbrella type that
57 /// groups all of the discovery types together. For example, if a plugin handled
58 /// discovery types 'foo', 'bar', and 'baz' (which are all related because they
59 /// are all handled by the same parser), they may all be grouped under one
60 /// unifying source type. This type is available on the node via
61 /// `NdrNode::GetSourceType()`.
62 ///
63 /// \section create How to Create a Parser Plugin
64 /// There are three steps to creating a parser plugin:
65 /// <ul>
66 /// <li>
67 /// Implement the parser plugin interface. An example parser plugin is
68 /// available in the plugin folder under `sdrOsl`. The `Parse()` method
69 /// should return the specialized node that derives from `NdrNode` (and
70 /// this node should also be constructed with its specialized
71 /// properties). Examples of a specialized node and property class are
72 /// `SdrShaderNode` and `SdrShaderProperty`.
73 /// </li>
74 /// <li>
75 /// Register your new plugin with the registry. The registration macro
76 /// must be called in your plugin's implementation file:
77 /// \code{.cpp}
78 /// NDR_REGISTER_PARSER_PLUGIN(<YOUR_PARSER_PLUGIN_CLASS_NAME>)
79 /// \endcode
80 /// This macro is available in parserPlugin.h.
81 /// </li>
82 /// <li>
83 /// In the same folder as your plugin, create a `plugInfo.json` file.
84 /// This file must be formatted like so, substituting
85 /// `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`, and `YOUR_DISPLAY_NAME`:
86 /// \code{.json}
87 /// {
88 /// "Plugins": [{
89 /// "Type": "library",
90 /// "Name": "YOUR_LIBRARY_NAME",
91 /// "Root": "@PLUG_INFO_ROOT@",
92 /// "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@",
93 /// "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@",
94 /// "Info": {
95 /// "Types": {
96 /// "YOUR_CLASS_NAME" : {
97 /// "bases": ["NdrParserPlugin"],
98 /// "displayName": "YOUR_DISPLAY_NAME"
99 /// }
100 /// }
101 /// }
102 /// }]
103 /// }
104 /// \endcode
105 ///
106 /// The SDR ships with one parser plugin, the `SdrOslParserPlugin`. Take
107 /// a look at its plugInfo.json file for example values for
108 /// `YOUR_LIBRARY_NAME`, `YOUR_CLASS_NAME`, and `YOUR_DISPLAY_NAME`. If
109 /// multiple parser plugins exist in the same folder, you can continue
110 /// adding additional plugins under the `Types` key in the JSON. More
111 /// detailed information about the plugInfo.json format can be found in
112 /// the documentation for the `plug` library (in pxr/base).
113 /// </li>
114 /// </ul>
115 ///
116 /// \deprecated
117 /// Deprecated in favor of SdrParserPlugin
119 {
120 public:
121  NDR_API
122  NdrParserPlugin();
123  NDR_API
124  virtual ~NdrParserPlugin();
125 
126  /// Takes the specified `NdrNodeDiscoveryResult` instance, which was a
127  /// result of the discovery process, and generates a new `NdrNode`.
128  /// The node's name, source type, and family must match.
129  ///
130  /// \deprecated
131  /// Deprecated in favor of SdrParserPlugin::ParseShaderNode
132  NDR_API
133  virtual NdrNodeUniquePtr Parse(
134  const NdrNodeDiscoveryResult& discoveryResult) = 0;
135 
136  /// Returns the types of nodes that this plugin can parse.
137  ///
138  /// "Type" here is the discovery type (in the case of files, this will
139  /// probably be the file extension, but in other systems will be data that
140  /// can be determined during discovery). This type should only be used to
141  /// match up a `NdrNodeDiscoveryResult` to its parser plugin; this value is
142  /// not exposed in the node's API.
143  NDR_API
144  virtual const NdrTokenVec& GetDiscoveryTypes() const = 0;
145 
146  /// Returns the source type that this parser operates on.
147  ///
148  /// A source type is the most general type for a node. The parser plugin is
149  /// responsible for parsing all discovery results that have the types
150  /// declared under `GetDiscoveryTypes()`, and those types are collectively
151  /// identified as one "source type".
152  NDR_API
153  virtual const TfToken& GetSourceType() const = 0;
154 
155  /// Gets an invalid node based on the discovery result provided. An invalid
156  /// node is a node that has no properties, but may have basic data found
157  /// during discovery.
158  ///
159  /// \deprecated
160  /// Deprecated in favor of SdrParserPlugin::GetInvalidShaderNode
161  NDR_API
163 };
164 
165 
166 /// \cond
167 /// Factory classes should be hidden from the documentation.
168 ///
169 /// \deprecated
170 /// Deprecated in favor of SdrParserPluginFactoryBase and
171 /// SdrParserPluginFactoryBase
172 class NdrParserPluginFactoryBase : public TfType::FactoryBase
173 {
174 public:
175  virtual NdrParserPlugin* New() const = 0;
176 };
177 
178 template <class T>
179 class NdrParserPluginFactory : public NdrParserPluginFactoryBase
180 {
181 public:
182  virtual NdrParserPlugin* New() const
183  {
184  return new T;
185  }
186 };
187 
188 /// \endcond
189 
191 
192 #endif // PXR_USD_NDR_PARSER_PLUGIN_H
NDR_API NdrParserPlugin()
std::vector< TfToken > NdrTokenVec
Definition: declare.h:50
virtual NDR_API ~NdrParserPlugin()
virtual NDR_API const NdrTokenVec & GetDiscoveryTypes() const =0
static NDR_API NdrNodeUniquePtr GetInvalidNode(const NdrNodeDiscoveryResult &dr)
Base class of all factory types.
Definition: type.h:56
Definition: token.h:70
virtual NDR_API const TfToken & GetSourceType() const =0
#define NDR_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual NDR_API NdrNodeUniquePtr Parse(const NdrNodeDiscoveryResult &discoveryResult)=0
std::unique_ptr< NdrNode > NdrNodeUniquePtr
Definition: declare.h:65
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74