otsdaq  3.03.00
ots::TableView Class Reference
+ Inheritance diagram for ots::TableView:

Public Types

typedef std::vector< std::vector< std::string > > DataView
 
typedef DataView::iterator iterator
 
typedef DataView::const_iterator const_iterator
 

Public Member Functions

 TableView (const std::string &tableName)
 = "");
 
void init (void)
 
TableViewcopy (const TableView &src, TableVersion destinationVersion, const std::string &author)
 
unsigned int copyRows (const std::string &author, const TableView &src, unsigned int srcOffsetRow=0, unsigned int srcRowsToCopy=(unsigned int) -1, unsigned int destOffsetRow=(unsigned int) -1, unsigned char generateUniqueDataColumns=false, const std::string &baseNameAutoUID="")
 
template<class T >
unsigned int findRow (unsigned int col, const T &value, unsigned int offsetRow=0, bool doNotThrow=false) const
 < in included .icc source
 
unsigned int findRow (unsigned int col, const std::string &value, unsigned int offsetRow=0, bool doNotThrow=false) const
 
template<class T >
unsigned int findRowInGroup (unsigned int col, const T &value, const std::string &groupId, const std::string &childLinkIndex, unsigned int offsetRow=0) const
 < in included .icc source
 
unsigned int findRowInGroup (unsigned int col, const std::string &value, const std::string &groupId, const std::string &childLinkIndex, unsigned int offsetRow=0) const
 
unsigned int findCol (const std::string &name) const
 
unsigned int findColByType (const std::string &type, unsigned int startingCol=0) const
 
const std::string & getCustomStorageData (void) const
 Getters.
 
const std::string & getTableName (void) const
 
const TableVersiongetVersion (void) const
 
const std::string & getComment (void) const
 
const std::string & getAuthor (void) const
 
const time_t & getCreationTime (void) const
 
const time_t & getLastAccessTime (void) const
 
const bool & getLooseColumnMatching (void) const
 
unsigned int getDataColumnSize (void) const
 getDataColumnSize More...
 
const unsigned int & getSourceColumnMismatch (void) const
 
const unsigned int & getSourceColumnMissing (void) const
 
const std::set< std::string > & getSourceColumnNames (void) const
 
std::set< std::string > getColumnNames (void) const
 
std::map< std::string, unsigned int > getColumnNamesMap (void) const
 
std::set< std::string > getColumnStorageNames (void) const
 
const std::vector< std::string > & getDefaultRowValues (void) const
 
std::string getMismatchColumnInfo (void) const
 
unsigned int getNumberOfRows (void) const
 
unsigned int getNumberOfColumns (void) const
 
unsigned int getColUID (void) const
 
unsigned int getColStatus (void) const
 
unsigned int getColPriority (void) const
 
std::set< std::string > getSetOfGroupIDs (const std::string &childLinkIndex, unsigned int row=-1) const
 
std::set< std::string > getSetOfGroupIDs (const unsigned int &col, unsigned int row=-1) const
 
bool isEntryInGroup (const unsigned int &row, const std::string &childLinkIndex, const std::string &groupNeedle) const
 
bool getChildLink (const unsigned int &col, bool &isGroup, std::pair< unsigned int, unsigned int > &linkPair) const
 
unsigned int getLinkGroupIDColumn (const std::string &childLinkIndex) const
 
std::vector< unsigned int > getGroupRows (const unsigned int groupIdCol, const std::string &groupID, bool onlyStatusTrue=false, bool orderedByPriority=false) const
 
std::vector< std::vector< unsigned int > > getGroupRowsByPriority (const unsigned int groupIdCol, const std::string &groupID, bool onlyStatusTrue=false) const
 
void addRowToGroup (const unsigned int &row, const unsigned int &col, const std::string &groupID)
 , const std::string& colDefault); More...
 
bool removeRowFromGroup (const unsigned int &row, const unsigned int &col, const std::string &groupID, bool deleteRowIfNoGroupLeft=false)
 
template<class T >
void getValue (T &value, unsigned int row, unsigned int col, bool doConvertEnvironmentVariables=true) const
 < in included .icc source
 
void getValue (std::string &value, unsigned int row, unsigned int col, bool doConvertEnvironmentVariables=true) const
 
template<class T >
validateValueForColumn (const std::string &value, unsigned int col, bool doConvertEnvironmentVariables=true) const
 < in included .icc source
 
std::string validateValueForColumn (const std::string &value, unsigned int col, bool convertEnvironmentVariables=true) const
 
std::string getValueAsString (unsigned int row, unsigned int col, bool convertEnvironmentVariables=true) const
 
std::string getEscapedValueAsString (unsigned int row, unsigned int col, bool convertEnvironmentVariables=true, bool quotesToDoubleQuotes=false) const
 
bool isURIEncodedCommentTheSame (const std::string &comment) const
 
const DataView & getDataView (void) const
 
const std::vector< TableViewColumnInfo > & getColumnsInfo (void) const
 
std::vector< TableViewColumnInfo > * getColumnsInfoP (void)
 
const TableViewColumnInfogetColumnInfo (unsigned int column) const
 
void setCustomStorageData (const std::string &storageData)
 
void setComment (const std::string &comment)
 
void setURIEncodedComment (const std::string &uriComment)
 
void setAuthor (const std::string &author)
 
void setCreationTime (time_t t)
 
void setLastAccessTime (time_t t=time(0))
 
void setLooseColumnMatching (bool setValue)
 
void doGetSourceRawData (bool setValue)
 
const std::string & getSourceRawData (void)
 
template<class T >
void setVersion (const T &version)
 < in included .icc source
 
template<class T >
void setValue (const T &value, unsigned int row, unsigned int col)
 < in included .icc source
 
void setValue (const std::string &value, unsigned int row, unsigned int col)
 
void setValue (const char *value, unsigned int row, unsigned int col)
 
void setValueAsString (const std::string &value, unsigned int row, unsigned int col)
 
const std::string & setUniqueColumnValue (unsigned int row, unsigned int col, std::string baseValueAsString="", bool doMathAppendStrategy=false, std::string childLinkIndex="", std::string groupId="")
 
void resizeDataView (unsigned int nRows, unsigned int nCols)
 
unsigned int addRow (const std::string &author="", unsigned char incrementUniqueData=false, const std::string &baseNameAutoUID="", unsigned int rowToAdd=(unsigned int) -1, std::string childLinkIndex="", std::string groupId="")
 
void deleteRow (int r)
 
void deleteAllRows (void)
 
iterator begin (void)
 
iterator end (void)
 
const_iterator begin (void) const
 
const_iterator end (void) const
 
void reset (void)
 
void print (std::ostream &out=std::cout) const
 
void printJSON (std::ostream &out=std::cout) const
 
void printCSV (std::ostream &out=std::cout, const std::string &valueDelimeter=",", const std::string &recordDelimeter="\n", bool includeColumnNames=true) const
 
int fillFromJSON (const std::string &json)
 
void fillFromCSV (const std::string &data, const int &dataOffset=0, const std::string &author="", const char rowDelimter=',', const char colDelimter='\n')
 
int fillFromEncodedCSV (const std::string &data, const int &dataOffset=0, const std::string &author="")
 
bool setURIEncodedValue (const std::string &value, const unsigned int &row, const unsigned int &col, const std::string &author="")
 

Static Public Attributes

static const unsigned int INVALID = -1
 

Friends

std::ostream & operator<< (std::ostream &out, const TableView &view)
 output table name for ostream operator
 

Detailed Description

Definition at line 20 of file TableView.h.

Member Function Documentation

◆ addRow()

unsigned int TableView::addRow ( const std::string &  author = "",
unsigned char  incrementUniqueData = false,
const std::string &  baseNameAutoUID = "",
unsigned int  rowToAdd = (unsigned int)-1,
std::string  childLinkIndex = "",
std::string  groupId = "" 
)

addRow returns index of added row, always is last row return -1 on failure (throw error)

if baseNameAutoUID != "", creates a UID based on this base name and increments and appends an integer relative to the previous last row

Parameters
incrementUniqueDataleave as unsigned char rather than bool, too many things (e.g. strings) evaluate successfully to bool values
rowToAddreturns index of added row, default is last row
childLinkIndexto allow for handling TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA

Definition at line 3517 of file TableView.cc.

◆ addRowToGroup()

void TableView::addRowToGroup ( const unsigned int &  row,
const unsigned int &  col,
const std::string &  groupID 
)

, const std::string& colDefault);

addRowToGroup Group entry can include | to place a record in multiple groups

Definition at line 1465 of file TableView.cc.

◆ begin()

iterator ots::TableView::begin ( void  )
inline

Note add Column is not allowed, freely; instead requires special access through Table Editor "Database Management" int addColumn(std::string name, std::string viewName, std::string viewType); //returns index of added column, always is last column

Definition at line 210 of file TableView.h.

◆ copyRows()

unsigned int TableView::copyRows ( const std::string &  author,
const TableView src,
unsigned int  srcOffsetRow = 0,
unsigned int  srcRowsToCopy = (unsigned int)-1,
unsigned int  destOffsetRow = (unsigned int)-1,
unsigned char  generateUniqueDataColumns = false,
const std::string &  baseNameAutoUID = "" 
)

copyRows return row offset of first row copied in

Parameters
generateUniqueDataColumnsleave as unsigned char rather than bool, too many things (e.g. strings) evaluate successfully to bool values

Definition at line 126 of file TableView.cc.

◆ deleteRow()

void TableView::deleteRow ( int  r)

deleteRow throws exception on failure

Definition at line 3602 of file TableView.cc.

◆ fillFromCSV()

void TableView::fillFromCSV ( const std::string &  data,
const int &  dataOffset = 0,
const std::string &  author = "",
const char  rowDelimter = ',',
const char  colDelimter = '\n' 
)

============================================================================== bool TableView::isValueTheSame(const std::string &valueStr, unsigned int r, unsigned int c) const fillFromCSV CSV parser that correctly handles:

  • Quoted fields ("a,b") and unquoted fields
  • Escaped quotes inside quoted fields ("" => ")
  • Commas/newlines inside quotes
  • Windows line endings (\r
    ).

Delimiter: pass '\t' for TSV or ';' for European CSV variants.

Throws exceptions on error

Definition at line 3161 of file TableView.cc.

◆ fillFromEncodedCSV()

int TableView::fillFromEncodedCSV ( const std::string &  data,
const int &  dataOffset = 0,
const std::string &  author = "" 
)

fillFromEncodedCSV Fills the view from the encoded CSV string.

Note: converts all %## to the ascii character, # is hex nibble (e.g. '' must be represented as "%25")

dataOffset := starting destination row

while there are row entries in the data.. replace data range from [dataOffset, dataOffset+chunkSize-1] ... note if less rows, this means rows were deleted ... if more, then rows were added.

',' next cell delimiter ';' next row delimiter

if author == "", do nothing special for author and timestamp column if author != "", assign author for any row that has been modified, and assign now as timestamp

Returns -1 if data was same and pre-existing content Returns 1 if data was same, but columns are different otherwise 0

Definition at line 3289 of file TableView.cc.

◆ fillFromJSON()

int TableView::fillFromJSON ( const std::string &  json)

fillFromJSON Fills (does not clear) the view from the JSON string. Returns -1 on failure

first level keys: NAME DATA_SET

Definition at line 2401 of file TableView.cc.

◆ findCol()

unsigned int TableView::findCol ( const std::string &  wildCardName) const

findCol throws exception if column not found by name

Definition at line 1952 of file TableView.cc.

◆ findColByType()

unsigned int TableView::findColByType ( const std::string &  type,
unsigned int  startingCol = 0 
) const

findColByType return invalid if type not found

Definition at line 1975 of file TableView.cc.

◆ getChildLink()

bool TableView::getChildLink ( const unsigned int &  c,
bool &  isGroup,
std::pair< unsigned int, unsigned int > &  linkPair 
) const

getChildLink ~ find the pair of columns associated with a child link.

c := a member column of the pair

returns: isGroup := indicates pair found is a group link linkPair := pair of columns that are part of the link

a unique link is defined by two columns: TYPE_START_CHILD_LINK, TYPE_START_CHILD_LINK_UID a group link is defined by two columns: TYPE_START_CHILD_LINK, TYPE_START_CHILD_LINK_GROUP_ID

returns true if column is member of a group or unique link.

Definition at line 3632 of file TableView.cc.

◆ getColPriority()

unsigned int TableView::getColPriority ( void  ) const

getColPriority const version, so don't attempt to lookup if column not found throw error

Note: common for Priority column to not exist, so be quiet with printouts so as to not scare people.

Definition at line 1438 of file TableView.cc.

◆ getColStatus()

unsigned int TableView::getColStatus ( void  ) const

getColStatus const version, so don't attempt to lookup if column not found throw error

Definition at line 1407 of file TableView.cc.

◆ getColUID()

unsigned int TableView::getColUID ( void  ) const

getColOfUID const version, so don't attempt to lookup if column not found throw error

Definition at line 1322 of file TableView.cc.

◆ getDataColumnSize()

unsigned int TableView::getDataColumnSize ( void  ) const

getDataColumnSize

Getters:

Definition at line 1992 of file TableView.cc.

◆ getEscapedValueAsString()

std::string TableView::getEscapedValueAsString ( unsigned int  row,
unsigned int  col,
bool  doConvertEnvironmentVariables = true,
bool  quotesToDoubleQuotes = false 
) const

getEscapedValueAsString gets the value with the proper data type and converts to string as though getValue was called. then escapes all special characters with slash. Note: this should be useful for values placed in double quotes, i.e. JSON.

Definition at line 1024 of file TableView.cc.

◆ getGroupRows()

std::vector< unsigned int > TableView::getGroupRows ( const unsigned int  groupIdCol,
const std::string &  groupID,
bool  onlyStatusTrue = false,
bool  orderedByPriority = false 
) const

getGroupRows Get the rows of all records with groupID with consideration for status on/off and priority, if enabled with flags

Note: empty group id of "" or '*' will return all rows

Definition at line 1497 of file TableView.cc.

◆ getGroupRowsByPriority()

std::vector< std::vector< unsigned int > > TableView::getGroupRowsByPriority ( const unsigned int  groupIdCol,
const std::string &  groupID,
bool  onlyStatusTrue = false 
) const

getGroupRowsByPriority Get the rows of all records with groupID with consideration for status on/off and priority, if enabled with flags

Note: empty group id of "" or '*' will return all rows

Definition at line 1520 of file TableView.cc.

◆ getLinkGroupIDColumn()

unsigned int TableView::getLinkGroupIDColumn ( const std::string &  childLinkIndex) const

getColOfLinkGroupID const version, if column not found throw error

Definition at line 1837 of file TableView.cc.

◆ getSetOfGroupIDs()

std::set< std::string > TableView::getSetOfGroupIDs ( const std::string &  childLinkIndex,
unsigned int  r = -1 
) const

getSetOfGroupIDs if row == -1, then considers all rows else just that row returns unique set of groupIds in GroupID column associate with childLinkIndex

Note: should mirror what happens in TableView::isEntryInGroupCol

Definition at line 1736 of file TableView.cc.

◆ getValue()

void TableView::getValue ( std::string &  value,
unsigned int  row,
unsigned int  col,
bool  doConvertEnvironmentVariables = true 
) const

special version of getValue for string type Note: necessary because types of std::basic_string<char> cause compiler problems if no string specific function

getValue string version Note: necessary because types of std::basic_string<char> cause compiler problems if no string specific function

Definition at line 885 of file TableView.cc.

◆ getValueAsString()

std::string TableView::getValueAsString ( unsigned int  row,
unsigned int  col,
bool  doConvertEnvironmentVariables = true 
) const

getValueAsString gets the value with the proper data type and converts to string as though getValue was called.

Definition at line 975 of file TableView.cc.

◆ init()

void TableView::init ( void  )

init Should be called after table is filled to setup special members and verify consistency. e.g. identifying the UID column, checking unique data fields, etc.

Note: this function also sanitizes yes/no, on/off, and true/false types 

Definition at line 195 of file TableView.cc.

◆ isEntryInGroup()

bool TableView::isEntryInGroup ( const unsigned int &  r,
const std::string &  childLinkIndex,
const std::string &  groupNeedle 
) const

isEntryInGroup All group link checking should use this function so that handling is consistent

Group entry can include | to place a record in multiple groups

Definition at line 1652 of file TableView.cc.

◆ removeRowFromGroup()

bool TableView::removeRowFromGroup ( const unsigned int &  row,
const unsigned int &  col,
const std::string &  groupNeedle,
bool  deleteRowIfNoGroupLeft = false 
)

removeRowFromGroup Group entry can include | to place a record in multiple groups

returns true if row was deleted because it had no group left

Definition at line 1599 of file TableView.cc.

◆ setCustomStorageData()

void ots::TableView::setCustomStorageData ( const std::string &  storageData)
inline

Setters

Definition at line 168 of file TableView.h.

◆ setUniqueColumnValue()

const std::string & TableView::setUniqueColumnValue ( unsigned int  row,
unsigned int  col,
std::string  baseValueAsString = "",
bool  doMathAppendStrategy = false,
std::string  childLinkIndex = "",
std::string  groupId = "" 
)

setUniqueColumnValue Auto-generates a unique value for the specified column and places value at row,col position (a la add row unique value handling)

Note: doMathAppendStrategy enables appending with a match string e.g. ${PORT} + 1 .. then + 2, etc. (i.e. baseValueAsString = "${PORT}")

Parameters
childLinkIndexto allow for handling TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA

Definition at line 1110 of file TableView.cc.

◆ setURIEncodedComment()

void TableView::setURIEncodedComment ( const std::string &  uriComment)

Setters

Definition at line 2107 of file TableView.cc.

◆ setURIEncodedValue()

bool TableView::setURIEncodedValue ( const std::string &  value,
const unsigned int &  r,
const unsigned int &  c,
const std::string &  author = "" 
)

setURIEncodedValue converts all %## to the ascii character returns true if value was different than original value

if author == "", do nothing special for author and timestamp column if author != "", assign author for any row that has been modified, and assign now as timestamp

Definition at line 3425 of file TableView.cc.

◆ setValue()

void TableView::setValue ( const std::string &  value,
unsigned int  row,
unsigned int  col 
)

setValue string version

Definition at line 1059 of file TableView.cc.

◆ setValueAsString()

void TableView::setValueAsString ( const std::string &  value,
unsigned int  row,
unsigned int  col 
)

Careful: The setValueAsString method is used to set the value without any consistency check with the data type

setValueAsString string version

Definition at line 1090 of file TableView.cc.

◆ validateValueForColumn()

std::string TableView::validateValueForColumn ( const std::string &  value,
unsigned int  col,
bool  doConvertEnvironmentVariables = true 
) const

special version of getValue for string type Note: necessary because types of std::basic_string<char> cause compiler problems if no string specific function

validateValueForColumn string version Note: necessary because types of std::basic_string<char> cause compiler problems if no string specific function

Definition at line 907 of file TableView.cc.


The documentation for this class was generated from the following files: