This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
registry.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_KIND_REGISTRY_H
8#define PXR_USD_KIND_REGISTRY_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/kind/api.h"
17#include "pxr/base/tf/token.h"
18
19#include <unordered_map>
20#include <vector>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
25#define KIND_TOKENS \
26 (model) \
27 (component) \
28 (group) \
29 (assembly) \
30 (subcomponent)
31
36TF_DECLARE_PUBLIC_TOKENS(KindTokens, KIND_API, KIND_TOKENS);
37
54{
55 KindRegistry(const KindRegistry&) = delete;
56 KindRegistry& operator=(const KindRegistry&) = delete;
57public:
59 KIND_API static KindRegistry& GetInstance();
60
62 KIND_API static bool HasKind(const TfToken& kind);
63
67 KIND_API static TfToken GetBaseKind(const TfToken &kind);
68
78 KIND_API static bool IsA(const TfToken& derivedKind, const TfToken &baseKind);
79
81 KIND_API static std::vector<TfToken> GetAllKinds();
82
84 KIND_API static bool IsModel(const TfToken& kind);
85
87 KIND_API static bool IsGroup(const TfToken& kind);
88
90 KIND_API static bool IsAssembly(const TfToken& kind);
91
93 KIND_API static bool IsComponent(const TfToken& kind);
94
96 KIND_API static bool IsSubComponent(const TfToken& kind);
97
98private:
99 friend class TfSingleton<KindRegistry>;
100
101 KindRegistry();
102 virtual ~KindRegistry();
103
104 bool _HasKind(const TfToken& kind) const;
105
106 TfToken _GetBaseKind(const TfToken &kind) const;
107
108 bool _IsA(const TfToken& derivedKind, const TfToken &baseKind) const;
109
110 std::vector<TfToken> _GetAllKinds() const;
111
115 void _Register(const TfToken& kind,
116 const TfToken& baseKind = TfToken());
117
118 void _RegisterDefaults();
119
120 struct _KindData {
121 TfToken baseKind;
122 };
123
124 typedef std::unordered_map<TfToken, _KindData, TfToken::HashFunctor>
125 _KindMap;
126
127private:
128 _KindMap _kindMap;
129};
130
131KIND_API_TEMPLATE_CLASS(TfSingleton<KindRegistry>);
132
133PXR_NAMESPACE_CLOSE_SCOPE
134
135#endif // PXR_USD_KIND_REGISTRY_H
A singleton that holds known kinds and information about them.
Definition: registry.h:54
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:105
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
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:81
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...