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