A comprehensive guide to using the {\ttfamily ebml\+Type\+C\+R\+TP} and {\ttfamily ebml\+Element\+C\+R\+TP} mixin templates.

This page provides detailed usage guidelines for implementing your own E\+B\+ML element types and instances using the library\textquotesingle{}s Curiously Recurring Template Pattern (C\+R\+TP) mixins.

\subsection*{The Purpose of the C\+R\+TP Mixins}

The {\ttfamily ebml\+Type\+C\+R\+TP} and {\ttfamily ebml\+Element\+C\+R\+TP} templates work together to provide compile-\/time type safety and automatic pointer conversions. By inheriting from these templates, your custom E\+B\+ML types gain all the necessary decoding, encoding, and instance creation functionality without the need for manual casting.

\subsection*{Usage Guidelines}

To create a paired E\+B\+ML element type and instance\+:


\begin{DoxyItemize}
\item {\bfseries Element Type\+:}
\begin{DoxyItemize}
\item Define your element type class ({\ttfamily ebmltype\+\_\+t}) to inherit from\+: {\ttfamily \mbox{\hyperlink{classebml_1_1ebmlTypeCRTP}{ebml\+::ebml\+Type\+C\+R\+TP}}$<$ebmltype\+\_\+t, ebmlinst\+\_\+t, typebase\+\_\+t$>$} where the default {\ttfamily typebase\+\_\+t} is {\ttfamily \mbox{\hyperlink{classebml_1_1ebmlElementType}{ebml\+::ebml\+Element\+Type}}}.
\end{DoxyItemize}
\item {\bfseries Element Instance\+:}
\begin{DoxyItemize}
\item Define your element instance class ({\ttfamily ebmlinst\+\_\+t}) to inherit from\+: {\ttfamily \mbox{\hyperlink{classebml_1_1ebmlElementCRTP}{ebml\+::ebml\+Element\+C\+R\+TP}}$<$ebmltype\+\_\+t, ebmlinst\+\_\+t, instbase\+\_\+t$>$} where the default {\ttfamily instbase\+\_\+t} is {\ttfamily \mbox{\hyperlink{classebml_1_1ebmlElement}{ebml\+::ebml\+Element}}}.
\item Both {\ttfamily \mbox{\hyperlink{classebml_1_1ebmlTypeCRTP}{ebml\+::ebml\+Type\+C\+R\+TP}}$<$ebmltype\+\_\+t, ebmlinst\+\_\+t, typebase\+\_\+t$>$} and {\ttfamily \mbox{\hyperlink{classebml_1_1ebmlElementCRTP}{ebml\+::ebml\+Element\+C\+R\+TP}}$<$ebmltype\+\_\+t, ebmlinst\+\_\+t, instbase\+\_\+t$>$} must be friend classes to {\ttfamily ebmltype\+\_\+t}.
\end{DoxyItemize}
\end{DoxyItemize}

\subsection*{Required Implementations}

To integrate proper decoding and cloning, the following must be implemented\+:


\begin{DoxyItemize}
\item {\bfseries Construction and Decoding\+:}
\begin{DoxyItemize}
\item A constructor of the form\+: {\ttfamily ebmlinst\+\_\+t\+::ebmlinst\+\_\+t(const ebmltype\+\_\+t$\ast$)}
\item For decoding from an {\ttfamily \mbox{\hyperlink{classebml_1_1parseString}{ebml\+::parse\+String}}}\+:
\begin{DoxyItemize}
\item Either implement\+:
\begin{DoxyItemize}
\item A constructor\+: {\ttfamily ebmlinst\+\_\+t\+::ebmlinst\+\_\+t(const ebmltype\+\_\+t$\ast$, const ebml\+::parse\+String\&)} {\itshape or}
\item A member function\+: {\ttfamily ebmlinst\+\_\+t\+::\+\_\+init(const ebml\+::parse\+String\&)}
\end{DoxyItemize}
\item Optionally, add a {\ttfamily \+\_\+cinit(const ebml\+::parse\+String\&)} for constructing a {\bfseries const} instance.
\end{DoxyItemize}
\end{DoxyItemize}
\item {\bfseries Decoding From Files\+:}
\begin{DoxyItemize}
\item (Optional) For direct decoding from {\ttfamily \mbox{\hyperlink{classebml_1_1parseFile}{ebml\+::parse\+File}}} (instead of converting it to {\ttfamily \mbox{\hyperlink{classebml_1_1parseString}{ebml\+::parse\+String}}}), implement\+:
\begin{DoxyItemize}
\item Either a constructor\+: {\ttfamily ebmlinst\+\_\+t\+::ebmlinst\+\_\+t(const ebmltype\+\_\+t$\ast$, const ebml\+::parse\+File\&)} {\itshape or}
\item A member function\+: {\ttfamily ebmlinst\+\_\+t\+::\+\_\+init(const ebml\+::parse\+File\&)}
\item Optionally, implement {\ttfamily \+\_\+cinit(const ebml\+::parse\+File\&)} for decoding into a {\bfseries const} instance.
\end{DoxyItemize}
\end{DoxyItemize}
\item {\bfseries Cloning\+:}
\begin{DoxyItemize}
\item Either provide a copy constructor\+: {\ttfamily ebmlinst\+\_\+t\+::ebmlinst\+\_\+t(const ebmlinst\+\_\+t\&)} or implement an internal clone method\+: {\ttfamily ebmlinst\+\_\+t\+::\+\_\+clone(const ebmlinst\+\_\+t\&)}.
\end{DoxyItemize}
\item {\bfseries Encoding Support\+:}
\begin{DoxyItemize}
\item Implement the following member functions (if not already handled by the C\+R\+TP mixin)\+:
\begin{DoxyItemize}
\item {\ttfamily ebmlinst\+\_\+t\+::data\+Size(char$\ast$)}
\item {\ttfamily ebmlinst\+\_\+t\+::\+\_\+encode(char$\ast$)} 
\end{DoxyItemize}
\end{DoxyItemize}
\end{DoxyItemize}