|
libebml_ng
|
A comprehensive guide to using the ebmlTypeCRTP and ebmlElementCRTP mixin templates.
This page provides detailed usage guidelines for implementing your own EBML element types and instances using the library's Curiously Recurring Template Pattern (CRTP) mixins.
The ebmlTypeCRTP and ebmlElementCRTP templates work together to provide compile-time type safety and automatic pointer conversions. By inheriting from these templates, your custom EBML types gain all the necessary decoding, encoding, and instance creation functionality without the need for manual casting.
To create a paired EBML element type and instance:
ebmltype_t) to inherit from: ebml::ebmlTypeCRTP<ebmltype_t, ebmlinst_t, typebase_t> where the default typebase_t is ebml::ebmlElementType.ebmlinst_t) to inherit from: ebml::ebmlElementCRTP<ebmltype_t, ebmlinst_t, instbase_t> where the default instbase_t is ebml::ebmlElement.ebml::ebmlTypeCRTP<ebmltype_t, ebmlinst_t, typebase_t> and ebml::ebmlElementCRTP<ebmltype_t, ebmlinst_t, instbase_t> must be friend classes to ebmltype_t.To integrate proper decoding and cloning, the following must be implemented:
ebmlinst_t::ebmlinst_t(const ebmltype_t*)ebml::parseString:ebmlinst_t::ebmlinst_t(const ebmltype_t*, const ebml::parseString&) orebmlinst_t::_init(const ebml::parseString&)_cinit(const ebml::parseString&) for constructing a const instance.ebml::parseFile (instead of converting it to ebml::parseString), implement:ebmlinst_t::ebmlinst_t(const ebmltype_t*, const ebml::parseFile&) orebmlinst_t::_init(const ebml::parseFile&)_cinit(const ebml::parseFile&) for decoding into a const instance.ebmlinst_t::ebmlinst_t(const ebmlinst_t&) or implement an internal clone method: ebmlinst_t::_clone(const ebmlinst_t&).ebmlinst_t::dataSize(char*)ebmlinst_t::_encode(char*)
1.8.14