7#ifndef PXR_USD_SDF_SCHEMA_H
8#define PXR_USD_SDF_SCHEMA_H
11#include "pxr/usd/sdf/api.h"
14#include "pxr/usd/sdf/valueTypeName.h"
16#include "pxr/base/plug/notice.h"
18#include "pxr/base/tf/hashmap.h"
22#include "pxr/base/tf/type.h"
24#include "pxr/base/vt/value.h"
30PXR_NAMESPACE_OPEN_SCOPE
36class Sdf_ValueTypeRegistry;
63 typedef std::vector< std::pair<TfToken, JsValue> > InfoVec;
65 SDF_API
const TfToken& GetName()
const;
66 SDF_API
const VtValue& GetFallbackValue()
const;
67 SDF_API
const InfoVec& GetInfo()
const;
69 SDF_API
bool IsPlugin()
const;
70 SDF_API
bool IsReadOnly()
const;
71 SDF_API
bool HoldsChildren()
const;
80 return (_valueValidator ?
81 _valueValidator(_schema,
VtValue(value)) :
86 SdfAllowed IsValidListValue(
const T& value)
const
88 return (_listValueValidator ?
89 _listValueValidator(_schema,
VtValue(value)) :
96 return (_mapKeyValidator ?
97 _mapKeyValidator(_schema,
VtValue(value)) :
102 SdfAllowed IsValidMapValue(
const T& value)
const
104 return (_mapValueValidator ?
105 _mapValueValidator(_schema,
VtValue(value)) :
140 Validator _valueValidator;
141 Validator _listValueValidator;
142 Validator _mapKeyValidator;
143 Validator _mapValueValidator;
149 _FieldInfo(): required(false), metadata(false) { }
155 class SpecDefinition;
168 return _requiredFields;
191 typedef TfHashMap<TfToken, _FieldInfo, TfToken::HashFunctor>
201 void _AddField(
const TfToken& name,
const _FieldInfo& fieldInfo);
212 #ifdef PXR_PREFER_SAFETY_OVER_SPEED
213 if (ARCH_UNLIKELY(specType < SdfSpecTypeUnknown ||
214 specType >= SdfNumSpecTypes))
216 return _IssueErrorForInvalidSpecType(specType);
220 return _specDefinitions[specType].second ?
221 &_specDefinitions[specType].first :
nullptr;
261 TfToken const &metadataField)
const;
271 for (
TfToken const &fname: _requiredFieldNames) {
272 if (fname == fieldName) {
289 static SdfAllowed IsValidIdentifier(
const std::string& name);
291 static SdfAllowed IsValidNamespacedIdentifier(
const std::string& name);
309 static SdfAllowed IsValidSubLayer(
const std::string& sublayer);
311 static SdfAllowed IsValidVariantIdentifier(
const std::string& name);
313 static SdfAllowed IsValidVariantSelection(
const std::string& sel);
371 const TfToken& name,
bool required =
false);
373 const TfToken& name,
bool required =
false);
376 bool required =
false);
385 , _definition(definition)
404 Type(
const TfToken& name,
const T& defaultValue)
408 Type(
char const *name,
const T& defaultValue)
419 Type& CPPTypeName(
const std::string& cppTypeName);
425 Type& DefaultUnit(
TfEnum unit);
428 Type& Role(
const TfToken& role);
436 const VtValue& defaultArrayValue);
439 std::unique_ptr<_Impl> _impl;
448 Sdf_ValueTypeRegistry* _registry;
469 const TfToken &fieldKey,
const T &fallback,
bool plugin =
false)
471 return _CreateField(fieldKey,
VtValue(fallback), plugin);
478 _specDefinitions[type].second =
true;
479 return _SpecDefiner(
this, &_specDefinitions[type].first);
505 typedef std::function<
VtValue(
const std::string&,
const JsValue&)>
510 const std::vector<const SdfSchemaBase::FieldDefinition *>
512 const std::string& metadataTag =
527 void _AddRequiredFieldName(
const TfToken &name);
529 const SpecDefinition* _CheckAndGetSpecDefinition(
SdfSpecType type)
const;
532 const SpecDefinition* _IssueErrorForInvalidSpecType(
SdfSpecType specType)
const;
534 friend struct Sdf_SchemaFieldTypeRegistrar;
535 FieldDefinition& _CreateField(
536 const TfToken &fieldKey,
const VtValue &fallback,
bool plugin =
false);
539 FieldDefinition& _DoRegisterField(
const TfToken &fieldKey,
const T &fallback)
541 return _DoRegisterField(fieldKey,
VtValue(fallback));
544 FieldDefinition& _DoRegisterField(
551 _FieldDefinitionMap _fieldDefinitions;
554 std::pair<SdfSchemaBase::SpecDefinition, bool>
555 _specDefinitions[SdfNumSpecTypes];
557 std::unique_ptr<Sdf_ValueTypeRegistry> _valueTypeRegistry;
585#define SDF_FIELD_KEYS \
586 ((Active, "active")) \
587 ((AllowedTokens, "allowedTokens")) \
588 ((AssetInfo, "assetInfo")) \
589 ((ColorConfiguration, "colorConfiguration")) \
590 ((ColorManagementSystem, "colorManagementSystem")) \
591 ((ColorSpace, "colorSpace")) \
592 ((Comment, "comment")) \
593 ((ConnectionPaths, "connectionPaths")) \
594 ((Custom, "custom")) \
595 ((CustomData, "customData")) \
596 ((CustomLayerData, "customLayerData")) \
597 ((Default, "default")) \
598 ((DefaultPrim, "defaultPrim")) \
599 ((DisplayGroup, "displayGroup")) \
600 ((DisplayGroupOrder, "displayGroupOrder")) \
601 ((DisplayName, "displayName")) \
602 ((DisplayUnit, "displayUnit")) \
603 ((Documentation, "documentation")) \
604 ((EndTimeCode, "endTimeCode")) \
605 ((ExpressionVariables, "expressionVariables")) \
606 ((FramePrecision, "framePrecision")) \
607 ((FramesPerSecond, "framesPerSecond")) \
608 ((Hidden, "hidden")) \
609 ((HasOwnedSubLayers, "hasOwnedSubLayers")) \
610 ((InheritPaths, "inheritPaths")) \
611 ((Instanceable, "instanceable")) \
613 ((LayerRelocates, "layerRelocates")) \
614 ((PrimOrder, "primOrder")) \
615 ((NoLoadHint, "noLoadHint")) \
617 ((Payload, "payload")) \
618 ((Permission, "permission")) \
619 ((Prefix, "prefix")) \
620 ((PrefixSubstitutions, "prefixSubstitutions")) \
621 ((PropertyOrder, "propertyOrder")) \
622 ((References, "references")) \
623 ((Relocates, "relocates")) \
624 ((SessionOwner, "sessionOwner")) \
625 ((Specializes, "specializes")) \
626 ((Specifier, "specifier")) \
627 ((Spline, "spline")) \
628 ((StartTimeCode, "startTimeCode")) \
629 ((SubLayers, "subLayers")) \
630 ((SubLayerOffsets, "subLayerOffsets")) \
631 ((Suffix, "suffix")) \
632 ((SuffixSubstitutions, "suffixSubstitutions")) \
633 ((SymmetricPeer, "symmetricPeer")) \
634 ((SymmetryArgs, "symmetryArgs")) \
635 ((SymmetryArguments, "symmetryArguments")) \
636 ((SymmetryFunction, "symmetryFunction")) \
637 ((TargetPaths, "targetPaths")) \
638 ((TimeSamples, "timeSamples")) \
639 ((TimeCodesPerSecond, "timeCodesPerSecond")) \
640 ((TypeName, "typeName")) \
641 ((VariantSelection, "variantSelection")) \
642 ((Variability, "variability")) \
643 ((VariantSetNames, "variantSetNames")) \
646 ((EndFrame, "endFrame")) \
647 ((StartFrame, "startFrame"))
649#define SDF_CHILDREN_KEYS \
650 ((ConnectionChildren, "connectionChildren")) \
651 ((ExpressionChildren, "expressionChildren")) \
652 ((MapperArgChildren, "mapperArgChildren")) \
653 ((MapperChildren, "mapperChildren")) \
654 ((PrimChildren, "primChildren")) \
655 ((PropertyChildren, "properties")) \
656 ((RelationshipTargetChildren, "targetChildren")) \
657 ((VariantChildren, "variantChildren")) \
658 ((VariantSetChildren, "variantSetChildren"))
663PXR_NAMESPACE_CLOSE_SCOPE
A discriminated union type for JSON values.
Notice sent after new plugins have been registered with the Plug registry.
Defines an interface to registered plugins.
Indicates if an operation is allowed and, if not, why not.
A path value used to locate objects in layers or scenegraphs.
Represents a payload and all its meta data.
Represents a reference and all its meta data.
Class that defines fields for a spec type.
_SpecDefiner & Field(const TfToken &name, bool required=false)
Functions for setting spec attributes during registration.
A helper for registering value types.
void AddType(const Type &type)
Register a value type and its corresponding array value type.
Class defining various attributes for a field.
FieldDefinition & FallbackValue(const VtValue &v)
Functions for setting field attributes during registration.
SdfAllowed IsValidValue(const T &value) const
Validation functions that return true if a given value passes the registered validator or if no valid...
Class representing fields and other information for a spec type.
SDF_API bool IsValidField(const TfToken &name) const
Returns whether the given field is valid for this spec.
TfTokenVector const & GetRequiredFields() const
Returns all value fields marked as required for this spec.
SDF_API TfTokenVector GetFields() const
Returns all fields for this spec.
SDF_API bool IsMetadataField(const TfToken &name) const
Returns whether the given field is metadata for this spec.
SDF_API bool IsRequiredField(const TfToken &name) const
Returns whether the given field is required for this spec.
SDF_API TfTokenVector GetMetadataFields() const
Returns all value fields marked as metadata for this spec.
SDF_API TfToken GetMetadataFieldDisplayGroup(const TfToken &name) const
Returns the display group for this metadata field.
Generic class that provides information about scene description fields but doesn't actually provide a...
void _RegisterPluginFields()
Registers plugin fields and sets up handling so that fields will be added when additional plugins are...
SDF_API std::vector< SdfValueTypeName > GetAllTypes() const
Returns all registered type names.
SDF_API TfToken GetMetadataFieldDisplayGroup(SdfSpecType specType, TfToken const &metadataField) const
Return the metadata field display group for metadata metadataField on specType.
SDF_API VtValue CastToTypeOf(const TfToken &fieldKey, const VtValue &value) const
Coerce value to the correct type for the specified field.
SDF_API const FieldDefinition * GetFieldDefinition(const TfToken &fieldKey) const
Returns the field definition for the given field.
SDF_API SdfValueTypeName FindType(const TfToken &typeName) const
Return the type name object for the given type name token.
std::function< VtValue(const std::string &, const JsValue &)> _DefaultValueFactoryFn
Factory function for creating a default value for a metadata field.
bool IsRequiredFieldName(const TfToken &fieldName) const
Return true if fieldName is a required field name for at least one spec type, return false otherwise.
SDF_API bool HoldsChildren(const TfToken &fieldKey) const
Returns whether the given field is a 'children' field – that is, it indexes certain children beneath ...
SDF_API TfTokenVector GetMetadataFields(SdfSpecType specType) const
Returns all metadata fields registered for the given spec type.
SDF_API SdfValueTypeName FindType(const VtValue &value, const TfToken &role=TfToken()) const
Return the type name object for the value's type and optional role.
_SpecDefiner _ExtendSpecDefinition(SdfSpecType specType)
Returns a _SpecDefiner for the previously-defined spec type for specifying additional fields.
SDF_API bool IsRegistered(const TfToken &fieldKey, VtValue *fallback=NULL) const
Convenience functions for accessing specific field information.
SDF_API SdfValueTypeName FindOrCreateType(const TfToken &typeName) const
Return the type name object for the given type name string if it exists otherwise create a temporary ...
static SDF_API SdfAllowed IsValidAttributeConnectionPath(const SdfPath &path)
Specific validation functions for various fields.
SDF_API const VtValue & GetFallback(const TfToken &fieldKey) const
Return the fallback value for the specified fieldKey or the empty value if fieldKey is not registered...
void _RegisterStandardTypes()
Registers standard attribute value types.
void _RegisterStandardFields()
Registers the standard fields.
SDF_API SdfAllowed IsValidValue(const VtValue &value) const
Scene description value types.
SDF_API SdfValueTypeName FindType(std::string const &typeName) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const std::vector< const SdfSchemaBase::FieldDefinition * > _UpdateMetadataFromPlugins(const PlugPluginPtrVector &plugins, const std::string &metadataTag=std::string(), const _DefaultValueFactoryFn &defFactory=_DefaultValueFactoryFn())
Registers all metadata fields specified in the given plugins under the given metadata tag.
const SpecDefinition * GetSpecDefinition(SdfSpecType specType) const
Returns the spec definition for the given spec type.
SDF_API bool IsValidFieldForSpec(const TfToken &fieldKey, SdfSpecType specType) const
Return whether the given field is valid for the given spec type.
SDF_API TfTokenVector GetFields(SdfSpecType specType) const
Returns all fields registered for the given spec type.
void _RegisterLegacyTypes()
Registers legacy attribute value types.
SDF_API SdfValueTypeName FindType(const TfType &type, const TfToken &role=TfToken()) const
Return the type name object for the given type and optional role.
_ValueTypeRegistrar _GetTypeRegistrar() const
Returns a type registrar.
SDF_API SdfValueTypeName FindType(const char *typeName) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
_SpecDefiner _Define(SdfSpecType type)
Registers the given spec type with this schema and return a _SpecDefiner for specifying additional fi...
SDF_API const TfTokenVector & GetRequiredFields(SdfSpecType specType) const
Returns all required fields registered for the given spec type.
FieldDefinition & _RegisterField(const TfToken &fieldKey, const T &fallback, bool plugin=false)
Creates and registers a new field named fieldKey with the fallback value fallback.
Construct an SdfSchemaBase but does not populate it with standard fields and types.
Class that provides information about the various scene description fields.
Represents a value type name, i.e.
An enum class that records both enum type and enum value.
Manage a single instance of an object (see.
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Token for efficient comparison, assignment, and hashing of known strings.
TfType represents a dynamic runtime type.
Enable a concrete base class for use with TfWeakPtr.
Represents an arbitrary dimensional rectangular container class.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
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.
Represents the shape of a value type (or that of an element in an array).
Functor to use for hash maps from tokens to other things.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
SdfSpecType
An enum that specifies the type of an object.
std::pair< SdfPath, SdfPath > SdfRelocate
A single relocate specifying a source SdfPath and a target SdfPath for a relocation.