Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

ColumnTem.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Column_ColumnTem_h
00002 #define Impala_Core_Column_ColumnTem_h
00003 
00004 #include <iostream>
00005 
00006 #include "Basis/ILog.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Column
00013 {
00014 
00015 
00019 template <class ElemT>
00020 class ColumnTem
00021 {
00022 public:
00023 
00024     typedef ElemT ColElemType;
00025 
00027     ColumnTem()
00028     {
00029         mCapacity = 0;
00030         mData = 0;
00031     }
00032 
00034     ColumnTem(int n)
00035     {
00036         mCapacity = n;
00037         mData = new ElemT[mCapacity];
00038     }
00039 
00041     ColumnTem(const ColumnTem& c)
00042     {
00043         mCapacity = c.mCapacity;
00044         mData = new ElemT[mCapacity];
00045         for (int i=0 ; i<mCapacity ; i++)
00046             mData[i] = c.mData[i];
00047     }
00048 
00050     virtual
00051     ~ColumnTem()
00052     {
00053         if (mData)
00054             delete [] mData; 
00055     }
00056 
00058     bool
00059     Valid() const
00060     {
00061         return true;
00062     }
00063 
00066     int
00067     Capacity() const
00068     { 
00069         return mCapacity; 
00070     }
00071     int
00072     Size() const
00073     { 
00074         return mCapacity; 
00075     }
00077 
00079     bool
00080     Reserve(int newCapacity, bool copyData)
00081     {
00082         if (newCapacity == mCapacity)
00083             return true;
00084         int common = (newCapacity > mCapacity) ? mCapacity : newCapacity;
00085         mCapacity = newCapacity;
00086         ElemT* newData = new ElemT[mCapacity];
00087         if (newData == 0)
00088         {
00089             std::cout << "ColumnTem: could not resize, no memory" << std::endl;
00090             return false;
00091         }
00092         if (copyData)
00093             for (int i=0 ; i<common ; i++)
00094                 newData[i] = mData[i];
00095         delete [] mData;
00096         mData = newData;
00097         return true;
00098     }
00099 
00101     ColumnTem&
00102     operator=(const ColumnTem& c)
00103     {
00104         if (this != &c)
00105         {
00106             if (mCapacity != c.mCapacity)
00107             {
00108                 delete [] mData;
00109                 mCapacity = c.mCapacity;
00110                 mData = new ElemT[mCapacity];
00111             }
00112             for (int i=0 ; i<mCapacity ; i++)
00113                 mData[i] = c.mData[i];
00114         }
00115         return *this;
00116     }
00117 
00119     ElemT&
00120     operator[](int i)
00121     { 
00122         //CheckIndex(i, "operator_array");
00123         return mData[i];
00124     }
00125 
00126     ElemT&
00127     Elem(int i)
00128     { 
00129         //CheckIndex(i, "Elem");
00130         return mData[i];
00131     }
00132 
00133     ElemT
00134     Get(int i) const
00135     { 
00136         //CheckIndex(i, "Get");
00137         return mData[i];
00138     }
00139 
00140     void
00141     Set(int i, ElemT e)
00142     {
00143         //CheckIndex(i, "Set");
00144         mData[i] = e;
00145     }
00146 
00147     // direct access, use with care
00148 
00149     ElemT*
00150     GetData()
00151     { 
00152         return mData;
00153     }
00154 
00155     void
00156     SetData(ElemT* data, int nrElem)
00157     {
00158         if (mData)
00159             delete mData;
00160         mData = data;
00161         mCapacity = nrElem;
00162     }
00163 
00164     void
00165     Print(int from=0, int to=-1)
00166     {
00167         if (to < 0 || to > mCapacity)
00168             to = mCapacity - 1;
00169         for (int i=from ; i<to ; ++i)
00170             std::cout << mData[i] << std::endl;
00171         std::cout << std::endl;
00172     }
00173 
00174 private:
00175 
00176     void
00177     CheckIndex(int index, String tag = "CheckIndex") const
00178     {
00179         ILOG_VAR(Impala.Core.Column.ColumnTem);
00180         if (index >= mCapacity)
00181             ILOG_ERROR("[" << tag << "] Index out of range: " << index);
00182     }
00183 
00184     int    mCapacity; // number of elements
00185     ElemT* mData;     // data pointer
00186 };
00187 
00188 } // namespace Column
00189 } // namespace Core
00190 } // namespace Impala
00191 
00192 #endif

Generated on Fri Mar 19 09:31:03 2010 for ImpalaSrc by  doxygen 1.5.1