TableFile.h

Go to the documentation of this file.
00001 //$$FILE$$
00002 //$$VERSION$$
00003 //$$DATE$$
00004 //$$LICENSE$$
00005 
00006 
00014 #ifndef TABLEFILE_H
00015 #define TABLEFILE_H
00016 
00017 
00018 #include <vector>
00019 #include <set>
00020 
00021 #include "mapped_ptr_vector.h"
00022 #include "mapped_ptr_vector.C"
00023 #include "ISTable.h"
00024 #include "FileNavigator.h"
00025 #include "FileNavigatorError.h"
00026 
00027 
00039 class Block
00040 {
00041   public:
00042     mapped_ptr_vector<ISTable, StringCompare> _tables;
00043 
00066     Block(const string& name, FileNavigator* fileNavP,
00067       const eFileMode fileMode = READ_MODE, const StringCompare::eCompareType
00068       caseSense = StringCompare::eCASE_SENSITIVE);
00069 
00085     ~Block();
00086 
00119     vector<pair<string, ISTable::eTableDiff> > operator==(Block& inBlock);
00120 
00136     inline void SetName(const string& name);
00137 
00151     inline string GetName() const;
00152 
00156     void AddTable(const string& name, const int indexInFile = 0,
00157       ISTable* isTableP = NULL);
00158 
00172     void GetTableNames(vector<string>& tableNames);
00173 
00188     bool IsTablePresent(const string& tableName);
00189 
00204     ISTable* GetTablePtr(const string& tableName);
00205 
00219     void DeleteTable(const string& tableName);
00220 
00236     void WriteTable(ISTable* isTableP);
00237 
00241     void Print();
00242 
00243   private:
00244     string _name;
00245     eFileMode _fileMode;
00246     FileNavigator* _fileNav;
00247 
00248     Block(const Block& t);
00249     Block& operator=(const Block& inBlock);
00250 
00251     ISTable* _GetTablePtr(const unsigned int tableIndex);
00252 };
00253 
00254 
00277 class TableFile
00278 {
00279   public:
00280     enum eStatusInd
00281     {
00282         eCLEAR_STATUS = 0x0000,
00283         eDUPLICATE_BLOCKS = 0x0001,
00284         eUNNAMED_BLOCKS = 0x0002
00285     };
00286 
00303     TableFile(const StringCompare::eCompareType caseSense =
00304       StringCompare::eCASE_SENSITIVE);
00305 
00327     TableFile(const eFileMode fileMode, const string& fileName,
00328       const StringCompare::eCompareType caseSense =
00329       StringCompare::eCASE_SENSITIVE);
00330 
00346     virtual ~TableFile();
00347 
00362     inline string GetFileName(void);
00363 
00380     inline eFileMode GetFileMode(void);
00381 
00396     inline StringCompare::eCompareType GetCaseSensitivity(void);
00397 
00416     inline unsigned int GetStatusInd(void);
00417 
00431     inline unsigned int GetNumBlocks();
00432 
00446     void GetBlockNames(vector<string>& blockNames);
00447 
00461     string GetFirstBlockName();
00462 
00477     bool IsBlockPresent(const string& blockName);
00478 
00500     string AddBlock(const string& blockName);
00501 
00516     Block& GetBlock(const string& blockName);
00517 
00538     string RenameBlock(const string& oldBlockName, const string& newBlockName);
00539 
00555     inline string RenameFirstBlock(const string& newBlockName);
00556 
00573     void Flush();
00574 
00590     void Serialize(const string& fileName);
00591 
00606     void Close();
00607 
00608   protected:
00609     string _fileName;
00610 
00611     eFileMode _fileMode;
00612 
00613     // Indicates case sensitivity of identifiers
00614     StringCompare::eCompareType _caseSense;
00615 
00616     // Indicates the current status of the object
00617     unsigned int _statusInd;  
00618 
00619     mapped_ptr_vector<Block, StringCompare> _blocks;
00620 
00621     FileNavigator* _f;
00622 
00623     void _SetStatusInd(const string& blockName);
00624 
00625     void _AddBlock(const string& blockName, FileNavigator* fileNav);
00626 
00627     void _GetNumTablesInBlocks(vector<Word>& numTablesInBlocks);
00628 
00629     ISTable* _GetTablePtr(const unsigned int blockIndex,
00630       const unsigned int tableIndex);
00631     void _GetAllTables();
00632 
00633     unsigned int GetTotalNumTables();
00634     void GetTableNames(vector<string>& tableNames);
00635 
00636     void GetTablesIndices(vector<unsigned int>& tablesIndices);
00637     void GetSortedTablesIndices(vector<unsigned int>& tablesIndices);
00638 
00639     int _ReadFileIndex();
00640     int _ReadFileIndexVersion0();
00641     int _ReadFileIndexVersion1();
00642     int _WriteFileIndex(FileNavigator* fileNav, const vector<int>& tableLocs);
00643 
00644   private:
00645     static const string _version;
00646     void Init();
00647     int Open(const string& fileName, const eFileMode fileMode);
00648     unsigned int GetBlockIndexFromTableId(const string& tableId);
00649     string GetTableNameFromTableId(const string& tableId);
00650     string MakeInternalBlockName(const string& blockName);
00651     void PrintHeaderInfo();
00652     inline void DumpFile(void);
00653     inline void PrintIndex(void);
00654     inline void PrintIndexPosition(int position);
00655 };
00656 
00657 
00658 inline void Block::SetName(const string& name)
00659 {
00660     _name = name;
00661 }
00662 
00663 
00664 inline string Block::GetName() const
00665 {
00666     return _name;
00667 } 
00668 
00669 
00670 inline string TableFile::GetFileName(void)
00671 {
00672     return _fileName;
00673 }
00674 
00675 
00676 inline eFileMode TableFile::GetFileMode(void)
00677 {
00678     return _fileMode;
00679 }
00680 
00681 
00682 inline StringCompare::eCompareType TableFile::GetCaseSensitivity(void)
00683 {
00684     return(_caseSense);
00685 }
00686 
00687 
00688 inline unsigned int TableFile::GetStatusInd(void)
00689 {
00690     return _statusInd;
00691 }
00692 
00693    
00694 inline unsigned int TableFile::GetNumBlocks()
00695 {
00696     return _blocks.size();
00697 }
00698 
00699 
00700 inline string TableFile::RenameFirstBlock(const string& newBlockName)
00701 {
00702     return(RenameBlock(GetFirstBlockName(), newBlockName));
00703 }
00704 
00705 
00706 inline void TableFile::DumpFile(void)
00707 {
00708     if (_f)
00709         _f->DumpFile();
00710 }
00711 
00712 
00713 inline void TableFile::PrintIndex(void)
00714 {
00715     if (_f)
00716         _f->PrintIndex();
00717 }
00718 
00719 
00720 inline void TableFile::PrintIndexPosition(int position)
00721 {
00722     if (_f)
00723         _f->PrintIndexPosition(position);
00724 }
00725 
00726 
00727 #endif // TABLEFILE_H

Generated on Tue Apr 24 08:45:21 2007 for tables-v8.0 by  doxygen 1.5.1