00001
00002
00003
00004
00005
00006
00014 #ifndef TTABLE_H
00015 #define TTABLE_H
00016
00017
00018 #include <string>
00019 #include <vector>
00020
00021 #include "GenString.h"
00022 #include "TableError.h"
00023 #include "FileNavigator.h"
00024
00025
00026 using namespace std;
00027
00028
00043 class TTable
00044 {
00045 public:
00059 TTable();
00060
00077 TTable(const TTable& inTable);
00078
00092 virtual ~TTable();
00093
00108 TTable& operator=(const TTable& inTable);
00109
00123 void Clear();
00124
00138 inline unsigned int GetNumColumns() const;
00139
00140
00141 unsigned int AddColumn(const vector<string>& col = vector<string> (0));
00142
00179 void InsertColumn(const unsigned int colIndex,
00180 const vector<string>& col = vector<string> (0));
00181
00215 void FillColumn(const unsigned int colIndex, const vector<string>& col,
00216 const unsigned int fromRowIndex = 0);
00217
00218 void GetColumn(vector<string>& col, const unsigned int colIndex,
00219 const unsigned int fromRowIndex, unsigned int toRowIndex);
00220
00237 void ClearColumn(const unsigned int colIndex);
00238
00255 void DeleteColumn(const unsigned int colIndex);
00256
00268 inline unsigned int GetNumRows() const;
00269
00299 unsigned int AddRow(const vector<string>& row =
00300 vector<string> (0));
00301
00342 unsigned int InsertRow(const unsigned int atRowIndex,
00343 const vector<string>& row = vector<string> (0));
00344
00369 void FillRow(const unsigned int rowIndex,
00370 const vector<string>& row, const unsigned int fromColIndex = 0);
00371
00411 void GetRow(vector<string>& row, const unsigned int rowIndex,
00412 const unsigned int fromColIndex, unsigned int toColIndex);
00413
00429 void ClearRow(const unsigned int rowIndex);
00430
00448 void DeleteRow(const unsigned int rowIndex);
00449
00471 string& operator()(const unsigned int rowIndex,
00472 const unsigned int colIndex);
00473
00495 const string& operator()(const unsigned int rowIndex,
00496 const unsigned int colIndex) const;
00497
00498 int Write(FileNavigator* fileNav, int& size);
00499 int Read(Word index, FileNavigator* fileNav);
00500
00501 private:
00502 unsigned int _numRows;
00503
00504 vector<vector<string>*> _data;
00505
00506 void CreateColumn(const unsigned int colIndex,
00507 const vector<string>& col = vector<string> (0));
00508
00509 inline unsigned int IntRowIndex(const unsigned int rowIndex) const;
00510
00511 #ifndef IS_TABLE_ROW_DELETE_AS_REMOVE
00512 unsigned int _numDelRows;
00513 vector<unsigned int> _rowMap;
00514
00515 void EnlargeRowMap(const unsigned int numRows);
00516 void ReduceRowMap(const unsigned int numRows);
00517 void MarkRowDeleted(const unsigned int rowIndex);
00518 void UnMarkRowDeleted(const unsigned int rowIndex);
00519 #endif
00520
00521 };
00522
00523
00524 ostream& operator<<(ostream& out, const TTable& sTable);
00525
00526
00527 inline unsigned int TTable::GetNumColumns() const
00528 {
00529 return(_data.size());
00530 }
00531
00532
00533 inline unsigned int TTable::GetNumRows() const
00534 {
00535 #ifndef IS_TABLE_ROW_DELETE_AS_REMOVE
00536 return(_numRows - _numDelRows);
00537 #else
00538 return(_numRows);
00539 #endif
00540 }
00541
00542 inline unsigned int TTable::IntRowIndex(const unsigned int rowIndex) const
00543 {
00544
00545
00546 #ifndef IS_TABLE_ROW_DELETE_AS_REMOVE
00547 return(_rowMap[rowIndex]);
00548 #else
00549 return(rowIndex);
00550 #endif
00551 }
00552
00553 #endif // TTABLE_H