00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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