ITTable.h
Go to the documentation of this file.
//$$FILE$$
//$$VERSION$$
//$$DATE$$
//$$LICENSE$$
#ifndef ITTABLE_H
#define ITTABLE_H
#include <float.h>
#include <string>
#include <vector>
#include <map>
#include <rcsb/GenString.h>
#include <rcsb/TTable.h>
#include <rcsb/Serializer.h>
typedef std::multimap<std::string, unsigned int, StringLess> tIndex;
class ITTable
{
public:
enum eOrientation
{
eCOLUMN_WISE = 0,
eROW_WISE
};
enum eSearchType
{
eEQUAL = 0,
eLESS_THAN,
eLESS_THAN_OR_EQUAL,
eGREATER_THAN,
eGREATER_THAN_OR_EQUAL
};
enum eSearchDir
{
eFORWARD = 0,
eBACKWARD
};
static const unsigned char DT_STRING_VAL = 1;
static const unsigned char DT_INTEGER_VAL = 2;
// static const unsigned char DT_DOUBLE_VAL = 3;
// Sets string comparison case sensitive
static const unsigned char CASE_SENSE = 0x00;
// Sets string comparison case insensitive
static const unsigned char CASE_INSENSE = 0x01;
// Sets string comparison to be sensitive to whitespace
static const unsigned char W_SPACE_SENSE = 0x00;
// Sets string comparison to ignore repeating whitspace.
// Also ignores leading and trailing whitespace
static const unsigned char W_SPACE_INSENSE = 0x02;
// string datatype
static const unsigned char DT_STRING = DT_STRING_VAL << 4;
// integer datatype
static const unsigned char DT_INTEGER = DT_INTEGER_VAL << 4;
// VLAD FEATURE NOT WORKING double is not working, maybe integer. check it // double datatype
// static const unsigned char DT_DOUBLE = DT_DOUBLE_VAL << 4;
ITTable();
ITTable(eOrientation orient);
ITTable(const ITTable& inTable);
~ITTable();
ITTable& operator=(const ITTable& inTable);
inline unsigned int GetNumColumns() const;
void AddColumn(const std::string& colName,
const std::vector<std::string>& col = std::vector<std::string>());
void InsertColumn(const std::string& colName,
const std::string& atColName, const std::vector<std::string>& col =
std::vector<std::string>());
void FillColumn(const std::string& colName,
const std::vector<std::string>& col);
void AppendToColumn(const std::string& colName, const std::string& cell);
void AppendToColumn(const std::string& colName,
const std::vector<std::string>& col);
void GetColumn(std::vector<std::string>& col, const std::string& colName);
void GetColumn(std::vector<std::string>& col, const std::string& colName,
const unsigned int fromRowIndex, unsigned int toRowIndex);
void GetColumn(std::vector<std::string>& col, const std::string& colName,
const std::vector<unsigned int>& rowIndex);
void ClearColumn(const std::string& colName);
void DeleteColumn(const std::string& colName);
inline unsigned int GetNumRows() const;
unsigned int AddRow(const std::vector<std::string>& row =
std::vector<std::string>());
unsigned int InsertRow(const unsigned int atRowIndex,
const std::vector<std::string>& row = std::vector<std::string>());
void FillRow(const unsigned int rowIndex,
const std::vector<std::string>& row);
void GetRow(std::vector<std::string>& row, const unsigned int rowIndex,
const std::string& fromColName = std::string(),
const std::string& toColName = std::string());
void ClearRow(const unsigned int rowIndex);
void DeleteRow(const unsigned int rowIndex);
void DeleteRows(const std::vector<unsigned int>& rows);
inline unsigned int GetLastRowIndex();
void UpdateCell(const unsigned int rowIndex, const std::string& colName,
const std::string& value);
const std::string& operator()(const unsigned int rowIndex,
const std::string& colName) const;
void SetFlags(const std::string& colName, const unsigned char flags);
unsigned char GetDataType(const std::string& colName);
#ifdef VLAD_SECOND_ITTABLE
unsigned int FindFirst(const std::vector<std::string>& targets,
const std::vector<std::string>& colNames,
const std::string& indexName = std::string());
#endif
#ifdef VLAD_SECOND_ITTABLE
void Search(std::vector<unsigned int>& res, const std::string& target,
const std::string& colName, const eSearchType searchType = eEQUAL);
#endif
#ifdef VLAD_SECOND_ITTABLE
void Search(std::vector<unsigned int>& res,
const std::vector<std::string>& targets,
const std::vector<std::string>& colNames,
const eSearchType searchType = eEQUAL,
const std::string& indexName = std::string());
#endif
void FindDuplicateRows(std::vector<std::pair<unsigned int,
unsigned int> >& duplRows,
const std::vector<std::string>& colNames, const bool keepDuplRows,
const eSearchDir searchDir = eFORWARD);
/* \todo Figure this out. */
void ValidateOptions(unsigned int colIndex);
void UpdateIndex(const unsigned int indexIndex,
const unsigned int rowIndex);
void InsertIndexEntry(const unsigned int indexIndex,
const unsigned int rowIndex);
void DeleteIndexEntry(const unsigned int indexIndex,
const unsigned int rowIndex);
void VerifyColumnsIndices(const std::vector<unsigned int>& colIndices);
int FindIndex(const std::vector<unsigned int>& colIndices);
int SetFlags(const unsigned char newOpts, const unsigned int colIndex);
unsigned int FindFirst(const std::vector<std::string>& targets,
const std::vector<unsigned int>& colIndices, const unsigned int indexIndex);
void Search(std::vector<unsigned int>& res,
const std::vector<std::string>& targets,
const std::vector<unsigned int>& colIndices,
const unsigned int indexIndex,
const eSearchType searchType = eEQUAL);
void DeleteIndex(const unsigned int indexIndex);
void Search(std::vector<unsigned int>& res, const std::string& target,
const unsigned int colIndex, const eSearchType searchType = eEQUAL);
void FindDuplicateRows(const std::vector<unsigned int>& colIndices,
std::vector<std::pair<unsigned int, unsigned int> >& duplRows,
const bool keep, const eSearchDir searchDir = eFORWARD);
void RebuildIndex(const unsigned int indexIndex);
void InsertColumn(const unsigned int colIndex,
const std::vector<std::string>& col = std::vector<std::string>());
void InsertColumn(const unsigned int colIndex,
std::vector<std::string>::const_iterator colBeg,
std::vector<std::string>::const_iterator colEnd);
void Clear();
const std::string& operator()(const unsigned int rowIndex,
const unsigned int colIndex) const;
int UpdateCell(const std::string& cell, const unsigned int colIndex,
const unsigned int rowIndex);
void FillColumn(const std::vector<std::string>& col,
const unsigned int colIndex);
void FillColumn(const unsigned int colIndex,
std::vector<std::string>::const_iterator colBeg,
std::vector<std::string>::const_iterator colEnd);
void AppendToColumn(const unsigned int colIndex,
const std::vector<std::string>& col);
void AppendToColumn(const unsigned int colIndex, const std::string& cell);
void CreateColumn(const unsigned int atColIndex,
const std::vector<std::string>& col = std::vector<std::string>());
void CreateColumn(const unsigned int atColIndex,
std::vector<std::string>::const_iterator colBeg,
std::vector<std::string>::const_iterator colEnd);
void GetColumn(std::vector<std::string>& col, const unsigned int colIndex,
const unsigned int fromRowIndex, unsigned int toRowIndex);
void GetColumn(std::vector<std::string>& col, const unsigned int colIndex,
const std::vector<unsigned int>& rowIndex);
void ClearColumn(const unsigned int colIndex);
void DeleteColumn(const unsigned int colIndex);
void GetColumn(std::vector<std::string>& col, const unsigned int colIndex);
void GetRow(std::vector<std::string>& row, const unsigned int rowIndex,
const unsigned int fromColIndex, unsigned int toColIndex);
const std::vector<std::string>& GetRow(const unsigned int rowIndex);
eOrientation GetOrientation();
void CreateIndex(const std::vector<unsigned int>& colIndices,
const unsigned int unique = 0);
void SetSerializer(Serializer* ser);
int WriteObject(Serializer* ser, int& size);
int GetObject(UInt32 index, Serializer* ser);
int Read(unsigned int indexInFile, Serializer* ser);
int Write(Serializer* ser, int& size);
void RebuildIndices();
void InsertEntry(const unsigned int rowIndex);
void DeleteEntry(const unsigned int rowIndex);
inline unsigned int GetNumIndices();
void GetColumn(std::vector<std::string>& col, const unsigned int colIndex,
const unsigned int indexIndex);
private:
// number of digit DBL_MIN_10_EXP, letter e is not included in size
static const unsigned int EXPONENT = 4;
static const unsigned int MAX_PRECISION = DBL_DIG;
//???DBL_MANT_DIG;
static const unsigned int MANTISSA = MAX_PRECISION + 2;
static const unsigned int INT_LIMIT = 11;
// datatype mask
static const unsigned char DT_MASK = 15 << 4;
// string comparison sensitivity mask
static const unsigned char SC_MASK = 0x01;
// white space sensitivity mask
static const unsigned char WS_MASK = 0x02;
static const unsigned char LAST_DT_VALUE = 3;
static const unsigned int DEFAULT_PRECISION = MAX_PRECISION;
static const unsigned char DEFAULT_OPTIONS;
// static const string _version;
TTable _ttable;
eOrientation _orient;
Serializer* _ser;
std::vector<unsigned char> _compare_opts;
std::vector<std::vector<unsigned int> > _listsOfColumns;
std::vector<unsigned int> _unique;
std::vector<tIndex> _indices;
bool AreListsOfColumnsValid(const std::vector<unsigned int>& colIndices);
void CreateKey(const std::vector<unsigned int>& colIndices);
void Init();
Char::eCompareType
GetCompareType(const std::vector<unsigned int>& colIndices);
std::string CellValue(const unsigned int colIndex,
const unsigned int rowIndex);
std::string ConvertString(const std::string& value,
const unsigned int colIndex);
std::string MultiStringsValue(const std::vector<std::string>& values,
const std::vector<unsigned int>& colIndices);
std::string SubRowValue(const std::vector<unsigned int>& colIndices,
const unsigned int rowIndex);
std::string AggregateRow(const std::vector<unsigned int>& colIndices,
const unsigned int rowIndex);
inline void AppendToAndDelimit(std::string& to,
const std::string& appending);
std::string CreateInternalIndexName(const unsigned int indexIndex);
void ClearIndex(const unsigned int indexIndex);
void UpdateIndices(const unsigned int rowIndex);
void ClearIndices();
bool IsColumnInIndex(const unsigned int indexIndex,
const unsigned int colIndex);
int FindKeyIndex();
void UpdateColListOnColInsert(const unsigned int colIndex);
void UpdateColListOnColDelete(const unsigned int colIndex);
void UpdateIndicesOnCellUpdate(const unsigned int rowIndex,
const unsigned int colIndex);
void ConvertToInt(const std::string& a, std::string& ret);
void ConvertDouble(const std::string& a, std::string& ret);
void ConvertToLowerNoWhiteSpace(const std::string& a, std::string& ret);
void Print(unsigned int indexIndex);
};
std::ostream& operator<<(std::ostream& out, const ITTable& isTable);
inline unsigned int ITTable::GetLastRowIndex()
{
return(GetNumRows() - 1);
}
inline unsigned int ITTable::GetNumIndices()
{
return(_listsOfColumns.size());
}
inline void ITTable::AppendToAndDelimit(std::string& to,
const std::string& appending)
{
to += appending;
// VLAD HARDCODED CONST
to += " ";
}
inline unsigned int ITTable::GetNumColumns() const
{
if (_orient == eCOLUMN_WISE)
return(_ttable.GetNumTuples());
else
return(_ttable.GetNumColumns());
}
inline unsigned int ITTable::GetNumRows() const
{
if (_orient == eCOLUMN_WISE)
return(_ttable.GetNumColumns());
else
return(_ttable.GetNumTuples());
}
#endif // ITTABLE_H
GenString.h
tIndex
std::multimap< std::string, unsigned int, StringLess > tIndex
Definition ITTable.h:29
operator<<
std::ostream & operator<<(std::ostream &out, const ITTable &isTable)
Serializer.h
TTable.h
Header file for TTable class.
Char::eCompareType
eCompareType
Definition GenString.h:27
ITTable
Private class that respresents a two-dimensional table of strings.
Definition ITTable.h:52
ITTable::GetColumn
void GetColumn(std::vector< std::string > &col, const std::string &colName)
ITTable::ITTable
ITTable(eOrientation orient)
ITTable::W_SPACE_SENSE
static const unsigned char W_SPACE_SENSE
Definition ITTable.h:84
ITTable::ITTable
ITTable()
ITTable::GetNumRows
unsigned int GetNumRows() const
Definition ITTable.h:1167
ITTable::FillColumn
void FillColumn(const unsigned int colIndex, std::vector< std::string >::const_iterator colBeg, std::vector< std::string >::const_iterator colEnd)
ITTable::GetColumn
void GetColumn(std::vector< std::string > &col, const unsigned int colIndex, const std::vector< unsigned int > &rowIndex)
ITTable::AddColumn
void AddColumn(const std::string &colName, const std::vector< std::string > &col=std::vector< std::string >())
ITTable::CASE_SENSE
static const unsigned char CASE_SENSE
Definition ITTable.h:80
ITTable::InsertEntry
void InsertEntry(const unsigned int rowIndex)
ITTable::GetColumn
void GetColumn(std::vector< std::string > &col, const std::string &colName, const unsigned int fromRowIndex, unsigned int toRowIndex)
ITTable::AppendToColumn
void AppendToColumn(const std::string &colName, const std::string &cell)
ITTable::InsertColumn
void InsertColumn(const unsigned int colIndex, std::vector< std::string >::const_iterator colBeg, std::vector< std::string >::const_iterator colEnd)
ITTable::SetFlags
int SetFlags(const unsigned char newOpts, const unsigned int colIndex)
ITTable::FillRow
void FillRow(const unsigned int rowIndex, const std::vector< std::string > &row)
ITTable::GetOrientation
eOrientation GetOrientation()
ITTable::operator()
const std::string & operator()(const unsigned int rowIndex, const std::string &colName) const
ITTable::FindDuplicateRows
void FindDuplicateRows(const std::vector< unsigned int > &colIndices, std::vector< std::pair< unsigned int, unsigned int > > &duplRows, const bool keep, const eSearchDir searchDir=eFORWARD)
ITTable::DeleteColumn
void DeleteColumn(const std::string &colName)
ITTable::GetDataType
unsigned char GetDataType(const std::string &colName)
ITTable::WriteObject
int WriteObject(Serializer *ser, int &size)
ITTable::FindIndex
int FindIndex(const std::vector< unsigned int > &colIndices)
ITTable::GetColumn
void GetColumn(std::vector< std::string > &col, const unsigned int colIndex)
ITTable::FindDuplicateRows
void FindDuplicateRows(std::vector< std::pair< unsigned int, unsigned int > > &duplRows, const std::vector< std::string > &colNames, const bool keepDuplRows, const eSearchDir searchDir=eFORWARD)
ITTable::ClearRow
void ClearRow(const unsigned int rowIndex)
ITTable::DeleteIndex
void DeleteIndex(const unsigned int indexIndex)
ITTable::DeleteEntry
void DeleteEntry(const unsigned int rowIndex)
ITTable::~ITTable
~ITTable()
ITTable::GetColumn
void GetColumn(std::vector< std::string > &col, const unsigned int colIndex, const unsigned int indexIndex)
ITTable::InsertRow
unsigned int InsertRow(const unsigned int atRowIndex, const std::vector< std::string > &row=std::vector< std::string >())
ITTable::W_SPACE_INSENSE
static const unsigned char W_SPACE_INSENSE
Definition ITTable.h:87
ITTable::ClearColumn
void ClearColumn(const std::string &colName)
ITTable::eSearchType
eSearchType
Definition ITTable.h:61
ITTable::eLESS_THAN_OR_EQUAL
@ eLESS_THAN_OR_EQUAL
Definition ITTable.h:64
ITTable::eLESS_THAN
@ eLESS_THAN
Definition ITTable.h:63
ITTable::eGREATER_THAN
@ eGREATER_THAN
Definition ITTable.h:65
ITTable::eEQUAL
@ eEQUAL
Definition ITTable.h:62
ITTable::eGREATER_THAN_OR_EQUAL
@ eGREATER_THAN_OR_EQUAL
Definition ITTable.h:66
ITTable::GetRow
const std::vector< std::string > & GetRow(const unsigned int rowIndex)
ITTable::GetRow
void GetRow(std::vector< std::string > &row, const unsigned int rowIndex, const unsigned int fromColIndex, unsigned int toColIndex)
ITTable::DT_STRING_VAL
static const unsigned char DT_STRING_VAL
Definition ITTable.h:75
ITTable::DT_INTEGER
static const unsigned char DT_INTEGER
Definition ITTable.h:91
ITTable::eSearchDir
eSearchDir
Definition ITTable.h:70
ITTable::eFORWARD
@ eFORWARD
Definition ITTable.h:71
ITTable::eBACKWARD
@ eBACKWARD
Definition ITTable.h:72
ITTable::InsertColumn
void InsertColumn(const std::string &colName, const std::string &atColName, const std::vector< std::string > &col=std::vector< std::string >())
ITTable::Clear
void Clear()
ITTable::operator=
ITTable & operator=(const ITTable &inTable)
ITTable::RebuildIndices
void RebuildIndices()
ITTable::DT_INTEGER_VAL
static const unsigned char DT_INTEGER_VAL
Definition ITTable.h:76
ITTable::RebuildIndex
void RebuildIndex(const unsigned int indexIndex)
ITTable::ValidateOptions
void ValidateOptions(unsigned int colIndex)
ITTable::Search
void Search(std::vector< unsigned int > &res, const std::vector< std::string > &targets, const std::vector< unsigned int > &colIndices, const unsigned int indexIndex, const eSearchType searchType=eEQUAL)
ITTable::AppendToColumn
void AppendToColumn(const unsigned int colIndex, const std::string &cell)
ITTable::DeleteColumn
void DeleteColumn(const unsigned int colIndex)
ITTable::FillColumn
void FillColumn(const std::string &colName, const std::vector< std::string > &col)
ITTable::Read
int Read(unsigned int indexInFile, Serializer *ser)
ITTable::CreateColumn
void CreateColumn(const unsigned int atColIndex, std::vector< std::string >::const_iterator colBeg, std::vector< std::string >::const_iterator colEnd)
ITTable::DeleteRows
void DeleteRows(const std::vector< unsigned int > &rows)
ITTable::CreateColumn
void CreateColumn(const unsigned int atColIndex, const std::vector< std::string > &col=std::vector< std::string >())
ITTable::AddRow
unsigned int AddRow(const std::vector< std::string > &row=std::vector< std::string >())
ITTable::eOrientation
eOrientation
Definition ITTable.h:55
ITTable::eROW_WISE
@ eROW_WISE
Definition ITTable.h:57
ITTable::eCOLUMN_WISE
@ eCOLUMN_WISE
Definition ITTable.h:56
ITTable::ITTable
ITTable(const ITTable &inTable)
ITTable::InsertIndexEntry
void InsertIndexEntry(const unsigned int indexIndex, const unsigned int rowIndex)
ITTable::ClearColumn
void ClearColumn(const unsigned int colIndex)
ITTable::InsertColumn
void InsertColumn(const unsigned int colIndex, const std::vector< std::string > &col=std::vector< std::string >())
ITTable::DT_STRING
static const unsigned char DT_STRING
Definition ITTable.h:89
ITTable::CreateIndex
void CreateIndex(const std::vector< unsigned int > &colIndices, const unsigned int unique=0)
ITTable::AppendToColumn
void AppendToColumn(const std::string &colName, const std::vector< std::string > &col)
ITTable::GetNumIndices
unsigned int GetNumIndices()
Definition ITTable.h:1140
ITTable::UpdateIndex
void UpdateIndex(const unsigned int indexIndex, const unsigned int rowIndex)
ITTable::SetFlags
void SetFlags(const std::string &colName, const unsigned char flags)
ITTable::DeleteRow
void DeleteRow(const unsigned int rowIndex)
ITTable::GetColumn
void GetColumn(std::vector< std::string > &col, const std::string &colName, const std::vector< unsigned int > &rowIndex)
ITTable::GetColumn
void GetColumn(std::vector< std::string > &col, const unsigned int colIndex, const unsigned int fromRowIndex, unsigned int toRowIndex)
ITTable::FillColumn
void FillColumn(const std::vector< std::string > &col, const unsigned int colIndex)
ITTable::Search
void Search(std::vector< unsigned int > &res, const std::string &target, const unsigned int colIndex, const eSearchType searchType=eEQUAL)
ITTable::GetLastRowIndex
unsigned int GetLastRowIndex()
Definition ITTable.h:1132
ITTable::AppendToColumn
void AppendToColumn(const unsigned int colIndex, const std::vector< std::string > &col)
ITTable::GetNumColumns
unsigned int GetNumColumns() const
Definition ITTable.h:1159
ITTable::VerifyColumnsIndices
void VerifyColumnsIndices(const std::vector< unsigned int > &colIndices)
ITTable::UpdateCell
int UpdateCell(const std::string &cell, const unsigned int colIndex, const unsigned int rowIndex)
ITTable::DeleteIndexEntry
void DeleteIndexEntry(const unsigned int indexIndex, const unsigned int rowIndex)
ITTable::GetRow
void GetRow(std::vector< std::string > &row, const unsigned int rowIndex, const std::string &fromColName=std::string(), const std::string &toColName=std::string())
ITTable::CASE_INSENSE
static const unsigned char CASE_INSENSE
Definition ITTable.h:82
ITTable::SetSerializer
void SetSerializer(Serializer *ser)
ITTable::UpdateCell
void UpdateCell(const unsigned int rowIndex, const std::string &colName, const std::string &value)
ITTable::FindFirst
unsigned int FindFirst(const std::vector< std::string > &targets, const std::vector< unsigned int > &colIndices, const unsigned int indexIndex)
ITTable::Write
int Write(Serializer *ser, int &size)
ITTable::GetObject
int GetObject(UInt32 index, Serializer *ser)
ITTable::operator()
const std::string & operator()(const unsigned int rowIndex, const unsigned int colIndex) const
Serializer
Definition Serializer.h:44
TTable
Private class that represents a table of tuples.
Definition TTable.h:42
TTable::GetNumColumns
unsigned int GetNumColumns() const
Definition TTable.h:550
TTable::GetNumTuples
unsigned int GetNumTuples() const
Definition TTable.h:544
UInt32
unsigned int UInt32
Definition rcsb_types.h:15