|
libebml_ng
|
The EBML library is designed with a clear separation between an element's metadata and factory functionality (the *type**) and its actual data and behavior (the instance). This allows you to:
The core public interfaces are defined in the abstract classes:
ebml::ebmlElementType Provides public member functions such as:ebml::ebmlElementType::operator()() to construct an element instance.ebml::ebmlElementType::decode() and ebml::ebmlElementType::cdecode() for converting raw EBML data into element instances.ebml::ebmlElement Offers a public interface for:ebml::ebmlElement::encode() functions.ebml::ebmlElement::clone() function.Notice that the public interface intentionally abstracts away complex internal details. The protected and private member functions focus on the implementation details of instance creation, decoding, and memory management.
To implement a new EBML element, you typically define a subclass pair:
ebmltype_t: A concrete subclass of ebml::ebmlElementType that encapsulates metadata and the factory methods.ebmlinst_t: A concrete subclass of ebml::ebmlElement that holds the actual element data.This section outlines the essential requirements and optional recommendations for successfully implementing these subclasses.
A pair of CRTP templates ebml::ebmlTypeCRTP<ebmltype_t, ebmlinst_t, typebase_t> and ebml::ebmlElementCRTP<ebmltype_t, ebmlinst_t, instbase_t> are provided to help simplify the process of subclassing ebml::ebmlElementType and ebml::ebmlElement. See The CRTP Design Pattern for more information.
It is still possible, however, to subclass directly from ebml::ebmlElementType and ebml::ebmlElement. To do this, in your element type subclass, you must implement the following protected virtual functions:
ebml::ebmlElement* ebmltype_t::_new() const; ebmlinst_t).ebml::ebmlElement* ebmltype_t::_decode_v(const ebml::parseString&) const; ebml::ebmlElement* ebmltype_t::_decode_v(const ebml::parseFile&) const; ebml::parseString or a ebml::parseFile) into an instance of your element.ebml::ebmlElement* ebmltype_t::_cdecode_v(const parseString&) const; ebml::ebmlElement* ebmltype_t::_cdecode_v(const parseFile&) const; ebmlinst_t), declare your element type class as a friend. For example: ebmltype_t::operator() in your ebmltype_t subclass to provide convenient factory functions that allow construction of ebmlinst_t objects using custom parameters.Your element instance subclass must at a minimum implement:
ebmlinst_t::ebmlinst_t(const ebmltype_t*) that accepts a pointer to the companion ebmltype_t (i.e. an instance of your element type class). ebml::ebmlElement.size_t ebmlinst_t::dataSize() const; size_t ebmlinst_t::_encode(char*) const; ebmlElement* ebmlinst_t::_clone() const; std::wstring minirepr() const; ebml::ebmlElementType and ebml::ebmlElement provides the essential tools for creating, decoding, and encoding EBML elements without exposing the internal complexities.ebml::ebmlElementType as ebmltype_t and implement the key virtual methods for instantiation and decoding.ebmlElement as ebmlinst_t and implement the methods for encoding, cloning, and representing the element.operator() if you require customized construction logic.This design encourages a robust, type-safe approach to working with EBML data, making it accessible to both new and experienced C++ developers.
1.8.14