About
A custom data type or an implementation of an interface will contain some internal data. A static custom DescribeIO()
function describes how this data is written to or from a file.
- Note
- DescribeIO() does not directly access the file but instructs Cinema 4D how to handle the data.
Data Serialization
A DescribeIO()
function handles the given maxon::DataSerializeInterface argument. This object should not be handled directly; only with these macros:
- PrepareDescribe(): Starts a description. Must happen before any
Describe()
calls are made.
- Describe(): Describes a class member for I/O operations.
- DescribeOther(): Describes a class member for I/O operations. Allows to cast to a different DataType before the description is made.
- DescribeLegacy(): Describes a legacy element that is no longer needed.
Certain elements may only be handled if a certain condition is fulfilled:
This snippet shows a simple custom data type:
{
public:
};
[files_describeio_simple_datatype]
Definition: describeio.h:10
maxon::Int _a
Definition: describeio.h:17
maxon::Int _c
Definition: describeio.h:19
maxon::Int _b
Definition: describeio.h:18
static maxon::Result< void > DescribeIO(const maxon::DataSerializeInterface &stream)
Definition: dataserialize.h:207
PyObject * stream
Definition: codecs.h:186
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
#define MAXON_DATATYPE(type, id)
Definition: datatype.h:295
This is the straightforward implementation of DescribeIO()
.
{
}
static constexpr ValueType NONE
Default.
Definition: dataserialize.h:136
#define Describe(name, memberName, type, flags)
Definition: dataserialize.h:294
#define PrepareDescribe(streamClass, className)
Definition: dataserialize.h:268
return OK
Definition: apibase.h:2690
#define iferr_scope
Definition: resultbase.h:1384
#define iferr_return
Definition: resultbase.h:1519
DescribeIO()
is invoked when an instance of the data type is written to or read from a file:
const maxon::Id fileID {
"net.maxonexample.simpletriplet" };
Definition: apibaseid.h:253
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< void > >::type ReadDocument(const Url &url, const Id &id, T &object, const DataDictionary &dict=DataDictionary())
Definition: io.h:35
Result< void > WriteDocument(const Url &url, OPENSTREAMFLAGS flags, const Id &id, const T &object, IOFORMAT format=IOFORMAT::DEFAULT, const DataDictionary &dict=DataDictionary())
Definition: io.h:67
The write-process will result in a file like this:
{
"identification": "net.example.simpletriplet",
"content": {
"_a": 100,
"_b": 200,
"_c": 300
}
}
Helper Classes
A helper class is used to define code that is executed when Cinema 4D handles the data. The helper class is used with these macros:
- PrepareHelper(): Declares and initializes an I/O helper class.
- DescribeHelper(): Describes a helper class member for I/O operations
- DescribeHelperIf(): Describes a helper class member for I/O operations and compares its value.
- CONSTHASH(): Expression to calculate the hash code of a member name during compile time. Such a hash value is needed in
WriteAction()
and ReadAction()
.
class TripletHelperClass
{
public:
{
{
_combined = maxon::String::IntToString(triplet.
_a);
_combined += "::"_s;
_combined += maxon::String::IntToString(triplet.
_b);
_combined += "::"_s;
_combined += maxon::String::IntToString(triplet.
_c);
}
}
{
{
}
}
};
{
}
Py_ssize_t count
Definition: abstract.h:640
[files_describeio_simple_datatype]
Definition: describeio.h:26
maxon::Int _a
Definition: describeio.h:32
maxon::Int _c
Definition: describeio.h:34
maxon::Int _b
Definition: describeio.h:33
static maxon::Result< void > DescribeIO(const maxon::DataSerializeInterface &stream)
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
Definition: basearray.h:573
Definition: string.h:1235
#define PrepareHelper(helperName, flags)
Definition: dataserialize.h:398
#define DescribeHelper(name, memberName, type, flags)
Definition: dataserialize.h:345
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
Definition: apibase.h:189
#define DebugAssert(condition,...)
Definition: debugdiagnostics.h:248
@ FINALIZE_READ
The helper's ReadAction will get a call with FINALIZEHASH after the class has been read.
@ INITIALIZE_WRITE
The helper's WriteAction will get a call with INITIALIZEHASH before the class has been written.
static const UInt INITIALIZEHASH
Definition: dataserialize.h:172
static const UInt FINALIZEHASH
Definition: dataserialize.h:173
This will result in a file like this:
{
"identification": "net.example.helpertriplet",
"content": {
"data": "100::200::300"
}
}
This more complex example uses DescribeHelperIf():
class CompactTripletHelperClass
{
public:
{
if (elementHash == _compactHash)
{
if (aEqualsB && bEqualsC)
{
_compact = true;
_compactValue = triplet.
_a;
}
else
{
_compact = false;
}
}
}
{
switch (elementHash)
{
case (_compactValueHash):
{
triplet.
_a = _compactValue;
triplet.
_b = _compactValue;
triplet.
_c = _compactValue;
break;
}
case (_zHash):
{
break;
}
default: { break; }
}
}
};
{
{
}
{
}
}
Definition: describeio.h:41
maxon::Int _a
Definition: describeio.h:47
maxon::Int _c
Definition: describeio.h:49
maxon::Int _b
Definition: describeio.h:48
static maxon::Result< void > DescribeIO(const maxon::DataSerializeInterface &stream)
static constexpr ValueType ACTION_AFTER_READ
If set there will be a call to the helper class ReadAction member function after an element is read.
Definition: dataserialize.h:143
static constexpr ValueType ACTION_BEFORE_WRITE
If set there will be a call to the helper class WriteAction member function before an element is writ...
Definition: dataserialize.h:142
#define DescribeHelperIf(name, memberName, type, flags, mask, value)
Definition: dataserialize.h:389
#define DescribeEndIf()
Definition: dataserialize.h:430
#define DescribeElse()
Definition: dataserialize.h:411
#define CONSTHASH(x)
Expression to calculate the hash code of a member name during compile time.
Definition: dataserialize.h:195
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:181
The maxon namespace contains all declarations of the MAXON API.
Definition: autoweight.h:14
A "compact" file using the same value for each channel will look like this:
{
"identification": "net.example.compacttriplet",
"content": {
"_compact": true,
"_compactValue": 100
}
}
A non-compact file will look like this:
{
"identification": "net.example.compacttriplet",
"content": {
"_compact": false,
"_x": 10,
"_y": 100,
"_z": 1000
}
}
Further Reading