\section{Basic\-Array$<$ T $>$ Class Template Reference}
\label{class_basic_array}\index{BasicArray@{BasicArray}}
A generic implementation of a dynamically allocated array.  


{\tt \#include $<$Basic\-Array.h$>$}

Collaboration diagram for Basic\-Array$<$ T $>$:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=65pt]{class_basic_array__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf Basic\-Array} (unsigned int initial\-Capacity=0)
\begin{CompactList}\small\item\em Create an empty array. \item\end{CompactList}\item 
{\bf $\sim$Basic\-Array} ()
\begin{CompactList}\small\item\em Destruct the array and all the data in it. \item\end{CompactList}\item 
bool {\bf is\-Empty} () const
\item 
unsigned int {\bf get\-Size} () const
\item 
void {\bf set\-Size} (const unsigned int {\bf size})
\begin{CompactList}\small\item\em {\bf set\-Size()}{\rm (p.\,\pageref{class_basic_array_a4})} will increase the array capacity if the new size is larger than the current capacity. \item\end{CompactList}\item 
unsigned int {\bf get\-Capacity} () const
\begin{CompactList}\small\item\em Will always be $>$= to {\bf get\-Size()}{\rm (p.\,\pageref{class_basic_array_a3})}. \item\end{CompactList}\item 
T $\ast$ {\bf get\-Buffer} ()
\begin{CompactList}\small\item\em Modifying or deallocating this buffer may adversely effect the contents of the array. \item\end{CompactList}\item 
T $\ast$ {\bf adopt} ()
\begin{CompactList}\small\item\em Release the internal buffer. \item\end{CompactList}\item 
void {\bf reset} (unsigned int initial\-Capacity=0)
\begin{CompactList}\small\item\em Set size to zero and deallocate memory. \item\end{CompactList}\item 
void {\bf clear} ()
\begin{CompactList}\small\item\em Set size to zero. \item\end{CompactList}\item 
void {\bf increase} (const unsigned int min\-Capacity, const unsigned int multiple=2)
\begin{CompactList}\small\item\em Increase array capacity if min\-Capacity is greater than the current capacity. \item\end{CompactList}\item 
void {\bf shrink} ()
\begin{CompactList}\small\item\em Calling this function assures that the array capacity is equal to its size by releasing any extra allocated memory. \item\end{CompactList}\item 
unsigned int {\bf put} (const T \&x)
\begin{CompactList}\small\item\em Add the array element to the end of the array. \item\end{CompactList}\item 
void {\bf put} (const unsigned int i, const T \&x)
\begin{CompactList}\small\item\em Add an array element. \item\end{CompactList}\item 
unsigned int {\bf put} (const T $\ast$x, const int count)
\begin{CompactList}\small\item\em Add an array of elements to the end of the array. \item\end{CompactList}\item 
void {\bf put} (const unsigned int i, const T $\ast$x, const int count)
\begin{CompactList}\small\item\em Add an array of elements to the array. \item\end{CompactList}\item 
void $\ast$ {\bf alloc} (const unsigned int count)
\begin{CompactList}\small\item\em Allocate space for. \item\end{CompactList}\item 
void $\ast$ {\bf alloc} (const unsigned int i, const unsigned int count)
\begin{CompactList}\small\item\em Allocate space for. \item\end{CompactList}\item 
T \& {\bf get} (const unsigned int i) const
\begin{CompactList}\small\item\em If the index is out of range a {\bf Basic\-Exception}{\rm (p.\,\pageref{class_basic_exception})} will be thrown. \item\end{CompactList}\item 
T \& {\bf operator[$\,$]} (const unsigned int i) const
\begin{CompactList}\small\item\em Allows you to access a Basic\-Array like a normal array. \item\end{CompactList}\end{CompactItemize}
\subsection*{Private Attributes}
\begin{CompactItemize}
\item 
unsigned int {\bf capacity}
\item 
unsigned int {\bf size}
\item 
T $\ast$ {\bf data}
\end{CompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$class T$>$ class Basic\-Array$<$ T $>$}

A generic implementation of a dynamically allocated array. 

WARNING class constructors and destructors are not called. Allocated memory is initially set to zero. This works well with arrays of pointers or basic data types, but will not work for classes such as std::string which requires the constructor be called. 



\subsection{Constructor \& Destructor Documentation}
\index{BasicArray@{Basic\-Array}!BasicArray@{BasicArray}}
\index{BasicArray@{BasicArray}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ {\bf Basic\-Array}$<$ T $>$::{\bf Basic\-Array} (unsigned int {\em initial\-Capacity} = {\tt 0})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a0}


Create an empty array. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em initial\-Capacity}]Initially allocate this many spaces. \end{description}
\end{Desc}
\index{BasicArray@{Basic\-Array}!~BasicArray@{$\sim$BasicArray}}
\index{~BasicArray@{$\sim$BasicArray}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ {\bf Basic\-Array}$<$ T $>$::$\sim${\bf Basic\-Array} ()\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a1}


Destruct the array and all the data in it. 



\subsection{Member Function Documentation}
\index{BasicArray@{Basic\-Array}!adopt@{adopt}}
\index{adopt@{adopt}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ T$\ast$ {\bf Basic\-Array}$<$ T $>$::adopt ()\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a7}


Release the internal buffer. 

It is then the callers responsibility to deallocate the returned pointer if not NULL.

\begin{Desc}
\item[Returns:]A pointer to the internal buffer. \end{Desc}
\index{BasicArray@{Basic\-Array}!alloc@{alloc}}
\index{alloc@{alloc}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void$\ast$ {\bf Basic\-Array}$<$ T $>$::alloc (const unsigned int {\em i}, const unsigned int {\em count})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a17}


Allocate space for. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em count}]elements at position \item[{\em i.}]This space may all ready be occupied by other array elements and writing to this memory may destroy their contents. If \item[{\em i}]+ \item[{\em count}]is geater than the array size then the array size will be increased. You should normally use the put and get methods to access the array contents.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]A void $\ast$ to the newly allocated memory. \end{Desc}
\index{BasicArray@{Basic\-Array}!alloc@{alloc}}
\index{alloc@{alloc}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void$\ast$ {\bf Basic\-Array}$<$ T $>$::alloc (const unsigned int {\em count})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a16}


Allocate space for. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em count}]elements at the end of the array. \end{description}
\end{Desc}
\begin{Desc}
\item[See also:]{\bf alloc(const unsigned int, const unsigned int)}{\rm (p.\,\pageref{class_basic_array_a17})}.\end{Desc}
\begin{Desc}
\item[Returns:]A void $\ast$ to the newly allocated memory. \end{Desc}
\index{BasicArray@{Basic\-Array}!clear@{clear}}
\index{clear@{clear}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf Basic\-Array}$<$ T $>$::clear ()\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a9}


Set size to zero. 

Does not effect capacity. Memory is not initialized to zero! \index{BasicArray@{Basic\-Array}!get@{get}}
\index{get@{get}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ T\& {\bf Basic\-Array}$<$ T $>$::get (const unsigned int {\em i}) const\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a18}


If the index is out of range a {\bf Basic\-Exception}{\rm (p.\,\pageref{class_basic_exception})} will be thrown. 

Array indexing starts from zero.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em i}]The index of the array element.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]A reference to the array element at index i. \end{Desc}
\index{BasicArray@{Basic\-Array}!getBuffer@{getBuffer}}
\index{getBuffer@{getBuffer}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ T$\ast$ {\bf Basic\-Array}$<$ T $>$::get\-Buffer ()\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a6}


Modifying or deallocating this buffer may adversely effect the contents of the array. 

\begin{Desc}
\item[Returns:]A pointer to the internal buffer. \end{Desc}
\index{BasicArray@{Basic\-Array}!getCapacity@{getCapacity}}
\index{getCapacity@{getCapacity}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ unsigned int {\bf Basic\-Array}$<$ T $>$::get\-Capacity () const\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a5}


Will always be $>$= to {\bf get\-Size()}{\rm (p.\,\pageref{class_basic_array_a3})}. 

\begin{Desc}
\item[Returns:]The number of slots currently allocated. \end{Desc}
\index{BasicArray@{Basic\-Array}!getSize@{getSize}}
\index{getSize@{getSize}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ unsigned int {\bf Basic\-Array}$<$ T $>$::get\-Size () const\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a3}


\begin{Desc}
\item[Returns:]The current size of the array. \end{Desc}
\index{BasicArray@{Basic\-Array}!increase@{increase}}
\index{increase@{increase}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf Basic\-Array}$<$ T $>$::increase (const unsigned int {\em min\-Capacity}, const unsigned int {\em multiple} = {\tt 2})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a10}


Increase array capacity if min\-Capacity is greater than the current capacity. 

The capacity will be increased to the larger of min\-Capacity or multiple times the current capacity. The default value for multiple is 2.0. The advantage of this liberal memory allocation comes from the unfortunate side effect that when a memory block is reallocated it may be copied to a new location. Doubling the capacity reduces the amortized time complexity of adding n elements one at a time from O(n$^\wedge$2) to O(n$\ast$log(n)). The disadvantage is that up to twice as much memory may be used. If you know the maximum size of the array ahead of time you can set the capacity to that size in the constructor. You may also pass a multiple of zero causing increase to allocate no more than min\-Capacity.

If memory allocation fails when capacity is greater than min\-Capacity then allocation is retried with capacity equal to min\-Capacity. If allocation fails again an std::bad\_\-alloc() exception will be thrown.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em min\-Capacity}]The minimum number of array slots needed. \item[{\em multiple}]The minimum capacity multiplier. \end{description}
\end{Desc}
\index{BasicArray@{Basic\-Array}!isEmpty@{isEmpty}}
\index{isEmpty@{isEmpty}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ bool {\bf Basic\-Array}$<$ T $>$::is\-Empty () const\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a2}


\begin{Desc}
\item[Returns:]true if size is zero, false otherwise. \end{Desc}
\index{BasicArray@{Basic\-Array}!operator[]@{operator[]}}
\index{operator[]@{operator[]}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ T\& {\bf Basic\-Array}$<$ T $>$::operator[$\,$] (const unsigned int {\em i}) const\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a19}


Allows you to access a Basic\-Array like a normal array. 

See {\bf get()}{\rm (p.\,\pageref{class_basic_array_a18})}. \index{BasicArray@{Basic\-Array}!put@{put}}
\index{put@{put}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf Basic\-Array}$<$ T $>$::put (const unsigned int {\em i}, const T $\ast$ {\em x}, const int {\em count})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a15}


Add an array of elements to the array. 

Elements from i to count - 1 will be overwritten. If i + count is greater than the current size the array will automatically be increased.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em i}]The starting index. \item[{\em x}]A pointer to the elements to be added. \item[{\em count}]The number of elements to copy into the array. \end{description}
\end{Desc}
\index{BasicArray@{Basic\-Array}!put@{put}}
\index{put@{put}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ unsigned int {\bf Basic\-Array}$<$ T $>$::put (const T $\ast$ {\em x}, const int {\em count})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a14}


Add an array of elements to the end of the array. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em x}]A pointer to the elements to be added. \item[{\em count}]The number of elements to be added.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The starting position of the added elements. \end{Desc}
\index{BasicArray@{Basic\-Array}!put@{put}}
\index{put@{put}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf Basic\-Array}$<$ T $>$::put (const unsigned int {\em i}, const T \& {\em x})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a13}


Add an array element. 

If there is all ready an element at this index it will be overwritten. If the index is beyond the current size of the array the array size will be automatically increased.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em i}]The index of the array element. \item[{\em x}]The new array element. \end{description}
\end{Desc}
\index{BasicArray@{Basic\-Array}!put@{put}}
\index{put@{put}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ unsigned int {\bf Basic\-Array}$<$ T $>$::put (const T \& {\em x})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a12}


Add the array element to the end of the array. 

The size of the array will be increased by one. See the notes on the {\bf increase()}{\rm (p.\,\pageref{class_basic_array_a10})} function.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em x}]A reference to the new array element\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The index of the new array element. \end{Desc}
\index{BasicArray@{Basic\-Array}!reset@{reset}}
\index{reset@{reset}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf Basic\-Array}$<$ T $>$::reset (unsigned int {\em initial\-Capacity} = {\tt 0})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a8}


Set size to zero and deallocate memory. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em initial\-Capacity}]New capacity. \end{description}
\end{Desc}
\index{BasicArray@{Basic\-Array}!setSize@{setSize}}
\index{setSize@{setSize}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf Basic\-Array}$<$ T $>$::set\-Size (const unsigned int {\em size})\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a4}


{\bf set\-Size()}{\rm (p.\,\pageref{class_basic_array_a4})} will increase the array capacity if the new size is larger than the current capacity. 

\begin{Desc}
\item[See also:]{\bf increase}{\rm (p.\,\pageref{class_basic_array_a10})}. If {\bf size}{\rm (p.\,\pageref{class_basic_array_r1})} is less than the current any array elements beyond the new {\bf size}{\rm (p.\,\pageref{class_basic_array_r1})} will no longer be accessable. {\bf set\-Size()}{\rm (p.\,\pageref{class_basic_array_a4})} does not deallocated any memory.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em size}]The new array size. \end{description}
\end{Desc}
\index{BasicArray@{Basic\-Array}!shrink@{shrink}}
\index{shrink@{shrink}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ void {\bf Basic\-Array}$<$ T $>$::shrink ()\hspace{0.3cm}{\tt  [inline]}}\label{class_basic_array_a11}


Calling this function assures that the array capacity is equal to its size by releasing any extra allocated memory. 

{\bf shrink()}{\rm (p.\,\pageref{class_basic_array_a11})} should normally only be used after the last {\bf put()}{\rm (p.\,\pageref{class_basic_array_a12})} call and before a call to {\bf adopt()}{\rm (p.\,\pageref{class_basic_array_a7})}. However, when the difference between capacity and size is small the recovered memory will often not be usable because of memory fragmentation. As a rule of thumb do not bother with {\bf shrink()}{\rm (p.\,\pageref{class_basic_array_a11})} when array sizes are small or when you have only a few array instances. It is generally more efficient to set the array capacity in the constructor. \begin{Desc}
\item[See also:]{\bf increase}{\rm (p.\,\pageref{class_basic_array_a10})}. \end{Desc}


\subsection{Member Data Documentation}
\index{BasicArray@{Basic\-Array}!capacity@{capacity}}
\index{capacity@{capacity}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ unsigned int {\bf Basic\-Array}$<$ T $>$::{\bf capacity}\hspace{0.3cm}{\tt  [private]}}\label{class_basic_array_r0}


\index{BasicArray@{Basic\-Array}!data@{data}}
\index{data@{data}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ T$\ast$ {\bf Basic\-Array}$<$ T $>$::{\bf data}\hspace{0.3cm}{\tt  [private]}}\label{class_basic_array_r2}


\index{BasicArray@{Basic\-Array}!size@{size}}
\index{size@{size}!BasicArray@{Basic\-Array}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}template$<$class T$>$ unsigned int {\bf Basic\-Array}$<$ T $>$::{\bf size}\hspace{0.3cm}{\tt  [private]}}\label{class_basic_array_r1}




The documentation for this class was generated from the following file:\begin{CompactItemize}
\item 
{\bf Basic\-Array.h}\end{CompactItemize}
