HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adapterRegistry.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 #ifndef PXR_USD_IMAGING_USD_IMAGING_ADAPTER_REGISTRY_H
8 #define PXR_USD_IMAGING_USD_IMAGING_ADAPTER_REGISTRY_H
9 
10 /// \file usdImaging/adapterRegistry.h
11 
12 #include "pxr/pxr.h"
14 #include "pxr/base/tf/singleton.h"
16 #include "pxr/base/tf/token.h"
17 #include "pxr/base/tf/type.h"
18 
19 #include <unordered_map>
20 
22 
23 
25 using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
26 
29  std::shared_ptr<UsdImagingAPISchemaAdapter>;
30 
31 #define USD_IMAGING_ADAPTER_KEY_TOKENS \
32  ((instanceAdapterKey, "__instanceAdapter")) \
33  ((drawModeAdapterKey, "__drawModeAdapter")) \
34 
35 TF_DECLARE_PUBLIC_TOKENS(UsdImagingAdapterKeyTokens,
38 
39 /// \class UsdImagingAdapterRegistry
40 ///
41 /// Registry of PrimAdapter plug-ins. Note: this is a registry of adapter
42 /// factories, and not adapter instances; we expect to store adapter instances
43 /// (created via ConstructAdapter) with per-stage data.
44 ///
45 class UsdImagingAdapterRegistry : public TfSingleton<UsdImagingAdapterRegistry>
46 {
49 
50  typedef std::unordered_map<TfToken,TfType,TfToken::HashFunctor> _TypeMap;
51  _TypeMap _typeMap;
52  TfTokenVector _adapterKeys;
53  _TypeMap _apiSchemaTypeMap;
54  TfTokenVector _apiSchemaAdapterKeys;
55 
56  typedef std::vector<TfType> _TypeVector;
57  _TypeVector _keylessApiSchemaAdapterTypes;
58 
59  template <typename T, typename factoryT>
60  std::shared_ptr<T> _ConstructAdapter(
61  TfToken const& adapterKey, const _TypeMap &tm);
62 
63  template <typename T, typename factoryT>
64  std::shared_ptr<T> _ConstructAdapter(
65  TfToken const& adapterKey, const TfType &adapterType);
66 
67 public:
68 
69  /// Returns true if external plugins are enabled.
70  /// Internal plugins have isInternal=1 set in their metadata. This flag is
71  /// only intended to be set for critical imaging plugins (mesh, cube,
72  /// sphere, curve, etc). This allows users to disable plugins that are
73  /// crashing or executing slowly.
74  ///
75  /// Driven by by the USDIMAGING_ENABLE_PLUGINS environment variable.
77  static bool AreExternalPluginsEnabled();
78 
82  }
83 
84  /// Returns true if an adapter has been registered to handle the given
85  /// \p adapterKey.
87  bool HasAdapter(TfToken const& adapterKey);
88 
89  /// Returns a new instance of the UsdImagingPrimAdapter that has been
90  /// registered to handle the given \p adapterKey. This key is either
91  /// a prim typename or a key specified in UsdImagingAdapterKeyTokens.
92  /// Returns NULL if no adapter was registered for this key.
95 
96  /// Returns the set of adapter keys this class responds to; i.e. the set of
97  /// usd prim types for which we've registered a prim adapter.
100 
101  /// Returns true if an api schema adapter has been registered to handle
102  /// the given \p adapterKey.
104  bool HasAPISchemaAdapter(TfToken const& adapterKey);
105 
106  /// Returns a new instance of the UsdImagingAPISchemaAdapter that has been
107  /// registered to handle the given \p adapterKey.
108  /// Returns NULL if no adapter was registered for this key.
111  TfToken const& adapterKey);
112 
113  /// Returns the set of api schema adapter keys this class responds to;
114  /// i.e. the set of usd api schema types for which we've registered an
115  /// adapter.
118 
119  using ApiSchemaAdapters = std::vector<UsdImagingAPISchemaAdapterSharedPtr>;
120 
121  /// Constructs instances of "keyless" api schema adapters which are
122  /// intended to run for every prim.
125 
126 };
127 
129 
131 
132 #endif //PXR_USD_IMAGING_USD_IMAGING_ADAPTER_REGISTRY_H
static T & GetInstance()
Definition: singleton.h:120
#define USDIMAGING_API
Definition: api.h:23
USDIMAGING_API bool HasAdapter(TfToken const &adapterKey)
USDIMAGING_API UsdImagingAPISchemaAdapterSharedPtr ConstructAPISchemaAdapter(TfToken const &adapterKey)
#define USD_IMAGING_ADAPTER_KEY_TOKENS
USDIMAGING_API ApiSchemaAdapters ConstructKeylessAPISchemaAdapters()
USDIMAGING_API_TEMPLATE_CLASS(TfSingleton< UsdImagingAdapterRegistry >)
std::shared_ptr< UsdImagingAPISchemaAdapter > UsdImagingAPISchemaAdapterSharedPtr
Definition: token.h:70
static USDIMAGING_API bool AreExternalPluginsEnabled()
USDIMAGING_API UsdImagingPrimAdapterSharedPtr ConstructAdapter(TfToken const &adapterKey)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USDIMAGING_API const TfTokenVector & GetAPISchemaAdapterKeys()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDIMAGING_API const TfTokenVector & GetAdapterKeys()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
Definition: type.h:47
std::vector< UsdImagingAPISchemaAdapterSharedPtr > ApiSchemaAdapters
USDIMAGING_API bool HasAPISchemaAdapter(TfToken const &adapterKey)
static USDIMAGING_API UsdImagingAdapterRegistry & GetInstance()
TF_DECLARE_PUBLIC_TOKENS(UsdImagingAdapterKeyTokens, USDIMAGING_API, USD_IMAGING_ADAPTER_KEY_TOKENS)