\hypertarget{classElementFactory}{
\section{ElementFactory Class Reference}
\label{classElementFactory}\index{ElementFactory@{ElementFactory}}
}


A factory for creating elements based on their type.  




{\ttfamily \#include $<$element\_\-factory.hh$>$}

\subsection*{Classes}
\begin{DoxyCompactItemize}
\item 
class \hyperlink{classElementFactory_1_1UnknownElement}{UnknownElement}
\begin{DoxyCompactList}\small\item\em Exception thrown if an Unknown element is being created. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Public Types}
\begin{DoxyCompactItemize}
\item 
\hypertarget{classElementFactory_aeac77a03d515d1d6b826eaf525c03c9d}{
typedef \hyperlink{classElement}{Element} $\ast$($\ast$ {\bfseries Callback} )(const char $\ast$)}
\label{classElementFactory_aeac77a03d515d1d6b826eaf525c03c9d}

\item 
\hypertarget{classElementFactory_abf79aba38866895d74e40c095b695484}{
typedef map$<$ string, Callback $>$ {\bfseries Map}}
\label{classElementFactory_abf79aba38866895d74e40c095b695484}

\end{DoxyCompactItemize}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{classElementFactory_a15093cb5b375fbb367c3fffb426c447b}{add} (const string \&key, Callback cb)
\begin{DoxyCompactList}\small\item\em Register a callback with \hyperlink{protocolthe-p}{the} factory. \item\end{DoxyCompactList}\item 
\hyperlink{classElement}{Element} $\ast$ \hyperlink{classElementFactory_a7b739a807274d2cde1ef9d74c9ac4d72}{create} (const string \&key, const char $\ast$arg)
\begin{DoxyCompactList}\small\item\em Create an element. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Static Public Member Functions}
\begin{DoxyCompactItemize}
\item 
static bool \hyperlink{classElementFactory_ae5cc78afd872080ddc8bad9b6dc1dd6c}{can\_\-create} (const string \&key)
\begin{DoxyCompactList}\small\item\em Checks whether a type exists. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Static Private Attributes}
\begin{DoxyCompactItemize}
\item 
static Map \hyperlink{classElementFactory_a2140f5807f0901c4e3b973f3f7da5035}{\_\-map}
\begin{DoxyCompactList}\small\item\em There is only one factory map. \item\end{DoxyCompactList}\item 
static \hyperlink{classRegisterElements}{RegisterElements} \hyperlink{classElementFactory_a508e6633dbdcb624db24dc828e1f59ec}{\_\-regelems}
\begin{DoxyCompactList}\small\item\em A class which registers defined callbacks upon creation. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
A factory for creating elements based on their type. Elements are created via their string represented type. They are initialized via a c-\/style string. If this string is null, then a default value is assigned to \hyperlink{protocolthe-p}{the} element.

Functions that perform \hyperlink{protocolthe-p}{the} creation are registered with \hyperlink{protocolthe-p}{the} factory at run-\/time.

An exception is throw on element creationg failure.

Similar to \hyperlink{classDispatcher}{Dispatcher}. 

\subsection{Member Function Documentation}
\hypertarget{classElementFactory_a15093cb5b375fbb367c3fffb426c447b}{
\index{ElementFactory@{ElementFactory}!add@{add}}
\index{add@{add}!ElementFactory@{ElementFactory}}
\subsubsection[{add}]{\setlength{\rightskip}{0pt plus 5cm}void ElementFactory::add (
\begin{DoxyParamCaption}
\item[{const string \&}]{key, }
\item[{Callback}]{cb}
\end{DoxyParamCaption}
)}}
\label{classElementFactory_a15093cb5b375fbb367c3fffb426c447b}


Register a callback with \hyperlink{protocolthe-p}{the} factory. 


\begin{DoxyParams}{Parameters}
{\em key} & \hyperlink{protocolthe-p}{the} element id/type. Must be unique. \\
\hline
{\em cb} & function to be called when \hyperlink{protocolthe-p}{the} element must be created. \\
\hline
\end{DoxyParams}
\hypertarget{classElementFactory_ae5cc78afd872080ddc8bad9b6dc1dd6c}{
\index{ElementFactory@{ElementFactory}!can\_\-create@{can\_\-create}}
\index{can\_\-create@{can\_\-create}!ElementFactory@{ElementFactory}}
\subsubsection[{can\_\-create}]{\setlength{\rightskip}{0pt plus 5cm}bool ElementFactory::can\_\-create (
\begin{DoxyParamCaption}
\item[{const string \&}]{key}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}static\mbox{]}}}}
\label{classElementFactory_ae5cc78afd872080ddc8bad9b6dc1dd6c}


Checks whether a type exists. 


\begin{DoxyParams}{Parameters}
{\em key} & \hyperlink{protocolthe-p}{the} element to check for. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if \hyperlink{protocolthe-p}{the} element can be create via \hyperlink{protocolthe-p}{the} factory. 
\end{DoxyReturn}
\hypertarget{classElementFactory_a7b739a807274d2cde1ef9d74c9ac4d72}{
\index{ElementFactory@{ElementFactory}!create@{create}}
\index{create@{create}!ElementFactory@{ElementFactory}}
\subsubsection[{create}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Element} $\ast$ ElementFactory::create (
\begin{DoxyParamCaption}
\item[{const string \&}]{key, }
\item[{const char $\ast$}]{arg}
\end{DoxyParamCaption}
)}}
\label{classElementFactory_a7b739a807274d2cde1ef9d74c9ac4d72}


Create an element. 

\begin{DoxyReturn}{Returns}
\hyperlink{protocolthe-p}{the} requested element. Caller is responsible for deletion. 
\end{DoxyReturn}

\begin{DoxyParams}{Parameters}
{\em key} & \hyperlink{protocolthe-p}{the} type of element that needs to be created. \\
\hline
{\em arg} & initial value of element. If null, a default is assigned. \\
\hline
\end{DoxyParams}


\subsection{Member Data Documentation}
\hypertarget{classElementFactory_a2140f5807f0901c4e3b973f3f7da5035}{
\index{ElementFactory@{ElementFactory}!\_\-map@{\_\-map}}
\index{\_\-map@{\_\-map}!ElementFactory@{ElementFactory}}
\subsubsection[{\_\-map}]{\setlength{\rightskip}{0pt plus 5cm}ElementFactory::Map {\bf ElementFactory::\_\-map}\hspace{0.3cm}{\ttfamily  \mbox{[}static, private\mbox{]}}}}
\label{classElementFactory_a2140f5807f0901c4e3b973f3f7da5035}


There is only one factory map. 

Creating additional factory objects is therefore safe. No need to pass a global factory around in \hyperlink{protocolthe-p}{the} various classes. \hypertarget{classElementFactory_a508e6633dbdcb624db24dc828e1f59ec}{
\index{ElementFactory@{ElementFactory}!\_\-regelems@{\_\-regelems}}
\index{\_\-regelems@{\_\-regelems}!ElementFactory@{ElementFactory}}
\subsubsection[{\_\-regelems}]{\setlength{\rightskip}{0pt plus 5cm}{\bf RegisterElements} {\bf ElementFactory::\_\-regelems}\hspace{0.3cm}{\ttfamily  \mbox{[}static, private\mbox{]}}}}
\label{classElementFactory_a508e6633dbdcb624db24dc828e1f59ec}


A class which registers defined callbacks upon creation. 

Callbacks are thus registered once \mbox{[}static\mbox{]} and before \hyperlink{protocolthe-p}{the} factory is actually used. 

The documentation for this class was generated from the following files:\begin{DoxyCompactItemize}
\item 
/home/greearb/git/xorp.ct.github/xorp/policy/common/element\_\-factory.hh\item 
/home/greearb/git/xorp.ct.github/xorp/policy/common/element\_\-factory.cc\end{DoxyCompactItemize}
