\hypertarget{classcref__ptr}{
\section{cref\_\-ptr$<$ \_\-Tp $>$ Class Template Reference}
\label{classcref__ptr}\index{cref\_\-ptr@{cref\_\-ptr}}
}


Compact Reference Counted Pointer Class.  




{\ttfamily \#include $<$ref\_\-ptr.hh$>$}

\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{classcref__ptr_ab43b94071694c5be0b49681093fef053}{cref\_\-ptr} (\_\-Tp $\ast$\_\-\_\-p=0)
\begin{DoxyCompactList}\small\item\em Construct a compact reference pointer for object. \item\end{DoxyCompactList}\item 
\hyperlink{classcref__ptr_afabafbb4f3c74200ac76160582d49ac9}{cref\_\-ptr} (const \hyperlink{classcref__ptr}{cref\_\-ptr} \&\_\-\_\-r)
\begin{DoxyCompactList}\small\item\em Copy Constructor. \item\end{DoxyCompactList}\item 
\hyperlink{classcref__ptr}{cref\_\-ptr} \& \hyperlink{classcref__ptr_adfdcd5b782402dd710c07d40b41df67d}{operator=} (const \hyperlink{classcref__ptr}{cref\_\-ptr} \&\_\-\_\-r)
\begin{DoxyCompactList}\small\item\em Assignment Operator. \item\end{DoxyCompactList}\item 
\hyperlink{classcref__ptr_a24a123ad182a83bc2a2dc19056f390ad}{$\sim$cref\_\-ptr} ()
\begin{DoxyCompactList}\small\item\em Destruct reference pointer instance and lower reference count on object being tracked. \item\end{DoxyCompactList}\item 
\_\-Tp $\ast$ \hyperlink{classcref__ptr_afee4c3c49149c2bd1810d008486c2f66}{get} () const 
\begin{DoxyCompactList}\small\item\em Dereference pointer to reference counted object. \item\end{DoxyCompactList}\item 
\_\-Tp \& \hyperlink{classcref__ptr_a31b4200dcda2c63b5cda124a7a1394e1}{operator$\ast$} () const 
\begin{DoxyCompactList}\small\item\em Dereference reference counted object. \item\end{DoxyCompactList}\item 
\_\-Tp $\ast$ \hyperlink{classcref__ptr_a168b77174da19757392521d7e0a1f3df}{operator-\/$>$} () const 
\begin{DoxyCompactList}\small\item\em Dereference pointer to reference counted object. \item\end{DoxyCompactList}\item 
bool \hyperlink{classcref__ptr_a8a035c4fe86f0ebe651159db9cd8d0bc}{operator==} (const \hyperlink{classcref__ptr}{cref\_\-ptr} \&rp) const 
\begin{DoxyCompactList}\small\item\em Equality Operator. \item\end{DoxyCompactList}\item 
bool \hyperlink{classcref__ptr_acbcc5b865d2f275b272679b7f893288f}{is\_\-empty} () const 
\begin{DoxyCompactList}\small\item\em Check if reference pointer refers to an object or whether it has been assigned a null object. \item\end{DoxyCompactList}\item 
bool \hyperlink{classcref__ptr_ad52be3d0f2becba3f95a92b604cb6457}{is\_\-only} () const 
\item 
bool \hyperlink{classcref__ptr_afc9fc160949730e1be27691e3854155d}{at\_\-least} (int32\_\-t n) const 
\item 
void \hyperlink{classcref__ptr_a9fc7ea608c59178e11a76ebd322ffd77}{release} () const 
\begin{DoxyCompactList}\small\item\em Release reference on object. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Private Member Functions}
\begin{DoxyCompactItemize}
\item 
\hypertarget{classcref__ptr_a32fecf82c32804fb88b213273c7cef2c}{
void \hyperlink{classcref__ptr_a32fecf82c32804fb88b213273c7cef2c}{ref} (const \hyperlink{classcref__ptr}{cref\_\-ptr} $\ast$\_\-\_\-r) const }
\label{classcref__ptr_a32fecf82c32804fb88b213273c7cef2c}

\begin{DoxyCompactList}\small\item\em Add reference. \item\end{DoxyCompactList}\item 
\hypertarget{classcref__ptr_a23814f21aefddd3039086d10b36870ac}{
void \hyperlink{classcref__ptr_a23814f21aefddd3039086d10b36870ac}{unref} () const }
\label{classcref__ptr_a23814f21aefddd3039086d10b36870ac}

\begin{DoxyCompactList}\small\item\em Remove reference. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Private Attributes}
\begin{DoxyCompactItemize}
\item 
\hypertarget{classcref__ptr_a2256b9a950e754e398d06cc00b8f8068}{
int32\_\-t {\bfseries \_\-M\_\-index}}
\label{classcref__ptr_a2256b9a950e754e398d06cc00b8f8068}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$class \_\-Tp$>$ class cref\_\-ptr$<$ \_\-Tp $>$}

Compact Reference Counted Pointer Class. The \hyperlink{classcref__ptr}{cref\_\-ptr} class is a strong reference class. It maintains a count of how many references to an object exist and releases \hyperlink{protocolthe-p}{the} memory associated with \hyperlink{protocolthe-p}{the} object when \hyperlink{protocolthe-p}{the} reference count reaches zero. The reference pointer can be dereferenced like an ordinary pointer to call methods on \hyperlink{protocolthe-p}{the} reference counted object.

In contrast to \hyperlink{protocolthe-p}{the} \hyperlink{classref__ptr}{ref\_\-ptr} class, accessing \hyperlink{protocolthe-p}{the} pointer requires two levels of indirection as \hyperlink{protocolthe-p}{the} pointer is stored in \hyperlink{protocolthe-p}{the} same table as \hyperlink{protocolthe-p}{the} counter. This is a performance hit, but means each \hyperlink{classcref__ptr}{cref\_\-ptr} only consumes 4-\/bytes.

At \hyperlink{protocolthe-p}{the} time of writing \hyperlink{protocolthe-p}{the} only supported memory management is through \hyperlink{protocolthe-p}{the} new and delete operators. At a future date, this class should support \hyperlink{protocolthe-p}{the} STL allocator classes or an equivalent to provide greater flexibility. 

\subsection{Constructor \& Destructor Documentation}
\hypertarget{classcref__ptr_ab43b94071694c5be0b49681093fef053}{
\index{cref\_\-ptr@{cref\_\-ptr}!cref\_\-ptr@{cref\_\-ptr}}
\index{cref\_\-ptr@{cref\_\-ptr}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{cref\_\-ptr}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ {\bf cref\_\-ptr}$<$ \_\-Tp $>$::{\bf cref\_\-ptr} (
\begin{DoxyParamCaption}
\item[{\_\-Tp $\ast$}]{\_\-\_\-p = {\ttfamily 0}}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_ab43b94071694c5be0b49681093fef053}


Construct a compact reference pointer for object. 


\begin{DoxyParams}{Parameters}
{\em p} & pointer to object to be reference counted. p must be allocated using operator new as it will be destructed using delete when \hyperlink{protocolthe-p}{the} reference count reaches zero. \\
\hline
\end{DoxyParams}
\hypertarget{classcref__ptr_afabafbb4f3c74200ac76160582d49ac9}{
\index{cref\_\-ptr@{cref\_\-ptr}!cref\_\-ptr@{cref\_\-ptr}}
\index{cref\_\-ptr@{cref\_\-ptr}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{cref\_\-ptr}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ {\bf cref\_\-ptr}$<$ \_\-Tp $>$::{\bf cref\_\-ptr} (
\begin{DoxyParamCaption}
\item[{const {\bf cref\_\-ptr}$<$ \_\-Tp $>$ \&}]{\_\-\_\-r}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_afabafbb4f3c74200ac76160582d49ac9}


Copy Constructor. 

Constructs a reference pointer for object. Raises reference count associated with object by 1. \hypertarget{classcref__ptr_a24a123ad182a83bc2a2dc19056f390ad}{
\index{cref\_\-ptr@{cref\_\-ptr}!$\sim$cref\_\-ptr@{$\sim$cref\_\-ptr}}
\index{$\sim$cref\_\-ptr@{$\sim$cref\_\-ptr}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{$\sim$cref\_\-ptr}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ {\bf cref\_\-ptr}$<$ \_\-Tp $>$::$\sim${\bf cref\_\-ptr} (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_a24a123ad182a83bc2a2dc19056f390ad}


Destruct reference pointer instance and lower reference count on object being tracked. 

The object being tracked will be deleted if \hyperlink{protocolthe-p}{the} reference count falls to zero because of \hyperlink{protocolthe-p}{the} destruction of \hyperlink{protocolthe-p}{the} reference pointer. 

\subsection{Member Function Documentation}
\hypertarget{classcref__ptr_afc9fc160949730e1be27691e3854155d}{
\index{cref\_\-ptr@{cref\_\-ptr}!at\_\-least@{at\_\-least}}
\index{at\_\-least@{at\_\-least}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{at\_\-least}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ bool {\bf cref\_\-ptr}$<$ \_\-Tp $>$::at\_\-least (
\begin{DoxyParamCaption}
\item[{int32\_\-t}]{n}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_afc9fc160949730e1be27691e3854155d}

\begin{DoxyParams}{Parameters}
{\em n} & minimum count. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if there are at least n references to object. 
\end{DoxyReturn}
\hypertarget{classcref__ptr_afee4c3c49149c2bd1810d008486c2f66}{
\index{cref\_\-ptr@{cref\_\-ptr}!get@{get}}
\index{get@{get}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{get}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ \_\-Tp$\ast$ {\bf cref\_\-ptr}$<$ \_\-Tp $>$::get (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_afee4c3c49149c2bd1810d008486c2f66}


Dereference pointer to reference counted object. 

\begin{DoxyReturn}{Returns}
pointer to object. 
\end{DoxyReturn}
\hypertarget{classcref__ptr_acbcc5b865d2f275b272679b7f893288f}{
\index{cref\_\-ptr@{cref\_\-ptr}!is\_\-empty@{is\_\-empty}}
\index{is\_\-empty@{is\_\-empty}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{is\_\-empty}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ bool {\bf cref\_\-ptr}$<$ \_\-Tp $>$::is\_\-empty (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_acbcc5b865d2f275b272679b7f893288f}


Check if reference pointer refers to an object or whether it has been assigned a null object. 

\begin{DoxyReturn}{Returns}
true if reference pointer refers to a null object. 
\end{DoxyReturn}
\hypertarget{classcref__ptr_ad52be3d0f2becba3f95a92b604cb6457}{
\index{cref\_\-ptr@{cref\_\-ptr}!is\_\-only@{is\_\-only}}
\index{is\_\-only@{is\_\-only}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{is\_\-only}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ bool {\bf cref\_\-ptr}$<$ \_\-Tp $>$::is\_\-only (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_ad52be3d0f2becba3f95a92b604cb6457}
\begin{DoxyReturn}{Returns}
true if reference pointer represents only reference to object. 
\end{DoxyReturn}
\hypertarget{classcref__ptr_a31b4200dcda2c63b5cda124a7a1394e1}{
\index{cref\_\-ptr@{cref\_\-ptr}!operator$\ast$@{operator$\ast$}}
\index{operator$\ast$@{operator$\ast$}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{operator$\ast$}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ \_\-Tp\& {\bf cref\_\-ptr}$<$ \_\-Tp $>$::operator$\ast$ (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_a31b4200dcda2c63b5cda124a7a1394e1}


Dereference reference counted object. 

\begin{DoxyReturn}{Returns}
reference to object. 
\end{DoxyReturn}
\hypertarget{classcref__ptr_a168b77174da19757392521d7e0a1f3df}{
\index{cref\_\-ptr@{cref\_\-ptr}!operator-\/$>$@{operator-\/$>$}}
\index{operator-\/$>$@{operator-\/$>$}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{operator-\/$>$}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ \_\-Tp$\ast$ {\bf cref\_\-ptr}$<$ \_\-Tp $>$::operator-\/$>$ (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_a168b77174da19757392521d7e0a1f3df}


Dereference pointer to reference counted object. 

\begin{DoxyReturn}{Returns}
pointer to object. 
\end{DoxyReturn}
\hypertarget{classcref__ptr_adfdcd5b782402dd710c07d40b41df67d}{
\index{cref\_\-ptr@{cref\_\-ptr}!operator=@{operator=}}
\index{operator=@{operator=}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{operator=}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ {\bf cref\_\-ptr}\& {\bf cref\_\-ptr}$<$ \_\-Tp $>$::operator= (
\begin{DoxyParamCaption}
\item[{const {\bf cref\_\-ptr}$<$ \_\-Tp $>$ \&}]{\_\-\_\-r}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_adfdcd5b782402dd710c07d40b41df67d}


Assignment Operator. 

Assigns reference pointer to new object. \hypertarget{classcref__ptr_a8a035c4fe86f0ebe651159db9cd8d0bc}{
\index{cref\_\-ptr@{cref\_\-ptr}!operator==@{operator==}}
\index{operator==@{operator==}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{operator==}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ bool {\bf cref\_\-ptr}$<$ \_\-Tp $>$::operator== (
\begin{DoxyParamCaption}
\item[{const {\bf cref\_\-ptr}$<$ \_\-Tp $>$ \&}]{rp}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_a8a035c4fe86f0ebe651159db9cd8d0bc}


Equality Operator. 

\begin{DoxyReturn}{Returns}
true if reference pointers refer to same object. 
\end{DoxyReturn}
\hypertarget{classcref__ptr_a9fc7ea608c59178e11a76ebd322ffd77}{
\index{cref\_\-ptr@{cref\_\-ptr}!release@{release}}
\index{release@{release}!cref_ptr@{cref\_\-ptr}}
\subsubsection[{release}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class \_\-Tp $>$ void {\bf cref\_\-ptr}$<$ \_\-Tp $>$::release (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classcref__ptr_a9fc7ea608c59178e11a76ebd322ffd77}


Release reference on object. 

The reference pointers underlying object is set to null, and \hyperlink{protocolthe-p}{the} former object is destructed if necessary. 

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