\hypertarget{classAlignData}{
\section{AlignData$<$ A $>$ Class Template Reference}
\label{classAlignData}\index{AlignData@{AlignData}}
}


A template class for aligning buffer data with a particular data type.  




{\ttfamily \#include $<$utils.hh$>$}

\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{classAlignData_a704363a76fa9353853493a86bca86ab1}{AlignData} (const vector$<$ uint8\_\-t $>$ \&buffer)
\begin{DoxyCompactList}\small\item\em Constructor. \item\end{DoxyCompactList}\item 
\hypertarget{classAlignData_ac11bdf2f40a7c5dd500d5910e5168fa2}{
\hyperlink{classAlignData_ac11bdf2f40a7c5dd500d5910e5168fa2}{$\sim$AlignData} ()}
\label{classAlignData_ac11bdf2f40a7c5dd500d5910e5168fa2}

\begin{DoxyCompactList}\small\item\em Destructor. \item\end{DoxyCompactList}\item 
const A $\ast$ \hyperlink{classAlignData_a3d1c37b44d3191fed064471f5d2efbcc}{payload} () const 
\begin{DoxyCompactList}\small\item\em Get \hyperlink{protocolthe-p}{the} aligned payload from \hyperlink{protocolthe-p}{the} beginning of \hyperlink{protocolthe-p}{the} buffer. \item\end{DoxyCompactList}\item 
const A $\ast$ \hyperlink{classAlignData_a708d7c8f9dea0dcc7779b96f0575559e}{payload\_\-by\_\-offset} (size\_\-t offset) const 
\begin{DoxyCompactList}\small\item\em Get \hyperlink{protocolthe-p}{the} aligned payload by given offset from \hyperlink{protocolthe-p}{the} beginning of \hyperlink{protocolthe-p}{the} buffer. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Private Attributes}
\begin{DoxyCompactItemize}
\item 
\hypertarget{classAlignData_a3f44b15bb36ec40751c35f2459a815db}{
void $\ast$ {\bfseries \_\-data}}
\label{classAlignData_a3f44b15bb36ec40751c35f2459a815db}

\item 
\hypertarget{classAlignData_a3fb484b88e72f39d91556a263c23f474}{
const void $\ast$ {\bfseries \_\-const\_\-data}}
\label{classAlignData_a3fb484b88e72f39d91556a263c23f474}

\item 
\hypertarget{classAlignData_a6cf2776144a74756cc3cbd68bb12f891}{
const A $\ast$ {\bfseries \_\-payload}}
\label{classAlignData_a6cf2776144a74756cc3cbd68bb12f891}

\end{DoxyCompactItemize}
\subsection*{Static Private Attributes}
\begin{DoxyCompactItemize}
\item 
\hypertarget{classAlignData_a8907b8bdd5016f7ed8d93b6cc780d3bb}{
static const bool {\bfseries \_\-data\_\-is\_\-copied} = false}
\label{classAlignData_a8907b8bdd5016f7ed8d93b6cc780d3bb}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$typename A$>$ class AlignData$<$ A $>$}

A template class for aligning buffer data with a particular data type. The technically correct solution is to allocate (using malloc()) new buffer and copy \hyperlink{protocolthe-p}{the} original data to it. By definition, \hyperlink{protocolthe-p}{the} malloc()-\/ed data is aligned, and therefore it can be casted to \hyperlink{protocolthe-p}{the} desired type.

The more efficient solution (but probably technically incorrect), is to assume that \hyperlink{protocolthe-p}{the} first byte of \char`\"{}vector$<$uint8\_\-t$>$\char`\"{} buffer is aligned similar to malloc()-\/ed data, and therefore it can be casted to \hyperlink{protocolthe-p}{the} desired type without creating a copy of it.

The desired behavior can be chosen by setting \hyperlink{protocolthe-p}{the} AlignData::\_\-data\_\-is\_\-copied constant to true or false. Note that \hyperlink{protocolthe-p}{the} constant is predefined for all \hyperlink{classAlignData}{AlignData} instances. If necessary, \hyperlink{protocolthe-p}{the} constant can become a variable that can have different value for each \hyperlink{classAlignData}{AlignData} instance. 

\subsection{Constructor \& Destructor Documentation}
\hypertarget{classAlignData_a704363a76fa9353853493a86bca86ab1}{
\index{AlignData@{AlignData}!AlignData@{AlignData}}
\index{AlignData@{AlignData}!AlignData@{AlignData}}
\subsubsection[{AlignData}]{\setlength{\rightskip}{0pt plus 5cm}template$<$typename A $>$ {\bf AlignData}$<$ A $>$::{\bf AlignData} (
\begin{DoxyParamCaption}
\item[{const vector$<$ uint8\_\-t $>$ \&}]{buffer}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classAlignData_a704363a76fa9353853493a86bca86ab1}


Constructor. 


\begin{DoxyParams}{Parameters}
{\em buffer} & \hyperlink{protocolthe-p}{the} buffer with \hyperlink{protocolthe-p}{the} data. \\
\hline
\end{DoxyParams}


\subsection{Member Function Documentation}
\hypertarget{classAlignData_a3d1c37b44d3191fed064471f5d2efbcc}{
\index{AlignData@{AlignData}!payload@{payload}}
\index{payload@{payload}!AlignData@{AlignData}}
\subsubsection[{payload}]{\setlength{\rightskip}{0pt plus 5cm}template$<$typename A $>$ const A$\ast$ {\bf AlignData}$<$ A $>$::payload (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classAlignData_a3d1c37b44d3191fed064471f5d2efbcc}


Get \hyperlink{protocolthe-p}{the} aligned payload from \hyperlink{protocolthe-p}{the} beginning of \hyperlink{protocolthe-p}{the} buffer. 

\begin{DoxyReturn}{Returns}
\hyperlink{protocolthe-p}{the} aligned payload from \hyperlink{protocolthe-p}{the} beginning of \hyperlink{protocolthe-p}{the} buffer. 
\end{DoxyReturn}
\hypertarget{classAlignData_a708d7c8f9dea0dcc7779b96f0575559e}{
\index{AlignData@{AlignData}!payload\_\-by\_\-offset@{payload\_\-by\_\-offset}}
\index{payload\_\-by\_\-offset@{payload\_\-by\_\-offset}!AlignData@{AlignData}}
\subsubsection[{payload\_\-by\_\-offset}]{\setlength{\rightskip}{0pt plus 5cm}template$<$typename A $>$ const A$\ast$ {\bf AlignData}$<$ A $>$::payload\_\-by\_\-offset (
\begin{DoxyParamCaption}
\item[{size\_\-t}]{offset}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classAlignData_a708d7c8f9dea0dcc7779b96f0575559e}


Get \hyperlink{protocolthe-p}{the} aligned payload by given offset from \hyperlink{protocolthe-p}{the} beginning of \hyperlink{protocolthe-p}{the} buffer. 

Note that \hyperlink{protocolthe-p}{the} given offset itself is suppose to point to aligned location.


\begin{DoxyParams}{Parameters}
{\em offset} & \hyperlink{protocolthe-p}{the} offset from \hyperlink{protocolthe-p}{the} beginning of \hyperlink{protocolthe-p}{the} buffer. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
\hyperlink{protocolthe-p}{the} aligned payload by given offset from \hyperlink{protocolthe-p}{the} beginning of \hyperlink{protocolthe-p}{the} buffer. 
\end{DoxyReturn}


The documentation for this class was generated from the following file:\begin{DoxyCompactItemize}
\item 
/home/greearb/git/xorp.ct.github/xorp/libxorp/utils.hh\end{DoxyCompactItemize}
