libebml_ng
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members

Abstract base class for EBML master element instances.This class provides the functionality to manage child elements, perform encoding/decoding, and traverse child elements through iterators. It uses CRTP to enable type safety. More...

#include <ebmlMasterElement.h>

Inheritance diagram for ebml::ebmlMasterElement:
ebml::ebmlElementCRTP< ebmlMasterElementType, ebmlMasterElement > ebml::ebmlElement ebml::ebmlElementCRTP< ebmlLazyLoadType, ebmlLazyLoad, ebmlMasterElement > ebml::ebmlElementCRTP< ebmlListType, ebmlList, ebmlMasterElement > ebml::ebmlElementCRTP< ebmlMapType< K, V, H, E, A, B >, ebmlMap< K, V, H, E, A, B >, ebmlMasterElement > ebml::ebmlElementCRTP< ebmlPairType< K, V >, ebmlPair< K, V >, ebmlMasterElement > ebml::ebmlElementCRTP< ebmlStructType, ebmlStruct, ebmlMasterElement > ebml::ebmlLazyLoad ebml::ebmlList ebml::ebmlMap< K, V, H, E, A, B > ebml::ebmlPair< K, V > ebml::ebmlStruct

Classes

class  _const_iterator
 
class  _iterator
 
class  const_iterator
 
class  iterator
 

Public Member Functions

size_t dataSize () const
 
sizetree_t sizetree () const
 Generates the size tree for the element hierarchy. More...
 
size_t encode (char *, const sizetree_t &) const
 Encodes the element using a precomputed size tree. More...
 
iterator begin ()
 
iterator end ()
 
const_iterator cbegin () const
 
const_iterator cend () const
 
Element Encoding Overloads

Provides a set of overloaded methods for encoding an EBML master element. The default implementations of ebml::ebmlElement::encode() functions makes a call to the dataSize() function, determining the entire size of the element without any information on the size of its descendants. This results in redundant calls to dataSize() on each of its descendants, with greater redundancy at higher depths. This implementation instead computes a sizetree_t containing size information for all the master element's descendants, thereby mitigating the redundancy.

size_t encode (char *) const
 
std::string encode () const
 
size_t encode (ioBase &) const
 
size_t encode (ioBase &, off_t) const
 
- Public Member Functions inherited from ebml::ebmlElementCRTP< ebmlMasterElementType, ebmlMasterElement >
 ebmlElementCRTP (const ebmlMasterElementType *cls, Args &&... args)
 
const ebmlMasterElementTypecls () const
 
ebml::ptr< ebmlMasterElementsp ()
 
ebml::ptr< const ebmlMasterElementsp () const
 
ebml::ptr< ebmlElementsp ()
 Returns a shared pointer to the element instance. More...
 
ebml::ptr< const ebmlElementsp () const
 Returns a shared pointer to a const element. More...
 
ebml::ptr< T > sp ()
 
ebml::ptr< T > sp () const
 
ebml::wptr< ebmlMasterElementwp ()
 
ebml::wptr< const ebmlMasterElementwp () const
 
ebml::wptr< ebmlElementwp ()
 
ebml::wptr< const ebmlElementwp () const
 
ebml::wptr< T > wp ()
 
ebml::wptr< T > wp () const
 
ebml::ptr< ebmlMasterElementclone () const
 
- Public Member Functions inherited from ebml::ebmlElement
virtual ~ebmlElement ()
 
ebmlID_t ebmlID () const
 Retrieve the EBML ID of the element. More...
 
template<typename T = ebmlElement>
T & as ()
 Dynamically cast the element to the requested type. More...
 
template<typename T = ebmlElement>
T & as () const
 Const version of the dynamic cast. More...
 
ebml::ptr< ebmlElementsp ()
 Returns a shared pointer to the element instance. More...
 
ebml::ptr< const ebmlElementsp () const
 Returns a shared pointer to a const element. More...
 
template<typename T >
ebml::ptr< T > sp ()
 
template<typename T >
ebml::ptr< T > sp () const
 
ebml::wptr< ebmlElementwp ()
 
ebml::wptr< const ebmlElementwp () const
 
template<typename T >
ebml::wptr< T > wp ()
 
template<typename T >
ebml::wptr< T > wp () const
 
bool parent_is_const () const
 Check if the element's parent is a const object. More...
 
ebml::ptr< ebmlMasterElementparent () const
 Retrieve the parent of this element. More...
 
ebml::ptr< const ebmlMasterElementc_parent () const
 Retrieve a const shared pointer to the parent element. More...
 
ebmlElement_sp root () const
 
c_ebmlElement_sp c_root () const
 
ebmlDocument_sp document () const
 
bool hasParent () const
 
unsigned char headSize () const
 
unsigned char headSize (size_t) const
 
unsigned char sizeWidth () const
 
unsigned char sizeWidth (size_t) const
 
size_t outerSize () const
 
size_t outerSize (size_t) const
 
off_t offsetInParent () const
 
off_t offsetInFile () const
 
off_t dataOffsetInParent () const
 
off_t dataOffsetInFile () const
 
ebml::ptr< ebmlElementclone () const
 
virtual std::wstring minirepr () const =0
 
virtual std::wstring repr () const
 
seekData_tmakeSeekData ()
 
seekData_tmakeSeekData () const
 
std::string encode () const
 Encodes the element and returns it as a std::string. More...
 
size_t encode (char *) const
 Encodes the element into a pre-allocated buffer. More...
 
size_t encode (ioBase &) const
 Encodes the element and writes it to a generic I/O stream. More...
 
size_t encode (ioBase &, off_t) const
 Encodes the element and writes it to a specific offset in a stream. More...
 
size_t encode (char *, size_t) const
 Encodes the element using a pre-computed size. More...
 

Protected Member Functions

 ebmlMasterElement (const ebmlMasterElementType *)
 
void _init (const parseString &)
 Initializes the element from a parsed EBML string. More...
 
void _init (const parseFile &)
 Initializes the element from parsed file data. More...
 
void _cinit (const parseString &)
 Const initialization from a parsed EBML string. More...
 
void _cinit (const parseFile &)
 Const initialization from parsed file data. More...
 
ebmlElement_decodeChild (const parseString &) const
 Decodes a child element from a parsed string. More...
 
ebmlElement_decodeChild (const parseFile &) const
 Decodes a child element from parsed file data. More...
 
ebmlElement_cdecodeChild (const parseString &) const
 Const version: Decodes a child element from a parsed string. More...
 
ebmlElement_cdecodeChild (const parseFile &) const
 Const version: Decodes a child element from parsed file data. More...
 
size_t _encode (char *) const
 
size_t _encode (char *, const sizetree_t &) const
 Encodes the element using a precomputed size tree. More...
 
virtual void _clear ()
 Clears all child elements. More...
 
virtual void _decodeChildren (parseString::iterator &)
 Decodes child elements from a parseString iterator. More...
 
virtual void _cdecodeChildren (parseString::iterator &)
 Const version of _decodeChildren. More...
 
virtual void _scanChildren (parseFile::iterator &)
 Scans for child elements from a parseFile iterator. More...
 
virtual void _cscanChildren (parseFile::iterator &)
 Scans for child elements from a parseFile iterator. (const version) More...
 
virtual void _handleParseFile (const parseFile &)
 Handles the parsing of seek data for a child element. More...
 
virtual void _chandleParseFile (const parseFile &)
 Handles the parsing of seek data for a child element. (const version) More...
 
virtual void _addChild (const ebmlElement_sp &)=0
 Attaches a child element (rvalue version). More...
 
virtual void _addChild (ebmlElement_sp &&)=0
 Attaches a child element (move version). More...
 
void _attachChild (const ebmlElement_sp &child, bool weak=true) const
 Attaches a child element to the master element. More...
 
void _detachChild (const ebmlElement_sp &child) const
 Detaches a child element. More...
 
void _attachChildren (const ebmlElement_l &elems, bool weak=true) const
 Const version of _attachChildren. More...
 
void _detachChildren (const ebmlElement_l &elems) const
 Detaches multiple child elements. More...
 
virtual ebmlMasterElement::_iterator_begin ()=0
 
virtual ebmlMasterElement::_iterator_end ()=0
 
virtual ebmlMasterElement::_const_iterator_cbegin () const =0
 
virtual ebmlMasterElement::_const_iterator_cend () const =0
 
void _clonedata (const ebmlElement *)
 
- Protected Member Functions inherited from ebml::ebmlElementCRTP< ebmlMasterElementType, ebmlMasterElement >
ebmlElement_clone () const
 
- Protected Member Functions inherited from ebml::ebmlElement
 ebmlElement (const ebmlElementType *)
 Protected constructor. More...
 
void _validate ()
 
void _setParent (const ebml::ptr< ebmlMasterElement > &parent, bool weak=true)
 
void _setParent (const ebml::ptr< const ebmlMasterElement > &parent, bool weak=true)
 
void _setParent (ebml::ptr< ebmlMasterElement > &&parent, bool weak=true)
 
void _setParent (ebml::ptr< const ebmlMasterElement > &&parent, bool weak=true)
 
void _setParent (ebmlMasterElement &parent, bool weak=true)
 
void _setParent (const ebmlMasterElement &parent, bool weak=true)
 
void _detach ()
 
size_t _encode_head (char *, size_t) const
 

Static Protected Member Functions

static iterator make_iter (_iterator *)
 
static const_iterator make_iter (_const_iterator *)
 

Protected Attributes

occur_d ebmlIDCount
 
- Protected Attributes inherited from ebml::ebmlElement
const ebmlElementType_cls
 Pointer to the companion element type (an ebmlElementClass subclass). More...
 
wptr< ebmlElement_self
 Custom weak pointer to self (used for shared-from-this semantics). More...
 
ebmlDocument_wp _document
 
vintWidth_t _sizeWidth = 0
 
off_t _offsetInParent = -1
 

Friends

class ebmlMasterElementType
 
class std::shared_ptr< ebmlMasterElement::_iterator >
 
class std::shared_ptr< ebmlMasterElement::_const_iterator >
 
template<typename T >
class childSlot_t
 
std::shared_ptr< ebmlMasterElement::_iteratorstd::make_shared ()
 
std::shared_ptr< ebmlMasterElement::_const_iteratorstd::make_shared ()
 

Additional Inherited Members

- Public Types inherited from ebml::ebmlElementCRTP< ebmlMasterElementType, ebmlMasterElement >
using ebmltype = ebmlMasterElementType
 

Detailed Description

Abstract base class for EBML master element instances.

This class provides the functionality to manage child elements, perform encoding/decoding, and traverse child elements through iterators. It uses CRTP to enable type safety.

See also
ebml::ebmlMasterElementType

Constructor & Destructor Documentation

◆ ebmlMasterElement()

ebml::ebmlMasterElement::ebmlMasterElement ( const ebmlMasterElementType cls)
protected

Member Function Documentation

◆ _addChild() [1/2]

virtual void ebml::ebmlMasterElement::_addChild ( const ebmlElement_sp )
protectedpure virtual

Attaches a child element (rvalue version).

Implements the mechanism for attaching a child element to the parent element.

Parameters
childShared pointer to the child element.

Implemented in ebml::ebmlStruct, ebml::ebmlLazyLoad, ebml::ebmlLazyLoad, ebml::ebmlPair< K, V >, ebml::ebmlMap< K, V, H, E, A, B >, and ebml::ebmlList.

◆ _addChild() [2/2]

virtual void ebml::ebmlMasterElement::_addChild ( ebmlElement_sp &&  )
protectedpure virtual

Attaches a child element (move version).

Implements the mechanism for moving a child element to the parent element.

Parameters
childRvalue reference to a shared pointer for the child element.

Implemented in ebml::ebmlStruct, ebml::ebmlLazyLoad, ebml::ebmlLazyLoad, ebml::ebmlPair< K, V >, ebml::ebmlMap< K, V, H, E, A, B >, and ebml::ebmlList.

◆ _attachChild()

void ebml::ebmlMasterElement::_attachChild ( const ebmlElement_sp child,
bool  weak = true 
) const
protected

Attaches a child element to the master element.

Manages the parent-child relationship by attaching the provided child element, with an option for a weak reference.

Parameters
childShared pointer to the child element.
weakIf true, attaches the child as a weak reference.

◆ _attachChildren()

void ebml::ebmlMasterElement::_attachChildren ( const ebmlElement_l elems,
bool  weak = true 
) const
protected

Const version of _attachChildren.

Attaches multiple child elements in a const context.

Parameters
elemsList of child elements.
weakIf true, attaches children as weak references.

◆ _begin()

virtual ebmlMasterElement::_iterator* ebml::ebmlMasterElement::_begin ( )
protectedpure virtual

◆ _cbegin()

virtual ebmlMasterElement::_const_iterator* ebml::ebmlMasterElement::_cbegin ( ) const
protectedpure virtual

◆ _cdecodeChild() [1/2]

ebmlElement * ebml::ebmlMasterElement::_cdecodeChild ( const parseString parsed) const
inlineprotected

Const version: Decodes a child element from a parsed string.

Parameters
parsedThe parsed EBML string.
Returns
A pointer to the decoded EBML element.

◆ _cdecodeChild() [2/2]

ebmlElement * ebml::ebmlMasterElement::_cdecodeChild ( const parseFile parsed) const
inlineprotected

Const version: Decodes a child element from parsed file data.

Parameters
parsedThe parsed file data.
Returns
A pointer to the decoded EBML element.

◆ _cdecodeChildren()

void ebml::ebmlMasterElement::_cdecodeChildren ( parseString::iterator iter)
protectedvirtual

Const version of _decodeChildren.

Default implementation iterates through the given parseString iterator to decode and attach child elements in decoding to a const ebml::ebmlMasterElement instance.

Parameters
iterIterator over the parseString.

◆ _cend()

virtual ebmlMasterElement::_const_iterator* ebml::ebmlMasterElement::_cend ( ) const
protectedpure virtual

◆ _chandleParseFile()

void ebml::ebmlMasterElement::_chandleParseFile ( const parseFile parsed)
protectedvirtual

Handles the parsing of seek data for a child element. (const version)

Processes the parsed file data corresponding to a child element. Default implementation decodes child and attaches it through _addChild.

Parameters
parsedParsed file data for a child element.

◆ _cinit() [1/2]

void ebml::ebmlMasterElement::_cinit ( const parseString parsed)
protected

Const initialization from a parsed EBML string.

Parameters
parsedThe parsed EBML string.

◆ _cinit() [2/2]

void ebml::ebmlMasterElement::_cinit ( const parseFile parsed)
protected

Const initialization from parsed file data.

Parameters
parsedThe parsed file data.

◆ _clear()

void ebml::ebmlMasterElement::_clear ( )
protectedvirtual

Clears all child elements.

Removes all currently attached child elements from the master element.

Reimplemented in ebml::ebmlStruct, ebml::ebmlPair< K, V >, ebml::ebmlMap< K, V, H, E, A, B >, and ebml::ebmlList.

◆ _clonedata()

void ebml::ebmlMasterElement::_clonedata ( const ebmlElement elem)
protected

◆ _cscanChildren()

void ebml::ebmlMasterElement::_cscanChildren ( parseFile::iterator iter)
protectedvirtual

Scans for child elements from a parseFile iterator. (const version)

Default implementation iterates over the ebml::parseFile::iterator and passes each dereferenced ebml::parseFile to _chandleParseFile in decoding to a const ebml::ebmlMasterElement instance.

Parameters
iterIterator over the parseFile.

◆ _decodeChild() [1/2]

ebmlElement * ebml::ebmlMasterElement::_decodeChild ( const parseString parsed) const
inlineprotected

Decodes a child element from a parsed string.

Parameters
parsedThe parsed EBML string.
Returns
A pointer to the decoded EBML element.

◆ _decodeChild() [2/2]

ebmlElement * ebml::ebmlMasterElement::_decodeChild ( const parseFile parsed) const
inlineprotected

Decodes a child element from parsed file data.

Parameters
parsedThe parsed file data.
Returns
A pointer to the decoded EBML element.

◆ _decodeChildren()

void ebml::ebmlMasterElement::_decodeChildren ( parseString::iterator iter)
protectedvirtual

Decodes child elements from a parseString iterator.

Default implementation terates through the given parseString iterator to decode and attach child elements.

Parameters
iterIterator over the parseString.

◆ _detachChild()

void ebml::ebmlMasterElement::_detachChild ( const ebmlElement_sp child) const
protected

Detaches a child element.

Removes the association between the master element and the specified child element.

Parameters
childShared pointer to the child element to detach.

◆ _detachChildren()

void ebml::ebmlMasterElement::_detachChildren ( const ebmlElement_l elems) const
protected

Detaches multiple child elements.

Iterates through the provided list and detaches each child element from the master element.

Parameters
elemsList of child elements to detach.

◆ _encode() [1/2]

size_t ebml::ebmlMasterElement::_encode ( char *  dest) const
protectedvirtual

Implements ebml::ebmlElement.

◆ _encode() [2/2]

size_t ebml::ebmlMasterElement::_encode ( char *  dest,
const sizetree_t _sizetree 
) const
protected

Encodes the element using a precomputed size tree.

Parameters
destPointer to the destination buffer.
_sizetreeA precomputed sizetree_t for the element.
Returns
The number of bytes encoded.

◆ _end()

virtual ebmlMasterElement::_iterator* ebml::ebmlMasterElement::_end ( )
protectedpure virtual

◆ _handleParseFile()

void ebml::ebmlMasterElement::_handleParseFile ( const parseFile parsed)
protectedvirtual

Handles the parsing of seek data for a child element.

Processes the parsed file data corresponding to a child element. Default implementation decodes child and attaches it through _addChild.

Parameters
parsedParsed file data for a child element.

Reimplemented in ebml::ebmlLazyLoad, and ebml::ebmlLazyLoad.

◆ _init() [1/2]

void ebml::ebmlMasterElement::_init ( const parseString parsed)
protected

Initializes the element from a parsed EBML string.

Parameters
parsedThe parsed EBML string.

◆ _init() [2/2]

void ebml::ebmlMasterElement::_init ( const parseFile parsed)
protected

Initializes the element from parsed file data.

Parameters
parsedThe parsed file data.

◆ _scanChildren()

void ebml::ebmlMasterElement::_scanChildren ( parseFile::iterator iter)
protectedvirtual

Scans for child elements from a parseFile iterator.

Default implementation iterates over the ebml::parseFile::iterator and passes each dereferenced ebml::parseFile to _handleParseFile in decoding to an ebml::ebmlMasterElement instance.

Parameters
iterIterator over the parseFile.

◆ begin()

ebmlMasterElement::iterator ebml::ebmlMasterElement::begin ( )

◆ cbegin()

ebmlMasterElement::const_iterator ebml::ebmlMasterElement::cbegin ( ) const

◆ cend()

ebmlMasterElement::const_iterator ebml::ebmlMasterElement::cend ( ) const

◆ dataSize()

size_t ebml::ebmlMasterElement::dataSize ( ) const
virtual

Implements ebml::ebmlElement.

Reimplemented in ebml::ebmlLazyLoad, and ebml::ebmlLazyLoad.

◆ encode() [1/5]

size_t ebml::ebmlMasterElement::encode ( char *  dest) const

◆ encode() [2/5]

std::string ebml::ebmlMasterElement::encode ( ) const

◆ encode() [3/5]

size_t ebml::ebmlMasterElement::encode ( ioBase dest) const

◆ encode() [4/5]

size_t ebml::ebmlMasterElement::encode ( ioBase dest,
off_t  offset 
) const

◆ encode() [5/5]

size_t ebml::ebmlMasterElement::encode ( char *  dest,
const sizetree_t _sizetree 
) const

Encodes the element using a precomputed size tree.

Parameters
destPointer to the destination buffer.
_sizetreeA precomputed sizetree_t for the element.
Returns
The number of bytes encoded.

◆ end()

ebmlMasterElement::iterator ebml::ebmlMasterElement::end ( )

◆ make_iter() [1/2]

ebmlMasterElement::iterator ebml::ebmlMasterElement::make_iter ( _iterator _iter)
staticprotected

◆ make_iter() [2/2]

ebmlMasterElement::const_iterator ebml::ebmlMasterElement::make_iter ( _const_iterator _iter)
staticprotected

◆ sizetree()

sizetree_t ebml::ebmlMasterElement::sizetree ( ) const

Generates the size tree for the element hierarchy.

Returns
A sizetree_t representing the size breakdown of the element and its descendants.

Friends And Related Function Documentation

◆ childSlot_t

template<typename T >
friend class childSlot_t
friend

◆ ebmlMasterElementType

friend class ebmlMasterElementType
friend

◆ std::make_shared [1/2]

std::shared_ptr<ebmlMasterElement::_iterator> std::make_shared ( )
friend

◆ std::make_shared [2/2]

std::shared_ptr<ebmlMasterElement::_const_iterator> std::make_shared ( )
friend

◆ std::shared_ptr< ebmlMasterElement::_const_iterator >

friend class std::shared_ptr< ebmlMasterElement::_const_iterator >
friend

◆ std::shared_ptr< ebmlMasterElement::_iterator >

friend class std::shared_ptr< ebmlMasterElement::_iterator >
friend

Member Data Documentation

◆ ebmlIDCount

occur_d ebml::ebmlMasterElement::ebmlIDCount
protected

The documentation for this class was generated from the following files: