D1Array< T > Class Template Reference

#include <TAPsD1Array.hpp>

Collaboration diagram for D1Array< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 D1Array (unsigned int size=1, unsigned int stride=1)
 Constructor.
T * GetAddressOfDataNumber (unsigned int i)
 Get the address of data number.
unsigned int GetSize () const
 Get size.
unsigned int GetStride () const
 Get size.
D1Array< T > & operator= (D1Array< T > const &obj)
 Assignment Operator.
bool Resize (unsigned int size, unsigned int stride)
 Resize.
virtual std::string StrArrayData () const
 Return all data in the array as a string.
virtual std::string StrInfo () const
 Return this object info as a string.
 ~D1Array ()
 Destructor.

Protected Attributes

T * m_atData
 Comparison Operators.
unsigned int m_uiSize
 size
unsigned int m_uiStride
 stride such as 4 for x,y,z,w

Friends

std::ostream & operator<< (std::ostream &output, D1Array< T > const &obj)
 Output Operator <<.


Detailed Description

template<typename T>
class D1Array< T >

An one dimensional array.

Definition at line 21 of file TAPsD1Array.hpp.


Constructor & Destructor Documentation

template<typename T>
BEGIN_NAMESPACE_TAPs__DS D1Array< T >::D1Array ( unsigned int  size = 1,
unsigned int  stride = 1 
) [inline]

Constructor.

Definition at line 17 of file TAPsD1Array.cpp.

00018     : m_atData( NULL), m_uiSize( size ), m_uiStride( stride )
00019 {
00020     if ( size == 0 ) {
00021         std::cerr << "ERROR (D1Array Ctor): Size is less than one!" << std::endl;
00022         exit( -1 );
00023     }
00024     if ( stride == 0 ) {
00025         std::cerr << "ERROR (D1Array Ctor): Stride is less than one!" << std::endl;
00026         exit( -1 );
00027     }
00028     if ( !(m_atData = new T[size * stride]) ) {
00029         std::cerr << "ERROR (D1Array Ctor): Cannot allocate data for D1Array<" << typeid(T).name() 
00030                     << "> with size ("<< m_uiSize << ") and stride (" << m_uiStride << ")!" << std::endl;
00031         exit( -1 );
00032     }
00033 }

template<typename T>
D1Array< T >::~D1Array (  )  [inline]

Destructor.

Definition at line 36 of file TAPsD1Array.cpp.

00037 {
00038     if ( m_atData ) {
00039         delete [] m_atData;
00040     }
00041 }


Member Function Documentation

template<typename T>
T* D1Array< T >::GetAddressOfDataNumber ( unsigned int  i  )  [inline]

Get the address of data number.

Definition at line 48 of file TAPsD1Array.hpp.

00048 { return m_atData + i*m_uiStride; }

template<typename T>
unsigned int D1Array< T >::GetSize (  )  const [inline]

Get size.

Definition at line 54 of file TAPsD1Array.hpp.

00054 { return m_uiSize; }

template<typename T>
unsigned int D1Array< T >::GetStride (  )  const [inline]

Get size.

Definition at line 57 of file TAPsD1Array.hpp.

00057 { return m_uiStride; }

template<typename T>
D1Array< T > & D1Array< T >::operator= ( D1Array< T > const &  obj  )  [inline]

Assignment Operator.

Definition at line 97 of file TAPsD1Array.cpp.

00098 {   
00099     if ( m_atData ) {
00100         delete [] m_atData;
00101     }
00102     m_uiSize   = obj.m_uiSize;
00103     m_uiStride = obj.m_uiStride;
00104     if ( !m_atData = new T[size * stride] ) {
00105         std::cerr << "ERROR (D1Array Assignment Operator): Cannot allocate data for D1Array<" << typeid(T).name() 
00106                     << "> with size ("<< m_uiSize << ") and stride (" << m_uiStride << ")!" << std::endl;
00107         exit( -1 );
00108     }
00109     return *this;
00110 }

template<typename T>
bool D1Array< T >::Resize ( unsigned int  size,
unsigned int  stride 
) [inline]

Resize.

Definition at line 44 of file TAPsD1Array.cpp.

00045 {
00046     if ( size == 0 ) {
00047         std::cerr << "ERROR (D1Array Ctor): Size is less than one!" << std::endl;
00048         return false;
00049     }
00050     if ( stride == 0 ) {
00051         std::cerr << "ERROR (D1Array Ctor): Stride is less than one!" << std::endl;
00052         return false;
00053     }
00054     T * newArray = new T[size * stride];
00055     if ( !newArray ) {
00056         std::cerr << "ERROR (D1Array Ctor): Cannot allocate data for D1Array<" << typeid(T).name() 
00057                     << "> with size ("<< m_uiSize << ") and stride (" << m_uiStride << ")!" << std::endl;
00058         return false;
00059     }
00060     unsigned int max = m_uiSize*m_uiStride;
00061     if ( max < size*stride )    max = size*stride;
00062     for ( unsigned int i = 0; i < max; ++i ) {
00063         newArray[i] = m_atData[i];
00064     }
00065     delete [] m_atData;
00066     m_atData    = newArray;
00067     m_uiSize    = size;
00068     m_uiStride  = stride;
00069     return true;
00070 }

template<typename T>
std::string D1Array< T >::StrArrayData (  )  const [inline, virtual]

Return all data in the array as a string.

Definition at line 81 of file TAPsD1Array.cpp.

00082 {
00083     std::ostringstream ss;
00084     ss << "D1Array<" << typeid(T).name() << "> with size ("<< m_uiSize << ") and stride (" << m_uiStride << ").\n";
00085     ss << std::fixed;
00086     for ( unsigned int i = 0, p = 0; i < m_uiSize; ++i ) {
00087         ss << "\t# " << i << ":";
00088         for ( unsigned int s = 0; s < m_uiStride; ++s ) {
00089             ss << "\t" << std::setprecision(6) << m_atData[p++];
00090         }
00091         ss << "\n";
00092     }
00093     return ss.str();
00094 }   

template<typename T>
std::string D1Array< T >::StrInfo (  )  const [inline, virtual]

Return this object info as a string.

Definition at line 73 of file TAPsD1Array.cpp.

00074 {
00075     std::ostringstream ss;
00076     ss << "D1Array<" << typeid(T).name() << "> with size ("<< m_uiSize << ") and stride (" << m_uiStride << ").";
00077     return ss.str();
00078 }   


Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  output,
D1Array< T > const &  obj 
) [friend]

Output Operator <<.

Definition at line 26 of file TAPsD1Array.hpp.

00027     {
00028         output << obj.StrInfo();
00029         return output;
00030     }


Member Data Documentation

template<typename T>
T* D1Array< T >::m_atData [protected]

Comparison Operators.

Find the dominate D1Array between D1Array a and D1Array b: return 1 if a dominates b return -1 if b dominates a return 0 if neither dominates the other data array

Definition at line 80 of file TAPsD1Array.hpp.

template<typename T>
unsigned int D1Array< T >::m_uiSize [protected]

size

Definition at line 81 of file TAPsD1Array.hpp.

template<typename T>
unsigned int D1Array< T >::m_uiStride [protected]

stride such as 4 for x,y,z,w

Definition at line 82 of file TAPsD1Array.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Oct 13 11:44:34 2008 for TAPs by  doxygen 1.5.6