All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
registry.h
Go to the documentation of this file.
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 KIND_REGISTRY_H
25 #define KIND_REGISTRY_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/kind/api.h"
31 #include "pxr/base/tf/weakBase.h"
32 #include "pxr/base/tf/singleton.h"
33 #include "pxr/base/tf/staticTokens.h"
34 #include "pxr/base/tf/token.h"
35 
36 #include <boost/noncopyable.hpp>
37 #include <unordered_map>
38 #include <vector>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
43 #define KIND_TOKENS \
44  (model) \
45  (component) \
46  (group) \
47  (assembly) \
48  (subcomponent)
49 
54 TF_DECLARE_PUBLIC_TOKENS(KindTokens, KIND_API, KIND_TOKENS);
55 
71 class KindRegistry : public TfWeakBase, boost::noncopyable
72 {
73 public:
75  KIND_API static KindRegistry& GetInstance();
76 
78  KIND_API static bool HasKind(const TfToken& kind);
79 
83  KIND_API static TfToken GetBaseKind(const TfToken &kind);
84 
94  KIND_API static bool IsA(const TfToken& derivedKind, const TfToken &baseKind);
95 
97  KIND_API static std::vector<TfToken> GetAllKinds();
98 
99 private:
100  friend class TfSingleton<KindRegistry>;
101 
102  KindRegistry();
103  virtual ~KindRegistry();
104 
105  bool _HasKind(const TfToken& kind) const;
106 
107  TfToken _GetBaseKind(const TfToken &kind) const;
108 
109  bool _IsA(const TfToken& derivedKind, const TfToken &baseKind) const;
110 
111  std::vector<TfToken> _GetAllKinds() const;
112 
116  void _Register(const TfToken& kind,
117  const TfToken& baseKind = TfToken());
118 
119  void _RegisterDefaults();
120 
121  struct _KindData {
122  TfToken baseKind;
123  };
124 
125  typedef std::unordered_map<TfToken, _KindData, TfToken::HashFunctor>
126  _KindMap;
127 
128 private:
129  _KindMap _kindMap;
130 };
131 
132 KIND_API_TEMPLATE_CLASS(TfSingleton<KindRegistry>);
133 
134 PXR_NAMESPACE_CLOSE_SCOPE
135 
136 #endif // KIND_REGISTRY_H
Manage a single instance of an object (see.
Definition: singleton.h:122
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
A singleton that holds known kinds and information about them.
Definition: registry.h:71
static KIND_API bool IsA(const TfToken &derivedKind, const TfToken &baseKind)
Test whether derivedKind is the same as baseKind or has it as a base kind (either directly or indirec...
static KIND_API TfToken GetBaseKind(const TfToken &kind)
Return the base kind of the given kind.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
static KIND_API KindRegistry & GetInstance()
Return the single KindRegistry instance.
static KIND_API std::vector< TfToken > GetAllKinds()
Return an unordered vector of all kinds known to the registry.
static KIND_API bool HasKind(const TfToken &kind)
Test whether kind is known to the registry.
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142