Loading...
Searching...
No Matches
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 PXR_USD_KIND_REGISTRY_H
25#define PXR_USD_KIND_REGISTRY_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usd/kind/api.h"
34#include "pxr/base/tf/token.h"
35
36#include <unordered_map>
37#include <vector>
38
39PXR_NAMESPACE_OPEN_SCOPE
40
42#define KIND_TOKENS \
43 (model) \
44 (component) \
45 (group) \
46 (assembly) \
47 (subcomponent)
48
53TF_DECLARE_PUBLIC_TOKENS(KindTokens, KIND_API, KIND_TOKENS);
54
71{
72 KindRegistry(const KindRegistry&) = delete;
73 KindRegistry& operator=(const KindRegistry&) = delete;
74public:
76 KIND_API static KindRegistry& GetInstance();
77
79 KIND_API static bool HasKind(const TfToken& kind);
80
84 KIND_API static TfToken GetBaseKind(const TfToken &kind);
85
95 KIND_API static bool IsA(const TfToken& derivedKind, const TfToken &baseKind);
96
98 KIND_API static std::vector<TfToken> GetAllKinds();
99
101 KIND_API static bool IsModel(const TfToken& kind);
102
104 KIND_API static bool IsGroup(const TfToken& kind);
105
107 KIND_API static bool IsAssembly(const TfToken& kind);
108
110 KIND_API static bool IsComponent(const TfToken& kind);
111
113 KIND_API static bool IsSubComponent(const TfToken& kind);
114
115private:
116 friend class TfSingleton<KindRegistry>;
117
118 KindRegistry();
119 virtual ~KindRegistry();
120
121 bool _HasKind(const TfToken& kind) const;
122
123 TfToken _GetBaseKind(const TfToken &kind) const;
124
125 bool _IsA(const TfToken& derivedKind, const TfToken &baseKind) const;
126
127 std::vector<TfToken> _GetAllKinds() const;
128
132 void _Register(const TfToken& kind,
133 const TfToken& baseKind = TfToken());
134
135 void _RegisterDefaults();
136
137 struct _KindData {
138 TfToken baseKind;
139 };
140
141 typedef std::unordered_map<TfToken, _KindData, TfToken::HashFunctor>
142 _KindMap;
143
144private:
145 _KindMap _kindMap;
146};
147
148KIND_API_TEMPLATE_CLASS(TfSingleton<KindRegistry>);
149
150PXR_NAMESPACE_CLOSE_SCOPE
151
152#endif // PXR_USD_KIND_REGISTRY_H
A singleton that holds known kinds and information about them.
Definition: registry.h:71
static KIND_API bool IsAssembly(const TfToken &kind)
Return true if kind IsA assembly kind.
static KIND_API bool IsGroup(const TfToken &kind)
Returns true if kind IsA group kind.
static KIND_API bool HasKind(const TfToken &kind)
Test whether kind is known to the registry.
static KIND_API KindRegistry & GetInstance()
Return the single KindRegistry instance.
static KIND_API bool IsSubComponent(const TfToken &kind)
Returns true if kind IsA subcomponent kind.
static KIND_API TfToken GetBaseKind(const TfToken &kind)
Return the base kind of the given kind.
static KIND_API std::vector< TfToken > GetAllKinds()
Return an unordered vector of all kinds known to the registry.
static KIND_API bool IsModel(const TfToken &kind)
Returns true if kind IsA model kind.
static KIND_API bool IsComponent(const TfToken &kind)
Returns true if kind IsA component kind.
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...
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:88
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
Manage a single instance of an object.
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:98
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...