00001
00002
00003
00004
00005
00006
00007 #ifndef TABLEFILE_H
00008 #define TABLEFILE_H
00009
00010
00011 #include <vector>
00012 #include <set>
00013
00014 #ifndef VLAD_DECIDE
00015 #include "mapped_vector.h"
00016 #include "mapped_vector.C"
00017 #endif
00018 #include "mapped_ptr_vector.h"
00019 #include "mapped_ptr_vector.C"
00020 #include "ISTable.h"
00021 #include "FileNavigator.h"
00022 #include "FileNavigatorError.h"
00023
00024
00028 class Block
00029 {
00030 private:
00031 string _name;
00032 eFileMode _fileMode;
00033 FileNavigator* _fileNav;
00034
00035 ISTable* _GetTablePtr(const unsigned int tableIndex);
00036
00037 public:
00038 mapped_ptr_vector<ISTable, StringCompare> _tables;
00039
00040 Block(const string& name, FileNavigator* fileNav,
00041 const eFileMode fileMode = READ_MODE, const StringCompare::eCompareType
00042 caseSense = StringCompare::eCASE_SENSITIVE);
00043 Block(const Block& t);
00044 ~Block();
00045
00046 vector<pair<string, ISTable::eTableDiff> > operator==(Block& inBlock);
00047
00048 inline void SetName(const string& name);
00049 inline string GetName() const;
00050
00052 void AddTable(const string& name,
00053 const int indexInFile = 0, ISTable* isTableP = NULL);
00054
00055 void GetTableNames(vector<string>& names);
00056 bool IsTablePresent(const string& name);
00057
00058 ISTable* GetTablePtr(const string& name);
00059
00060 void DeleteTable(const string& name);
00061
00063 void WriteTable(ISTable* isTableP);
00064
00065 void Print();
00066 };
00067
00068
00072 class TableFile
00073 {
00074 private:
00075 static const string _version;
00076 void Init();
00077 int Open(const string& fileName, const eFileMode fileMode);
00078
00079 protected:
00080 string _fileName;
00081
00082 eFileMode _fileMode;
00083
00084
00085 StringCompare::eCompareType _caseSense;
00086
00087
00088 unsigned int _statusInd;
00089
00090 mapped_ptr_vector<Block, StringCompare> _blocks;
00091
00092 FileNavigator* _f;
00093
00094 void _SetStatusInd(const string& blockName);
00095
00096 void _AddBlock(const string& blockName, FileNavigator* fileNav);
00097
00098 void _GetNumTablesInBlocks(vector<Word>& numTablesInBlocks);
00099
00100 ISTable* _GetTablePtr(const unsigned int blockIndex,
00101 const unsigned int tableIndex);
00102 void _GetAllTables();
00103
00104 unsigned int GetTotalNumTables();
00105 void GetTableNames(vector<string>& tableNames);
00106
00107 void GetTablesIndices(vector<unsigned int>& tablesIndices);
00108 void GetSortedTablesIndices(vector<unsigned int>& tablesIndices);
00109
00110 int _ReadFileIndex();
00111 int _ReadFileIndexVersion0();
00112 int _ReadFileIndexVersion1();
00113 int _WriteFileIndex(FileNavigator* fileNav, const vector<int>& tableLocs);
00114
00115 public:
00116 enum eStatusInd
00117 {
00118 eCLEAR_STATUS = 0x0000,
00119 eDUPLICATE_BLOCKS = 0x0001,
00120 eUNNAMED_BLOCKS = 0x0002
00121 };
00122
00123 TableFile(const StringCompare::eCompareType caseSense =
00124 StringCompare::eCASE_SENSITIVE);
00125
00126 TableFile(const eFileMode fileMode, const string& fileName,
00127 const StringCompare::eCompareType caseSense =
00128 StringCompare::eCASE_SENSITIVE);
00129
00130 virtual ~TableFile();
00131
00132 inline string GetFileName(void);
00133 inline eFileMode GetFileMode(void);
00134 inline StringCompare::eCompareType GetCaseSensitivity(void);
00135 inline unsigned int GetStatusInd(void);
00136
00138 string AddBlock(const string& blockName);
00139
00140 bool IsBlockPresent(const string& blockName);
00141
00142 inline unsigned int GetNumBlocks();
00143 string GetFirstBlockName();
00144 void GetBlockNames(vector<string>& blockNames);
00145 #ifndef VLAD_DECIDE
00146 void GetBlockNames(mapped_vector<string>& blockNames);
00147 #endif
00148 void RenameBlock(const string& oldBlockName, const string& newBlockName);
00149 inline void RenameFirstBlock(const string& newBlockName);
00150
00151 Block& GetBlock(const string& blockName);
00152
00153 void Flush();
00154
00155 void Serialize(const string& fileName);
00156
00157 void Close();
00158
00159 void PrintHeaderInfo();
00160
00161 inline void DumpFile(void);
00162 inline void PrintIndex(void);
00163 inline void PrintIndexPosition(int position);
00164 };
00165
00166
00167 inline void Block::SetName(const string& name)
00168 {
00169 _name = name;
00170 }
00171
00172
00173 inline string Block::GetName() const
00174 {
00175 return _name;
00176 }
00177
00178
00179 inline string TableFile::GetFileName(void)
00180 {
00181 return _fileName;
00182 }
00183
00184
00185 inline eFileMode TableFile::GetFileMode(void)
00186 {
00187 return _fileMode;
00188 }
00189
00190
00191 inline StringCompare::eCompareType TableFile::GetCaseSensitivity(void)
00192 {
00193 return(_caseSense);
00194 }
00195
00196
00197 inline unsigned int TableFile::GetStatusInd(void)
00198 {
00199 return _statusInd;
00200 }
00201
00202
00203 inline unsigned int TableFile::GetNumBlocks()
00204 {
00205 return _blocks.size();
00206 }
00207
00208
00209 inline void TableFile::RenameFirstBlock(const string& newBlockName)
00210 {
00211 RenameBlock(GetFirstBlockName(), newBlockName);
00212 }
00213
00214
00215 inline void TableFile::DumpFile(void)
00216 {
00217 if (_f)
00218 _f->DumpFile();
00219 }
00220
00221
00222 inline void TableFile::PrintIndex(void)
00223 {
00224 if (_f)
00225 _f->PrintIndex();
00226 }
00227
00228
00229 inline void TableFile::PrintIndexPosition(int position)
00230 {
00231 if (_f)
00232 _f->PrintIndexPosition(position);
00233 }
00234
00235
00236 #endif // TABLEFILE_H