00001
00002
00003
00004
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 "Serializer.h"
00025 #include "rcsb_types.h"
00026
00027
00039 class Block
00040 {
00041 public:
00042 mapped_ptr_vector<ISTable, StringCompare> _tables;
00043
00066 Block(const string& name, Serializer* serP,
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
00185 void RenameTable(const string& oldName, const string& newName);
00186
00200 void GetTableNames(vector<string>& tableNames);
00201
00216 bool IsTablePresent(const string& tableName);
00217
00232 ISTable* GetTablePtr(const string& tableName);
00233
00247 void DeleteTable(const string& tableName);
00248
00264 void WriteTable(ISTable* isTableP);
00265
00269 void Print();
00270
00271 private:
00272 string _name;
00273 eFileMode _fileMode;
00274 Serializer* _ser;
00275
00276 Block(const Block& t);
00277 Block& operator=(const Block& inBlock);
00278
00279 ISTable* _GetTablePtr(const unsigned int tableIndex);
00280 };
00281
00282
00305 class TableFile
00306 {
00307 public:
00308 enum eStatusInd
00309 {
00310 eCLEAR_STATUS = 0x0000,
00311 eDUPLICATE_BLOCKS = 0x0001,
00312 eUNNAMED_BLOCKS = 0x0002
00313 };
00314
00331 TableFile(const StringCompare::eCompareType caseSense =
00332 StringCompare::eCASE_SENSITIVE);
00333
00355 TableFile(const eFileMode fileMode, const string& fileName,
00356 const StringCompare::eCompareType caseSense =
00357 StringCompare::eCASE_SENSITIVE);
00358
00374 virtual ~TableFile();
00375
00390 inline string GetFileName(void);
00391
00408 inline eFileMode GetFileMode(void);
00409
00424 inline StringCompare::eCompareType GetCaseSensitivity(void);
00425
00444 inline unsigned int GetStatusInd(void);
00445
00459 inline unsigned int GetNumBlocks();
00460
00474 void GetBlockNames(vector<string>& blockNames);
00475
00489 string GetFirstBlockName();
00490
00505 bool IsBlockPresent(const string& blockName);
00506
00528 string AddBlock(const string& blockName);
00529
00544 Block& GetBlock(const string& blockName);
00545
00566 string RenameBlock(const string& oldBlockName, const string& newBlockName);
00567
00583 inline string RenameFirstBlock(const string& newBlockName);
00584
00601 void Flush();
00602
00618 void Serialize(const string& fileName);
00619
00634 void Close();
00635
00636 protected:
00637 string _fileName;
00638
00639 eFileMode _fileMode;
00640
00641
00642 StringCompare::eCompareType _caseSense;
00643
00644
00645 unsigned int _statusInd;
00646
00647 mapped_ptr_vector<Block, StringCompare> _blocks;
00648
00649 Serializer* _f;
00650
00651 void _SetStatusInd(const string& blockName);
00652
00653 void _AddBlock(const string& blockName, Serializer* serP);
00654
00655 void _GetNumTablesInBlocks(vector<UInt32>& numTablesInBlocks);
00656
00657 ISTable* _GetTablePtr(const unsigned int blockIndex,
00658 const unsigned int tableIndex);
00659 void _GetAllTables();
00660
00661 unsigned int GetTotalNumTables();
00662 void GetTableNames(vector<string>& tableNames);
00663
00664 void GetTablesIndices(vector<unsigned int>& tablesIndices);
00665 void GetSortedTablesIndices(vector<unsigned int>& tablesIndices);
00666
00667 void _ReadFileIndex();
00668 void _ReadFileIndexVersion0();
00669 void _ReadFileIndexVersion1();
00670 void _WriteFileIndex(Serializer* serP,
00671 const vector<unsigned int>& tableLocs);
00672
00673 private:
00674 static const string _version;
00675 void Init();
00676 void Open(const string& fileName, const eFileMode fileMode);
00677 unsigned int GetBlockIndexFromTableId(const string& tableId);
00678 string GetTableNameFromTableId(const string& tableId);
00679 string MakeInternalBlockName(const string& blockName,
00680 const unsigned int blockIndex);
00681 void PrintHeaderInfo();
00682 };
00683
00684
00685 inline void Block::SetName(const string& name)
00686 {
00687 _name = name;
00688 }
00689
00690
00691 inline string Block::GetName() const
00692 {
00693 return _name;
00694 }
00695
00696
00697 inline string TableFile::GetFileName(void)
00698 {
00699 return _fileName;
00700 }
00701
00702
00703 inline eFileMode TableFile::GetFileMode(void)
00704 {
00705 return _fileMode;
00706 }
00707
00708
00709 inline StringCompare::eCompareType TableFile::GetCaseSensitivity(void)
00710 {
00711 return(_caseSense);
00712 }
00713
00714
00715 inline unsigned int TableFile::GetStatusInd(void)
00716 {
00717 return _statusInd;
00718 }
00719
00720
00721 inline unsigned int TableFile::GetNumBlocks()
00722 {
00723 return _blocks.size();
00724 }
00725
00726
00727 inline string TableFile::RenameFirstBlock(const string& newBlockName)
00728 {
00729 return(RenameBlock(GetFirstBlockName(), newBlockName));
00730 }
00731
00732
00733 #endif // TABLEFILE_H