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" || theDataView_[row][col] ==
"on" ||
641 theDataView_[row][col] ==
"On" || theDataView_[row][col] ==
"ON")
642 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_ON;
643 else if(theDataView_[row][col] ==
"0" ||
644 theDataView_[row][col] ==
"off" ||
645 theDataView_[row][col] ==
"Off" ||
646 theDataView_[row][col] ==
"OFF")
647 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_OFF;
650 __SS__ << getTableName() <<
" Error:\t the value '"
651 << theDataView_[row][col] <<
"' in column "
652 << columnsInfo_[col].getName()
653 <<
" is not a valid Type (On/Off) std::string. Possible "
654 "values are 1, on, On, ON, 0, off, Off, OFF."
659 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_TRUE_FALSE)
660 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
662 if(theDataView_[row][col] ==
"1" ||
663 theDataView_[row][col] ==
"true" ||
664 theDataView_[row][col] ==
"True" ||
665 theDataView_[row][col] ==
"TRUE")
666 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_TRUE;
667 else if(theDataView_[row][col] ==
"0" ||
668 theDataView_[row][col] ==
"false" ||
669 theDataView_[row][col] ==
"False" ||
670 theDataView_[row][col] ==
"FALSE")
671 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_FALSE;
674 __SS__ << getTableName() <<
" Error:\t the value '"
675 << theDataView_[row][col] <<
"' in column "
676 << columnsInfo_[col].getName()
677 <<
" is not a valid Type (True/False) std::string. "
678 "Possible values are 1, true, True, TRUE, 0, false, "
684 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_YES_NO)
685 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
687 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"yes" ||
688 theDataView_[row][col] ==
"Yes" || theDataView_[row][col] ==
"YES")
689 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_YES;
690 else if(theDataView_[row][col] ==
"0" ||
691 theDataView_[row][col] ==
"no" ||
692 theDataView_[row][col] ==
"No" ||
693 theDataView_[row][col] ==
"NO")
694 theDataView_[row][col] = TableViewColumnInfo::TYPE_VALUE_NO;
697 __SS__ << getTableName() <<
" Error:\t the value '"
698 << theDataView_[row][col] <<
"' in column "
699 << columnsInfo_[col].getName()
700 <<
" is not a valid Type (Yes/No) std::string. Possible "
701 "values are 1, yes, Yes, YES, 0, no, No, NO."
706 else if(columnsInfo_[col].isGroupID())
708 colLinkGroupIDs_[columnsInfo_[col].getChildLinkIndex()] =
711 groupIdIndexes.emplace(columnsInfo_[col].getChildLinkIndex());
712 ++groupIdIndexesCount;
714 else if(columnsInfo_[col].isChildLink())
717 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
718 if(theDataView_[row][col] ==
"NoLink" ||
719 theDataView_[row][col] ==
"No_Link" ||
720 theDataView_[row][col] ==
"NOLINK" ||
721 theDataView_[row][col] ==
"NO_LINK" ||
722 theDataView_[row][col] ==
"Nolink" ||
723 theDataView_[row][col] ==
"nolink" ||
724 theDataView_[row][col] ==
"noLink")
725 theDataView_[row][col] =
726 TableViewColumnInfo::DATATYPE_LINK_DEFAULT;
729 childLinkIndexes.emplace(columnsInfo_[col].getChildLinkIndex());
730 ++childLinkIndexesCount;
733 if(columnsInfo_[col].getDataType() !=
734 TableViewColumnInfo::DATATYPE_STRING)
736 __SS__ << getTableName() <<
" Error:\t"
737 <<
"Column " << col <<
" with name '"
738 << columnsInfo_[col].getName()
739 <<
"' is a Child Link column and has an illegal data type of '"
740 << columnsInfo_[col].getDataType()
741 <<
"'. The data type for Child Link columns must be "
742 << TableViewColumnInfo::DATATYPE_STRING << __E__;
749 else if(columnsInfo_[col].isChildLinkUID() ||
750 columnsInfo_[col].isChildLinkGroupID())
753 childLinkIdLabels.emplace(columnsInfo_[col].getChildLinkIndex());
754 ++childLinkIdLabelsCount;
757 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
758 if(theDataView_[row][col] ==
"")
759 theDataView_[row][col] = rowDefaults[col];
766 if(columnsInfo_[col].isNumberDataType())
768 std::string minimumValueString = columnsInfo_[col].getMinValue();
769 std::string maximumValueString = columnsInfo_[col].getMaxValue();
770 double minimumValue, maximumValue, valueFromTable;
771 bool minExists =
false, maxExists =
false;
773 if(!minimumValueString.empty())
780 __SS__ <<
"Inavlid user spec'd min value '" << minimumValueString
781 <<
"' which is not a valid number. The minimum value must "
782 "be a number (environment variables and math "
783 "operations are allowed)."
789 if(!maximumValueString.empty())
796 __SS__ <<
"Inavlid user spec'd max value '" << maximumValueString
797 <<
"' which is not a valid number. The maximum value must "
798 "be a number (environment variables and math "
799 "operations are allowed)."
805 if(minExists && maxExists && minimumValue > maximumValue)
807 __SS__ <<
"Minimum value is greater than maximum, check table editor "
813 if(minExists || maxExists)
814 for(
unsigned int row = 0; row < getNumberOfRows(); ++row)
817 if(minExists && valueFromTable < minimumValue)
820 <<
"The value '" << valueFromTable <<
"'("
823 <<
") at [row,col]=[" << row <<
"," << col
824 <<
"] is outside the established limits: "
826 <<
" is lower than the specified minimum " << minimumValue
830 if(maxExists && valueFromTable > maximumValue)
833 <<
"This value '" << valueFromTable <<
"'("
836 <<
") at [row,col]=[" << row <<
"," << col
837 <<
"] is outside the established limits: "
839 <<
" is greater than the specified maximum "
840 << maximumValue <<
"." << __E__;
848 if(groupIdIndexes.size() != groupIdIndexesCount)
850 __SS__ << (
"GroupId Labels are not unique!") <<
"There are "
851 << groupIdIndexesCount <<
" GroupId Labels and the unique count is "
852 << groupIdIndexes.size() << __E__;
855 if(childLinkIndexes.size() != childLinkIndexesCount)
857 __SS__ << (
"Child Link Labels are not unique!") <<
"There are "
858 << childLinkIndexesCount
859 <<
" Child Link Labels and the unique count is "
860 << childLinkIndexes.size() << __E__;
863 if(childLinkIdLabels.size() != childLinkIdLabelsCount)
865 __SS__ << (
"Child Link ID Labels are not unique!") <<
"There are "
866 << childLinkIdLabelsCount
867 <<
" Child Link ID Labels and the unique count is "
868 << childLinkIdLabels.size() << __E__;
874 __COUT__ <<
"Error occured in TableView::init() for version=" << version_
888 bool doConvertEnvironmentVariables)
const
890 if(!(row < getNumberOfRows() && col < theDataView_[row].size()))
892 __SS__ <<
"Invalid row col requested " << row <<
"," << col <<
" vs "
893 << getNumberOfRows() <<
"," << columnsInfo_.size() <<
"/"
894 << theDataView_[row].size() << __E__;
899 theDataView_[row][col], col, doConvertEnvironmentVariables);
909 bool doConvertEnvironmentVariables)
const
911 if(col >= columnsInfo_.size())
913 __SS__ <<
"Invalid col requested" << __E__;
917 if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA &&
919 value == columnsInfo_[col].getDefaultDefaultValue(columnsInfo_[col].getType(),
920 columnsInfo_[col].getDataType()))
924 std::vector<std::string> choices = columnsInfo_[col].getDataChoices();
927 bool skipOne = (choices.size() && choices[0].find(
"arbitraryBool=") == 0);
928 size_t index = (skipOne ? 1 : 0);
929 if(choices.size() > index)
931 return doConvertEnvironmentVariables
937 if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_STRING)
938 return doConvertEnvironmentVariables
941 else if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
944 doConvertEnvironmentVariables
950 __SS__ <<
"\tUnrecognized column data type: " << columnsInfo_[col].getDataType()
951 <<
" in configuration " << tableName_
952 <<
" at column=" << columnsInfo_[col].getName()
953 <<
" for getValue with type '"
968 bool doConvertEnvironmentVariables)
const
970 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
972 __SS__ << (
"Invalid row col requested") << __E__;
976 __COUTS__(30) << columnsInfo_[col].getType() <<
" " << col << __E__;
978 if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_ON_OFF)
980 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"on" ||
981 theDataView_[row][col] ==
"On" || theDataView_[row][col] ==
"ON")
982 return TableViewColumnInfo::TYPE_VALUE_ON;
984 return TableViewColumnInfo::TYPE_VALUE_OFF;
986 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_TRUE_FALSE)
988 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"true" ||
989 theDataView_[row][col] ==
"True" || theDataView_[row][col] ==
"TRUE")
990 return TableViewColumnInfo::TYPE_VALUE_TRUE;
992 return TableViewColumnInfo::TYPE_VALUE_FALSE;
994 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_YES_NO)
996 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"yes" ||
997 theDataView_[row][col] ==
"Yes" || theDataView_[row][col] ==
"YES")
998 return TableViewColumnInfo::TYPE_VALUE_YES;
1000 return TableViewColumnInfo::TYPE_VALUE_NO;
1003 return doConvertEnvironmentVariables
1005 : theDataView_[row][col];
1018 bool doConvertEnvironmentVariables ,
1019 bool quotesToDoubleQuotes )
const
1021 std::string val =
getValueAsString(row, col, doConvertEnvironmentVariables);
1022 std::string retVal =
"";
1023 retVal.reserve(val.size());
1024 for(
unsigned int i = 0; i < val.size(); ++i)
1028 else if(val[i] ==
'\t')
1030 else if(val[i] ==
'\r')
1037 if(quotesToDoubleQuotes && val[i] ==
'"')
1039 else if(!quotesToDoubleQuotes && val[i] ==
'"')
1052 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1054 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1058 if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_STRING)
1059 theDataView_[row][col] = value;
1063 __SS__ <<
"\tUnrecognized column data type: " << columnsInfo_[col].getDataType()
1064 <<
" in configuration " << tableName_
1065 <<
" at column=" << columnsInfo_[col].getName()
1066 <<
" for setValue with type '"
1075 setValue(std::string(value), row, col);
1085 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1087 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1091 theDataView_[row][col] = value;
1104 std::string baseValueAsString ,
1105 bool doMathAppendStrategy ,
1106 std::string childLinkIndex ,
1107 std::string groupId )
1109 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1111 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1115 bool isUniqueGroupCol =
1116 (columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA);
1117 unsigned int childLinkIndexCol = -1;
1118 if(isUniqueGroupCol)
1120 __COUTVS__(12, childLinkIndex);
1121 __COUTVS__(12, groupId);
1123 __COUTVS__(12, childLinkIndexCol);
1126 __COUTT__ <<
"Current '" << columnsInfo_[col].getName() <<
"' "
1127 << (isUniqueGroupCol ?
"(Unique in Group) " :
"")
1128 <<
"unique data entry is data[" << row <<
"][" << col <<
"] = '"
1129 << theDataView_[row][col] <<
"' baseValueAsString = " << baseValueAsString
1130 <<
" doMathAppendStrategy = " << doMathAppendStrategy << __E__;
1132 bool firstConflict =
true;
1133 int maxUniqueData = -1;
1134 std::string tmpString =
"";
1137 std::string numString;
1138 std::string opString;
1144 for(
unsigned int r = 0; r < getNumberOfRows(); ++r)
1149 if(isUniqueGroupCol && !isEntryInGroupCol(r, childLinkIndexCol, groupId))
1155 tmpString = theDataView_[r][col];
1157 __COUTS__(3) <<
"row[" << r <<
"] tmpString " << tmpString << __E__;
1159 for(index = tmpString.length() - 1; index < tmpString.length(); --index)
1161 __COUTS__(3) << index <<
" tmpString[index] " << tmpString[index] << __E__;
1162 if(!(tmpString[index] >=
'0' && tmpString[index] <=
'9'))
1167 __COUTS__(3) <<
"index " << index <<
" foundAny " << foundAny << __E__;
1169 if(tmpString.length() && foundAny)
1172 numString = tmpString.substr(index + 1);
1175 tmpString = tmpString.substr(0, index + 1);
1177 if(doMathAppendStrategy && tmpString.size())
1181 for(index = tmpString.length() - 1; index < tmpString.length(); --index)
1184 << index <<
" tmpString[index] " << tmpString[index] << __E__;
1185 if(!(tmpString[index] ==
'+' || tmpString[index] ==
' '))
1193 opString = tmpString.substr(index + 1);
1196 tmpString = tmpString.substr(0, index + 1);
1200 __COUTS__(3) << tmpString <<
" vs " << baseValueAsString << __E__;
1202 if(baseValueAsString !=
"" && tmpString != baseValueAsString)
1205 __COUTS__(3) <<
"Found unique data base string '" << tmpString
1206 <<
"' and number string '" << numString <<
"' in last record '"
1207 << theDataView_[r][col] <<
"'" << __E__;
1212 if(baseValueAsString.size() &&
1213 baseValueAsString[baseValueAsString.size() - 1] >=
'0' &&
1214 baseValueAsString[baseValueAsString.size() - 1] <=
'9')
1215 baseValueAsString +=
'_';
1217 firstConflict =
false;
1221 sscanf(numString.c_str(),
"%u", &index);
1223 if((
int)index > maxUniqueData)
1225 maxUniqueData = (int)index;
1227 if(baseValueAsString ==
"")
1228 baseValueAsString = tmpString;
1231 else if(maxUniqueData < 0 &&
1232 (baseValueAsString ==
"" || tmpString == baseValueAsString))
1237 if(baseValueAsString.size() &&
1238 baseValueAsString[baseValueAsString.size() - 1] >=
'0' &&
1239 baseValueAsString[baseValueAsString.size() - 1] <=
'9')
1240 baseValueAsString +=
'_';
1242 firstConflict =
false;
1249 __COUTVS__(12, maxUniqueData);
1250 __COUTVS__(12, baseValueAsString);
1252 if(maxUniqueData == -1)
1254 if(baseValueAsString !=
"")
1255 theDataView_[row][col] = baseValueAsString;
1257 theDataView_[row][col] = columnsInfo_[col].getDefaultValue();
1263 char indexString[1000];
1264 sprintf(indexString,
"%u", maxUniqueData);
1266 __COUTVS__(12, indexString);
1267 __COUTVS__(12, baseValueAsString);
1269 if(doMathAppendStrategy)
1270 theDataView_[row][col] = baseValueAsString +
" + " + indexString;
1272 theDataView_[row][col] = baseValueAsString + indexString;
1275 __COUTT__ <<
"New unique data entry is data[" << row <<
"][" << col <<
"] = '"
1276 << theDataView_[row][col] <<
"'" << __E__;
1280 std::stringstream ss;
1282 __COUT_MULTI__(13, ss.str());
1285 return theDataView_[row][col];
1291 unsigned int TableView::initColUID(
void)
1293 if(colUID_ != INVALID)
1298 if(colUID_ == INVALID)
1300 __COUT__ <<
"Column Types: " << __E__;
1301 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1302 std::cout << columnsInfo_[col].getType() <<
"() "
1303 << columnsInfo_[col].getName() << __E__;
1304 __SS__ <<
"\tMissing UID Column in table named '" << tableName_ <<
"'" << __E__;
1315 if(colUID_ != INVALID)
1318 __COUT__ <<
"Column Types: " << __E__;
1319 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1320 std::cout << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1323 __SS__ << (
"Missing UID Column in config named " + tableName_ +
1324 ". (Possibly TableView was just not initialized?" +
1325 " This is the const call so can not alter class members)")
1336 unsigned int TableView::initColStatus(
void)
1338 if(colStatus_ != INVALID)
1342 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1343 if(columnsInfo_[col].getName() == TableViewColumnInfo::COL_NAME_STATUS)
1348 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1349 if(columnsInfo_[col].getName() == TableViewColumnInfo::COL_NAME_ENABLED)
1357 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_STATUS
1358 <<
"' or '" << TableViewColumnInfo::COL_NAME_ENABLED <<
"' in table '"
1359 << tableName_ <<
".'" << __E__;
1360 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1361 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1362 ss << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1372 unsigned int TableView::initColPriority(
void)
1374 if(colPriority_ != INVALID)
1375 return colPriority_;
1379 findCol(
"*" + TableViewColumnInfo::COL_NAME_PRIORITY);
1380 if(colPriority_ == INVALID)
1382 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_PRIORITY
1383 <<
"' in table '" << tableName_ <<
".'" << __E__;
1384 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1385 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1386 ss << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1391 return colPriority_;
1400 if(colStatus_ != INVALID)
1403 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_STATUS
1404 <<
"' or '" << TableViewColumnInfo::COL_NAME_ENABLED <<
"' in table '"
1405 << tableName_ <<
".'"
1406 <<
" (The Status column is identified when the TableView is initialized)"
1409 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1410 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1411 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1418 __COUT_WARN__ << ss.str();
1431 if(colPriority_ != INVALID)
1432 return colPriority_;
1434 __SS__ <<
"Priority column was not found... \nColumn Types: " << __E__;
1436 ss <<
"Missing " << TableViewColumnInfo::COL_NAME_PRIORITY
1437 <<
" Column in table named '" << tableName_
1438 <<
".' (The Priority column is identified when the TableView is initialized)"
1442 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1443 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1444 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1457 const unsigned int& col,
1458 const std::string& groupID)
1461 if(isEntryInGroupCol(row, col, groupID))
1463 __SS__ <<
"GroupID (" << groupID <<
") added to row (" << row
1464 <<
" is already present!" << __E__;
1473 if(getDataView()[row][col] ==
"" ||
1474 getDataView()[row][col] == getDefaultRowValues()[col])
1477 setValue(groupID +
" | " + getDataView()[row][col], row, col);
1489 const unsigned int groupIdCol,
1490 const std::string& groupID,
1491 bool onlyStatusTrue ,
1492 bool orderedByPriority )
const
1494 std::vector<
unsigned int > retVector;
1495 std::vector<std::vector<
unsigned int >> groupRowVectors =
1496 getGroupRowsInVectors(groupIdCol, groupID, onlyStatusTrue, orderedByPriority);
1498 for(
const auto& groupRowVector : groupRowVectors)
1499 for(
const auto& groupRow : groupRowVector)
1500 retVector.push_back(groupRow);
1512 const unsigned int groupIdCol,
1513 const std::string& groupID,
1514 bool onlyStatusTrue )
const
1516 return getGroupRowsInVectors(
1517 groupIdCol, groupID, onlyStatusTrue,
true );
1528 std::vector<std::vector<
unsigned int >> TableView::getGroupRowsInVectors(
1529 const unsigned int groupIdCol,
1530 const std::string& groupID,
1531 bool onlyStatusTrue,
1532 bool orderedByPriority)
const
1534 std::map<uint64_t , std::vector<
unsigned int >>
1536 std::vector<std::vector<
unsigned int >> retVector;
1537 uint64_t tmpPriority;
1540 if(!(orderedByPriority &&
1541 colPriority_ != INVALID))
1542 retVector.push_back(std::vector<unsigned int /*group row*/>());
1544 for(
unsigned int r = 0; r < getNumberOfRows(); ++r)
1545 if(groupID ==
"" || groupID ==
"*" || groupIdCol == INVALID ||
1546 isEntryInGroupCol(r, groupIdCol, groupID))
1549 if(onlyStatusTrue && colStatus_ != INVALID)
1551 getValue(tmpStatus, r, colStatus_);
1557 if(orderedByPriority && colPriority_ != INVALID)
1559 getValue(tmpPriority, r, colPriority_);
1561 mapByPriority[tmpPriority ? tmpPriority : 100].push_back(r);
1564 retVector[0].push_back(r);
1567 if(orderedByPriority && colPriority_ != INVALID)
1571 for(
const auto& priorityChildRowVector : mapByPriority)
1573 retVector.push_back(std::vector<unsigned int /*group row*/>());
1574 for(
const auto& priorityChildRow : priorityChildRowVector.second)
1575 retVector[retVector.size() - 1].push_back(priorityChildRow);
1578 __COUT__ <<
"Returning priority children list." << __E__;
1591 const unsigned int& col,
1592 const std::string& groupNeedle,
1593 bool deleteRowIfNoGroupLeft)
1595 __COUT__ <<
"groupNeedle " << groupNeedle << __E__;
1596 std::set<std::string> groupIDList;
1597 if(!isEntryInGroupCol(row, col, groupNeedle, &groupIDList))
1599 __SS__ <<
"GroupID (" << groupNeedle <<
") removed from row (" << row
1600 <<
") was already removed!" << __E__;
1609 std::string newValue =
"";
1610 unsigned int cnt = 0;
1611 for(
const auto& groupID : groupIDList)
1614 if(groupID == groupNeedle)
1619 newValue += groupID;
1622 bool wasDeleted =
false;
1623 if(deleteRowIfNoGroupLeft && newValue ==
"")
1625 __COUT__ <<
"Delete row since it no longer part of any group." << __E__;
1644 const std::string& childLinkIndex,
1645 const std::string& groupNeedle)
const
1649 return isEntryInGroupCol(r, c, groupNeedle);
1661 bool TableView::isEntryInGroupCol(
const unsigned int& r,
1662 const unsigned int& c,
1663 const std::string& groupNeedle,
1664 std::set<std::string>* groupIDList)
const
1666 if(r >= getNumberOfRows() || c >= getNumberOfColumns())
1668 __SS__ <<
"Invalid row/col requested!" << __E__;
1680 for(; j < theDataView_[r][c].size(); ++j)
1681 if((theDataView_[r][c][j] ==
' ' ||
1682 theDataView_[r][c][j] ==
'|') &&
1685 else if((theDataView_[r][c][j] ==
1687 theDataView_[r][c][j] ==
'|') &&
1691 groupIDList->emplace(theDataView_[r][c].substr(i, j - i));
1695 if(groupNeedle == theDataView_[r][c].substr(i, j - i))
1708 groupIDList->emplace(theDataView_[r][c].substr(i, j - i));
1712 if(groupNeedle == theDataView_[r][c].substr(i, j - i))
1728 unsigned int r)
const
1733 unsigned int r)
const
1737 std::set<std::string> retSet;
1742 if(r != (
unsigned int)-1)
1744 if(r >= getNumberOfRows())
1746 __SS__ <<
"Invalid row requested!" << __E__;
1778 for(r = 0; r < getNumberOfRows(); ++r)
1830 if(!childLinkIndex.size())
1832 __SS__ <<
"Empty childLinkIndex string parameter!" << __E__;
1837 const char* needleChildLinkIndex = &childLinkIndex[0];
1841 size_t spacePos = childLinkIndex.find(
' ');
1842 if(spacePos != std::string::npos &&
1843 spacePos + 1 < childLinkIndex.size())
1846 needleChildLinkIndex = &childLinkIndex[spacePos + 1];
1849 std::map<std::string, unsigned int>::const_iterator it =
1850 colLinkGroupIDs_.find(needleChildLinkIndex);
1852 colLinkGroupIDs_.end())
1856 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1859 if(columnsInfo_[col].isChildLink() || columnsInfo_[col].isChildLinkUID() ||
1860 columnsInfo_[col].isChildLinkGroupID() || columnsInfo_[col].isGroupID())
1862 if(needleChildLinkIndex == columnsInfo_[col].getChildLinkIndex())
1868 <<
"Error! Incompatible table for this group link! Table '" << tableName_
1869 <<
"' is missing a GroupID column with data type '"
1870 << TableViewColumnInfo::TYPE_START_GROUP_ID <<
"-" << needleChildLinkIndex
1872 <<
"Note: you can separate the child GroupID column data type from "
1873 <<
"the parent GroupLink column data type; this is accomplished by using a space "
1874 <<
"character at the parent level - the string after the space will be treated "
1876 <<
"child GroupID column data type." << __E__;
1877 ss <<
"Existing Column GroupIDs: " << __E__;
1878 for(
auto& groupIdColPair : colLinkGroupIDs_)
1879 ss <<
"\t" << groupIdColPair.first <<
" : col-" << groupIdColPair.second << __E__;
1881 ss <<
"Existing Column Types: " << __E__;
1882 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1883 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1893 const std::string& value,
1894 unsigned int offsetRow,
1895 bool doNotThrow )
const
1897 for(
unsigned int row = offsetRow; row < theDataView_.size(); ++row)
1899 if(theDataView_[row][col] == value)
1903 return TableView::INVALID;
1905 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find value=" << value
1906 <<
" in column named " << columnsInfo_[col].getName()
1907 <<
" with type=" << columnsInfo_[col].getType() << __E__ << __E__
1918 const std::string& value,
1919 const std::string& groupId,
1920 const std::string& childLinkIndex,
1921 unsigned int offsetRow)
const
1924 for(
unsigned int row = offsetRow; row < theDataView_.size(); ++row)
1926 if(theDataView_[row][col] == value && isEntryInGroupCol(row, groupIdCol, groupId))
1930 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find in group the value=" << value
1931 <<
" in column named '" << columnsInfo_[col].getName()
1932 <<
"' with type=" << columnsInfo_[col].getType() <<
" and GroupID: '"
1933 << groupId <<
"' in column '" << groupIdCol
1934 <<
"' with GroupID child link index '" << childLinkIndex <<
"'" << __E__;
1945 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1947 columnsInfo_[col].getName() ))
1950 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find column named '" << wildCardName
1952 ss <<
"Existing columns:\n";
1953 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1954 ss <<
"\t" << columnsInfo_[col].getName() <<
"\n";
1967 unsigned int startingCol)
const
1969 for(
unsigned int col = startingCol; col < columnsInfo_.size(); ++col)
1971 __COUTS__(40) << columnsInfo_[col].getType() << __E__;
1972 if(columnsInfo_[col].getType() == type)
1986 if(!getNumberOfRows())
1987 return getNumberOfColumns();
1988 return theDataView_[0].size();
1992 std::set<std::string> TableView::getColumnNames(
void)
const
1994 std::set<std::string> retSet;
1995 for(
auto& colInfo : columnsInfo_)
1996 retSet.emplace(colInfo.getName());
2001 std::map<std::string,
unsigned int > TableView::getColumnNamesMap(
void)
const
2003 std::map<std::string,
unsigned int > retMap;
2005 for(
auto& colInfo : columnsInfo_)
2006 retMap.emplace(std::make_pair(colInfo.getName(), c++));
2011 std::set<std::string> TableView::getColumnStorageNames(
void)
const
2013 std::set<std::string> retSet;
2014 for(
auto& colInfo : columnsInfo_)
2015 retSet.emplace(colInfo.getStorageName());
2020 const std::vector<std::string>& TableView::initRowDefaults(
void)
2022 std::vector<std::string>& retVec = rowDefaultValues_;
2026 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
2033 if(columnsInfo_[col].isChildLink())
2035 const std::vector<std::string>& theDataChoices =
2036 columnsInfo_[col].getDataChoices();
2039 if(!theDataChoices.size() ||
2040 theDataChoices[0] ==
"arbitraryBool=1")
2041 retVec.push_back(columnsInfo_[col].getDefaultValue());
2045 (theDataChoices.size() && theDataChoices[0] ==
"arbitraryBool=0");
2050 bool foundDefault =
false;
2052 for(
const auto& choice : theDataChoices)
2053 if(skipOne && !hasSkipped)
2058 else if(choice == columnsInfo_[col].getDefaultValue())
2060 foundDefault =
true;
2065 if(!foundDefault && theDataChoices.size() > (skipOne ? 1 : 0))
2066 retVec.push_back(theDataChoices[(skipOne ? 1 : 0)]);
2068 retVec.push_back(columnsInfo_[col].getDefaultValue());
2072 retVec.push_back(columnsInfo_[col].getDefaultValue());
2077 return rowDefaultValues_;
2083 if(column >= columnsInfo_.size())
2085 __SS__ <<
"\nCan't find column " << column
2086 <<
"\n\n\n\nThe column info is likely missing due to incomplete "
2087 "Configuration View filling.\n\n"
2092 return columnsInfo_[column];
2104 void TableView::setAuthor(
const std::string& author) { author_ = author; }
2107 void TableView::setCreationTime(time_t t) { creationTime_ = t; }
2110 void TableView::setLastAccessTime(time_t t) { lastAccessTime_ = t; }
2113 void TableView::setLooseColumnMatching(
bool setValue)
2115 fillWithLooseColumnMatching_ =
setValue;
2119 void TableView::doGetSourceRawData(
bool setValue) { getSourceRawData_ =
setValue; }
2122 void TableView::reset(
void)
2127 columnsInfo_.clear();
2128 theDataView_.clear();
2132 void TableView::print(std::ostream& out )
const
2134 out <<
"============================================================================="
2137 out <<
"Print: " << tableName_ <<
" Version: " << version_ <<
" Comment: " << comment_
2138 <<
" Author: " << author_ <<
" Creation Time: " << ctime(&creationTime_) << __E__;
2139 out <<
"\t\tNumber of Cols " << getNumberOfColumns() << __E__;
2140 out <<
"\t\tNumber of Rows " << getNumberOfRows() << __E__;
2142 out <<
"Columns:\t";
2143 for(
int i = 0; i < (int)columnsInfo_.size(); ++i)
2144 out << i <<
":" << columnsInfo_[i].getName() <<
":"
2145 << columnsInfo_[i].getStorageName() <<
":" << columnsInfo_[i].getType() <<
":"
2146 << columnsInfo_[i].getDataType() <<
"\t ";
2149 out <<
"Rows:" << __E__;
2152 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2154 out << (int)r <<
":\t";
2155 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2157 out << (int)c <<
":";
2160 if(columnsInfo_[c].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA)
2162 int choiceIndex = -1;
2163 std::vector<std::string> choices = columnsInfo_[c].getDataChoices();
2166 if(val == columnsInfo_[c].getDefaultValue())
2170 for(
int i = 0; i < (int)choices.size(); ++i)
2171 if(val == choices[i])
2172 choiceIndex = i + 1;
2175 out <<
"ChoiceIndex=" << choiceIndex <<
":";
2178 out << theDataView_[r][c];
2198 void TableView::printJSON(std::ostream& out )
const
2201 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2203 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2205 __COUTS__(32) <<
" '" << tableName_ <<
"' vs " << tmpCachePrepend <<
" or "
2206 << tmpJsonDocPrepend << __E__;
2208 if(tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend ||
2209 tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend)
2217 out <<
"\"NAME\" : \"" << tableName_ <<
"\",\n";
2221 out <<
"\"COMMENT\" : ";
2227 for(
unsigned int i = 0; i < val.size(); ++i)
2231 else if(val[i] ==
'\t')
2233 else if(val[i] ==
'\r')
2238 if(val[i] ==
'"' || val[i] ==
'\\')
2245 out <<
"\"AUTHOR\" : \"" << author_ <<
"\",\n";
2246 out <<
"\"CREATION_TIME\" : " << creationTime_ <<
",\n";
2251 out <<
"\"COL_TYPES\" : {\n";
2252 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2254 out <<
"\t\t\"" << columnsInfo_[c].getStorageName() <<
"\" : ";
2255 out <<
"\"" << columnsInfo_[c].getDataType() <<
"\"";
2256 if(c + 1 < (
int)getNumberOfColumns())
2262 out <<
"\"DATA_SET\" : [\n";
2264 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2267 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2269 out <<
"\t\t\"" << columnsInfo_[c].getStorageName() <<
"\" : ";
2274 if(c + 1 < (
int)getNumberOfColumns())
2279 if(r + 1 < (
int)getNumberOfRows())
2289 void TableView::printCSV(std::ostream& out ,
2290 const std::string& valueDelimeter ,
2291 const std::string& recordDelimeter ,
2292 bool includeColumnNames )
const
2295 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2297 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2299 __COUTS__(32) <<
" '" << tableName_ <<
"' vs " << tmpCachePrepend <<
" or "
2300 << tmpJsonDocPrepend << __E__;
2302 if(tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend ||
2303 tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend)
2305 __SS__ <<
"Cannot convert custom storage data to CSV!" << __E__;
2312 for(
int c = 0; includeColumnNames && c < (int)getNumberOfColumns(); ++c)
2315 out << valueDelimeter;
2316 out <<
"\"" << columnsInfo_[c].getStorageName() <<
"\"";
2318 if(includeColumnNames)
2319 out << recordDelimeter;
2321 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2323 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2326 out << valueDelimeter;
2331 out << recordDelimeter;
2347 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2349 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2353 if(tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend ||
2354 tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend)
2356 __COUTS__(3) <<
"Special JSON doc: " << json << __E__;
2363 bool rawData = getSourceRawData_;
2364 if(getSourceRawData_)
2366 __COUTV__(getSourceRawData_);
2367 getSourceRawData_ =
false;
2368 sourceRawData_ =
"";
2371 std::map<std::string ,
unsigned int > keyEntryCountMap;
2372 std::vector<std::string> keys;
2373 keys.push_back(
"NAME");
2374 keys.push_back(
"COMMENT");
2375 keys.push_back(
"AUTHOR");
2376 keys.push_back(
"CREATION_TIME");
2378 keys.push_back(
"DATA_SET");
2382 CV_JSON_FILL_COMMENT,
2383 CV_JSON_FILL_AUTHOR,
2384 CV_JSON_FILL_CREATION_TIME,
2386 CV_JSON_FILL_DATA_SET
2391 __COUTV__(tableName_);
2392 __COUTTV__(getNumberOfRows());
2396 sourceColumnMismatchCount_ = 0;
2397 sourceColumnMissingCount_ = 0;
2398 sourceColumnNames_.clear();
2399 unsigned int colFoundCount = 0;
2401 unsigned int row = -1;
2402 unsigned int colSpeedup = 0;
2403 unsigned int startString, startNumber = 0, endNumber = -1;
2404 unsigned int bracketCount = 0;
2405 unsigned int sqBracketCount = 0;
2410 bool keyIsMatch, keyIsComment;
2411 unsigned int keyIsMatchIndex, keyIsMatchStorageIndex, keyIsMatchCommentIndex;
2412 const std::string COMMENT_ALT_KEY =
"COMMENT";
2414 std::string extractedString =
"", currKey =
"", currVal =
"";
2415 unsigned int currDepth = 0;
2417 std::vector<std::string> jsonPath;
2418 std::vector<char> jsonPathType;
2419 char lastPopType =
'_';
2421 unsigned int matchedKey = -1;
2422 unsigned int lastCol = -1;
2425 for(; i < json.size(); ++i)
2430 if(i - 1 < json.size() &&
2431 json[i - 1] ==
'\\')
2434 inQuotes = !inQuotes;
2440 json.substr(startString + 1, i - startString - 1));
2449 if(jsonPathType[jsonPathType.size() - 1] !=
'{' ||
2452 __COUT__ <<
"Invalid ':' position" << __E__;
2457 jsonPathType.push_back(
'K');
2458 jsonPath.push_back(extractedString);
2477 if(lastPopType ==
'{')
2480 if(jsonPathType[jsonPathType.size() - 1] ==
'K')
2483 jsonPath.pop_back();
2484 jsonPathType.pop_back();
2490 currVal = extractedString;
2493 if(endNumber == (
unsigned int)-1 ||
2494 endNumber <= startNumber)
2497 if(endNumber <= startNumber)
2500 currVal = json.substr(startNumber + 1, endNumber - startNumber - 1);
2503 currDepth = bracketCount;
2505 if(jsonPathType[jsonPathType.size() - 1] ==
'K')
2507 currKey = jsonPath[jsonPathType.size() - 1];
2512 jsonPath.pop_back();
2513 jsonPathType.pop_back();
2515 else if(jsonPathType[jsonPathType.size() - 1] ==
2519 for(
unsigned int k = jsonPathType.size() - 2; k < jsonPathType.size();
2521 if(jsonPathType[k] ==
'K')
2523 currKey = jsonPath[k];
2528 __COUT__ <<
"Invalid array position" << __E__;
2537 __COUT__ <<
"Invalid ',' position" << __E__;
2548 jsonPathType.push_back(
'{');
2549 jsonPath.push_back(
"{");
2562 if(lastPopType !=
'{' &&
2563 jsonPathType[jsonPathType.size() - 1] ==
'K')
2565 currDepth = bracketCount;
2566 currKey = jsonPath[jsonPathType.size() - 1];
2568 currVal = extractedString;
2571 if(endNumber == (
unsigned int)-1 ||
2572 endNumber <= startNumber)
2575 if(endNumber <= startNumber)
2579 json.substr(startNumber + 1, endNumber - startNumber - 1);
2583 jsonPath.pop_back();
2584 jsonPathType.pop_back();
2587 if(jsonPathType[jsonPathType.size() - 1] !=
'{')
2589 __COUT__ <<
"Invalid '}' position" << __E__;
2593 jsonPath.pop_back();
2594 jsonPathType.pop_back();
2600 jsonPathType.push_back(
'[');
2601 jsonPath.push_back(
"[");
2610 if(jsonPathType[jsonPathType.size() - 1] !=
'[')
2612 __COUT__ <<
"Invalid ']' position" << __E__;
2616 currDepth = bracketCount;
2620 currVal = extractedString;
2623 if(endNumber == (
unsigned int)-1 ||
2624 endNumber <= startNumber)
2627 if(endNumber <= startNumber)
2630 currVal = json.substr(startNumber + 1, endNumber - startNumber - 1);
2635 for(
unsigned int k = jsonPathType.size() - 2; k < jsonPathType.size(); --k)
2636 if(jsonPathType[k] ==
'K')
2638 currKey = jsonPath[k];
2643 __COUT__ <<
"Invalid array position" << __E__;
2648 if(jsonPathType[jsonPathType.size() - 1] !=
'[')
2650 __COUT__ <<
"Invalid ']' position" << __E__;
2654 jsonPath.pop_back();
2655 jsonPathType.pop_back();
2664 if(startNumber != (
unsigned int)-1 && endNumber == (
unsigned int)-1)
2678 std::cout << i <<
":\t" << json[i] <<
" - ";
2688 std::cout <<
"ExtKey=";
2689 for(
unsigned int k = 0; k < jsonPath.size(); ++k)
2690 std::cout << jsonPath[k] <<
"/";
2692 std::cout << lastPopType <<
" ";
2693 std::cout << bracketCount <<
" ";
2694 std::cout << sqBracketCount <<
" ";
2695 std::cout << inQuotes <<
" ";
2696 std::cout << newValue <<
"-";
2697 std::cout << currKey <<
"-{" << currDepth <<
"}:";
2698 std::cout << currVal <<
" ";
2699 std::cout << startNumber <<
"-";
2700 std::cout << endNumber <<
" ";
2702 __COUTTV__(fillWithLooseColumnMatching_);
2703 __COUTTV__(getNumberOfRows());
2712 for(
unsigned int k = 0; k < keys.size(); ++k)
2713 if((currDepth == 1 && keys[k] == currKey) ||
2714 (currDepth > 1 && keys[k] == jsonPath[1]))
2723 if(matchedKey == CV_JSON_FILL_COMMENT)
2724 setComment(currVal);
2725 else if(matchedKey == CV_JSON_FILL_AUTHOR)
2727 else if(matchedKey == CV_JSON_FILL_CREATION_TIME)
2728 setCreationTime(strtol(currVal.c_str(), 0, 10));
2730 else if(currDepth == 2)
2733 sourceRawData_ += StringMacros::encodeURIComponent(currKey) +
"," +
2734 StringMacros::encodeURIComponent(currVal) +
",";
2735 sourceColumnNames_.emplace(currKey);
2738 else if(matchedKey != (
unsigned int)-1)
2741 __COUTT__ <<
"New Data for:: key[" << matchedKey <<
"]-"
2742 << keys[matchedKey] <<
"\n";
2746 case CV_JSON_FILL_NAME:
2752 if(currVal != getTableName() &&
2754 "TABLE_GROUP_METADATA")
2755 __COUT_WARN__ <<
"JSON-fill Table name mismatch: " << currVal
2756 <<
" vs " << getTableName() << __E__;
2759 case CV_JSON_FILL_COMMENT:
2761 setComment(currVal);
2763 case CV_JSON_FILL_AUTHOR:
2767 case CV_JSON_FILL_CREATION_TIME:
2769 setCreationTime(strtol(currVal.c_str(), 0, 10));
2774 case CV_JSON_FILL_DATA_SET:
2776 __COUTT__ <<
"CV_JSON_FILL_DATA_SET New Data for::" << matchedKey
2777 <<
"]-" << keys[matchedKey] <<
"/" << currDepth
2778 <<
".../" << currKey <<
"\n";
2784 unsigned int col, ccnt = 0;
2785 unsigned int noc = getNumberOfColumns();
2786 for(; ccnt < noc; ++ccnt)
2792 if(fillWithLooseColumnMatching_)
2805 if(getNumberOfRows() == 1)
2806 sourceColumnNames_.emplace(currKey);
2810 if(row >= getNumberOfRows())
2812 __SS__ <<
"Invalid row"
2814 std::cout << ss.str();
2819 theDataView_[row][col] =
2827 col = (ccnt + colSpeedup) % noc;
2833 keyIsComment =
true;
2834 for(keyIsMatchIndex = 0,
2835 keyIsMatchStorageIndex = 0,
2836 keyIsMatchCommentIndex = 0;
2837 keyIsMatchIndex < currKey.size();
2840 if(columnsInfo_[col]
2841 .getStorageName()[keyIsMatchStorageIndex] ==
2843 ++keyIsMatchStorageIndex;
2845 if(currKey[keyIsMatchIndex] ==
'_')
2849 if(keyIsMatchStorageIndex >=
2850 columnsInfo_[col].getStorageName().size() ||
2851 currKey[keyIsMatchIndex] !=
2853 .getStorageName()[keyIsMatchStorageIndex])
2863 keyIsMatchCommentIndex < COMMENT_ALT_KEY.size())
2865 if(currKey[keyIsMatchIndex] !=
2866 COMMENT_ALT_KEY[keyIsMatchCommentIndex])
2869 keyIsComment =
false;
2873 ++keyIsMatchStorageIndex;
2878 __COUTTV__(keyIsMatch);
2879 __COUTTV__(keyIsComment);
2880 __COUTTV__(currKey);
2881 __COUTTV__(columnsInfo_[col].getStorageName());
2882 __COUTTV__(getNumberOfRows());
2885 if(keyIsMatch || keyIsComment)
2888 if(keyEntryCountMap.find(currKey) ==
2889 keyEntryCountMap.end())
2890 keyEntryCountMap[currKey] =
2893 ++keyEntryCountMap.at(currKey);
2896 if(keyEntryCountMap.size() == 1 ||
2897 (keyEntryCountMap.at(currKey) &&
2898 keyEntryCountMap.at(currKey) >
2901 if(getNumberOfRows())
2902 sourceColumnMissingCount_ +=
2903 getNumberOfColumns() - colFoundCount;
2911 if(getNumberOfRows() == 1)
2912 sourceColumnNames_.emplace(currKey);
2916 if(row >= getNumberOfRows())
2918 __SS__ <<
"Invalid row"
2920 __COUT__ <<
"\n" << ss.str();
2925 theDataView_[row][col] = currVal;
2931 if(ccnt >= getNumberOfColumns())
2934 <<
"Invalid column in JSON source data: " << currKey
2935 <<
" not found in column names of table named "
2936 << getTableName() <<
"."
2941 ++sourceColumnMismatchCount_;
2942 if(getNumberOfRows() ==
2944 sourceColumnNames_.emplace(currKey);
2947 __COUT_WARN__ <<
"Trying to ignore error, and not populating "
2952 colSpeedup = (colSpeedup + 1) % noc;
2971 __COUTTV__(fillWithLooseColumnMatching_);
2972 __COUTTV__(sourceColumnNames_.size());
2975 if(!fillWithLooseColumnMatching_ && sourceColumnMissingCount_ > 0)
2977 __COUTV__(sourceColumnMissingCount_);
2978 __SS__ <<
"Can not ignore errors because not every column was found in the "
2980 <<
". Please see the details below:\n\n"
2985 if(sourceColumnNames_.size() ==
2988 for(
unsigned int i = 0; i < getNumberOfColumns(); ++i)
2989 sourceColumnNames_.emplace(getColumnsInfo()[i].getStorageName());
2998 std::string TableView::getMismatchColumnInfo(
void)
const
3000 const std::set<std::string>& srcColNames = getSourceColumnNames();
3001 std::set<std::string> destColNames = getColumnStorageNames();
3003 __SS__ <<
"The source column size was found to be " << srcColNames.size()
3004 <<
", and the current number of columns for this table is "
3005 << getNumberOfColumns() <<
". This resulted in a count of "
3006 << getSourceColumnMismatch() <<
" source column mismatches, and a count of "
3007 << getSourceColumnMissing() <<
" table entries missing in "
3008 << getNumberOfRows() <<
" row(s) of data." << __E__;
3011 << srcColNames.size()
3012 <<
" Source column names in ALPHABETICAL order were as follows:\n";
3014 std::string preIndexStr =
"";
3015 for(
auto& srcColName : srcColNames)
3017 if(destColNames.find(srcColName) == destColNames.end())
3018 ss <<
"\n\t*** " << preIndexStr << index <<
". " << srcColName <<
" ***";
3020 ss <<
"\n\t" << preIndexStr << index <<
". " << srcColName;
3033 << destColNames.size()
3034 <<
" Current table column names in ALPHABETICAL order are as follows:\n";
3037 for(
auto& destColName : destColNames)
3039 if(srcColNames.find(destColName) == srcColNames.end())
3040 ss <<
"\n\t*** " << preIndexStr << index <<
". " << destColName <<
" ***";
3042 ss <<
"\n\t" << preIndexStr << index <<
". " << destColName;
3057 bool TableView::isURIEncodedCommentTheSame(
const std::string& comment)
const
3060 return comment_ == compareStr;
3105 const int& dataOffset ,
3106 const std::string& author ,
3107 const char rowDelimter ,
3108 const char colDelimter )
3110 int row = dataOffset;
3112 std::string currentValue =
"";
3113 bool insideQuotes =
false;
3114 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3115 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3117 for(
size_t i = 0; i < data.size(); ++i)
3120 const char nextChar = (i + 1 < data.size() ? data[i + 1] :
' ');
3124 if(insideQuotes && nextChar ==
'"')
3127 currentValue +=
'"';
3133 insideQuotes = !insideQuotes;
3136 else if(c == rowDelimter && !insideQuotes)
3138 if(col == 0 && row >= (
int)getNumberOfRows())
3144 else if((c == colDelimter || c ==
'\r') && !insideQuotes)
3154 __COUT__ <<
"First row detected as column names." << __E__;
3162 setValue(time(0), row, timestampCol);
3186 __COUT__ <<
"First row detected as column names." << __E__;
3194 setValue(time(0), row, timestampCol);
3233 const int& dataOffset,
3234 const std::string& author)
3242 int j = data.find(
',', i);
3243 int k = data.find(
';', i);
3245 bool rowWasModified;
3246 unsigned int countRowsModified = 0;
3247 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3248 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3251 while(k != (
int)(std::string::npos))
3253 rowWasModified =
false;
3254 if(r >= (
int)getNumberOfRows())
3258 rowWasModified =
true;
3261 while(j < k && j != (
int)(std::string::npos))
3266 if(c >= (
int)getNumberOfColumns() - 2)
3269 j = data.find(
',', i);
3275 rowWasModified =
true;
3278 j = data.find(
',', i);
3283 if(author !=
"" && rowWasModified)
3285 __COUTT__ <<
"Row=" << (int)r <<
" was modified!" << __E__;
3287 setValue(time(0), r, timestampCol);
3291 ++countRowsModified;
3297 j = data.find(
',', i);
3298 k = data.find(
';', i);
3302 while(r < (
int)getNumberOfRows())
3305 __COUT__ <<
"Row deleted: " << (int)r << __E__;
3306 ++countRowsModified;
3309 __COUT_INFO__ <<
"countRowsModified=" << countRowsModified << __E__;
3311 if(!countRowsModified)
3316 bool match = getColumnStorageNames().size() == getSourceColumnNames().size();
3319 for(
auto& destColName : getColumnStorageNames())
3320 if(getSourceColumnNames().find(destColName) ==
3321 getSourceColumnNames().end())
3323 __COUT__ <<
"Found column name mismach for '" << destColName
3324 <<
"'... So allowing same data!" << __E__;
3333 __SS__ <<
"No rows were modified! No reason to fill a view with same content."
3335 __COUT__ <<
"\n" << ss.str();
3345 sourceColumnNames_.clear();
3346 for(
unsigned int i = 0; i < getNumberOfColumns(); ++i)
3347 sourceColumnNames_.emplace(getColumnsInfo()[i].getStorageName());
3369 const unsigned int& r,
3370 const unsigned int& c,
3371 const std::string& author)
3373 if(!(c < columnsInfo_.size() && r < getNumberOfRows()))
3375 __SS__ <<
"Invalid row (" << (int)r <<
") col (" << (
int)c <<
") requested!"
3376 <<
"Number of Rows = " << getNumberOfRows()
3377 <<
"Number of Columns = " << columnsInfo_.size() << __E__;
3383 std::string originalValueStr =
3407 theDataView_[r][c] = valueStr;
3411 else if(columnsInfo_[c].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
3423 setValue(time_t(strtol(valueStr.c_str(), 0, 10)), r, c);
3426 theDataView_[r][c] = valueStr;
3428 bool rowWasModified =
3429 (originalValueStr !=
3433 if(author !=
"" && rowWasModified)
3435 __COUT__ <<
"Row=" << (int)r <<
" was modified!" << __E__;
3436 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3437 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3439 setValue(time(0), r, timestampCol);
3442 return rowWasModified;
3446 void TableView::resizeDataView(
unsigned int nRows,
unsigned int nCols)
3450 theDataView_.resize(nRows, std::vector<std::string>(nCols));
3461 const std::string& author,
3463 incrementUniqueData ,
3466 const std::string& baseNameAutoUID ,
3467 unsigned int rowToAdd ,
3468 std::string childLinkIndex ,
3469 std::string groupId )
3472 if(rowToAdd == (
unsigned int)-1)
3473 rowToAdd = getNumberOfRows();
3475 theDataView_.resize(getNumberOfRows() + 1,
3476 std::vector<std::string>(getNumberOfColumns()));
3479 for(
unsigned int r = getNumberOfRows() - 2; r >= rowToAdd; --r)
3481 if(r == (
unsigned int)-1)
3483 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
3484 theDataView_[r + 1][col] = theDataView_[r][col];
3487 std::vector<std::string> defaultRowValues = getDefaultRowValues();
3490 std::string tmpString, baseString;
3494 std::string numString;
3499 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
3507 if(incrementUniqueData &&
3508 (col ==
getColUID() || columnsInfo_[col].isChildLinkGroupID() ||
3509 (getNumberOfRows() > 1 &&
3510 (columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_UNIQUE_DATA ||
3511 columnsInfo_[col].getType() ==
3512 TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA))))
3514 if(col ==
getColUID() || columnsInfo_[col].isChildLinkGroupID())
3516 rowToAdd, col, baseNameAutoUID );
3526 theDataView_[rowToAdd][col] = defaultRowValues[col];
3531 __COUT__ <<
"Row=" << rowToAdd <<
" was created!" << __E__;
3533 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3534 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3535 setValue(author, rowToAdd, authorCol);
3536 setValue(time(0), rowToAdd, timestampCol);
3547 if(r >= (
int)getNumberOfRows())
3550 __SS__ <<
"Row " << (int)r
3551 <<
" is out of bounds (Row Count = " << getNumberOfRows()
3552 <<
") and can not be deleted." << __E__;
3556 theDataView_.erase(theDataView_.begin() + r);
3576 const unsigned int& c,
3578 std::pair<unsigned int /*link col*/, unsigned int /*link id col*/>& linkPair)
const
3580 if(!(c < columnsInfo_.size()))
3582 __SS__ <<
"Invalid col (" << (int)c <<
") requested for child link!" << __E__;
3590 if((isGroup = columnsInfo_[c].isChildLinkGroupID()) ||
3591 columnsInfo_[c].isChildLinkUID())
3595 linkPair.second = c;
3596 std::string index = columnsInfo_[c].getChildLinkIndex();
3601 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
3607 else if(columnsInfo_[col].isChildLink() &&
3608 index == columnsInfo_[col].getChildLinkIndex())
3613 linkPair.first = col;
3619 __SS__ <<
"\tIn view: " << tableName_
3620 <<
", Can't find complete child link for column name "
3621 << columnsInfo_[c].getName() << __E__;
3625 if(!columnsInfo_[c].isChildLink())
3630 std::string index = columnsInfo_[c].getChildLinkIndex();
3635 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
3652 if(((columnsInfo_[col].isChildLinkUID() && !(isGroup =
false)) ||
3653 (columnsInfo_[col].isChildLinkGroupID() && (isGroup =
true))) &&
3654 index == columnsInfo_[col].getChildLinkIndex())
3659 linkPair.second = col;
3665 __SS__ <<
"\tIn view: " << tableName_
3666 <<
", Can't find complete child link id for column name "
3667 << 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 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)