24 #ifndef PXR_USD_SDF_SCHEMA_H 25 #define PXR_USD_SDF_SCHEMA_H 28 #include "pxr/usd/sdf/api.h" 31 #include "pxr/usd/sdf/valueTypeName.h" 33 #include "pxr/base/plug/notice.h" 35 #include "pxr/base/tf/hashmap.h" 39 #include "pxr/base/tf/type.h" 41 #include "pxr/base/vt/value.h" 47 PXR_NAMESPACE_OPEN_SCOPE
53 class Sdf_ValueTypeRegistry;
79 typedef std::vector< std::pair<TfToken, JsValue> > InfoVec;
81 SDF_API
const TfToken& GetName()
const;
82 SDF_API
const VtValue& GetFallbackValue()
const;
83 SDF_API
const InfoVec& GetInfo()
const;
85 SDF_API
bool IsPlugin()
const;
86 SDF_API
bool IsReadOnly()
const;
87 SDF_API
bool HoldsChildren()
const;
96 return (_valueValidator ?
97 _valueValidator(_schema,
VtValue(value)) :
102 SdfAllowed IsValidListValue(
const T& value)
const 104 return (_listValueValidator ?
105 _listValueValidator(_schema,
VtValue(value)) :
110 SdfAllowed IsValidMapKey(
const T& value)
const 112 return (_mapKeyValidator ?
113 _mapKeyValidator(_schema,
VtValue(value)) :
118 SdfAllowed IsValidMapValue(
const T& value)
const 120 return (_mapValueValidator ?
121 _mapValueValidator(_schema,
VtValue(value)) :
132 FieldDefinition& Plugin();
133 FieldDefinition& Children();
134 FieldDefinition& ReadOnly();
139 FieldDefinition& ValueValidator(Validator v);
140 FieldDefinition& ListValueValidator(Validator v);
141 FieldDefinition& MapKeyValidator(Validator v);
142 FieldDefinition& MapValueValidator(Validator v);
156 Validator _valueValidator;
157 Validator _listValueValidator;
158 Validator _mapKeyValidator;
159 Validator _mapValueValidator;
165 _FieldInfo(): required(false), metadata(false) { }
171 class SpecDefinition;
184 return _requiredFields;
207 typedef TfHashMap<TfToken, _FieldInfo, TfToken::HashFunctor>
217 void _AddField(
const TfToken& name,
const _FieldInfo& fieldInfo);
228 return _specDefinitions[specType].second ?
229 &_specDefinitions[specType].first :
nullptr;
269 TfToken const &metadataField)
const;
279 for (
TfToken const &fname: _requiredFieldNames) {
280 if (fname == fieldName) {
297 static SdfAllowed IsValidIdentifier(
const std::string& name);
299 static SdfAllowed IsValidNamespacedIdentifier(
const std::string& name);
313 static SdfAllowed IsValidSubLayer(
const std::string& sublayer);
315 static SdfAllowed IsValidVariantIdentifier(
const std::string& name);
373 const TfToken& name,
bool required =
false);
375 const TfToken& name,
bool required =
false);
378 bool required =
false);
387 , _definition(definition)
406 Type(
const TfToken& name,
const T& defaultValue)
410 Type(
char const *name,
const T& defaultValue)
421 Type& CPPTypeName(
const std::string& cppTypeName);
427 Type& DefaultUnit(
TfEnum unit);
430 Type& Role(
const TfToken& role);
438 const VtValue& defaultArrayValue);
441 std::unique_ptr<_Impl> _impl;
447 void AddType(
const Type& type);
450 Sdf_ValueTypeRegistry* _registry;
471 const TfToken &fieldKey,
const T &fallback,
bool plugin =
false)
473 return _CreateField(fieldKey,
VtValue(fallback), plugin);
480 _specDefinitions[type].second =
true;
481 return _SpecDefiner(
this, &_specDefinitions[type].first);
507 typedef std::function<
VtValue(
const std::string&,
const JsValue&)>
512 const std::vector<const SdfSchemaBase::FieldDefinition *>
514 const std::string& metadataTag =
529 void _AddRequiredFieldName(
const TfToken &name);
531 const SpecDefinition* _CheckAndGetSpecDefinition(
SdfSpecType type)
const;
533 friend struct Sdf_SchemaFieldTypeRegistrar;
534 FieldDefinition& _CreateField(
535 const TfToken &fieldKey,
const VtValue &fallback,
bool plugin =
false);
538 FieldDefinition& _DoRegisterField(
const TfToken &fieldKey,
const T &fallback)
540 return _DoRegisterField(fieldKey,
VtValue(fallback));
543 FieldDefinition& _DoRegisterField(
550 _FieldDefinitionMap _fieldDefinitions;
553 std::pair<SdfSchemaBase::SpecDefinition, bool>
554 _specDefinitions[SdfNumSpecTypes];
556 std::unique_ptr<Sdf_ValueTypeRegistry> _valueTypeRegistry;
584 #define SDF_FIELD_KEYS \ 585 ((Active, "active")) \ 586 ((AllowedTokens, "allowedTokens")) \ 587 ((AssetInfo, "assetInfo")) \ 588 ((ColorConfiguration, "colorConfiguration")) \ 589 ((ColorManagementSystem, "colorManagementSystem")) \ 590 ((ColorSpace, "colorSpace")) \ 591 ((Comment, "comment")) \ 592 ((ConnectionPaths, "connectionPaths")) \ 593 ((Custom, "custom")) \ 594 ((CustomData, "customData")) \ 595 ((CustomLayerData, "customLayerData")) \ 596 ((Default, "default")) \ 597 ((DefaultPrim, "defaultPrim")) \ 598 ((DisplayGroup, "displayGroup")) \ 599 ((DisplayGroupOrder, "displayGroupOrder")) \ 600 ((DisplayName, "displayName")) \ 601 ((DisplayUnit, "displayUnit")) \ 602 ((Documentation, "documentation")) \ 603 ((EndTimeCode, "endTimeCode")) \ 604 ((FramePrecision, "framePrecision")) \ 605 ((FramesPerSecond, "framesPerSecond")) \ 606 ((Hidden, "hidden")) \ 607 ((HasOwnedSubLayers, "hasOwnedSubLayers")) \ 608 ((InheritPaths, "inheritPaths")) \ 609 ((Instanceable, "instanceable")) \ 611 ((PrimOrder, "primOrder")) \ 612 ((NoLoadHint, "noLoadHint")) \ 614 ((Payload, "payload")) \ 615 ((Permission, "permission")) \ 616 ((Prefix, "prefix")) \ 617 ((PrefixSubstitutions, "prefixSubstitutions")) \ 618 ((PropertyOrder, "propertyOrder")) \ 619 ((References, "references")) \ 620 ((Relocates, "relocates")) \ 621 ((SessionOwner, "sessionOwner")) \ 622 ((Specializes, "specializes")) \ 623 ((Specifier, "specifier")) \ 624 ((StartTimeCode, "startTimeCode")) \ 625 ((SubLayers, "subLayers")) \ 626 ((SubLayerOffsets, "subLayerOffsets")) \ 627 ((Suffix, "suffix")) \ 628 ((SuffixSubstitutions, "suffixSubstitutions")) \ 629 ((SymmetricPeer, "symmetricPeer")) \ 630 ((SymmetryArgs, "symmetryArgs")) \ 631 ((SymmetryArguments, "symmetryArguments")) \ 632 ((SymmetryFunction, "symmetryFunction")) \ 633 ((TargetPaths, "targetPaths")) \ 634 ((TimeSamples, "timeSamples")) \ 635 ((TimeCodesPerSecond, "timeCodesPerSecond")) \ 636 ((TypeName, "typeName")) \ 637 ((VariantSelection, "variantSelection")) \ 638 ((Variability, "variability")) \ 639 ((VariantSetNames, "variantSetNames")) \ 642 ((EndFrame, "endFrame")) \ 643 ((StartFrame, "startFrame")) 645 #define SDF_CHILDREN_KEYS \ 646 ((ConnectionChildren, "connectionChildren")) \ 647 ((ExpressionChildren, "expressionChildren")) \ 648 ((MapperArgChildren, "mapperArgChildren")) \ 649 ((MapperChildren, "mapperChildren")) \ 650 ((PrimChildren, "primChildren")) \ 651 ((PropertyChildren, "properties")) \ 652 ((RelationshipTargetChildren, "targetChildren")) \ 653 ((VariantChildren, "variantChildren")) \ 654 ((VariantSetChildren, "variantSetChildren")) 659 PXR_NAMESPACE_CLOSE_SCOPE
661 #endif // PXR_USD_SDF_SCHEMA_H SDF_API bool IsRegistered(const TfToken &fieldKey, VtValue *fallback=NULL) const
Convenience functions for accessing specific field information.
SDF_API TfTokenVector GetMetadataFields(SdfSpecType specType) const
Returns all metadata fields registered for the given spec type.
SDF_API TfTokenVector GetFields(SdfSpecType specType) const
Returns all fields registered for the given spec type.
Manage a single instance of an object.
void _RegisterPluginFields()
Registers plugin fields and sets up handling so that fields will be added when additional plugins are...
std::function< VtValue(const std::string &, const JsValue &)> _DefaultValueFactoryFn
Factory function for creating a default value for a metadata field.
static SDF_API SdfAllowed IsValidAttributeConnectionPath(const SdfPath &path)
Specific validation functions for various fields.
Manage a single instance of an object (see.
SDF_API const FieldDefinition * GetFieldDefinition(const TfToken &fieldKey) const
Returns the field definition for the given 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 VtValue CastToTypeOf(const TfToken &fieldKey, const VtValue &value) const
Coerce value to the correct type for the specified field.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
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 TfToken GetMetadataFieldDisplayGroup(SdfSpecType specType, TfToken const &metadataField) const
Return the metadata field display group for metadata metadataField on specType.
TfTokenVector const & GetRequiredFields() const
Returns all value fields marked as required for this spec.
void _RegisterLegacyTypes()
Registers legacy attribute value types.
_ValueTypeRegistrar _GetTypeRegistrar() const
Returns a type registrar.
Generic class that provides information about scene description fields but doesn't actually provide a...
SDF_API bool IsValidField(const TfToken &name) const
Returns whether the given field is valid for this spec.
Class that defines fields for a spec type.
An enum class that records both enum type and enum value.
Functor to use for hash maps from tokens to other things.
_SpecDefiner & Field(const TfToken &name, bool required=false)
Functions for setting spec attributes during registration.
Represents a value type name, i.e.
Token for efficient comparison, assignment, and hashing of known strings.
FieldDefinition & _RegisterField(const TfToken &fieldKey, const T &fallback, bool plugin=false)
Creates and registers a new field named fieldKey with the fallback value fallback.
Class defining various attributes for a field.
SDF_API TfToken GetMetadataFieldDisplayGroup(const TfToken &name) const
Returns the display group for this metadata field.
Indicates if an operation is allowed and, if not, why not.
A discriminated union type for JSON values.
_SpecDefiner _ExtendSpecDefinition(SdfSpecType specType)
Returns a _SpecDefiner for the previously-defined spec type for specifying additional fields.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Represents a payload and all its meta data.
SDF_API SdfAllowed IsValidValue(const VtValue &value) const
Scene description value types.
std::vector< TfToken > TfTokenVector
Convenience types.
Class representing fields and other information for a spec type.
Represents an arbitrary dimensional rectangular container class.
A path value used to locate objects in layers or scenegraphs.
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
void AddType(const Type &type)
Register a value type and its corresponding array value 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 GetMetadataFields() const
Returns all value fields marked as metadata for this spec.
A helper for registering value types.
void _RegisterStandardTypes()
Registers standard attribute value types.
Represents a reference and all its meta data.
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...
Defines an interface to registered plugins.
SdfAllowed IsValidValue(const T &value) const
Validation functions that return true if a given value passes the registered validator or if no valid...
SDF_API TfTokenVector GetFields() const
Returns all fields for this spec.
This file defines some macros that are useful for declaring and using static TfTokens.
void _RegisterStandardFields()
Registers the standard fields.
SdfSpecType
An enum that specifies the type of an object.
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.
Notice sent after new plugins have been registered with the Plug registry.
FieldDefinition & FallbackValue(const VtValue &v)
Functions for setting field attributes during registration.
_SpecDefiner _Define(SdfSpecType type)
Registers the given spec type with this schema and return a _SpecDefiner for specifying additional fi...
const SpecDefinition * GetSpecDefinition(SdfSpecType specType) const
Returns the spec definition for the given spec type.
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.
TfType represents a dynamic runtime type.
Represents the shape of a value type (or that of an element in an array).
Class that provides information about the various scene description fields.
SDF_API std::vector< SdfValueTypeName > GetAllTypes() const
Returns all registered type names.
SDF_API const TfTokenVector & GetRequiredFields(SdfSpecType specType) const
Returns all required fields registered for the given spec type.
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 ...
Enable a concrete base class for use with TfWeakPtr.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
SDF_API SdfValueTypeName FindType(const TfToken &typeName) const
Return the type name object for the given type name token.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
Construct an SdfSchemaBase but does not populate it with standard fields and types.