librcsb-core-wrapper  1.005
TableFile.h
Go to the documentation of this file.
1 //$$FILE$$
2 //$$VERSION$$
3 //$$DATE$$
4 //$$LICENSE$$
5 
6 
14 #ifndef TABLEFILE_H
15 #define TABLEFILE_H
16 
17 
18 #include <vector>
19 #include <set>
20 
21 #include <rcsb/rcsb_types.h>
22 #include <rcsb/mapped_ptr_vector.h>
23 #include <rcsb/mapped_ptr_vector.C>
24 #include <rcsb/GenString.h>
25 #include <rcsb/ISTable.h>
26 #include <rcsb/Serializer.h>
27 
28 
40 class Block
41 {
42  public:
44 
67  Block(const string& name, Serializer* serP,
68  const eFileMode fileMode = READ_MODE, const Char::eCompareType
69  caseSense = Char::eCASE_SENSITIVE);
70 
86  ~Block();
87 
120  vector<pair<string, ISTable::eTableDiff> > operator==(Block& inBlock);
121 
137  inline void SetName(const string& name);
138 
152  inline const string& GetName() const;
153 
173  ISTable& AddTable(const std::string& name = string(),
174  const Char::eCompareType colCaseSense = Char::eCASE_SENSITIVE);
175 
179  void AddTable(const string& name, const int indexInFile = 0,
180  ISTable* isTableP = NULL);
181 
208  void RenameTable(const string& oldName, const string& newName);
209 
223  void GetTableNames(vector<string>& tableNames);
224 
239  bool IsTablePresent(const string& tableName);
240 
255  ISTable& GetTable(const string& tableName);
256 
271  ISTable* GetTablePtr(const string& tableName);
272 
286  void DeleteTable(const string& tableName);
287 
303  void WriteTable(ISTable& isTable);
304 
320  void WriteTable(ISTable* isTableP);
321 
325  void Print();
326 
327  private:
328  string _name;
329  eFileMode _fileMode;
330  Serializer* _ser;
331 
332  Block(const Block& t);
333  Block& operator=(const Block& inBlock);
334 
335  ISTable* _GetTablePtr(const unsigned int tableIndex);
336 };
337 
338 
362 {
363  public:
365  {
366  eCLEAR_STATUS = 0x0000,
369  };
370 
388 
410  TableFile(const eFileMode fileMode, const string& fileName,
411  const Char::eCompareType caseSense = Char::eCASE_SENSITIVE);
412 
428  virtual ~TableFile();
429 
444  inline string GetFileName(void);
445 
462  inline eFileMode GetFileMode(void);
463 
479 
498  inline unsigned int GetStatusInd(void);
499 
513  inline unsigned int GetNumBlocks();
514 
528  void GetBlockNames(vector<string>& blockNames);
529 
543  string GetFirstBlockName();
544 
559  bool IsBlockPresent(const string& blockName);
560 
582  string AddBlock(const string& blockName);
583 
598  Block& GetBlock(const string& blockName);
599 
620  string RenameBlock(const string& oldBlockName, const string& newBlockName);
621 
637  inline string RenameFirstBlock(const string& newBlockName);
638 
655  void Flush();
656 
672  void Serialize(const string& fileName);
673 
688  void Close();
689 
690  protected:
691  string _fileName;
692 
694 
695  // Indicates case sensitivity of identifiers
697 
698  // Indicates the current status of the object
699  unsigned int _statusInd;
700 
702 
704 
705  void _SetStatusInd(const string& blockName);
706 
707  void _AddBlock(const string& blockName, Serializer* serP);
708 
709  void _GetNumTablesInBlocks(vector<UInt32>& numTablesInBlocks);
710 
711  ISTable* _GetTablePtr(const unsigned int blockIndex,
712  const unsigned int tableIndex);
713  void _GetAllTables();
714 
715  unsigned int GetTotalNumTables();
716  void GetTableNames(vector<string>& tableNames);
717 
718  void GetTablesIndices(vector<unsigned int>& tablesIndices);
719  void GetSortedTablesIndices(vector<unsigned int>& tablesIndices);
720 
721  void _ReadFileIndex();
722  void _ReadFileIndexVersion0();
723  void _ReadFileIndexVersion1();
724  void _WriteFileIndex(Serializer* serP,
725  const vector<unsigned int>& tableLocs);
726 
727  private:
728  static const string _version;
729  void Init();
730  void Open(const string& fileName, const eFileMode fileMode);
731  unsigned int GetBlockIndexFromTableId(const string& tableId);
732  string GetTableNameFromTableId(const string& tableId);
733  string MakeInternalBlockName(const string& blockName,
734  const unsigned int blockIndex);
735  void PrintHeaderInfo();
736 };
737 
738 
739 inline void Block::SetName(const string& name)
740 {
741  _name = name;
742 }
743 
744 
745 inline const string& Block::GetName() const
746 {
747  return _name;
748 }
749 
750 
751 inline string TableFile::GetFileName(void)
752 {
753  return _fileName;
754 }
755 
756 
758 {
759  return _fileMode;
760 }
761 
762 
764 {
765  return(_caseSense);
766 }
767 
768 
769 inline unsigned int TableFile::GetStatusInd(void)
770 {
771  return _statusInd;
772 }
773 
774 
775 inline unsigned int TableFile::GetNumBlocks()
776 {
777  return _blocks.size();
778 }
779 
780 
781 inline string TableFile::RenameFirstBlock(const string& newBlockName)
782 {
783  return(RenameBlock(GetFirstBlockName(), newBlockName));
784 }
785 
786 
787 #endif // TABLEFILE_H
Serializer * _f
Definition: TableFile.h:703
void _GetNumTablesInBlocks(vector< UInt32 > &numTablesInBlocks)
void _ReadFileIndex()
void GetTablesIndices(vector< unsigned int > &tablesIndices)
unsigned int _statusInd
Definition: TableFile.h:699
Definition: TableFile.h:367
void Close()
string GetFileName(void)
Definition: TableFile.h:751
unsigned int GetNumBlocks()
Definition: TableFile.h:775
string GetFirstBlockName()
void RenameTable(const string &oldName, const string &newName)
eFileMode _fileMode
Definition: TableFile.h:693
string _fileName
Definition: TableFile.h:691
Char::eCompareType GetCaseSensitivity(void)
Definition: TableFile.h:763
Definition: GenString.h:28
bool IsTablePresent(const string &tableName)
void GetTableNames(vector< string > &tableNames)
void WriteTable(ISTable &isTable)
void GetSortedTablesIndices(vector< unsigned int > &tablesIndices)
void _AddBlock(const string &blockName, Serializer *serP)
void _GetAllTables()
const string & GetName() const
Definition: TableFile.h:745
Block(const string &name, Serializer *serP, const eFileMode fileMode=READ_MODE, const Char::eCompareType caseSense=Char::eCASE_SENSITIVE)
void GetTableNames(vector< string > &tableNames)
void Flush()
virtual ~TableFile()
unsigned int GetTotalNumTables()
TableFile(const Char::eCompareType caseSense=Char::eCASE_SENSITIVE)
eStatusInd
Definition: TableFile.h:364
void _SetStatusInd(const string &blockName)
unsigned int GetStatusInd(void)
Definition: TableFile.h:769
void _WriteFileIndex(Serializer *serP, const vector< unsigned int > &tableLocs)
string RenameBlock(const string &oldBlockName, const string &newBlockName)
unsigned int size() const
Definition: mapped_ptr_vector.C:78
Public class that represents a data block, that contains tables.
Definition: TableFile.h:40
Definition: TableFile.h:368
ISTable * _GetTablePtr(const unsigned int blockIndex, const unsigned int tableIndex)
void Serialize(const string &fileName)
ISTable & AddTable(const std::string &name=string(), const Char::eCompareType colCaseSense=Char::eCASE_SENSITIVE)
ISTable * GetTablePtr(const string &tableName)
Block & GetBlock(const string &blockName)
void _ReadFileIndexVersion1()
Header file for ISTable class.
Definition: TableFile.h:366
void Print()
Definition: Serializer.h:43
void DeleteTable(const string &tableName)
ISTable & GetTable(const string &tableName)
string RenameFirstBlock(const string &newBlockName)
Definition: TableFile.h:781
void SetName(const string &name)
Definition: TableFile.h:739
mapped_ptr_vector< Block, StringLess > _blocks
Definition: TableFile.h:701
Public class that represents a file composed of blocks with tables.
Definition: TableFile.h:361
vector< pair< string, ISTable::eTableDiff > > operator==(Block &inBlock)
mapped_ptr_vector< ISTable, StringLess > _tables
Definition: TableFile.h:43
string AddBlock(const string &blockName)
Char::eCompareType _caseSense
Definition: TableFile.h:696
void GetBlockNames(vector< string > &blockNames)
void _ReadFileIndexVersion0()
Definition: Serializer.h:36
eFileMode GetFileMode(void)
Definition: TableFile.h:757
Public class that respresents a two-dimensional table of strings.
Definition: ISTable.h:53
bool IsBlockPresent(const string &blockName)
eCompareType
Definition: GenString.h:26
eFileMode
Definition: Serializer.h:33