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

src/data/DataTable.cpp

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 #include <spl/data/DataTable.h>
00018 
00019 DataTable::DataTable()
00020 : m_name("table"), m_rows(100), m_cols(), m_colIdx()
00021 {
00022 }
00023 
00024 DataTable::DataTable(const String& name)
00025 : m_name(name), m_rows(100), m_cols(), m_colIdx()
00026 {
00027 }
00028 
00029 DataTable::DataTable(const DataTable& dt)
00030 : m_name(), m_rows(), m_cols(), m_colIdx()
00031 {
00032         *this = dt;
00033 }
00034 
00035 DataTable::~DataTable()
00036 {
00037 }
00038 
00039 DataTable& DataTable::operator =(const DataTable& dt)
00040 {
00041         m_name = dt.m_name;
00042         m_cols = dt.m_cols;
00043         m_colIdx = dt.m_colIdx;
00044 
00045         for (int x = 0; x < dt.m_rows.Count(); x++ )
00046         {
00047                 m_rows.Add(DataRowPtr(new  DataRow(dt.m_rows.ElementAt(x))));
00048         }
00049 
00050         return *this;
00051 }
00052 
00053 DataRowPtr DataTable::AddRow()
00054 {
00055         DataRowPtr row( new DataRow(m_cols) );
00056         m_rows.Add(row);
00057         return row;
00058 }
00059 
00060 void DataTable::AddRow(DataRowPtr row)
00061 {
00062         ASSERT(m_cols.Count() == 0 || row->Count() == m_cols.Count());
00063         m_rows.Add(row);
00064 }
00065 
00066 DataColumnPtr DataTable::AddColumn(const String& name)
00067 {
00068         DataColumnPtr col(new DataColumn(name));
00069         m_cols.Add(col);
00070 
00071         for (int x = 0; x < m_rows.Count(); x++ )
00072         {
00073                 m_rows.ElementAt(x)->AddColumn(col);
00074         }
00075 
00076         return col;
00077 }
00078 
00079 void DataTable::AddColumn(DataColumnPtr col)
00080 {
00081         m_cols.Add(col);
00082         for (int x = 0; x < m_rows.Count(); x++ )
00083         {
00084                 m_rows.ElementAt(x)->AddColumn(col);
00085         }
00086 }
00087 
00088 #if defined(DEBUG)
00089 void DataTable::CheckMem() const
00090 {
00091         m_name.CheckMem();
00092         m_rows.CheckMem();
00093         m_cols.CheckMem();
00094         m_colIdx.CheckMem();
00095 }
00096 
00097 void DataTable::ValidateMem() const
00098 {
00099         m_name.ValidateMem();
00100         m_rows.ValidateMem();
00101         m_cols.ValidateMem();
00102         m_colIdx.ValidateMem();
00103 }
00104 #endif