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 
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usdImaging/usdImaging/api.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 
21 PXR_NAMESPACE_OPEN_SCOPE
22 
23 
25 using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
26 
28 using UsdImagingAPISchemaAdapterSharedPtr =
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,
36  USDIMAGING_API,
37  USD_IMAGING_ADAPTER_KEY_TOKENS);
38 
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 
76  USDIMAGING_API
77  static bool AreExternalPluginsEnabled();
78 
79  USDIMAGING_API
82  }
83 
86  USDIMAGING_API
87  bool HasAdapter(TfToken const& adapterKey);
88 
93  USDIMAGING_API
94  UsdImagingPrimAdapterSharedPtr ConstructAdapter(TfToken const& adapterKey);
95 
98  USDIMAGING_API
100 
103  USDIMAGING_API
104  bool HasAPISchemaAdapter(TfToken const& adapterKey);
105 
109  USDIMAGING_API
110  UsdImagingAPISchemaAdapterSharedPtr ConstructAPISchemaAdapter(
111  TfToken const& adapterKey);
112 
116  USDIMAGING_API
118 
119  using ApiSchemaAdapters = std::vector<UsdImagingAPISchemaAdapterSharedPtr>;
120 
123  USDIMAGING_API
124  ApiSchemaAdapters ConstructKeylessAPISchemaAdapters();
125 
126 };
127 
128 USDIMAGING_API_TEMPLATE_CLASS(TfSingleton<UsdImagingAdapterRegistry>);
129 
130 PXR_NAMESPACE_CLOSE_SCOPE
131 
132 #endif //PXR_USD_IMAGING_USD_IMAGING_ADAPTER_REGISTRY_H
Manage a single instance of an object.
Manage a single instance of an object (see.
Definition: singleton.h:107
USDIMAGING_API const TfTokenVector & GetAPISchemaAdapterKeys()
Returns the set of api schema adapter keys this class responds to; i.e.
Base class for all API schema adapters.
USDIMAGING_API ApiSchemaAdapters ConstructKeylessAPISchemaAdapters()
Constructs instances of "keyless" api schema adapters which are intended to run for every prim.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:80
USDIMAGING_API bool HasAdapter(TfToken const &adapterKey)
Returns true if an adapter has been registered to handle the given adapterKey.
Base class for all PrimAdapters.
Definition: primAdapter.h:52
USDIMAGING_API UsdImagingPrimAdapterSharedPtr ConstructAdapter(TfToken const &adapterKey)
Returns a new instance of the UsdImagingPrimAdapter that has been registered to handle the given adap...
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92
USDIMAGING_API const TfTokenVector & GetAdapterKeys()
Returns the set of adapter keys this class responds to; i.e.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:489
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:122
USDIMAGING_API UsdImagingAPISchemaAdapterSharedPtr ConstructAPISchemaAdapter(TfToken const &adapterKey)
Returns a new instance of the UsdImagingAPISchemaAdapter that has been registered to handle the given...
This file defines some macros that are useful for declaring and using static TfTokens.
Registry of PrimAdapter plug-ins.
TfType represents a dynamic runtime type.
Definition: type.h:47
static USDIMAGING_API bool AreExternalPluginsEnabled()
Returns true if external plugins are enabled.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
USDIMAGING_API bool HasAPISchemaAdapter(TfToken const &adapterKey)
Returns true if an api schema adapter has been registered to handle the given adapterKey.