DataDescriptionObjectInterface Manual

About

maxon::DataDescriptionObjectInterface is an interface that can be used as a base for custom interfaces. It allows to add data descriptions to the reference object.

Interface

The maxon::DataDescriptionObjectInterface defines the maxon::DataDescriptionObjectInterface::GetObjectDescription() function. This function can be used to access the description from the given object. The needed argument can be constructed with maxon::CreateDataDictionaryReferenceObject().

// This example creates a new object of a custom type. GetObjectDescription() is used to
// get the data description of that instance. The attributes are printed to the console.
// create new object
const DescriptionElementRef element = DescriptionElementClass().Create() iferr_return;
element.SetAttributeCount(2);
// get description data
maxon::DataDescription description;
maxon::DataDictionary settings;
maxon::DataDictionaryObjectRef dataRef = maxon::CreateDataDictionaryReferenceObject(&settings) iferr_return;
const maxon::LanguageRef language = maxon::Resource::GetDefaultLanguage();
description = element.GetObjectDescription(category, language, dataRef) iferr_return;
// list all attributes
const auto attributes = description.GetEntries() iferr_return;
for (const auto& attribute : attributes)
{
const maxon::InternedId ID = attribute.Get(maxon::DESCRIPTION::BASE::IDENTIFIER) iferr_return;
const maxon::Id dataType = attribute.Get(maxon::DESCRIPTION::DATA::BASE::DATATYPE) iferr_return;
DiagnosticOutput("Attribute \"@\", of type @. Default value: @", ID, dataType, defaultData);
}
@ DEFAULTVALUE
Dummy value for the default value GeData constructor.
Definition: c4d_gedata.h:65
Definition: datatypebase.h:1229
Result< typename std::conditional< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, T, typename ByValueParam< T >::type >::type > Get() const
Definition: datatypebase.h:1389
Definition: apibaseid.h:243
Definition: datatypelib.h:32
const Id & Get() const
Definition: datatypelib.h:165
const Id & Get() const
Definition: apibaseid.h:159
static MAXON_METHOD LanguageRef GetDefaultLanguage()
Result< DataDictionaryObjectRef > CreateDataDictionaryReferenceObject(DataDictionary *reference)
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170
static constexpr LiteralId DATADESCRIPTION_CATEGORY_DATA
Definition: datadescriptiondatabase.h:15
#define iferr_return
Definition: resultbase.h:1524
PyObject * element
Definition: unicodeobject.h:1016

Another function is maxon::DataDescriptionObjectInterface::GetObjectName(), which returns the name of the objects (maxon::OBJECT::BASE::NAME) for the given language.

Implementation

A custom interface can be based on maxon::DataDescriptionObjectInterface. The resulting reference object will store a data description. The default implementation of maxon::DataDescriptionObjectInterface is maxon::DataDescriptionObjectClass.

A custom implementation can re-implement maxon::DataDescriptionObjectInterface::GetObjectDescription() to modify the returned description.

// This example shows an implementation of an interface based on DataDescriptionObjectInterface.
// It implements GetObjectDescription() to edit the returned DataDescription.
// implementation of DescriptionElementInterface
class DescriptionElementImpl : public maxon::Component<DescriptionElementImpl, DescriptionElementInterface>
{
// use the default implementation "DataDescriptionObjectClass"
MAXON_COMPONENT(NORMAL, maxon::DataDescriptionObjectClass);
public:
MAXON_METHOD void SetAttributeCount(maxon::Int count)
{
_count = count;
}
MAXON_METHOD maxon::Result<maxon::DataDescription> GetObjectDescription(const maxon::Id& category, const maxon::LanguageRef& language, const maxon::DataDictionaryObjectRef& objectData) const
{
// load default description
maxon::DataDescription description = super.GetObjectDescription(category, language, objectData) iferr_return;
// check category
{
// add dynamic attributes of the type "maxon::String"
for (maxon::Int i = 0; i < _count; ++i)
{
// generate dynamic ID
const maxon::String number = maxon::String::IntToString(i);
const maxon::String identifier("net.maxonexample.class.descriptionElement.dynamic_"_s + number);
maxon::InternedId dynamicID;
const maxon::Id stringDataType = maxon::GetDataType<maxon::String>()->GetId();
// set attribute settings
maxon::DataDictionary dynamicAttribute;
dynamicAttribute.Set(maxon::DESCRIPTION::BASE::IDENTIFIER, dynamicID) iferr_return;
dynamicAttribute.Set(maxon::DESCRIPTION::DATA::BASE::DATATYPE, stringDataType) iferr_return;
dynamicAttribute.Set(maxon::DESCRIPTION::DATA::BASE::DEFAULTVALUE, "Hello World"_s) iferr_return;
// add new attribute
description.SetEntry(dynamicAttribute) iferr_return;
}
}
return description;
}
private:
maxon::Int _count = 0;
};
Py_ssize_t i
Definition: abstract.h:645
Py_ssize_t count
Definition: abstract.h:640
PyObject * identifier
Definition: asdl.h:5
Definition: objectbase.h:2655
Result< void > Init(const Id &i)
Definition: resultbase.h:766
Definition: string.h:1237
@ NORMAL
Normal Tag morphing.
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:202
#define MAXON_COMPONENT(KIND,...)
Definition: objectbase.h:2212
#define MAXON_METHOD
Definition: interfacebase.h:1012
#define iferr_scope
Definition: resultbase.h:1389
Definition: object.h:105

Further Reading