All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
schemaRegistry.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 PXR_USD_USD_SCHEMA_REGISTRY_H
25 #define PXR_USD_USD_SCHEMA_REGISTRY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/common.h"
30 
31 #include "pxr/usd/sdf/layer.h"
32 #include "pxr/usd/sdf/primSpec.h"
33 
34 #include "pxr/base/tf/hash.h"
35 #include "pxr/base/tf/singleton.h"
36 #include "pxr/base/tf/hashmap.h"
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 SDF_DECLARE_HANDLES(SdfAttributeSpec);
41 SDF_DECLARE_HANDLES(SdfRelationshipSpec);
42 
43 class UsdPrimDefinition;
44 
64 class UsdSchemaRegistry : public TfWeakBase, boost::noncopyable {
65 public:
66  USD_API
67  static UsdSchemaRegistry& GetInstance() {
69  }
70 
73  USD_API
74  static TfToken GetSchemaTypeName(const TfType &schemaType);
75 
78  template <class SchemaType>
79  static
81  return GetSchemaTypeName(SchemaType::_GetStaticTfType());
82  }
83 
86  USD_API
87  static TfToken GetConcreteSchemaTypeName(const TfType &schemaType);
88 
91  USD_API
92  static TfToken GetAPISchemaTypeName(const TfType &schemaType);
93 
96  USD_API
97  static TfType GetTypeFromSchemaTypeName(const TfToken &typeName);
98 
101  USD_API
102  static TfType GetConcreteTypeFromSchemaTypeName(const TfToken &typeName);
103 
106  USD_API
107  static TfType GetAPITypeFromSchemaTypeName(const TfToken &typeName);
108 
116  USD_API
117  static bool IsDisallowedField(const TfToken &fieldName);
118 
120  USD_API
121  static bool IsTyped(const TfType& primType);
122 
128  USD_API
129  static UsdSchemaKind GetSchemaKind(const TfType &schemaType);
130 
136  USD_API
137  static UsdSchemaKind GetSchemaKind(const TfToken &typeName);
138 
141  USD_API
142  static bool IsConcrete(const TfType& primType);
143 
146  USD_API
147  static bool IsConcrete(const TfToken& primType);
148 
150  USD_API
151  static bool IsAppliedAPISchema(const TfType& apiSchemaType);
152 
154  USD_API
155  static bool IsAppliedAPISchema(const TfToken& apiSchemaType);
156 
158  USD_API
159  static bool IsMultipleApplyAPISchema(const TfType& apiSchemaType);
160 
162  USD_API
163  static bool IsMultipleApplyAPISchema(const TfToken& apiSchemaType);
164 
187  USD_API
188  static TfType GetTypeFromName(const TfToken& typeName);
189 
210  USD_API
211  static std::pair<TfToken, TfToken> GetTypeNameAndInstance(
212  const TfToken &apiSchemaName);
213 
223  USD_API
224  static bool IsAllowedAPISchemaInstanceName(
225  const TfToken &apiSchemaName,
226  const TfToken &instanceName);
227 
240  USD_API
242  const TfToken &apiSchemaName,
243  const TfToken &instanceName = TfToken());
244 
253  USD_API
254  static const std::map<TfToken, TfTokenVector> &GetAutoApplyAPISchemas();
255 
267  USD_API
269  std::map<TfToken, TfTokenVector> *autoApplyAPISchemas);
270 
273  USD_API
275  const TfToken &multiApplyAPISchemaName) const;
276 
281  const TfToken &typeName) const {
282  auto it = _concreteTypedPrimDefinitions.find(typeName);
283  return it != _concreteTypedPrimDefinitions.end() ? it->second : nullptr;
284  }
285 
290  const TfToken &typeName) const {
291  auto it = _appliedAPIPrimDefinitions.find(typeName);
292  return it != _appliedAPIPrimDefinitions.end() ? it->second : nullptr;
293  }
294 
297  return _emptyPrimDefinition;
298  }
299 
304  USD_API
305  std::unique_ptr<UsdPrimDefinition>
307  const TfToken &primType, const TfTokenVector &appliedAPISchemas) const;
308 
321  return _fallbackPrimTypes;
322  }
323 
324 private:
325  friend class TfSingleton<UsdSchemaRegistry>;
326 
328 
329  void _FindAndAddPluginSchema();
330 
331  void _ApplyAPISchemasToPrimDefinition(
332  UsdPrimDefinition *primDef, const TfTokenVector &appliedAPISchemas) const;
333 
334  SdfLayerRefPtr _schematics;
335  typedef TfHashMap<TfToken, UsdPrimDefinition *,
336  TfToken::HashFunctor> _TypeNameToPrimDefinitionMap;
337 
338  _TypeNameToPrimDefinitionMap _concreteTypedPrimDefinitions;
339  _TypeNameToPrimDefinitionMap _appliedAPIPrimDefinitions;
340  UsdPrimDefinition *_emptyPrimDefinition;
341 
342  TfHashMap<TfToken, TfToken, TfToken::HashFunctor>
343  _multipleApplyAPISchemaNamespaces;
344 
345  VtDictionary _fallbackPrimTypes;
346 
347  friend class UsdPrimDefinition;
348 };
349 
350 USD_API_TEMPLATE_CLASS(TfSingleton<UsdSchemaRegistry>);
351 
352 // Utility function for extracting the metadata about applying API schemas from
353 // the plugin metadata for the schema's type. It is useful for certain clients
354 // to be able to access this plugin data in the same way that the
355 // UsdSchemaRegistry does.
356 void Usd_GetAPISchemaPluginApplyToInfoForType(
357  const TfType &apiSchemaType,
358  const TfToken &apiSchemaName,
359  std::map<TfToken, TfTokenVector> *autoApplyAPISchemasMap,
360  TfHashMap<TfToken, TfTokenVector, TfHash> *canOnlyApplyAPISchemasMap,
361  TfHashMap<TfToken, TfToken::Set, TfHash> *allowedInstanceNamesMap);
362 
363 PXR_NAMESPACE_CLOSE_SCOPE
364 
365 #endif //PXR_USD_USD_SCHEMA_REGISTRY_H
static USD_API bool IsMultipleApplyAPISchema(const TfType &apiSchemaType)
Returns true if apiSchemaType is a multiple-apply API schema type.
Manage a single instance of an object.
static USD_API const TfTokenVector & GetAPISchemaCanOnlyApplyToTypeNames(const TfToken &apiSchemaName, const TfToken &instanceName=TfToken())
Returns a list of prim type names that the given apiSchemaName can only be applied to...
Manage a single instance of an object (see.
Definition: singleton.h:122
static USD_API TfToken GetAPISchemaTypeName(const TfType &schemaType)
Return the type name in the USD schema for API schema types only from the given registered schemaType...
A map with string keys and VtValue values.
Definition: dictionary.h:63
Functor to use for hash maps from tokens to other things.
Definition: token.h:166
const VtDictionary & GetFallbackPrimTypes() const
Returns a dictionary mapping concrete schema prim type names to a VtTokenArray of fallback prim type ...
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:127
static USD_API bool IsAppliedAPISchema(const TfType &apiSchemaType)
Returns true if apiSchemaType is an applied API schema type.
static USD_API bool IsAllowedAPISchemaInstanceName(const TfToken &apiSchemaName, const TfToken &instanceName)
Returns true if the given instanceName is an allowed instance name for the multiple apply API schema ...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
A subclass of SdfPropertySpec that holds typed data.
Definition: attributeSpec.h:56
static USD_API std::pair< TfToken, TfToken > GetTypeNameAndInstance(const TfToken &apiSchemaName)
Returns the schema type name and the instance name parsed from the given apiSchemaName.
USD_API TfToken GetPropertyNamespacePrefix(const TfToken &multiApplyAPISchemaName) const
Returns the namespace prefix that is prepended to all properties of the given multiApplyAPISchemaName...
static USD_API UsdSchemaKind GetSchemaKind(const TfType &schemaType)
Returns the kind of the schema the given schemaType represents.
USD_API std::unique_ptr< UsdPrimDefinition > BuildComposedPrimDefinition(const TfToken &primType, const TfTokenVector &appliedAPISchemas) const
Composes and returns a new UsdPrimDefinition from the given primType and list of appliedSchemas.
static USD_API void CollectAddtionalAutoApplyAPISchemasFromPlugins(std::map< TfToken, TfTokenVector > *autoApplyAPISchemas)
Collects all the additional auto apply schemas that can be defined in a plugin through &quot;AutoApplyAPIS...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:137
static USD_API TfType GetTypeFromSchemaTypeName(const TfToken &typeName)
Return the TfType of the schema corresponding to the given prim or API schema name typeName...
static USD_API bool IsDisallowedField(const TfToken &fieldName)
Returns true if the field fieldName cannot have fallback values specified in schemas.
A property that contains a reference to one or more SdfPrimSpec instances.
static USD_API bool IsConcrete(const TfType &primType)
Returns true if the prim type primType is instantiable in scene description.
static USD_API TfType GetConcreteTypeFromSchemaTypeName(const TfToken &typeName)
Return the TfType of the schema corresponding to the given concrete prim type name typeName...
Class representing the builtin definition of a prim given the schemas registered in the schema regist...
static USD_API TfType GetAPITypeFromSchemaTypeName(const TfToken &typeName)
Return the TfType of the schema corresponding to the given API schema type name typeName.
static TfToken GetSchemaTypeName()
Return the type name in the USD schema for prims or API schemas of the given registered SchemaType...
static USD_API bool IsTyped(const TfType &primType)
Returns true if the prim type primType inherits from UsdTyped.
static USD_API TfType GetTypeFromName(const TfToken &typeName)
Finds the TfType of a schema with typeName.
TfType represents a dynamic runtime type.
Definition: type.h:64
static USD_API const std::map< TfToken, TfTokenVector > & GetAutoApplyAPISchemas()
Returns a map of the names of all registered auto apply API schemas to the list of type names each is...
Singleton registry that provides access to schema type information and the prim definitions for regis...
const UsdPrimDefinition * FindAppliedAPIPrimDefinition(const TfToken &typeName) const
Finds the prim definition for the given typeName token if typeName is a registered applied API schema...
static USD_API TfToken GetConcreteSchemaTypeName(const TfType &schemaType)
Return the type name in the USD schema for concrete prim types only from the given registered schemaT...
const UsdPrimDefinition * GetEmptyPrimDefinition() const
Returns the empty prim definition.
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
const UsdPrimDefinition * FindConcretePrimDefinition(const TfToken &typeName) const
Finds the prim definition for the given typeName token if typeName is a registered concrete typed sch...