1 #include "otsdaq/TableCore/TableView.h"
2 #include "otsdaq/Macros/StringMacros.h"
3 #include "otsdaq/TableCore/TableBase.h"
13 #define __MF_SUBJECT__ "TableView"
15 #define __COUT_HDR__ (tableName_ + "v" + version_.toString() + "\t<> ")
17 const unsigned int TableView::INVALID = -1;
21 : storageData_(tableName)
22 , tableName_(
TableBase::convertToCaps(storageData_))
26 , creationTime_(time(0))
30 , colPriority_(INVALID)
31 , fillWithLooseColumnMatching_(false)
32 , getSourceRawData_(false)
33 , sourceColumnMismatchCount_(0)
34 , sourceColumnMissingCount_(0)
40 __SS__ <<
"Do not allow anonymous table view construction!" << __E__;
48 TableView::~TableView(
void) {}
56 __SS__ <<
"Invalid use of operator=... Should not directly copy a TableView. Please "
57 "use TableView::copy(sourceView,author,comment)";
60 __COUT__ << ss.str() << __E__;
68 const std::string& author)
71 version_ = destinationVersion;
72 comment_ = src.comment_;
75 lastAccessTime_ = time(0);
80 for(
auto& c : src.columnsInfo_)
81 columnsInfo_.push_back(c);
83 theDataView_ = src.theDataView_;
84 sourceColumnNames_ = src.sourceColumnNames_;
90 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
92 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
96 if(tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend ||
97 tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend)
99 __COUTT__ <<
"TableView copy for '" << tableName_ <<
"' done." << __E__;
128 unsigned int srcOffsetRow ,
129 unsigned int srcRowsToCopy ,
130 unsigned int destOffsetRow ,
131 unsigned char generateUniqueDataColumns ,
132 const std::string& baseNameAutoUID )
134 __COUTTV__(destOffsetRow);
135 __COUTTV__(srcOffsetRow);
136 __COUTTV__(srcRowsToCopy);
138 unsigned int retRow = (
unsigned int)-1;
141 if(src.getNumberOfColumns() != getNumberOfColumns())
143 __SS__ <<
"Error! Number of Columns of source view must match destination view."
144 <<
"Dimension of source is [" << src.getNumberOfColumns()
145 <<
"] and of destination is [" << getNumberOfColumns() <<
"]." << __E__;
149 unsigned int srcRows = src.getNumberOfRows();
151 for(
unsigned int r = 0; r < srcRowsToCopy; ++r)
153 if(r + srcOffsetRow >= srcRows)
156 destOffsetRow =
addRow(author,
157 generateUniqueDataColumns ,
161 if(retRow == (
unsigned int)-1)
162 retRow = destOffsetRow;
165 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
166 if(generateUniqueDataColumns &&
168 columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_UNIQUE_DATA ||
169 columnsInfo_[col].getType() ==
170 TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA))
174 __COUTT__ <<
"Copying [" << r + srcOffsetRow <<
"][" << col <<
"] to ["
175 << destOffsetRow <<
"][" << col
176 <<
"] = " << src.theDataView_[r + srcOffsetRow][col] << __E__;
177 theDataView_[destOffsetRow][col] =
178 src.theDataView_[r + srcOffsetRow][col];
203 std::set<std::string> colNameSet;
204 std::string capsColName, colName;
205 for(
auto& colInfo : columnsInfo_)
207 colName = colInfo.getStorageName();
208 if(colName ==
"COMMENT_DESCRIPTION")
211 for(
unsigned int i = 0; i < colName.size(); ++i)
213 if(colName[i] ==
'_')
215 capsColName += colName[i];
218 colNameSet.emplace(capsColName);
221 if(colNameSet.size() != columnsInfo_.size())
223 __SS__ <<
"Table Error:\t"
224 <<
" Columns names must be unique! There are " << columnsInfo_.size()
225 <<
" columns and the unique name count is " << colNameSet.size()
247 if(sourceColumnNames_.size() == 0)
248 for(
unsigned int i = 0; i < getNumberOfColumns(); ++i)
249 sourceColumnNames_.emplace(getColumnsInfo()[i].getStorageName());
253 if((colPos =
findColByType(TableViewColumnInfo::TYPE_COMMENT)) != INVALID)
255 if(columnsInfo_[colPos].getName() != TableViewColumnInfo::COL_NAME_COMMENT)
257 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_COMMENT
258 <<
" data type column must have name="
259 << TableViewColumnInfo::COL_NAME_COMMENT << __E__;
263 if(
findColByType(TableViewColumnInfo::TYPE_COMMENT, colPos + 1) !=
266 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_COMMENT
267 <<
" data type in column " << columnsInfo_[colPos].getName()
268 <<
" is repeated. This is not allowed." << __E__;
272 if(colPos != getNumberOfColumns() - 3)
274 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_COMMENT
275 <<
" data type column must be 3rd to last (in column "
276 << getNumberOfColumns() - 3 <<
")." << __E__;
282 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_COMMENT
283 <<
" data type column "
284 <<
" is missing. This is not allowed." << __E__;
289 if((colPos =
findColByType(TableViewColumnInfo::TYPE_AUTHOR)) != INVALID)
291 if(
findColByType(TableViewColumnInfo::TYPE_AUTHOR, colPos + 1) !=
294 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_AUTHOR
295 <<
" data type in column " << columnsInfo_[colPos].getName()
296 <<
" is repeated. This is not allowed." << __E__;
300 if(colPos != getNumberOfColumns() - 2)
302 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_AUTHOR
303 <<
" data type column must be 2nd to last (in column "
304 << getNumberOfColumns() - 2 <<
")." << __E__;
310 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_AUTHOR
311 <<
" data type column "
312 <<
" is missing. This is not allowed." << __E__;
317 if((colPos =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP)) != INVALID)
319 if(
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP, colPos + 1) !=
322 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_TIMESTAMP
323 <<
" data type in column " << columnsInfo_[colPos].getName()
324 <<
" is repeated. This is not allowed." << __E__;
328 if(colPos != getNumberOfColumns() - 1)
330 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_TIMESTAMP
331 <<
" data type column must be last (in column "
332 << getNumberOfColumns() - 1 <<
")." << __E__;
333 __COUT_ERR__ <<
"\n" << ss.str();
339 __SS__ <<
"Table Error:\t" << TableViewColumnInfo::TYPE_TIMESTAMP
340 <<
" data type column "
341 <<
" is missing. This is not allowed." << __E__;
348 std::set<std::string > uidSet;
349 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
351 if(uidSet.find(theDataView_[row][colUID_]) != uidSet.end())
353 __SS__ << (
"Entries in UID are not unique. Specifically at row=" +
354 std::to_string(row) +
" value=" + theDataView_[row][colUID_])
359 if(theDataView_[row][colUID_].size() == 0)
361 __SS__ <<
"An invalid UID '" << theDataView_[row][colUID_] <<
"' "
362 <<
" was identified. UIDs must contain at least 1 character."
367 for(
unsigned int i = 0; i < theDataView_[row][colUID_].size(); ++i)
368 if(!((theDataView_[row][colUID_][i] >=
'A' &&
369 theDataView_[row][colUID_][i] <=
'Z') ||
370 (theDataView_[row][colUID_][i] >=
'a' &&
371 theDataView_[row][colUID_][i] <=
'z') ||
372 (theDataView_[row][colUID_][i] >=
'0' &&
373 theDataView_[row][colUID_][i] <=
'9') ||
374 (theDataView_[row][colUID_][i] ==
'-' ||
375 theDataView_[row][colUID_][i] ==
'_')))
377 __SS__ <<
"An invalid UID '" << theDataView_[row][colUID_] <<
"' "
378 <<
" was identified. UIDs must contain only letters, numbers, "
379 <<
"dashes, and underscores." << __E__;
383 uidSet.insert(theDataView_[row][colUID_]);
385 if(uidSet.size() != getNumberOfRows())
387 __SS__ <<
"Entries in UID are not unique!"
388 <<
"There are " << getNumberOfRows()
389 <<
" records and the unique UID count is " << uidSet.size() << __E__;
394 colPos = (
unsigned int)-1;
395 while((colPos =
findColByType(TableViewColumnInfo::TYPE_UNIQUE_DATA,
396 colPos + 1)) != INVALID)
398 std::set<std::string > uDataSet;
399 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
401 if(uDataSet.find(theDataView_[row][colPos]) != uDataSet.end())
403 __SS__ <<
"Entries in Unique Data column "
404 << columnsInfo_[colPos].getName()
405 << (
" are not unique. Specifically at row=" +
406 std::to_string(row) +
407 " value=" + theDataView_[row][colPos])
411 uDataSet.insert(theDataView_[row][colPos]);
413 if(uDataSet.size() != getNumberOfRows())
415 __SS__ <<
"Entries in Unique Data column "
416 << columnsInfo_[colPos].getName() <<
" are not unique!"
417 <<
"There are " << getNumberOfRows()
418 <<
" records and the unique data count is " << uDataSet.size()
426 colPos = (
unsigned int)-1;
427 while((colPos =
findColByType(TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA,
428 colPos + 1)) != INVALID)
433 for(
unsigned int groupIdColPos = 0; groupIdColPos < columnsInfo_.size();
435 if(columnsInfo_[groupIdColPos].isGroupID())
437 std::map<std::string ,
438 std::pair<
unsigned int ,
439 std::set<std::string >>>
442 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
446 for(
const auto& groupId : groupIds)
448 uGroupDataSets[groupId].first++;
450 if(uGroupDataSets[groupId].second.find(
451 theDataView_[row][colPos]) !=
452 uGroupDataSets[groupId].second.end())
454 __SS__ <<
"Entries in Unique Group Data column " << colPos
455 <<
":" << columnsInfo_[colPos].getName()
456 <<
" are not unique for group ID '" << groupId
457 <<
".' Specifically at row=" << std::to_string(row)
458 <<
" value=" << theDataView_[row][colPos] << __E__;
461 uGroupDataSets[groupId].second.insert(
462 theDataView_[row][colPos]);
466 for(
const auto& groupPair : uGroupDataSets)
467 if(uGroupDataSets[groupPair.first].second.size() !=
468 uGroupDataSets[groupPair.first].first)
471 <<
"Entries in Unique Data column "
472 << columnsInfo_[colPos].getName()
473 <<
" are not unique for group '" << groupPair.first
475 <<
"There are " << uGroupDataSets[groupPair.first].first
476 <<
" records and the unique data count is "
477 << uGroupDataSets[groupPair.first].second.size() << __E__;
483 auto rowDefaults = initRowDefaults();
490 std::set<std::string> groupIdIndexes, childLinkIndexes, childLinkIdLabels;
491 unsigned int groupIdIndexesCount = 0, childLinkIndexesCount = 0,
492 childLinkIdLabelsCount = 0;
494 std::pair<
unsigned int ,
unsigned int > tmpLinkPair;
497 if(getNumberOfRows() != theDataView_.size())
499 __SS__ <<
"Impossible row mismatch " << getNumberOfRows() <<
" vs "
500 << theDataView_.size() <<
"! How did you get here?" << __E__;
503 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
504 if(getNumberOfColumns() != theDataView_[row].size())
506 __SS__ <<
"Impossible col mismatch " << getNumberOfColumns() <<
" vs ["
507 << row <<
"]" << theDataView_[row].size()
508 <<
"! How did you get here?" << __E__;
511 if(getNumberOfColumns() != columnsInfo_.size())
513 __SS__ <<
"Impossible col info mismatch " << getNumberOfColumns() <<
" vs "
514 << columnsInfo_.size() <<
"! How did you get here?" << __E__;
517 if(getNumberOfColumns() != rowDefaults.size())
519 __SS__ <<
"Impossible col default mismatch " << getNumberOfColumns() <<
" vs "
520 << rowDefaults.size() <<
"! How did you get here?" << __E__;
524 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
526 if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA)
528 const std::vector<std::string>& theDataChoices =
529 columnsInfo_[col].getDataChoices();
532 if(theDataChoices.size() && theDataChoices[0] ==
"arbitraryBool=1")
536 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
540 if(theDataView_[row][col] == rowDefaults[col])
543 for(
const auto& choice : theDataChoices)
545 if(theDataView_[row][col] == choice)
553 __SS__ << getTableName() <<
" Error:\t'" << theDataView_[row][col]
554 <<
"' in column " << columnsInfo_[col].getName()
555 <<
" is not a valid Fixed Choice option. "
556 <<
"Possible values are as follows: ";
558 ss << columnsInfo_[col].getDefaultValue()
559 << (columnsInfo_[col].getDataChoices().size() ?
", " :
"");
560 for(
unsigned int i = 0;
561 i < columnsInfo_[col].getDataChoices().size();
564 if(columnsInfo_[col].getDataChoices()[i] ==
"arbitraryBool=0")
567 if(i && (i != 1 || columnsInfo_[col].getDataChoices()[0] !=
570 ss << columnsInfo_[col].getDataChoices()[i];
577 else if(columnsInfo_[col].isChildLink())
581 const std::vector<std::string>& theDataChoices =
582 columnsInfo_[col].getDataChoices();
585 if(!theDataChoices.size() || theDataChoices[0] ==
"arbitraryBool=1")
590 (theDataChoices.size() && theDataChoices[0] ==
"arbitraryBool=0");
594 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
599 for(
const auto& choice : theDataChoices)
601 if(skipOne && !hasSkipped)
607 if(theDataView_[row][col] == choice)
615 __SS__ << getTableName() <<
" Error:\t the value '"
616 << theDataView_[row][col] <<
"' in column "
617 << columnsInfo_[col].getName()
618 <<
" is not a valid Fixed Choice option. "
619 <<
"Possible values are as follows: ";
624 for(
unsigned int i = skipOne ? 1 : 0;
625 i < columnsInfo_[col].getDataChoices().size();
628 if(i > (skipOne ? 1 : 0))
630 ss << columnsInfo_[col].getDataChoices()[i];
637 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_ON_OFF)
638 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
640 if(theDataView_[row][col] ==
"1" ||
641 theDataView_[row][col] ==
"TRUE" ||
642 theDataView_[row][col] ==
"on" || theDataView_[row][col] ==
"On" ||
643 theDataView_[row][col] ==
"ON")
644 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_ON;
645 else if(theDataView_[row][col] ==
"0" ||
646 theDataView_[row][col] ==
"FALSE" ||
647 theDataView_[row][col] ==
"off" ||
648 theDataView_[row][col] ==
"Off" ||
649 theDataView_[row][col] ==
"OFF")
650 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_OFF;
653 __SS__ << getTableName() <<
" Error:\t the value '"
654 << theDataView_[row][col] <<
"' in column "
655 << columnsInfo_[col].getName()
656 <<
" is not a valid Type (On/Off) std::string. Possible "
657 "values are 1, on, On, ON, 0, off, Off, OFF."
662 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_TRUE_FALSE)
663 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
665 if(theDataView_[row][col] ==
"1" ||
666 theDataView_[row][col] ==
"true" ||
667 theDataView_[row][col] ==
"True" ||
668 theDataView_[row][col] ==
"TRUE")
669 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_TRUE;
670 else if(theDataView_[row][col] ==
"0" ||
671 theDataView_[row][col] ==
"false" ||
672 theDataView_[row][col] ==
"False" ||
673 theDataView_[row][col] ==
"FALSE")
674 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_FALSE;
677 __SS__ << getTableName() <<
" Error:\t the value '"
678 << theDataView_[row][col] <<
"' in column "
679 << columnsInfo_[col].getName()
680 <<
" is not a valid Type (True/False) std::string. "
681 "Possible values are 1, true, True, TRUE, 0, false, "
687 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_YES_NO)
688 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
690 if(theDataView_[row][col] ==
"1" ||
691 theDataView_[row][col] ==
"TRUE" ||
692 theDataView_[row][col] ==
"yes" ||
693 theDataView_[row][col] ==
"Yes" || theDataView_[row][col] ==
"YES")
694 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_YES;
695 else if(theDataView_[row][col] ==
"0" ||
696 theDataView_[row][col] ==
"FALSE" ||
697 theDataView_[row][col] ==
"no" ||
698 theDataView_[row][col] ==
"No" ||
699 theDataView_[row][col] ==
"NO")
700 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_NO;
703 __SS__ << getTableName() <<
" Error:\t the value '"
704 << theDataView_[row][col] <<
"' in column "
705 << columnsInfo_[col].getName()
706 <<
" is not a valid Type (Yes/No) std::string. Possible "
707 "values are 1, yes, Yes, YES, 0, no, No, NO."
712 else if(columnsInfo_[col].isGroupID())
714 colLinkGroupIDs_[columnsInfo_[col].getChildLinkIndex()] =
717 groupIdIndexes.emplace(columnsInfo_[col].getChildLinkIndex());
718 ++groupIdIndexesCount;
720 else if(columnsInfo_[col].isChildLink())
723 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
724 if(theDataView_[row][col] ==
"NoLink" ||
725 theDataView_[row][col] ==
"No_Link" ||
726 theDataView_[row][col] ==
"NOLINK" ||
727 theDataView_[row][col] ==
"NO_LINK" ||
728 theDataView_[row][col] ==
"Nolink" ||
729 theDataView_[row][col] ==
"nolink" ||
730 theDataView_[row][col] ==
"noLink")
731 theDataView_[row][col] =
732 TableViewColumnInfo::DATATYPE_LINK_DEFAULT;
735 childLinkIndexes.emplace(columnsInfo_[col].getChildLinkIndex());
736 ++childLinkIndexesCount;
739 if(columnsInfo_[col].getDataType() !=
740 TableViewColumnInfo::DATATYPE_STRING)
742 __SS__ << getTableName() <<
" Error:\t"
743 <<
"Column " << col <<
" with name '"
744 << columnsInfo_[col].getName()
745 <<
"' is a Child Link column and has an illegal data type of '"
746 << columnsInfo_[col].getDataType()
747 <<
"'. The data type for Child Link columns must be "
748 << TableViewColumnInfo::DATATYPE_STRING << __E__;
755 else if(columnsInfo_[col].isChildLinkUID() ||
756 columnsInfo_[col].isChildLinkGroupID())
759 childLinkIdLabels.emplace(columnsInfo_[col].getChildLinkIndex());
760 ++childLinkIdLabelsCount;
763 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
764 if(theDataView_[row][col] ==
"")
765 theDataView_[row][col] = rowDefaults[col];
772 if(columnsInfo_[col].isNumberDataType())
774 std::string minimumValueString = columnsInfo_[col].getMinValue();
775 std::string maximumValueString = columnsInfo_[col].getMaxValue();
776 double minimumValue, maximumValue, valueFromTable;
777 bool minExists =
false, maxExists =
false;
779 if(!minimumValueString.empty())
786 __SS__ <<
"Inavlid user spec'd min value '" << minimumValueString
787 <<
"' which is not a valid number. The minimum value must "
788 "be a number (environment variables and math "
789 "operations are allowed)."
795 if(!maximumValueString.empty())
802 __SS__ <<
"Inavlid user spec'd max value '" << maximumValueString
803 <<
"' which is not a valid number. The maximum value must "
804 "be a number (environment variables and math "
805 "operations are allowed)."
811 if(minExists && maxExists && minimumValue > maximumValue)
813 __SS__ <<
"Minimum value is greater than maximum, check table editor "
819 if(minExists || maxExists)
820 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
823 if(minExists && valueFromTable < minimumValue)
826 <<
"The value '" << valueFromTable <<
"'("
829 <<
") at [row,col]=[" << row <<
"," << col
830 <<
"] is outside the established limits: "
832 <<
" is lower than the specified minimum " << minimumValue
836 if(maxExists && valueFromTable > maximumValue)
839 <<
"This value '" << valueFromTable <<
"'("
842 <<
") at [row,col]=[" << row <<
"," << col
843 <<
"] is outside the established limits: "
845 <<
" is greater than the specified maximum "
846 << maximumValue <<
"." << __E__;
854 if(groupIdIndexes.size() != groupIdIndexesCount)
856 __SS__ << (
"GroupId Labels are not unique!") <<
"There are "
857 << groupIdIndexesCount <<
" GroupId Labels and the unique count is "
858 << groupIdIndexes.size() << __E__;
861 if(childLinkIndexes.size() != childLinkIndexesCount)
863 __SS__ << (
"Child Link Labels are not unique!") <<
"There are "
864 << childLinkIndexesCount
865 <<
" Child Link Labels and the unique count is "
866 << childLinkIndexes.size() << __E__;
869 if(childLinkIdLabels.size() != childLinkIdLabelsCount)
871 __SS__ << (
"Child Link ID Labels are not unique!") <<
"There are "
872 << childLinkIdLabelsCount
873 <<
" Child Link ID Labels and the unique count is "
874 << childLinkIdLabels.size() << __E__;
880 __COUT__ <<
"Error occured in TableView::init() for version=" << version_
894 bool doConvertEnvironmentVariables)
const
896 if(!(row < getNumberOfRows() && col < theDataView_[row].size()))
898 __SS__ <<
"Invalid row col requested " << row <<
"," << col <<
" vs "
899 << getNumberOfRows() <<
"," << columnsInfo_.size() <<
"/"
900 << theDataView_[row].size() << __E__;
905 theDataView_[row][col], col, doConvertEnvironmentVariables);
915 bool doConvertEnvironmentVariables)
const
917 if(col >= columnsInfo_.size())
919 __SS__ <<
"Invalid col requested" << __E__;
923 if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA &&
925 value == columnsInfo_[col].getDefaultDefaultValue(columnsInfo_[col].getType(),
926 columnsInfo_[col].getDataType()))
930 std::vector<std::string> choices = columnsInfo_[col].getDataChoices();
933 bool skipOne = (choices.size() && choices[0].find(
"arbitraryBool=") == 0);
934 size_t index = (skipOne ? 1 : 0);
935 if(choices.size() > index)
937 return doConvertEnvironmentVariables
943 if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_STRING)
944 return doConvertEnvironmentVariables
947 else if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
950 doConvertEnvironmentVariables
956 __SS__ <<
"\tUnrecognized column data type: " << columnsInfo_[col].getDataType()
957 <<
" in configuration " << tableName_
958 <<
" at column=" << columnsInfo_[col].getName()
959 <<
" for getValue with type '"
974 bool doConvertEnvironmentVariables)
const
976 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
978 __SS__ << (
"Invalid row col requested") << __E__;
982 __COUTS__(30) << columnsInfo_[col].getType() <<
" " << col << __E__;
984 if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_ON_OFF)
986 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"on" ||
987 theDataView_[row][col] ==
"On" || theDataView_[row][col] ==
"ON")
988 return TableViewColumnInfo::TYPE_VALUE_ON;
990 return TableViewColumnInfo::TYPE_VALUE_OFF;
992 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_TRUE_FALSE)
994 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"true" ||
995 theDataView_[row][col] ==
"True" || theDataView_[row][col] ==
"TRUE")
996 return TableViewColumnInfo::TYPE_VALUE_TRUE;
998 return TableViewColumnInfo::TYPE_VALUE_FALSE;
1000 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_YES_NO)
1002 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"yes" ||
1003 theDataView_[row][col] ==
"Yes" || theDataView_[row][col] ==
"YES")
1004 return TableViewColumnInfo::TYPE_VALUE_YES;
1006 return TableViewColumnInfo::TYPE_VALUE_NO;
1009 return doConvertEnvironmentVariables
1011 : theDataView_[row][col];
1024 bool doConvertEnvironmentVariables ,
1025 bool quotesToDoubleQuotes )
const
1027 std::string val =
getValueAsString(row, col, doConvertEnvironmentVariables);
1028 std::string retVal =
"";
1029 retVal.reserve(val.size());
1030 for(
unsigned int i = 0; i < val.size(); ++i)
1034 else if(val[i] ==
'\t')
1036 else if(val[i] ==
'\r')
1043 if(quotesToDoubleQuotes && val[i] ==
'"')
1045 else if(!quotesToDoubleQuotes && val[i] ==
'"')
1058 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1060 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1064 if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_STRING)
1065 theDataView_[row][col] = value;
1069 __SS__ <<
"\tUnrecognized column data type: " << columnsInfo_[col].getDataType()
1070 <<
" in configuration " << tableName_
1071 <<
" at column=" << columnsInfo_[col].getName()
1072 <<
" for setValue with type '"
1081 setValue(std::string(value), row, col);
1091 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1093 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1097 theDataView_[row][col] = value;
1110 std::string baseValueAsString ,
1111 bool doMathAppendStrategy ,
1112 std::string childLinkIndex ,
1113 std::string groupId )
1115 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1117 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1121 bool isUniqueGroupCol =
1122 (columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA);
1123 unsigned int childLinkIndexCol = -1;
1124 if(isUniqueGroupCol)
1126 __COUTVS__(12, childLinkIndex);
1127 __COUTVS__(12, groupId);
1129 __COUTVS__(12, childLinkIndexCol);
1132 __COUTT__ <<
"Current '" << columnsInfo_[col].getName() <<
"' "
1133 << (isUniqueGroupCol ?
"(Unique in Group) " :
"")
1134 <<
"unique data entry is data[" << row <<
"][" << col <<
"] = '"
1135 << theDataView_[row][col] <<
"' baseValueAsString = " << baseValueAsString
1136 <<
" doMathAppendStrategy = " << doMathAppendStrategy << __E__;
1138 bool firstConflict =
true;
1139 int maxUniqueData = -1;
1140 std::string tmpString =
"";
1143 std::string numString;
1144 std::string opString;
1150 for(
unsigned int r = 0; r < getNumberOfRows(); ++r)
1155 if(isUniqueGroupCol && !isEntryInGroupCol(r, childLinkIndexCol, groupId))
1161 tmpString = theDataView_[r][col];
1163 __COUTS__(3) <<
"row[" << r <<
"] tmpString " << tmpString << __E__;
1165 for(index = tmpString.length() - 1; index < tmpString.length(); --index)
1167 __COUTS__(3) << index <<
" tmpString[index] " << tmpString[index] << __E__;
1168 if(!(tmpString[index] >=
'0' && tmpString[index] <=
'9'))
1173 __COUTS__(3) <<
"index " << index <<
" foundAny " << foundAny << __E__;
1175 if(tmpString.length() && foundAny)
1178 numString = tmpString.substr(index + 1);
1181 tmpString = tmpString.substr(0, index + 1);
1183 if(doMathAppendStrategy && tmpString.size())
1187 for(index = tmpString.length() - 1; index < tmpString.length(); --index)
1190 << index <<
" tmpString[index] " << tmpString[index] << __E__;
1191 if(!(tmpString[index] ==
'+' || tmpString[index] ==
' '))
1199 opString = tmpString.substr(index + 1);
1202 tmpString = tmpString.substr(0, index + 1);
1206 __COUTS__(3) << tmpString <<
" vs " << baseValueAsString << __E__;
1208 if(baseValueAsString !=
"" && tmpString != baseValueAsString)
1211 __COUTS__(3) <<
"Found unique data base string '" << tmpString
1212 <<
"' and number string '" << numString <<
"' in last record '"
1213 << theDataView_[r][col] <<
"'" << __E__;
1218 if(baseValueAsString.size() &&
1219 baseValueAsString[baseValueAsString.size() - 1] >=
'0' &&
1220 baseValueAsString[baseValueAsString.size() - 1] <=
'9')
1221 baseValueAsString +=
'_';
1223 firstConflict =
false;
1227 sscanf(numString.c_str(),
"%u", &index);
1229 if((
int)index > maxUniqueData)
1231 maxUniqueData = (int)index;
1233 if(baseValueAsString ==
"")
1234 baseValueAsString = tmpString;
1237 else if(maxUniqueData < 0 &&
1238 (baseValueAsString ==
"" || tmpString == baseValueAsString))
1243 if(baseValueAsString.size() &&
1244 baseValueAsString[baseValueAsString.size() - 1] >=
'0' &&
1245 baseValueAsString[baseValueAsString.size() - 1] <=
'9')
1246 baseValueAsString +=
'_';
1248 firstConflict =
false;
1255 __COUTVS__(12, maxUniqueData);
1256 __COUTVS__(12, baseValueAsString);
1258 if(maxUniqueData == -1)
1260 if(baseValueAsString !=
"")
1261 theDataView_[row][col] = baseValueAsString;
1263 theDataView_[row][col] = columnsInfo_[col].getDefaultValue();
1269 char indexString[1000];
1270 sprintf(indexString,
"%u", maxUniqueData);
1272 __COUTVS__(12, indexString);
1273 __COUTVS__(12, baseValueAsString);
1275 if(doMathAppendStrategy)
1276 theDataView_[row][col] = baseValueAsString +
" + " + indexString;
1278 theDataView_[row][col] = baseValueAsString + indexString;
1281 __COUTT__ <<
"New unique data entry is data[" << row <<
"][" << col <<
"] = '"
1282 << theDataView_[row][col] <<
"'" << __E__;
1286 std::stringstream ss;
1288 __COUT_MULTI__(13, ss.str());
1291 return theDataView_[row][col];
1297 unsigned int TableView::initColUID(
void)
1299 if(colUID_ != INVALID)
1304 if(colUID_ == INVALID)
1306 __COUT__ <<
"Column Types: " << __E__;
1307 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1308 std::cout << columnsInfo_[col].getType() <<
"() "
1309 << columnsInfo_[col].getName() << __E__;
1310 __SS__ <<
"\tMissing UID Column in table named '" << tableName_ <<
"'" << __E__;
1321 if(colUID_ != INVALID)
1324 __COUT__ <<
"Column Types: " << __E__;
1325 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1326 std::cout << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1329 __SS__ << (
"Missing UID Column in config named " + tableName_ +
1330 ". (Possibly TableView was just not initialized?" +
1331 " This is the const call so can not alter class members)")
1342 unsigned int TableView::initColStatus(
void)
1344 if(colStatus_ != INVALID)
1348 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1349 if(columnsInfo_[col].getName() == TableViewColumnInfo::COL_NAME_STATUS)
1354 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1355 if(columnsInfo_[col].getName() == TableViewColumnInfo::COL_NAME_ENABLED)
1363 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_STATUS
1364 <<
"' or '" << TableViewColumnInfo::COL_NAME_ENABLED <<
"' in table '"
1365 << tableName_ <<
".'" << __E__;
1366 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1367 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1368 ss << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1378 unsigned int TableView::initColPriority(
void)
1380 if(colPriority_ != INVALID)
1381 return colPriority_;
1385 findCol(
"*" + TableViewColumnInfo::COL_NAME_PRIORITY);
1386 if(colPriority_ == INVALID)
1388 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_PRIORITY
1389 <<
"' in table '" << tableName_ <<
".'" << __E__;
1390 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1391 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1392 ss << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1397 return colPriority_;
1406 if(colStatus_ != INVALID)
1409 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_STATUS
1410 <<
"' or '" << TableViewColumnInfo::COL_NAME_ENABLED <<
"' in table '"
1411 << tableName_ <<
".'"
1412 <<
" (The Status column is identified when the TableView is initialized)"
1415 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1416 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1417 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1424 __COUTT__ << ss.str();
1437 if(colPriority_ != INVALID)
1438 return colPriority_;
1440 __SS__ <<
"Priority column was not found... \nColumn Types: " << __E__;
1442 ss <<
"Missing " << TableViewColumnInfo::COL_NAME_PRIORITY
1443 <<
" Column in table named '" << tableName_
1444 <<
".' (The Priority column is identified when the TableView is initialized)"
1448 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1449 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1450 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1463 const unsigned int& col,
1464 const std::string& groupID)
1467 if(isEntryInGroupCol(row, col, groupID))
1469 __SS__ <<
"GroupID (" << groupID <<
") added to row (" << row
1470 <<
" is already present!" << __E__;
1479 if(getDataView()[row][col] ==
"" ||
1480 getDataView()[row][col] == getDefaultRowValues()[col])
1483 setValue(groupID +
" | " + getDataView()[row][col], row, col);
1495 const unsigned int groupIdCol,
1496 const std::string& groupID,
1497 bool onlyStatusTrue ,
1498 bool orderedByPriority )
const
1500 std::vector<
unsigned int > retVector;
1501 std::vector<std::vector<
unsigned int >> groupRowVectors =
1502 getGroupRowsInVectors(groupIdCol, groupID, onlyStatusTrue, orderedByPriority);
1504 for(
const auto& groupRowVector : groupRowVectors)
1505 for(
const auto& groupRow : groupRowVector)
1506 retVector.push_back(groupRow);
1518 const unsigned int groupIdCol,
1519 const std::string& groupID,
1520 bool onlyStatusTrue )
const
1522 return getGroupRowsInVectors(
1523 groupIdCol, groupID, onlyStatusTrue,
true );
1534 std::vector<std::vector<
unsigned int >> TableView::getGroupRowsInVectors(
1535 const unsigned int groupIdCol,
1536 const std::string& groupID,
1537 bool onlyStatusTrue,
1538 bool orderedByPriority)
const
1540 std::map<uint64_t , std::vector<
unsigned int >>
1542 std::vector<std::vector<
unsigned int >> retVector;
1543 uint64_t tmpPriority;
1546 if(!(orderedByPriority &&
1547 colPriority_ != INVALID))
1548 retVector.push_back(std::vector<unsigned int /*group row*/>());
1550 __COUTS__(2) <<
"getGroupRowsInVectors: " << groupID <<
" at col " << groupIdCol
1552 for(
unsigned int r = 0; r < getNumberOfRows(); ++r)
1553 if(groupID ==
"" || groupID ==
"*" || groupIdCol == INVALID ||
1554 isEntryInGroupCol(r, groupIdCol, groupID))
1556 if(groupIdCol != INVALID)
1557 __COUTS__(2) <<
"Row " << r <<
" '" << getDataView()[r][groupIdCol]
1558 <<
"' is in group " << groupID << __E__;
1560 if(onlyStatusTrue && colStatus_ != INVALID)
1562 getValue(tmpStatus, r, colStatus_);
1568 if(orderedByPriority && colPriority_ != INVALID)
1570 getValue(tmpPriority, r, colPriority_);
1572 mapByPriority[tmpPriority ? tmpPriority : 100].push_back(r);
1575 retVector[0].push_back(r);
1578 __COUTS__(2) <<
"Row " << r <<
" '" << getDataView()[r][groupIdCol]
1579 <<
"' is NOT in group " << groupID << __E__;
1581 if(orderedByPriority && colPriority_ != INVALID)
1585 for(
const auto& priorityChildRowVector : mapByPriority)
1587 retVector.push_back(std::vector<unsigned int /*group row*/>());
1588 for(
const auto& priorityChildRow : priorityChildRowVector.second)
1589 retVector[retVector.size() - 1].push_back(priorityChildRow);
1592 __COUT__ <<
"Returning priority children list." << __E__;
1605 const unsigned int& col,
1606 const std::string& groupNeedle,
1607 bool deleteRowIfNoGroupLeft)
1609 __COUT__ <<
"removeRowFromGroup groupNeedle " << groupNeedle << __E__;
1610 std::set<std::string> groupIDList;
1611 if(!isEntryInGroupCol(row, col, groupNeedle, &groupIDList))
1614 <<
"GroupID (" << groupNeedle <<
") removed from row (" << row
1615 <<
") was already removed! Is there a strange GroupID wildcard match issue? {"
1625 std::string newValue =
"";
1626 unsigned int cnt = 0;
1627 for(
const auto& groupID : groupIDList)
1629 __COUTT__ << groupID <<
" " << groupNeedle <<
" " << newValue << __E__;
1630 if(groupID == groupNeedle)
1635 newValue += groupID;
1638 bool wasDeleted =
false;
1639 if(deleteRowIfNoGroupLeft && newValue ==
"")
1641 __COUTT__ <<
"Delete row since it no longer part of any group." << __E__;
1648 __COUTT__ << getDataView()[row][col] << __E__;
1661 const std::string& childLinkIndex,
1662 const std::string& groupNeedle)
const
1666 return isEntryInGroupCol(r, c, groupNeedle);
1678 bool TableView::isEntryInGroupCol(
const unsigned int& r,
1679 const unsigned int& c,
1680 const std::string& groupNeedle,
1681 std::set<std::string>* groupIDList)
const
1683 if(r >= getNumberOfRows() || c >= getNumberOfColumns())
1685 __SS__ <<
"Invalid row/col requested!" << __E__;
1694 __COUTS__(2) <<
"groupNeedle " << groupNeedle << __E__;
1697 for(; j < theDataView_[r][c].size(); ++j)
1698 if((theDataView_[r][c][j] ==
' ' ||
1699 theDataView_[r][c][j] ==
'|') &&
1702 else if((theDataView_[r][c][j] ==
1704 theDataView_[r][c][j] ==
'|') &&
1708 groupIDList->emplace(theDataView_[r][c].substr(i, j - i));
1710 __COUTS__(2) <<
"Group found to compare: "
1711 << theDataView_[r][c].substr(i, j - i) << __E__;
1712 if(groupIDList ? groupNeedle == theDataView_[r][c].substr(i, j - i)
1714 theDataView_[r][c].substr(i, j - i), groupNeedle))
1716 __COUTS__(2) <<
"'" << theDataView_[r][c].substr(i, j - i)
1717 <<
"' is in group '" << groupNeedle <<
"'!" << __E__;
1729 groupIDList->emplace(theDataView_[r][c].substr(i, j - i));
1731 __COUTS__(2) <<
"Group found to compare: " << theDataView_[r][c].substr(i, j - i)
1733 if(groupIDList ? groupNeedle == theDataView_[r][c].substr(i, j - i)
1737 __COUTS__(2) <<
"'" << theDataView_[r][c].substr(i, j - i)
1738 <<
"' is in group '" << groupNeedle <<
"'!" << __E__;
1755 unsigned int r)
const
1760 unsigned int r)
const
1764 std::set<std::string> retSet;
1769 if(r != (
unsigned int)-1)
1771 if(r >= getNumberOfRows())
1773 __SS__ <<
"Invalid row requested!" << __E__;
1805 for(r = 0; r < getNumberOfRows(); ++r)
1857 if(!childLinkIndex.size())
1859 __SS__ <<
"Empty childLinkIndex string parameter!" << __E__;
1864 const char* needleChildLinkIndex = &childLinkIndex[0];
1868 size_t spacePos = childLinkIndex.find(
' ');
1869 if(spacePos != std::string::npos &&
1870 spacePos + 1 < childLinkIndex.size())
1873 needleChildLinkIndex = &childLinkIndex[spacePos + 1];
1876 std::map<std::string, unsigned int>::const_iterator it =
1877 colLinkGroupIDs_.find(needleChildLinkIndex);
1879 colLinkGroupIDs_.end())
1883 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1886 if(columnsInfo_[col].isChildLink() || columnsInfo_[col].isChildLinkUID() ||
1887 columnsInfo_[col].isChildLinkGroupID() || columnsInfo_[col].isGroupID())
1889 if(needleChildLinkIndex == columnsInfo_[col].getChildLinkIndex())
1895 <<
"Error! Incompatible table for this group link! Table '" << tableName_
1896 <<
"' is missing a GroupID column with data type '"
1897 << TableViewColumnInfo::TYPE_START_GROUP_ID <<
"-" << needleChildLinkIndex
1899 <<
"Note: you can separate the child GroupID column data type from "
1900 <<
"the parent GroupLink column data type; this is accomplished by using a space "
1901 <<
"character at the parent level - the string after the space will be treated "
1903 <<
"child GroupID column data type." << __E__;
1904 ss <<
"Existing Column GroupIDs: " << __E__;
1905 for(
auto& groupIdColPair : colLinkGroupIDs_)
1906 ss <<
"\t" << groupIdColPair.first <<
" : col-" << groupIdColPair.second << __E__;
1908 ss <<
"Existing Column Types: " << __E__;
1909 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1910 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1920 const std::string& value,
1921 unsigned int offsetRow,
1922 bool doNotThrow )
const
1924 for(
unsigned int row = offsetRow; row < theDataView_.size(); ++row)
1926 if(theDataView_[row][col] == value)
1930 return TableView::INVALID;
1932 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find value=" << value
1933 <<
" in column named " << columnsInfo_[col].getName()
1934 <<
" with type=" << columnsInfo_[col].getType() << __E__ << __E__
1945 const std::string& value,
1946 const std::string& groupId,
1947 const std::string& childLinkIndex,
1948 unsigned int offsetRow)
const
1951 for(
unsigned int row = offsetRow; row < theDataView_.size(); ++row)
1953 if(theDataView_[row][col] == value && isEntryInGroupCol(row, groupIdCol, groupId))
1957 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find in group the value=" << value
1958 <<
" in column named '" << columnsInfo_[col].getName()
1959 <<
"' with type=" << columnsInfo_[col].getType() <<
" and GroupID: '"
1960 << groupId <<
"' in column '" << groupIdCol
1961 <<
"' with GroupID child link index '" << childLinkIndex <<
"'" << __E__;
1972 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1974 columnsInfo_[col].getName() ))
1977 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find column named '" << wildCardName
1979 ss <<
"Existing columns:\n";
1980 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1981 ss <<
"\t" << columnsInfo_[col].getName() <<
"\n";
1994 unsigned int startingCol)
const
1996 for(
unsigned int col = startingCol; col < columnsInfo_.size(); ++col)
1998 __COUTS__(40) << columnsInfo_[col].getType() << __E__;
1999 if(columnsInfo_[col].getType() == type)
2013 if(!getNumberOfRows())
2014 return getNumberOfColumns();
2015 return theDataView_[0].size();
2019 std::set<std::string> TableView::getColumnNames(
void)
const
2021 std::set<std::string> retSet;
2022 for(
auto& colInfo : columnsInfo_)
2023 retSet.emplace(colInfo.getName());
2028 std::map<std::string,
unsigned int > TableView::getColumnNamesMap(
void)
const
2030 std::map<std::string,
unsigned int > retMap;
2032 for(
auto& colInfo : columnsInfo_)
2033 retMap.emplace(std::make_pair(colInfo.getName(), c++));
2038 std::set<std::string> TableView::getColumnStorageNames(
void)
const
2040 std::set<std::string> retSet;
2041 for(
auto& colInfo : columnsInfo_)
2042 retSet.emplace(colInfo.getStorageName());
2047 const std::vector<std::string>& TableView::initRowDefaults(
void)
2049 std::vector<std::string>& retVec = rowDefaultValues_;
2053 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
2060 if(columnsInfo_[col].isChildLink())
2062 const std::vector<std::string>& theDataChoices =
2063 columnsInfo_[col].getDataChoices();
2066 if(!theDataChoices.size() ||
2067 theDataChoices[0] ==
"arbitraryBool=1")
2068 retVec.push_back(columnsInfo_[col].getDefaultValue());
2072 (theDataChoices.size() && theDataChoices[0] ==
"arbitraryBool=0");
2077 bool foundDefault =
false;
2079 for(
const auto& choice : theDataChoices)
2080 if(skipOne && !hasSkipped)
2085 else if(choice == columnsInfo_[col].getDefaultValue())
2087 foundDefault =
true;
2092 if(!foundDefault && theDataChoices.size() > (skipOne ? 1 : 0))
2093 retVec.push_back(theDataChoices[(skipOne ? 1 : 0)]);
2095 retVec.push_back(columnsInfo_[col].getDefaultValue());
2099 retVec.push_back(columnsInfo_[col].getDefaultValue());
2104 return rowDefaultValues_;
2110 if(column >= columnsInfo_.size())
2112 __SS__ <<
"\nCan't find column " << column
2113 <<
"\n\n\n\nThe column info is likely missing due to incomplete "
2114 "Configuration View filling.\n\n"
2119 return columnsInfo_[column];
2131 void TableView::setAuthor(
const std::string& author) { author_ = author; }
2134 void TableView::setCreationTime(time_t t) { creationTime_ = t; }
2137 void TableView::setLastAccessTime(time_t t) { lastAccessTime_ = t; }
2140 void TableView::setLooseColumnMatching(
bool setValue)
2142 fillWithLooseColumnMatching_ =
setValue;
2146 void TableView::doGetSourceRawData(
bool setValue) { getSourceRawData_ =
setValue; }
2149 void TableView::reset(
void)
2154 columnsInfo_.clear();
2155 theDataView_.clear();
2159 void TableView::print(std::ostream& out )
const
2161 out <<
"============================================================================="
2164 out <<
"Print: " << tableName_ <<
" Version: " << version_ <<
" Comment: " << comment_
2165 <<
" Author: " << author_ <<
" Creation Time: " << ctime(&creationTime_) << __E__;
2166 out <<
"\t\tNumber of Cols " << getNumberOfColumns() << __E__;
2167 out <<
"\t\tNumber of Rows " << getNumberOfRows() << __E__;
2169 out <<
"Columns:\t";
2170 for(
int i = 0; i < (int)columnsInfo_.size(); ++i)
2171 out << i <<
":" << columnsInfo_[i].getName() <<
":"
2172 << columnsInfo_[i].getStorageName() <<
":" << columnsInfo_[i].getType() <<
":"
2173 << columnsInfo_[i].getDataType() <<
"\t ";
2176 out <<
"Rows:" << __E__;
2179 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2181 out << (int)r <<
":\t";
2182 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2184 out << (int)c <<
":";
2187 if(columnsInfo_[c].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA)
2189 int choiceIndex = -1;
2190 std::vector<std::string> choices = columnsInfo_[c].getDataChoices();
2193 if(val == columnsInfo_[c].getDefaultValue())
2197 for(
int i = 0; i < (int)choices.size(); ++i)
2198 if(val == choices[i])
2199 choiceIndex = i + 1;
2202 out <<
"ChoiceIndex=" << choiceIndex <<
":";
2205 out << theDataView_[r][c];
2225 void TableView::printJSON(std::ostream& out )
const
2228 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2230 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2232 __COUTS__(32) <<
" '" << tableName_ <<
"' vs " << tmpCachePrepend <<
" or "
2233 << tmpJsonDocPrepend << __E__;
2235 if(tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend ||
2236 tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend)
2244 out <<
"\"NAME\" : \"" << tableName_ <<
"\",\n";
2248 out <<
"\"COMMENT\" : ";
2254 for(
unsigned int i = 0; i < val.size(); ++i)
2258 else if(val[i] ==
'\t')
2260 else if(val[i] ==
'\r')
2265 if(val[i] ==
'"' || val[i] ==
'\\')
2272 out <<
"\"AUTHOR\" : \"" << author_ <<
"\",\n";
2273 out <<
"\"CREATION_TIME\" : " << creationTime_ <<
",\n";
2278 out <<
"\"COL_TYPES\" : {\n";
2279 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2281 out <<
"\t\t\"" << columnsInfo_[c].getStorageName() <<
"\" : ";
2282 out <<
"\"" << columnsInfo_[c].getDataType() <<
"\"";
2283 if(c + 1 < (
int)getNumberOfColumns())
2289 out <<
"\"DATA_SET\" : [\n";
2291 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2294 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2296 out <<
"\t\t\"" << columnsInfo_[c].getStorageName() <<
"\" : ";
2301 if(c + 1 < (
int)getNumberOfColumns())
2306 if(r + 1 < (
int)getNumberOfRows())
2316 void TableView::printCSV(std::ostream& out ,
2317 const std::string& valueDelimeter ,
2318 const std::string& recordDelimeter ,
2319 bool includeColumnNames )
const
2322 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2324 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2326 __COUTS__(32) <<
" '" << tableName_ <<
"' vs " << tmpCachePrepend <<
" or "
2327 << tmpJsonDocPrepend << __E__;
2329 if(tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend ||
2330 tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend)
2332 __SS__ <<
"Cannot convert custom storage data to CSV!" << __E__;
2339 for(
int c = 0; includeColumnNames && c < (int)getNumberOfColumns(); ++c)
2342 out << valueDelimeter;
2343 out <<
"\"" << columnsInfo_[c].getStorageName() <<
"\"";
2345 if(includeColumnNames)
2346 out << recordDelimeter;
2348 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2350 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2353 out << valueDelimeter;
2358 out << recordDelimeter;
2374 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2376 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2380 if(tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend ||
2381 tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend)
2383 __COUTS__(3) <<
"Special JSON doc: " << json << __E__;
2390 bool rawData = getSourceRawData_;
2391 if(getSourceRawData_)
2393 __COUTV__(getSourceRawData_);
2394 getSourceRawData_ =
false;
2395 sourceRawData_ =
"";
2398 std::map<std::string ,
unsigned int > keyEntryCountMap;
2399 std::vector<std::string> keys;
2400 keys.push_back(
"NAME");
2401 keys.push_back(
"COMMENT");
2402 keys.push_back(
"AUTHOR");
2403 keys.push_back(
"CREATION_TIME");
2405 keys.push_back(
"DATA_SET");
2409 CV_JSON_FILL_COMMENT,
2410 CV_JSON_FILL_AUTHOR,
2411 CV_JSON_FILL_CREATION_TIME,
2413 CV_JSON_FILL_DATA_SET
2418 __COUTV__(tableName_);
2419 __COUTTV__(getNumberOfRows());
2423 sourceColumnMismatchCount_ = 0;
2424 sourceColumnMissingCount_ = 0;
2425 sourceColumnNames_.clear();
2426 unsigned int colFoundCount = 0;
2428 unsigned int row = -1;
2429 unsigned int colSpeedup = 0;
2430 unsigned int startString, startNumber = 0, endNumber = -1;
2431 unsigned int bracketCount = 0;
2432 unsigned int sqBracketCount = 0;
2437 bool keyIsMatch, keyIsComment;
2438 unsigned int keyIsMatchIndex, keyIsMatchStorageIndex, keyIsMatchCommentIndex;
2439 const std::string COMMENT_ALT_KEY =
"COMMENT";
2441 std::string extractedString =
"", currKey =
"", currVal =
"";
2442 unsigned int currDepth = 0;
2444 std::vector<std::string> jsonPath;
2445 std::vector<char> jsonPathType;
2446 char lastPopType =
'_';
2448 unsigned int matchedKey = -1;
2449 unsigned int lastCol = -1;
2452 for(; i < json.size(); ++i)
2457 if(i - 1 < json.size() &&
2458 json[i - 1] ==
'\\')
2461 inQuotes = !inQuotes;
2467 json.substr(startString + 1, i - startString - 1));
2476 if(jsonPathType[jsonPathType.size() - 1] !=
'{' ||
2479 __COUT__ <<
"Invalid ':' position" << __E__;
2484 jsonPathType.push_back(
'K');
2485 jsonPath.push_back(extractedString);
2504 if(lastPopType ==
'{')
2507 if(jsonPathType[jsonPathType.size() - 1] ==
'K')
2510 jsonPath.pop_back();
2511 jsonPathType.pop_back();
2517 currVal = extractedString;
2520 if(endNumber == (
unsigned int)-1 ||
2521 endNumber <= startNumber)
2524 if(endNumber <= startNumber)
2527 currVal = json.substr(startNumber + 1, endNumber - startNumber - 1);
2530 currDepth = bracketCount;
2532 if(jsonPathType[jsonPathType.size() - 1] ==
'K')
2534 currKey = jsonPath[jsonPathType.size() - 1];
2539 jsonPath.pop_back();
2540 jsonPathType.pop_back();
2542 else if(jsonPathType[jsonPathType.size() - 1] ==
2546 for(
unsigned int k = jsonPathType.size() - 2; k < jsonPathType.size();
2548 if(jsonPathType[k] ==
'K')
2550 currKey = jsonPath[k];
2555 __COUT__ <<
"Invalid array position" << __E__;
2564 __COUT__ <<
"Invalid ',' position" << __E__;
2575 jsonPathType.push_back(
'{');
2576 jsonPath.push_back(
"{");
2589 if(lastPopType !=
'{' &&
2590 jsonPathType[jsonPathType.size() - 1] ==
'K')
2592 currDepth = bracketCount;
2593 currKey = jsonPath[jsonPathType.size() - 1];
2595 currVal = extractedString;
2598 if(endNumber == (
unsigned int)-1 ||
2599 endNumber <= startNumber)
2602 if(endNumber <= startNumber)
2606 json.substr(startNumber + 1, endNumber - startNumber - 1);
2610 jsonPath.pop_back();
2611 jsonPathType.pop_back();
2614 if(jsonPathType[jsonPathType.size() - 1] !=
'{')
2616 __COUT__ <<
"Invalid '}' position" << __E__;
2620 jsonPath.pop_back();
2621 jsonPathType.pop_back();
2627 jsonPathType.push_back(
'[');
2628 jsonPath.push_back(
"[");
2637 if(jsonPathType[jsonPathType.size() - 1] !=
'[')
2639 __COUT__ <<
"Invalid ']' position" << __E__;
2643 currDepth = bracketCount;
2647 currVal = extractedString;
2650 if(endNumber == (
unsigned int)-1 ||
2651 endNumber <= startNumber)
2654 if(endNumber <= startNumber)
2657 currVal = json.substr(startNumber + 1, endNumber - startNumber - 1);
2662 for(
unsigned int k = jsonPathType.size() - 2; k < jsonPathType.size(); --k)
2663 if(jsonPathType[k] ==
'K')
2665 currKey = jsonPath[k];
2670 __COUT__ <<
"Invalid array position" << __E__;
2675 if(jsonPathType[jsonPathType.size() - 1] !=
'[')
2677 __COUT__ <<
"Invalid ']' position" << __E__;
2681 jsonPath.pop_back();
2682 jsonPathType.pop_back();
2691 if(startNumber != (
unsigned int)-1 && endNumber == (
unsigned int)-1)
2705 std::cout << i <<
":\t" << json[i] <<
" - ";
2715 std::cout <<
"ExtKey=";
2716 for(
unsigned int k = 0; k < jsonPath.size(); ++k)
2717 std::cout << jsonPath[k] <<
"/";
2719 std::cout << lastPopType <<
" ";
2720 std::cout << bracketCount <<
" ";
2721 std::cout << sqBracketCount <<
" ";
2722 std::cout << inQuotes <<
" ";
2723 std::cout << newValue <<
"-";
2724 std::cout << currKey <<
"-{" << currDepth <<
"}:";
2725 std::cout << currVal <<
" ";
2726 std::cout << startNumber <<
"-";
2727 std::cout << endNumber <<
" ";
2729 __COUTTV__(fillWithLooseColumnMatching_);
2730 __COUTTV__(getNumberOfRows());
2739 for(
unsigned int k = 0; k < keys.size(); ++k)
2740 if((currDepth == 1 && keys[k] == currKey) ||
2741 (currDepth > 1 && keys[k] == jsonPath[1]))
2750 if(matchedKey == CV_JSON_FILL_COMMENT)
2751 setComment(currVal);
2752 else if(matchedKey == CV_JSON_FILL_AUTHOR)
2754 else if(matchedKey == CV_JSON_FILL_CREATION_TIME)
2755 setCreationTime(strtol(currVal.c_str(), 0, 10));
2757 else if(currDepth == 2)
2760 sourceRawData_ += StringMacros::encodeURIComponent(currKey) +
"," +
2761 StringMacros::encodeURIComponent(currVal) +
",";
2762 sourceColumnNames_.emplace(currKey);
2765 else if(matchedKey != (
unsigned int)-1)
2768 __COUTT__ <<
"New Data for:: key[" << matchedKey <<
"]-"
2769 << keys[matchedKey] <<
"\n";
2773 case CV_JSON_FILL_NAME:
2779 if(currVal != getTableName() &&
2781 "TABLE_GROUP_METADATA")
2782 __COUT_WARN__ <<
"JSON-fill Table name mismatch: " << currVal
2783 <<
" vs " << getTableName() << __E__;
2786 case CV_JSON_FILL_COMMENT:
2788 setComment(currVal);
2790 case CV_JSON_FILL_AUTHOR:
2794 case CV_JSON_FILL_CREATION_TIME:
2796 setCreationTime(strtol(currVal.c_str(), 0, 10));
2801 case CV_JSON_FILL_DATA_SET:
2803 __COUTT__ <<
"CV_JSON_FILL_DATA_SET New Data for::" << matchedKey
2804 <<
"]-" << keys[matchedKey] <<
"/" << currDepth
2805 <<
".../" << currKey <<
"\n";
2811 unsigned int col, ccnt = 0;
2812 unsigned int noc = getNumberOfColumns();
2813 for(; ccnt < noc; ++ccnt)
2819 if(fillWithLooseColumnMatching_)
2832 if(getNumberOfRows() == 1)
2833 sourceColumnNames_.emplace(currKey);
2837 if(row >= getNumberOfRows())
2839 __SS__ <<
"Invalid row"
2841 std::cout << ss.str();
2846 theDataView_[row][col] =
2854 col = (ccnt + colSpeedup) % noc;
2860 keyIsComment =
true;
2861 for(keyIsMatchIndex = 0,
2862 keyIsMatchStorageIndex = 0,
2863 keyIsMatchCommentIndex = 0;
2864 keyIsMatchIndex < currKey.size();
2867 if(columnsInfo_[col]
2868 .getStorageName()[keyIsMatchStorageIndex] ==
2870 ++keyIsMatchStorageIndex;
2872 if(currKey[keyIsMatchIndex] ==
'_')
2876 if(keyIsMatchStorageIndex >=
2877 columnsInfo_[col].getStorageName().size() ||
2878 currKey[keyIsMatchIndex] !=
2880 .getStorageName()[keyIsMatchStorageIndex])
2890 keyIsMatchCommentIndex < COMMENT_ALT_KEY.size())
2892 if(currKey[keyIsMatchIndex] !=
2893 COMMENT_ALT_KEY[keyIsMatchCommentIndex])
2896 keyIsComment =
false;
2900 ++keyIsMatchStorageIndex;
2905 __COUTTV__(keyIsMatch);
2906 __COUTTV__(keyIsComment);
2907 __COUTTV__(currKey);
2908 __COUTTV__(columnsInfo_[col].getStorageName());
2909 __COUTTV__(getNumberOfRows());
2912 if(keyIsMatch || keyIsComment)
2915 if(keyEntryCountMap.find(currKey) ==
2916 keyEntryCountMap.end())
2917 keyEntryCountMap[currKey] =
2920 ++keyEntryCountMap.at(currKey);
2923 if(keyEntryCountMap.size() == 1 ||
2924 (keyEntryCountMap.at(currKey) &&
2925 keyEntryCountMap.at(currKey) >
2928 if(getNumberOfRows())
2929 sourceColumnMissingCount_ +=
2930 getNumberOfColumns() - colFoundCount;
2938 if(getNumberOfRows() == 1)
2939 sourceColumnNames_.emplace(currKey);
2943 if(row >= getNumberOfRows())
2945 __SS__ <<
"Invalid row"
2947 __COUT__ <<
"\n" << ss.str();
2952 theDataView_[row][col] = currVal;
2958 if(ccnt >= getNumberOfColumns())
2961 <<
"Invalid column in JSON source data: " << currKey
2962 <<
" not found in column names of table named "
2963 << getTableName() <<
"."
2968 ++sourceColumnMismatchCount_;
2969 if(getNumberOfRows() ==
2971 sourceColumnNames_.emplace(currKey);
2974 __COUT_WARN__ <<
"Trying to ignore error, and not populating "
2979 colSpeedup = (colSpeedup + 1) % noc;
2998 __COUTTV__(fillWithLooseColumnMatching_);
2999 __COUTTV__(sourceColumnNames_.size());
3002 if(!fillWithLooseColumnMatching_ && sourceColumnMissingCount_ > 0)
3004 __COUTV__(sourceColumnMissingCount_);
3005 __SS__ <<
"Can not ignore errors because not every column was found in the "
3007 <<
". Please see the details below:\n\n"
3012 if(sourceColumnNames_.size() ==
3015 for(
unsigned int i = 0; i < getNumberOfColumns(); ++i)
3016 sourceColumnNames_.emplace(getColumnsInfo()[i].getStorageName());
3025 std::string TableView::getMismatchColumnInfo(
void)
const
3027 const std::set<std::string>& srcColNames = getSourceColumnNames();
3028 std::set<std::string> destColNames = getColumnStorageNames();
3030 __SS__ <<
"The source column size was found to be " << srcColNames.size()
3031 <<
", and the current number of columns for this table is "
3032 << getNumberOfColumns() <<
". This resulted in a count of "
3033 << getSourceColumnMismatch() <<
" source column mismatches, and a count of "
3034 << getSourceColumnMissing() <<
" table entries missing in "
3035 << getNumberOfRows() <<
" row(s) of data." << __E__;
3038 << srcColNames.size()
3039 <<
" Source column names in ALPHABETICAL order were as follows:\n";
3041 std::string preIndexStr =
"";
3042 for(
auto& srcColName : srcColNames)
3044 if(destColNames.find(srcColName) == destColNames.end())
3045 ss <<
"\n\t*** " << preIndexStr << index <<
". " << srcColName <<
" ***";
3047 ss <<
"\n\t" << preIndexStr << index <<
". " << srcColName;
3060 << destColNames.size()
3061 <<
" Current table column names in ALPHABETICAL order are as follows:\n";
3064 for(
auto& destColName : destColNames)
3066 if(srcColNames.find(destColName) == srcColNames.end())
3067 ss <<
"\n\t*** " << preIndexStr << index <<
". " << destColName <<
" ***";
3069 ss <<
"\n\t" << preIndexStr << index <<
". " << destColName;
3084 bool TableView::isURIEncodedCommentTheSame(
const std::string& comment)
const
3087 return comment_ == compareStr;
3132 const int& dataOffset ,
3133 const std::string& author ,
3134 const char rowDelimter ,
3135 const char colDelimter )
3137 int row = dataOffset;
3139 std::string currentValue =
"";
3140 bool insideQuotes =
false;
3141 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3142 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3144 for(
size_t i = 0; i < data.size(); ++i)
3147 const char nextChar = (i + 1 < data.size() ? data[i + 1] :
' ');
3151 if(insideQuotes && nextChar ==
'"')
3154 currentValue +=
'"';
3160 insideQuotes = !insideQuotes;
3163 else if(c == rowDelimter && !insideQuotes)
3165 if(col == 0 && row >= (
int)getNumberOfRows())
3171 else if((c == colDelimter || c ==
'\r') && !insideQuotes)
3181 __COUT__ <<
"First row detected as column names." << __E__;
3189 setValue(time(0), row, timestampCol);
3213 __COUT__ <<
"First row detected as column names." << __E__;
3221 setValue(time(0), row, timestampCol);
3260 const int& dataOffset,
3261 const std::string& author)
3269 int j = data.find(
',', i);
3270 int k = data.find(
';', i);
3272 bool rowWasModified;
3273 unsigned int countRowsModified = 0;
3274 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3275 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3278 while(k != (
int)(std::string::npos))
3280 rowWasModified =
false;
3281 if(r >= (
int)getNumberOfRows())
3285 rowWasModified =
true;
3288 while(j < k && j != (
int)(std::string::npos))
3293 if(c >= (
int)getNumberOfColumns() - 2)
3296 j = data.find(
',', i);
3302 rowWasModified =
true;
3305 j = data.find(
',', i);
3310 if(author !=
"" && rowWasModified)
3312 __COUTT__ <<
"Row=" << (int)r <<
" was modified!" << __E__;
3314 setValue(time(0), r, timestampCol);
3318 ++countRowsModified;
3324 j = data.find(
',', i);
3325 k = data.find(
';', i);
3329 while(r < (
int)getNumberOfRows())
3332 __COUT__ <<
"Row deleted: " << (int)r << __E__;
3333 ++countRowsModified;
3336 __COUT_INFO__ <<
"countRowsModified=" << countRowsModified << __E__;
3338 if(!countRowsModified)
3343 bool match = getColumnStorageNames().size() == getSourceColumnNames().size();
3346 for(
auto& destColName : getColumnStorageNames())
3347 if(getSourceColumnNames().find(destColName) ==
3348 getSourceColumnNames().end())
3350 __COUT__ <<
"Found column name mismach for '" << destColName
3351 <<
"'... So allowing same data!" << __E__;
3360 __SS__ <<
"No rows were modified! No reason to fill a view with same content."
3362 __COUT__ <<
"\n" << ss.str();
3372 sourceColumnNames_.clear();
3373 for(
unsigned int i = 0; i < getNumberOfColumns(); ++i)
3374 sourceColumnNames_.emplace(getColumnsInfo()[i].getStorageName());
3396 const unsigned int& r,
3397 const unsigned int& c,
3398 const std::string& author)
3400 if(!(c < columnsInfo_.size() && r < getNumberOfRows()))
3402 __SS__ <<
"Invalid row (" << (int)r <<
") col (" << (
int)c <<
") requested!"
3403 <<
"Number of Rows = " << getNumberOfRows()
3404 <<
"Number of Columns = " << columnsInfo_.size() << __E__;
3410 std::string originalValueStr =
3434 theDataView_[r][c] = valueStr;
3438 else if(columnsInfo_[c].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
3450 setValue(time_t(strtol(valueStr.c_str(), 0, 10)), r, c);
3453 theDataView_[r][c] = valueStr;
3455 bool rowWasModified =
3456 (originalValueStr !=
3460 if(author !=
"" && rowWasModified)
3462 __COUT__ <<
"Row=" << (int)r <<
" was modified!" << __E__;
3463 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3464 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3466 setValue(time(0), r, timestampCol);
3469 return rowWasModified;
3473 void TableView::resizeDataView(
unsigned int nRows,
unsigned int nCols)
3477 theDataView_.resize(nRows, std::vector<std::string>(nCols));
3488 const std::string& author,
3490 incrementUniqueData ,
3493 const std::string& baseNameAutoUID ,
3494 unsigned int rowToAdd ,
3495 std::string childLinkIndex ,
3496 std::string groupId )
3499 if(rowToAdd == (
unsigned int)-1)
3500 rowToAdd = getNumberOfRows();
3502 theDataView_.resize(getNumberOfRows() + 1,
3503 std::vector<std::string>(getNumberOfColumns()));
3506 for(
unsigned int r = getNumberOfRows() - 2; r >= rowToAdd; --r)
3508 if(r == (
unsigned int)-1)
3510 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
3511 theDataView_[r + 1][col] = theDataView_[r][col];
3514 std::vector<std::string> defaultRowValues = getDefaultRowValues();
3517 std::string tmpString, baseString;
3521 std::string numString;
3526 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
3534 if(incrementUniqueData &&
3535 (col ==
getColUID() || columnsInfo_[col].isChildLinkGroupID() ||
3536 (getNumberOfRows() > 1 &&
3537 (columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_UNIQUE_DATA ||
3538 columnsInfo_[col].getType() ==
3539 TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA))))
3541 if(col ==
getColUID() || columnsInfo_[col].isChildLinkGroupID())
3543 rowToAdd, col, baseNameAutoUID );
3553 theDataView_[rowToAdd][col] = defaultRowValues[col];
3558 __COUT__ <<
"Row=" << rowToAdd <<
" was created!" << __E__;
3560 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3561 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3562 setValue(author, rowToAdd, authorCol);
3563 setValue(time(0), rowToAdd, timestampCol);
3574 if(r >= (
int)getNumberOfRows())
3577 __SS__ <<
"Row " << (int)r
3578 <<
" is out of bounds (Row Count = " << getNumberOfRows()
3579 <<
") and can not be deleted." << __E__;
3583 theDataView_.erase(theDataView_.begin() + r);
3603 const unsigned int& c,
3605 std::pair<unsigned int /*link col*/, unsigned int /*link id col*/>& linkPair)
const
3607 if(!(c < columnsInfo_.size()))
3609 __SS__ <<
"Invalid col (" << (int)c <<
") requested for child link!" << __E__;
3617 if((isGroup = columnsInfo_[c].isChildLinkGroupID()) ||
3618 columnsInfo_[c].isChildLinkUID())
3622 linkPair.second = c;
3623 std::string index = columnsInfo_[c].getChildLinkIndex();
3628 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
3634 else if(columnsInfo_[col].isChildLink() &&
3635 index == columnsInfo_[col].getChildLinkIndex())
3640 linkPair.first = col;
3646 __SS__ <<
"\tIn view: " << tableName_
3647 <<
", Can't find complete child link for column name "
3648 << columnsInfo_[c].getName() << __E__;
3652 if(!columnsInfo_[c].isChildLink())
3657 std::string index = columnsInfo_[c].getChildLinkIndex();
3662 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
3679 if(((columnsInfo_[col].isChildLinkUID() && !(isGroup =
false)) ||
3680 (columnsInfo_[col].isChildLinkGroupID() && (isGroup =
true))) &&
3681 index == columnsInfo_[col].getChildLinkIndex())
3686 linkPair.second = col;
3692 __SS__ <<
"\tIn view: " << tableName_
3693 <<
", Can't find complete child link id for column name "
3694 << columnsInfo_[c].getName() << __E__;
static std::string convertToCaps(std::string &str, bool isConfigName=false)
static const std::string DATATYPE_NUMBER
static const std::string TYPE_UID
NOTE: Do NOT put '-' in static const TYPEs because it will mess up javascript handling in the web gui...
unsigned int findRow(unsigned int col, const T &value, unsigned int offsetRow=0, bool doNotThrow=false) const
< in included .icc source
std::string getEscapedValueAsString(unsigned int row, unsigned int col, bool convertEnvironmentVariables=true, bool quotesToDoubleQuotes=false) const
bool isEntryInGroup(const unsigned int &row, const std::string &childLinkIndex, const std::string &groupNeedle) const
void setValueAsString(const std::string &value, unsigned int row, unsigned int col)
std::vector< std::vector< unsigned int > > getGroupRowsByPriority(const unsigned int groupIdCol, const std::string &groupID, bool onlyStatusTrue=false) const
T validateValueForColumn(const std::string &value, unsigned int col, bool doConvertEnvironmentVariables=true) const
< in included .icc source
TableView(const std::string &tableName)
= "");
unsigned int getColStatus(void) const
unsigned int getLinkGroupIDColumn(const std::string &childLinkIndex) const
bool removeRowFromGroup(const unsigned int &row, const unsigned int &col, const std::string &groupID, bool deleteRowIfNoGroupLeft=false)
unsigned int findColByType(const std::string &type, unsigned int startingCol=0) const
bool getChildLink(const unsigned int &col, bool &isGroup, std::pair< unsigned int, unsigned int > &linkPair) const
void addRowToGroup(const unsigned int &row, const unsigned int &col, const std::string &groupID)
, const std::string& colDefault);
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="")
unsigned int getColPriority(void) const
const std::string & setUniqueColumnValue(unsigned int row, unsigned int col, std::string baseValueAsString="", bool doMathAppendStrategy=false, std::string childLinkIndex="", std::string groupId="")
std::string getValueAsString(unsigned int row, unsigned int col, bool convertEnvironmentVariables=true) const
std::vector< unsigned int > getGroupRows(const unsigned int groupIdCol, const std::string &groupID, bool onlyStatusTrue=false, bool orderedByPriority=false) const
const std::string & getCustomStorageData(void) const
Getters.
std::set< std::string > getSetOfGroupIDs(const std::string &childLinkIndex, unsigned int row=-1) const
void getValue(T &value, unsigned int row, unsigned int col, bool doConvertEnvironmentVariables=true) const
< in included .icc source
unsigned int getDataColumnSize(void) const
getDataColumnSize
int fillFromJSON(const std::string &json)
unsigned int getColUID(void) const
bool setURIEncodedValue(const std::string &value, const unsigned int &row, const unsigned int &col, const std::string &author="")
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="")
unsigned int findCol(const std::string &name) const
void setValue(const T &value, unsigned int row, unsigned int col)
< in included .icc source
void setURIEncodedComment(const std::string &uriComment)
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="")
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
void setCustomStorageData(const std::string &storageData)
defines used also by OtsConfigurationWizardSupervisor
static std::string getTimestampString(const std::string &linuxTimeInSeconds)
static const std::string & trim(std::string &s)
static void getSetFromString(const std::string &inputString, std::set< std::string > &setToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
static std::string setToString(const std::set< T > &setToReturn, const std::string &delimeter=", ")
setToString ~
static std::string convertEnvironmentVariables(const std::string &data)
static std::string demangleTypeName(const char *name)
static std::string restoreJSONStringEntities(const std::string &str)
static bool wildCardMatch(const std::string &needle, const std::string &haystack, unsigned int *priorityIndex=0)
static std::string decodeURIComponent(const std::string &data)
static std::string stackTrace(void)
static bool getNumber(const std::string &s, T &retValue)