TableFile.h
Go to the documentation of this file.
//$$FILE$$
//$$VERSION$$
//$$DATE$$
//$$LICENSE$$
#ifndef TABLEFILE_H
#define TABLEFILE_H
#include <vector>
#include <set>
#include <rcsb/rcsb_types.h>
#include <rcsb/mapped_ptr_vector.h>
#include <rcsb/mapped_ptr_vector.C>
#include <rcsb/GenString.h>
#include <rcsb/ISTable.h>
#include <rcsb/Serializer.h>
class Block
{
public:
mapped_ptr_vector<ISTable, StringLess> _tables;
Block(const string& name, Serializer* serP,
const eFileMode fileMode = READ_MODE, const Char::eCompareType
caseSense = Char::eCASE_SENSITIVE);
~Block();
vector<pair<string, ISTable::eTableDiff> > operator==(Block& inBlock);
inline void SetName(const string& name);
inline const string& GetName() const;
ISTable& AddTable(const std::string& name = string(),
const Char::eCompareType colCaseSense = Char::eCASE_SENSITIVE);
void AddTable(const string& name, const int indexInFile = 0,
ISTable* isTableP = NULL);
void RenameTable(const string& oldName, const string& newName);
void GetTableNames(vector<string>& tableNames);
bool IsTablePresent(const string& tableName);
ISTable& GetTable(const string& tableName);
ISTable* GetTablePtr(const string& tableName);
void DeleteTable(const string& tableName);
void WriteTable(ISTable& isTable);
void WriteTable(ISTable* isTableP);
void Print();
private:
string _name;
eFileMode _fileMode;
Serializer* _ser;
Block(const Block& t);
Block& operator=(const Block& inBlock);
ISTable* _GetTablePtr(const unsigned int tableIndex);
};
class TableFile
{
public:
enum eStatusInd
{
eCLEAR_STATUS = 0x0000,
eDUPLICATE_BLOCKS = 0x0001,
eUNNAMED_BLOCKS = 0x0002
};
TableFile(const Char::eCompareType caseSense = Char::eCASE_SENSITIVE);
TableFile(const eFileMode fileMode, const string& fileName,
const Char::eCompareType caseSense = Char::eCASE_SENSITIVE);
virtual ~TableFile();
inline string GetFileName(void);
inline eFileMode GetFileMode(void);
inline Char::eCompareType GetCaseSensitivity(void);
inline unsigned int GetStatusInd(void);
inline unsigned int GetNumBlocks();
void GetBlockNames(vector<string>& blockNames);
string GetFirstBlockName();
bool IsBlockPresent(const string& blockName);
string AddBlock(const string& blockName);
Block& GetBlock(const string& blockName);
string RenameBlock(const string& oldBlockName, const string& newBlockName);
inline string RenameFirstBlock(const string& newBlockName);
void Flush();
void Serialize(const string& fileName);
void Close();
protected:
string _fileName;
eFileMode _fileMode;
// Indicates case sensitivity of identifiers
Char::eCompareType _caseSense;
// Indicates the current status of the object
unsigned int _statusInd;
mapped_ptr_vector<Block, StringLess> _blocks;
Serializer* _f;
void _SetStatusInd(const string& blockName);
void _AddBlock(const string& blockName, Serializer* serP);
void _GetNumTablesInBlocks(vector<UInt32>& numTablesInBlocks);
ISTable* _GetTablePtr(const unsigned int blockIndex,
const unsigned int tableIndex);
void _GetAllTables();
unsigned int GetTotalNumTables();
void GetTableNames(vector<string>& tableNames);
void GetTablesIndices(vector<unsigned int>& tablesIndices);
void GetSortedTablesIndices(vector<unsigned int>& tablesIndices);
void _ReadFileIndex();
void _ReadFileIndexVersion0();
void _ReadFileIndexVersion1();
void _WriteFileIndex(Serializer* serP,
const vector<unsigned int>& tableLocs);
private:
static const string _version;
void Init();
void Open(const string& fileName, const eFileMode fileMode);
unsigned int GetBlockIndexFromTableId(const string& tableId);
string GetTableNameFromTableId(const string& tableId);
string MakeInternalBlockName(const string& blockName,
const unsigned int blockIndex);
void PrintHeaderInfo();
};
inline void Block::SetName(const string& name)
{
_name = name;
}
inline const string& Block::GetName() const
{
return _name;
}
inline string TableFile::GetFileName(void)
{
return _fileName;
}
inline eFileMode TableFile::GetFileMode(void)
{
return _fileMode;
}
inline Char::eCompareType TableFile::GetCaseSensitivity(void)
{
return(_caseSense);
}
inline unsigned int TableFile::GetStatusInd(void)
{
return _statusInd;
}
inline unsigned int TableFile::GetNumBlocks()
{
return _blocks.size();
}
inline string TableFile::RenameFirstBlock(const string& newBlockName)
{
return(RenameBlock(GetFirstBlockName(), newBlockName));
}
#endif // TABLEFILE_H
TableFile::_f
Serializer * _f
Definition: TableFile.h:703
TableFile::_statusInd
unsigned int _statusInd
Definition: TableFile.h:699
TableFile::GetFileName
string GetFileName(void)
Definition: TableFile.h:751
TableFile::GetNumBlocks
unsigned int GetNumBlocks()
Definition: TableFile.h:775
Block::~Block
~Block()
Block::RenameTable
void RenameTable(const string &oldName, const string &newName)
TableFile::_fileMode
eFileMode _fileMode
Definition: TableFile.h:693
TableFile::_fileName
string _fileName
Definition: TableFile.h:691
TableFile::GetCaseSensitivity
Char::eCompareType GetCaseSensitivity(void)
Definition: TableFile.h:763
Char::eCASE_SENSITIVE
Definition: GenString.h:28
Block::IsTablePresent
bool IsTablePresent(const string &tableName)
Block::WriteTable
void WriteTable(ISTable &isTable)
Block::Block
Block(const string &name, Serializer *serP, const eFileMode fileMode=READ_MODE, const Char::eCompareType caseSense=Char::eCASE_SENSITIVE)
Block::GetTableNames
void GetTableNames(vector< string > &tableNames)
Block::GetName
const string & GetName() const
Definition: TableFile.h:745
mapped_ptr_vector.C
TableFile::eStatusInd
eStatusInd
Definition: TableFile.h:364
TableFile::GetStatusInd
unsigned int GetStatusInd(void)
Definition: TableFile.h:769
Block
Public class that represents a data block, that contains tables.
Definition: TableFile.h:40
mapped_ptr_vector.h
Block::AddTable
ISTable & AddTable(const std::string &name=string(), const Char::eCompareType colCaseSense=Char::eCASE_SENSITIVE)
Block::GetTablePtr
ISTable * GetTablePtr(const string &tableName)
ISTable.h
Header file for ISTable class.
Block::Print
void Print()
Serializer
Definition: Serializer.h:43
Block::DeleteTable
void DeleteTable(const string &tableName)
Block::GetTable
ISTable & GetTable(const string &tableName)
mapped_ptr_vector< ISTable, StringLess >
TableFile::RenameFirstBlock
string RenameFirstBlock(const string &newBlockName)
Definition: TableFile.h:781
Block::SetName
void SetName(const string &name)
Definition: TableFile.h:739
TableFile::_blocks
mapped_ptr_vector< Block, StringLess > _blocks
Definition: TableFile.h:701
GenString.h
TableFile
Public class that represents a file composed of blocks with tables.
Definition: TableFile.h:361
Block::operator==
vector< pair< string, ISTable::eTableDiff > > operator==(Block &inBlock)
Block::_tables
mapped_ptr_vector< ISTable, StringLess > _tables
Definition: TableFile.h:43
Serializer.h
rcsb_types.h
TableFile::_caseSense
Char::eCompareType _caseSense
Definition: TableFile.h:696
READ_MODE
Definition: Serializer.h:36
TableFile::GetFileMode
eFileMode GetFileMode(void)
Definition: TableFile.h:757
ISTable
Public class that respresents a two-dimensional table of strings.
Definition: ISTable.h:53
Char::eCompareType
eCompareType
Definition: GenString.h:26
eFileMode
eFileMode
Definition: Serializer.h:33