All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pluginEntry.h
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 HF_PLUGIN_ENTRY_H
25 #define HF_PLUGIN_ENTRY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/tf/token.h"
29 #include "pxr/base/tf/type.h"
30 #include "pxr/imaging/hf/perfLog.h"
31 #include <string>
32 #include <functional>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
36 class HfPluginBase;
37 struct HfPluginDesc;
38 
39 
40 
44 class Hf_PluginEntry final {
45 public:
46  HF_MALLOC_TAG_NEW("new Hf_PluginEntry");
47 
55  typedef std::function<HfPluginBase *()> _PluginFactoryFn;
56 
61  Hf_PluginEntry(const TfType &type,
62  const std::string &displayName,
63  int priority);
64  ~Hf_PluginEntry();
65 
69  Hf_PluginEntry(Hf_PluginEntry &&source);
70  Hf_PluginEntry &operator =(Hf_PluginEntry &&source);
71 
75  const TfType &GetType() const { return _type; }
76  const std::string &GetDisplayName() const { return _displayName; }
77  int GetPriority() const { return _priority; }
78  HfPluginBase *GetInstance() const { return _instance; }
79 
83  TfToken GetId() const;
84 
89  void GetDesc(HfPluginDesc *desc) const;
90 
95  void IncRefCount();
96  void DecRefCount();
97 
102  bool operator <(const Hf_PluginEntry &other) const;
103 
107  static void SetFactory(TfType &type, _PluginFactoryFn &func);
108 
109 private:
117  class _Factory final : public TfType::FactoryBase
118  {
119  public:
120 
121  _Factory(_PluginFactoryFn &func) : _func(func) {}
122 
123  HfPluginBase *New() const { return _func(); }
124 
125  private:
126  _PluginFactoryFn _func;
127  };
128 
129 
130  TfType _type;
131  std::string _displayName;
132  int _priority;
133  HfPluginBase *_instance;
134  int _refCount;
135 
139  Hf_PluginEntry() = delete;
140  Hf_PluginEntry(const Hf_PluginEntry &) = delete;
141  Hf_PluginEntry &operator =(const Hf_PluginEntry &) = delete;
142 };
143 
144 
145 
146 PXR_NAMESPACE_CLOSE_SCOPE
147 
148 #endif // HF_PLUGIN_ENTRY_H
Base class for all hydra plugin classes.
Definition: pluginBase.h:39
Base class of all factory types.
Definition: type.h:79
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
TfType represents a dynamic runtime type.
Definition: type.h:70
Common structure used to report registered plugins in one of the plugin registries.
Definition: pluginDesc.h:47