• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/data/DataTable.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _datatable_h
00018 #define _datatable_h
00019 
00020 #include <spl/Debug.h>
00021 #include <spl/collection/Hashtable.h>
00022 #include <spl/Memory.h>
00023 #include <spl/data/DataColumn.h>
00024 #include <spl/data/DataRow.h>
00025 #include <spl/String.h>
00026 
00036 class DataTable : public IMemoryValidate
00037 {
00038 private:
00039         String m_name;
00040         Vector<DataRowPtr> m_rows;
00041         Vector<DataColumnPtr> m_cols;
00042         Hashtable<String, DataColumnPtr> m_colIdx;
00043 
00044 public:
00045         DataTable();
00046         DataTable(const String& name);
00047         DataTable(const DataTable& dt);
00048         virtual ~DataTable();
00049 
00050         DataTable& operator =(const DataTable& dt);
00051 
00052         inline String& Name() { return m_name; }
00053         
00054         inline int RowCount() const { return m_rows.Count(); }
00055 
00056         inline DataRowPtr Row(int rowNum) const { return m_rows.ElementAt(rowNum); }
00057 
00058         inline VariantPtr Cell(int rowNum, int colNum) const { return m_rows.ElementAt(rowNum)->Cell(colNum); }
00059 
00060         inline VariantPtr Cell(int rowNum, const String& colName) const
00061         { 
00062                 return m_rows.ElementAt(rowNum)->Cell(m_colIdx.Get(colName)->Index()); 
00063         }
00064 
00065         inline DataColumnPtr Column(const String& name) const
00066         {
00067                 return m_colIdx.Get(name);
00068         }
00069 
00070         inline DataColumnPtr Column(int index) const
00071         {
00072                 return m_cols.ElementAt(index);
00073         }
00074 
00075         inline int ColumnCount() const { return m_cols.Count(); }
00076 
00077         inline void Clear() { m_cols.Clear(); m_rows.Clear(); m_colIdx.Clear(); m_name = ""; }
00078 
00079         DataRowPtr AddRow();
00080         void AddRow(DataRowPtr row);
00081 
00082         DataColumnPtr AddColumn(const String& name);
00083         void AddColumn(DataColumnPtr col);
00084 
00085 #if defined(DEBUG)
00086         virtual void CheckMem() const;
00087         virtual void ValidateMem() const;
00088 #endif
00089 };
00090 
00093 #endif