libebml_ng
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ebml::ebmlElement Class Referenceabstract

Abstract base class for EBML Element instances. More...

#include <ebmlElement.h>

Inheritance diagram for ebml::ebmlElement:
ebml::ebmlElementCRTP< ebmlDataType< const T >, ebmlDataElement< const T > > ebml::ebmlElementCRTP< ebmlDataType< T >, ebmlDataElement< T > > ebml::ebmlElementCRTP< ebmlMasterElementType, ebmlMasterElement > ebml::ebmlElementCRTP< ebmlVoidType, ebmlVoid > ebml::ebmlDataElement< const T > ebml::ebmlMasterElement ebml::ebmlVoid 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

Public Member Functions

virtual ~ebmlElement ()
 
virtual const ebmlElementTypecls () const
 Returns a reference to the associated element class. More...
 
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
 
virtual size_t dataSize () const =0
 
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
 
Encode Functions

Provides a set of overloaded methods for encoding an EBML element.

This group of methods converts an EBML element instance into a raw byte representation according to the EBML specification.

Exceptions
ebml::ebmlEncodeErrorif an internal encoding error occurs.
std::ios_base::failureif an I/O error occurs when writing to a file or stream.
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

 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
 
virtual size_t _encode (char *) const =0
 
virtual ebmlElement_clone () const =0
 

Protected Attributes

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 ebmlDocument
 
class ebmlElementType
 
class ebmlMasterElement
 
class ebmlLazyLoad
 
template<typename T >
class ebmlDataElementClass
 

Detailed Description

Abstract base class for EBML Element instances.

Each EBML element instance corresponds to an entry in an EBML file or data stream. This abstract class defines the interface for encoding/decoding, cloning, accessing parent/child relationships, and obtaining size and location information.

The class also employs shared and weak pointer semantics tailored for EBML operations.

See also
EBML Element Type Definitions
ebml::ebmlElementCRTP<ebmltype_t, ebmlinst_t, instbase_t>
ebml::ebmlElementType

Constructor & Destructor Documentation

◆ ebmlElement()

ebml::ebmlElement::ebmlElement ( const ebmlElementType cls)
protected

Protected constructor.

Parameters
clsPointer to the companion ebml::ebmlElementType instance describing this element type.

This constructor can only be called by friend classes (typically the companion element type).

◆ ~ebmlElement()

ebml::ebmlElement::~ebmlElement ( )
virtual

Member Function Documentation

◆ _clone()

virtual ebmlElement* ebml::ebmlElement::_clone ( ) const
protectedpure virtual

◆ _detach()

void ebml::ebmlElement::_detach ( )
protected

◆ _encode()

virtual size_t ebml::ebmlElement::_encode ( char *  ) const
protectedpure virtual

◆ _encode_head()

size_t ebml::ebmlElement::_encode_head ( char *  dest,
size_t  dataSize 
) const
protected

◆ _setParent() [1/6]

void ebml::ebmlElement::_setParent ( const ebml::ptr< ebmlMasterElement > &  parent,
bool  weak = true 
)
protected

◆ _setParent() [2/6]

void ebml::ebmlElement::_setParent ( const ebml::ptr< const ebmlMasterElement > &  parent,
bool  weak = true 
)
protected

◆ _setParent() [3/6]

void ebml::ebmlElement::_setParent ( ebml::ptr< ebmlMasterElement > &&  parent,
bool  weak = true 
)
protected

◆ _setParent() [4/6]

void ebml::ebmlElement::_setParent ( ebml::ptr< const ebmlMasterElement > &&  parent,
bool  weak = true 
)
protected

◆ _setParent() [5/6]

void ebml::ebmlElement::_setParent ( ebmlMasterElement parent,
bool  weak = true 
)
protected

◆ _setParent() [6/6]

void ebml::ebmlElement::_setParent ( const ebmlMasterElement parent,
bool  weak = true 
)
protected

◆ _validate()

void ebml::ebmlElement::_validate ( )
inlineprotected

◆ as() [1/2]

template<typename T >
T & ebml::ebmlElement::as ( )
inline

Dynamically cast the element to the requested type.

Template Parameters
TThe desired element type (defaults to ebmlElement).
Returns
A reference to the element cast to type T.
Exceptions
std::bad_castif the dynamic_cast fails.

◆ as() [2/2]

template<typename T >
T & ebml::ebmlElement::as ( ) const
inline

Const version of the dynamic cast.

Template Parameters
TThe desired element type.
Returns
A reference to the element cast to type T.
Exceptions
std::bad_castif the dynamic_cast fails.

◆ c_parent()

ebml::ptr< const ebmlMasterElement > ebml::ebmlElement::c_parent ( ) const

Retrieve a const shared pointer to the parent element.

Returns
A shared pointer to const ebmlMasterElement.

◆ c_root()

c_ebmlElement_sp ebml::ebmlElement::c_root ( ) const

◆ clone()

ebml::ptr< ebmlElement > ebml::ebmlElement::clone ( ) const

◆ cls()

const ebmlElementType & ebml::ebmlElement::cls ( ) const
virtual

◆ dataOffsetInFile()

off_t ebml::ebmlElement::dataOffsetInFile ( ) const

◆ dataOffsetInParent()

off_t ebml::ebmlElement::dataOffsetInParent ( ) const

◆ dataSize()

size_t ebml::ebmlElement::dataSize ( ) const
pure virtual

◆ document()

ebmlDocument_sp ebml::ebmlElement::document ( ) const

◆ ebmlID()

ebmlID_t ebml::ebmlElement::ebmlID ( ) const

Retrieve the EBML ID of the element.

Returns
EBML ID as an unsigned integer.

◆ encode() [1/5]

std::string ebml::ebmlElement::encode ( ) const
inline

Encodes the element and returns it as a std::string.

◆ encode() [2/5]

size_t ebml::ebmlElement::encode ( char *  dest) const
inline

Encodes the element into a pre-allocated buffer.

◆ encode() [3/5]

size_t ebml::ebmlElement::encode ( ioBase dest) const
inline

Encodes the element and writes it to a generic I/O stream.

◆ encode() [4/5]

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

Encodes the element and writes it to a specific offset in a stream.

◆ encode() [5/5]

size_t ebml::ebmlElement::encode ( char *  dest,
size_t  dataSize 
) const

Encodes the element using a pre-computed size.

This specialized overload takes a pre-computed size as an argument, which avoids redundant dataSize() calls for master elements and their descendants, significantly improving performance for deep trees.

Parameters
destA pointer to the destination buffer where the encoded element will be written.
dataSizeThe pre-computed size of the element's data payload.
Returns
The total size, in bytes, of the encoded element, including its header.

◆ hasParent()

bool ebml::ebmlElement::hasParent ( ) const

◆ headSize() [1/2]

unsigned char ebml::ebmlElement::headSize ( ) const

◆ headSize() [2/2]

unsigned char ebml::ebmlElement::headSize ( size_t  dataSize) const

◆ makeSeekData() [1/2]

seekData_t * ebml::ebmlElement::makeSeekData ( )

◆ makeSeekData() [2/2]

seekData_t * ebml::ebmlElement::makeSeekData ( ) const

◆ minirepr()

virtual std::wstring ebml::ebmlElement::minirepr ( ) const
pure virtual

◆ offsetInFile()

off_t ebml::ebmlElement::offsetInFile ( ) const

◆ offsetInParent()

off_t ebml::ebmlElement::offsetInParent ( ) const
inline

◆ outerSize() [1/2]

size_t ebml::ebmlElement::outerSize ( ) const

◆ outerSize() [2/2]

size_t ebml::ebmlElement::outerSize ( size_t  dataSize) const

◆ parent()

ebml::ptr< ebmlMasterElement > ebml::ebmlElement::parent ( ) const

Retrieve the parent of this element.

Returns
A shared pointer to the parent ebmlMasterElement.
Exceptions
std::runtime_errorIf the parent is const.

◆ parent_is_const()

bool ebml::ebmlElement::parent_is_const ( ) const

Check if the element's parent is a const object.

Returns
True if parent is a const pointer; otherwise false.

◆ repr()

std::wstring ebml::ebmlElement::repr ( ) const
virtual

Reimplemented in ebml::ebmlVoid.

◆ root()

ebmlElement_sp ebml::ebmlElement::root ( ) const

◆ sizeWidth() [1/2]

unsigned char ebml::ebmlElement::sizeWidth ( ) const

◆ sizeWidth() [2/2]

unsigned char ebml::ebmlElement::sizeWidth ( size_t  dataSize) const

◆ sp() [1/4]

ebml::ptr< ebmlElement > ebml::ebmlElement::sp ( )

Returns a shared pointer to the element instance.

Returns
The shared pointer version of this element.

◆ sp() [2/4]

ebml::ptr< const ebmlElement > ebml::ebmlElement::sp ( ) const

Returns a shared pointer to a const element.

Returns
The shared pointer (const) version of this element.

◆ sp() [3/4]

template<typename T >
ebml::ptr<T> ebml::ebmlElement::sp ( )
inline

◆ sp() [4/4]

template<typename T >
ebml::ptr<T> ebml::ebmlElement::sp ( ) const
inline

◆ wp() [1/4]

ebml::wptr< ebmlElement > ebml::ebmlElement::wp ( )

◆ wp() [2/4]

ebml::wptr< const ebmlElement > ebml::ebmlElement::wp ( ) const

◆ wp() [3/4]

template<typename T >
ebml::wptr< T > ebml::ebmlElement::wp ( )
inline

◆ wp() [4/4]

template<typename T >
ebml::wptr< T > ebml::ebmlElement::wp ( ) const
inline

Friends And Related Function Documentation

◆ ebmlDataElementClass

template<typename T >
friend class ebmlDataElementClass
friend

◆ ebmlDocument

friend class ebmlDocument
friend

◆ ebmlElementType

friend class ebmlElementType
friend

◆ ebmlLazyLoad

friend class ebmlLazyLoad
friend

◆ ebmlMasterElement

friend class ebmlMasterElement
friend

Member Data Documentation

◆ _cls

const ebmlElementType* ebml::ebmlElement::_cls
protected

Pointer to the companion element type (an ebmlElementClass subclass).

◆ _document

ebmlDocument_wp ebml::ebmlElement::_document
protected

◆ _offsetInParent

off_t ebml::ebmlElement::_offsetInParent = -1
protected

◆ _self

wptr<ebmlElement> ebml::ebmlElement::_self
protected

Custom weak pointer to self (used for shared-from-this semantics).

◆ _sizeWidth

vintWidth_t ebml::ebmlElement::_sizeWidth = 0
protected

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