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
959 __SS__ <<
"\tUnrecognized column data type: " << columnsInfo_[col].getDataType()
960 <<
" in configuration " << tableName_
961 <<
" at column=" << columnsInfo_[col].getName()
962 <<
" for getValue with type '"
977 bool doConvertEnvironmentVariables)
const
979 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
981 __SS__ << (
"Invalid row col requested") << __E__;
987 if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_ON_OFF)
989 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"on" ||
990 theDataView_[row][col] ==
"On" || theDataView_[row][col] ==
"ON")
991 return TableViewColumnInfo::TYPE_VALUE_ON;
993 return TableViewColumnInfo::TYPE_VALUE_OFF;
995 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_TRUE_FALSE)
997 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"true" ||
998 theDataView_[row][col] ==
"True" || theDataView_[row][col] ==
"TRUE")
999 return TableViewColumnInfo::TYPE_VALUE_TRUE;
1001 return TableViewColumnInfo::TYPE_VALUE_FALSE;
1003 else if(columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_YES_NO)
1005 if(theDataView_[row][col] ==
"1" || theDataView_[row][col] ==
"yes" ||
1006 theDataView_[row][col] ==
"Yes" || theDataView_[row][col] ==
"YES")
1007 return TableViewColumnInfo::TYPE_VALUE_YES;
1009 return TableViewColumnInfo::TYPE_VALUE_NO;
1013 return doConvertEnvironmentVariables
1015 : theDataView_[row][col];
1027 bool doConvertEnvironmentVariables ,
1028 bool quotesToDoubleQuotes )
const
1030 std::string val =
getValueAsString(row, col, doConvertEnvironmentVariables);
1031 std::string retVal =
"";
1032 retVal.reserve(val.size());
1033 for(
unsigned int i = 0; i < val.size(); ++i)
1037 else if(val[i] ==
'\t')
1039 else if(val[i] ==
'\r')
1046 if(quotesToDoubleQuotes && val[i] ==
'"')
1048 else if(!quotesToDoubleQuotes && val[i] ==
'"')
1061 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1063 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1067 if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_STRING)
1068 theDataView_[row][col] = value;
1072 __SS__ <<
"\tUnrecognized column data type: " << columnsInfo_[col].getDataType()
1073 <<
" in configuration " << tableName_
1074 <<
" at column=" << columnsInfo_[col].getName()
1075 <<
" for setValue with type '"
1084 setValue(std::string(value), row, col);
1094 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1096 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1100 theDataView_[row][col] = value;
1113 std::string baseValueAsString ,
1114 bool doMathAppendStrategy ,
1115 std::string childLinkIndex ,
1116 std::string groupId )
1118 if(!(col < columnsInfo_.size() && row < getNumberOfRows()))
1120 __SS__ <<
"Invalid row (" << row <<
") col (" << col <<
") requested!" << __E__;
1124 bool isUniqueGroupCol =
1125 (columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA);
1126 unsigned int childLinkIndexCol = -1;
1127 if(isUniqueGroupCol)
1129 __COUTVS__(12, childLinkIndex);
1130 __COUTVS__(12, groupId);
1132 __COUTVS__(12, childLinkIndexCol);
1135 __COUTT__ <<
"Current '" << columnsInfo_[col].getName() <<
"' "
1136 << (isUniqueGroupCol ?
"(Unique in Group) " :
"")
1137 <<
"unique data entry is data[" << row <<
"][" << col <<
"] = '"
1138 << theDataView_[row][col] <<
"' baseValueAsString = " << baseValueAsString
1139 <<
" doMathAppendStrategy = " << doMathAppendStrategy << __E__;
1141 bool firstConflict =
true;
1142 int maxUniqueData = -1;
1143 std::string tmpString =
"";
1146 std::string numString;
1147 std::string opString;
1153 for(
unsigned int r = 0; r < getNumberOfRows(); ++r)
1158 if(isUniqueGroupCol && !isEntryInGroupCol(r, childLinkIndexCol, groupId))
1164 tmpString = theDataView_[r][col];
1166 __COUTS__(3) <<
"row[" << r <<
"] tmpString " << tmpString << __E__;
1168 for(index = tmpString.length() - 1; index < tmpString.length(); --index)
1170 __COUTS__(3) << index <<
" tmpString[index] " << tmpString[index] << __E__;
1171 if(!(tmpString[index] >=
'0' && tmpString[index] <=
'9'))
1176 __COUTS__(3) <<
"index " << index <<
" foundAny " << foundAny << __E__;
1178 if(tmpString.length() && foundAny)
1181 numString = tmpString.substr(index + 1);
1184 tmpString = tmpString.substr(0, index + 1);
1186 if(doMathAppendStrategy && tmpString.size())
1190 for(index = tmpString.length() - 1; index < tmpString.length(); --index)
1193 << index <<
" tmpString[index] " << tmpString[index] << __E__;
1194 if(!(tmpString[index] ==
'+' || tmpString[index] ==
' '))
1202 opString = tmpString.substr(index + 1);
1205 tmpString = tmpString.substr(0, index + 1);
1209 __COUTS__(3) << tmpString <<
" vs " << baseValueAsString << __E__;
1211 if(baseValueAsString !=
"" && tmpString != baseValueAsString)
1214 __COUTS__(3) <<
"Found unique data base string '" << tmpString
1215 <<
"' and number string '" << numString <<
"' in last record '"
1216 << theDataView_[r][col] <<
"'" << __E__;
1221 if(baseValueAsString.size() &&
1222 baseValueAsString[baseValueAsString.size() - 1] >=
'0' &&
1223 baseValueAsString[baseValueAsString.size() - 1] <=
'9')
1224 baseValueAsString +=
'_';
1226 firstConflict =
false;
1230 sscanf(numString.c_str(),
"%u", &index);
1232 if((
int)index > maxUniqueData)
1234 maxUniqueData = (int)index;
1236 if(baseValueAsString ==
"")
1237 baseValueAsString = tmpString;
1240 else if(maxUniqueData < 0 &&
1241 (baseValueAsString ==
"" || tmpString == baseValueAsString))
1246 if(baseValueAsString.size() &&
1247 baseValueAsString[baseValueAsString.size() - 1] >=
'0' &&
1248 baseValueAsString[baseValueAsString.size() - 1] <=
'9')
1249 baseValueAsString +=
'_';
1251 firstConflict =
false;
1258 __COUTVS__(12, maxUniqueData);
1259 __COUTVS__(12, baseValueAsString);
1261 if(maxUniqueData == -1)
1263 if(baseValueAsString !=
"")
1264 theDataView_[row][col] = baseValueAsString;
1266 theDataView_[row][col] = columnsInfo_[col].getDefaultValue();
1272 char indexString[1000];
1273 sprintf(indexString,
"%u", maxUniqueData);
1275 __COUTVS__(12, indexString);
1276 __COUTVS__(12, baseValueAsString);
1278 if(doMathAppendStrategy)
1279 theDataView_[row][col] = baseValueAsString +
" + " + indexString;
1281 theDataView_[row][col] = baseValueAsString + indexString;
1284 __COUTT__ <<
"New unique data entry is data[" << row <<
"][" << col <<
"] = '"
1285 << theDataView_[row][col] <<
"'" << __E__;
1289 std::stringstream ss;
1291 __COUT_MULTI__(13, ss.str());
1294 return theDataView_[row][col];
1300 unsigned int TableView::initColUID(
void)
1302 if(colUID_ != INVALID)
1307 if(colUID_ == INVALID)
1309 __COUT__ <<
"Column Types: " << __E__;
1310 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1311 std::cout << columnsInfo_[col].getType() <<
"() "
1312 << columnsInfo_[col].getName() << __E__;
1313 __SS__ <<
"\tMissing UID Column in table named '" << tableName_ <<
"'" << __E__;
1324 if(colUID_ != INVALID)
1327 __COUT__ <<
"Column Types: " << __E__;
1328 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1329 std::cout << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1332 __SS__ << (
"Missing UID Column in config named " + tableName_ +
1333 ". (Possibly TableView was just not initialized?" +
1334 " This is the const call so can not alter class members)")
1345 unsigned int TableView::initColStatus(
void)
1347 if(colStatus_ != INVALID)
1351 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1352 if(columnsInfo_[col].getName() == TableViewColumnInfo::COL_NAME_STATUS)
1357 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1358 if(columnsInfo_[col].getName() == TableViewColumnInfo::COL_NAME_ENABLED)
1366 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_STATUS
1367 <<
"' or '" << TableViewColumnInfo::COL_NAME_ENABLED <<
"' in table '"
1368 << tableName_ <<
".'" << __E__;
1369 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1370 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1371 ss << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1381 unsigned int TableView::initColPriority(
void)
1383 if(colPriority_ != INVALID)
1384 return colPriority_;
1388 findCol(
"*" + TableViewColumnInfo::COL_NAME_PRIORITY);
1389 if(colPriority_ == INVALID)
1391 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_PRIORITY
1392 <<
"' in table '" << tableName_ <<
".'" << __E__;
1393 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1394 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1395 ss << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1400 return colPriority_;
1409 if(colStatus_ != INVALID)
1412 __SS__ <<
"\tMissing column named '" << TableViewColumnInfo::COL_NAME_STATUS
1413 <<
"' or '" << TableViewColumnInfo::COL_NAME_ENABLED <<
"' in table '"
1414 << tableName_ <<
".'"
1415 <<
" (The Status column is identified when the TableView is initialized)"
1418 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1419 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1420 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1427 __COUT_WARN__ << ss.str();
1440 if(colPriority_ != INVALID)
1441 return colPriority_;
1443 __SS__ <<
"Priority column was not found... \nColumn Types: " << __E__;
1445 ss <<
"Missing " << TableViewColumnInfo::COL_NAME_PRIORITY
1446 <<
" Column in table named '" << tableName_
1447 <<
".' (The Priority column is identified when the TableView is initialized)"
1451 ss <<
"\n\nTable '" << tableName_ <<
"' Columns: " << __E__;
1452 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1453 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1466 const unsigned int& col,
1467 const std::string& groupID)
1470 if(isEntryInGroupCol(row, col, groupID))
1472 __SS__ <<
"GroupID (" << groupID <<
") added to row (" << row
1473 <<
" is already present!" << __E__;
1482 if(getDataView()[row][col] ==
"" ||
1483 getDataView()[row][col] == getDefaultRowValues()[col])
1486 setValue(groupID +
" | " + getDataView()[row][col], row, col);
1498 const unsigned int groupIdCol,
1499 const std::string& groupID,
1500 bool onlyStatusTrue ,
1501 bool orderedByPriority )
const
1503 std::vector<
unsigned int > retVector;
1504 std::vector<std::vector<
unsigned int >> groupRowVectors =
1505 getGroupRowsInVectors(groupIdCol, groupID, onlyStatusTrue, orderedByPriority);
1507 for(
const auto& groupRowVector : groupRowVectors)
1508 for(
const auto& groupRow : groupRowVector)
1509 retVector.push_back(groupRow);
1521 const unsigned int groupIdCol,
1522 const std::string& groupID,
1523 bool onlyStatusTrue )
const
1525 return getGroupRowsInVectors(
1526 groupIdCol, groupID, onlyStatusTrue,
true );
1537 std::vector<std::vector<
unsigned int >> TableView::getGroupRowsInVectors(
1538 const unsigned int groupIdCol,
1539 const std::string& groupID,
1540 bool onlyStatusTrue,
1541 bool orderedByPriority)
const
1543 std::map<uint64_t , std::vector<
unsigned int >>
1545 std::vector<std::vector<
unsigned int >> retVector;
1546 uint64_t tmpPriority;
1549 if(!(orderedByPriority &&
1550 colPriority_ != INVALID))
1551 retVector.push_back(std::vector<unsigned int /*group row*/>());
1553 for(
unsigned int r = 0; r < getNumberOfRows(); ++r)
1554 if(groupID ==
"" || groupID ==
"*" || groupIdCol == INVALID ||
1555 isEntryInGroupCol(r, groupIdCol, groupID))
1558 if(onlyStatusTrue && colStatus_ != INVALID)
1560 getValue(tmpStatus, r, colStatus_);
1566 if(orderedByPriority && colPriority_ != INVALID)
1568 getValue(tmpPriority, r, colPriority_);
1570 mapByPriority[tmpPriority ? tmpPriority : 100].push_back(r);
1573 retVector[0].push_back(r);
1576 if(orderedByPriority && colPriority_ != INVALID)
1580 for(
const auto& priorityChildRowVector : mapByPriority)
1582 retVector.push_back(std::vector<unsigned int /*group row*/>());
1583 for(
const auto& priorityChildRow : priorityChildRowVector.second)
1584 retVector[retVector.size() - 1].push_back(priorityChildRow);
1587 __COUT__ <<
"Returning priority children list." << __E__;
1600 const unsigned int& col,
1601 const std::string& groupNeedle,
1602 bool deleteRowIfNoGroupLeft)
1604 __COUT__ <<
"groupNeedle " << groupNeedle << __E__;
1605 std::set<std::string> groupIDList;
1606 if(!isEntryInGroupCol(row, col, groupNeedle, &groupIDList))
1608 __SS__ <<
"GroupID (" << groupNeedle <<
") removed from row (" << row
1609 <<
") was already removed!" << __E__;
1618 std::string newValue =
"";
1619 unsigned int cnt = 0;
1620 for(
const auto& groupID : groupIDList)
1623 if(groupID == groupNeedle)
1628 newValue += groupID;
1631 bool wasDeleted =
false;
1632 if(deleteRowIfNoGroupLeft && newValue ==
"")
1634 __COUT__ <<
"Delete row since it no longer part of any group." << __E__;
1653 const std::string& childLinkIndex,
1654 const std::string& groupNeedle)
const
1658 return isEntryInGroupCol(r, c, groupNeedle);
1670 bool TableView::isEntryInGroupCol(
const unsigned int& r,
1671 const unsigned int& c,
1672 const std::string& groupNeedle,
1673 std::set<std::string>* groupIDList)
const
1675 if(r >= getNumberOfRows() || c >= getNumberOfColumns())
1677 __SS__ <<
"Invalid row/col requested!" << __E__;
1689 for(; j < theDataView_[r][c].size(); ++j)
1690 if((theDataView_[r][c][j] ==
' ' ||
1691 theDataView_[r][c][j] ==
'|') &&
1694 else if((theDataView_[r][c][j] ==
1696 theDataView_[r][c][j] ==
'|') &&
1700 groupIDList->emplace(theDataView_[r][c].substr(i, j - i));
1704 if(groupNeedle == theDataView_[r][c].substr(i, j - i))
1717 groupIDList->emplace(theDataView_[r][c].substr(i, j - i));
1721 if(groupNeedle == theDataView_[r][c].substr(i, j - i))
1737 unsigned int r)
const
1742 unsigned int r)
const
1746 std::set<std::string> retSet;
1751 if(r != (
unsigned int)-1)
1753 if(r >= getNumberOfRows())
1755 __SS__ <<
"Invalid row requested!" << __E__;
1787 for(r = 0; r < getNumberOfRows(); ++r)
1839 if(!childLinkIndex.size())
1841 __SS__ <<
"Empty childLinkIndex string parameter!" << __E__;
1846 const char* needleChildLinkIndex = &childLinkIndex[0];
1850 size_t spacePos = childLinkIndex.find(
' ');
1851 if(spacePos != std::string::npos &&
1852 spacePos + 1 < childLinkIndex.size())
1855 needleChildLinkIndex = &childLinkIndex[spacePos + 1];
1858 std::map<std::string, unsigned int>::const_iterator it =
1859 colLinkGroupIDs_.find(needleChildLinkIndex);
1861 colLinkGroupIDs_.end())
1865 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1868 if(columnsInfo_[col].isChildLink() || columnsInfo_[col].isChildLinkUID() ||
1869 columnsInfo_[col].isChildLinkGroupID() || columnsInfo_[col].isGroupID())
1871 if(needleChildLinkIndex == columnsInfo_[col].getChildLinkIndex())
1877 <<
"Error! Incompatible table for this group link! Table '" << tableName_
1878 <<
"' is missing a GroupID column with data type '"
1879 << TableViewColumnInfo::TYPE_START_GROUP_ID <<
"-" << needleChildLinkIndex
1881 <<
"Note: you can separate the child GroupID column data type from "
1882 <<
"the parent GroupLink column data type; this is accomplished by using a space "
1883 <<
"character at the parent level - the string after the space will be treated "
1885 <<
"child GroupID column data type." << __E__;
1886 ss <<
"Existing Column GroupIDs: " << __E__;
1887 for(
auto& groupIdColPair : colLinkGroupIDs_)
1888 ss <<
"\t" << groupIdColPair.first <<
" : col-" << groupIdColPair.second << __E__;
1890 ss <<
"Existing Column Types: " << __E__;
1891 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1892 ss <<
"\t" << columnsInfo_[col].getType() <<
"() " << columnsInfo_[col].getName()
1902 const std::string& value,
1903 unsigned int offsetRow,
1904 bool doNotThrow )
const
1906 for(
unsigned int row = offsetRow; row < theDataView_.size(); ++row)
1908 if(theDataView_[row][col] == value)
1912 return TableView::INVALID;
1914 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find value=" << value
1915 <<
" in column named " << columnsInfo_[col].getName()
1916 <<
" with type=" << columnsInfo_[col].getType() << __E__ << __E__
1927 const std::string& value,
1928 const std::string& groupId,
1929 const std::string& childLinkIndex,
1930 unsigned int offsetRow)
const
1933 for(
unsigned int row = offsetRow; row < theDataView_.size(); ++row)
1935 if(theDataView_[row][col] == value && isEntryInGroupCol(row, groupIdCol, groupId))
1939 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find in group the value=" << value
1940 <<
" in column named '" << columnsInfo_[col].getName()
1941 <<
"' with type=" << columnsInfo_[col].getType() <<
" and GroupID: '"
1942 << groupId <<
"' in column '" << groupIdCol
1943 <<
"' with GroupID child link index '" << childLinkIndex <<
"'" << __E__;
1954 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1956 columnsInfo_[col].getName() ))
1959 __SS__ <<
"\tIn view: " << tableName_ <<
", Can't find column named '" << wildCardName
1961 ss <<
"Existing columns:\n";
1962 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
1963 ss <<
"\t" << columnsInfo_[col].getName() <<
"\n";
1976 unsigned int startingCol)
const
1978 for(
unsigned int col = startingCol; col < columnsInfo_.size(); ++col)
1980 __COUTS__(40) << columnsInfo_[col].getType() << __E__;
1981 if(columnsInfo_[col].getType() == type)
1995 if(!getNumberOfRows())
1996 return getNumberOfColumns();
1997 return theDataView_[0].size();
2001 std::set<std::string> TableView::getColumnNames(
void)
const
2003 std::set<std::string> retSet;
2004 for(
auto& colInfo : columnsInfo_)
2005 retSet.emplace(colInfo.getName());
2010 std::map<std::string,
unsigned int > TableView::getColumnNamesMap(
void)
const
2012 std::map<std::string,
unsigned int > retMap;
2014 for(
auto& colInfo : columnsInfo_)
2015 retMap.emplace(std::make_pair(colInfo.getName(), c++));
2020 std::set<std::string> TableView::getColumnStorageNames(
void)
const
2022 std::set<std::string> retSet;
2023 for(
auto& colInfo : columnsInfo_)
2024 retSet.emplace(colInfo.getStorageName());
2029 const std::vector<std::string>& TableView::initRowDefaults(
void)
2031 std::vector<std::string>& retVec = rowDefaultValues_;
2035 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
2042 if(columnsInfo_[col].isChildLink())
2044 const std::vector<std::string>& theDataChoices =
2045 columnsInfo_[col].getDataChoices();
2048 if(!theDataChoices.size() ||
2049 theDataChoices[0] ==
"arbitraryBool=1")
2050 retVec.push_back(columnsInfo_[col].getDefaultValue());
2054 (theDataChoices.size() && theDataChoices[0] ==
"arbitraryBool=0");
2059 bool foundDefault =
false;
2061 for(
const auto& choice : theDataChoices)
2062 if(skipOne && !hasSkipped)
2067 else if(choice == columnsInfo_[col].getDefaultValue())
2069 foundDefault =
true;
2074 if(!foundDefault && theDataChoices.size() > (skipOne ? 1 : 0))
2075 retVec.push_back(theDataChoices[(skipOne ? 1 : 0)]);
2077 retVec.push_back(columnsInfo_[col].getDefaultValue());
2081 retVec.push_back(columnsInfo_[col].getDefaultValue());
2086 return rowDefaultValues_;
2092 if(column >= columnsInfo_.size())
2094 __SS__ <<
"\nCan't find column " << column
2095 <<
"\n\n\n\nThe column info is likely missing due to incomplete "
2096 "Configuration View filling.\n\n"
2101 return columnsInfo_[column];
2113 void TableView::setAuthor(
const std::string& author) { author_ = author; }
2116 void TableView::setCreationTime(time_t t) { creationTime_ = t; }
2119 void TableView::setLastAccessTime(time_t t) { lastAccessTime_ = t; }
2122 void TableView::setLooseColumnMatching(
bool setValue)
2124 fillWithLooseColumnMatching_ =
setValue;
2128 void TableView::doGetSourceRawData(
bool setValue) { getSourceRawData_ =
setValue; }
2131 void TableView::reset(
void)
2136 columnsInfo_.clear();
2137 theDataView_.clear();
2141 void TableView::print(std::ostream& out )
const
2143 out <<
"============================================================================="
2146 out <<
"Print: " << tableName_ <<
" Version: " << version_ <<
" Comment: " << comment_
2147 <<
" Author: " << author_ <<
" Creation Time: " << ctime(&creationTime_) << __E__;
2148 out <<
"\t\tNumber of Cols " << getNumberOfColumns() << __E__;
2149 out <<
"\t\tNumber of Rows " << getNumberOfRows() << __E__;
2151 out <<
"Columns:\t";
2152 for(
int i = 0; i < (int)columnsInfo_.size(); ++i)
2153 out << i <<
":" << columnsInfo_[i].getName() <<
":"
2154 << columnsInfo_[i].getStorageName() <<
":" << columnsInfo_[i].getType() <<
":"
2155 << columnsInfo_[i].getDataType() <<
"\t ";
2158 out <<
"Rows:" << __E__;
2161 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2163 out << (int)r <<
":\t";
2164 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2166 out << (int)c <<
":";
2169 if(columnsInfo_[c].getType() == TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA)
2171 int choiceIndex = -1;
2172 std::vector<std::string> choices = columnsInfo_[c].getDataChoices();
2175 if(val == columnsInfo_[c].getDefaultValue())
2179 for(
int i = 0; i < (int)choices.size(); ++i)
2180 if(val == choices[i])
2181 choiceIndex = i + 1;
2184 out <<
"ChoiceIndex=" << choiceIndex <<
":";
2187 out << theDataView_[r][c];
2207 void TableView::printJSON(std::ostream& out )
const
2210 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2212 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2214 __COUTS__(32) <<
" '" << tableName_ <<
"' vs " << tmpCachePrepend <<
" or "
2215 << tmpJsonDocPrepend << __E__;
2217 if(tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend ||
2218 tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend)
2226 out <<
"\"NAME\" : \"" << tableName_ <<
"\",\n";
2230 out <<
"\"COMMENT\" : ";
2236 for(
unsigned int i = 0; i < val.size(); ++i)
2240 else if(val[i] ==
'\t')
2242 else if(val[i] ==
'\r')
2247 if(val[i] ==
'"' || val[i] ==
'\\')
2254 out <<
"\"AUTHOR\" : \"" << author_ <<
"\",\n";
2255 out <<
"\"CREATION_TIME\" : " << creationTime_ <<
",\n";
2260 out <<
"\"COL_TYPES\" : {\n";
2261 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2263 out <<
"\t\t\"" << columnsInfo_[c].getStorageName() <<
"\" : ";
2264 out <<
"\"" << columnsInfo_[c].getDataType() <<
"\"";
2265 if(c + 1 < (
int)getNumberOfColumns())
2271 out <<
"\"DATA_SET\" : [\n";
2273 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2276 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2278 out <<
"\t\t\"" << columnsInfo_[c].getStorageName() <<
"\" : ";
2283 if(c + 1 < (
int)getNumberOfColumns())
2288 if(r + 1 < (
int)getNumberOfRows())
2298 void TableView::printCSV(std::ostream& out ,
2299 const std::string& valueDelimeter ,
2300 const std::string& recordDelimeter ,
2301 bool includeColumnNames )
const
2304 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2306 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2308 __COUTS__(32) <<
" '" << tableName_ <<
"' vs " << tmpCachePrepend <<
" or "
2309 << tmpJsonDocPrepend << __E__;
2311 if(tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend ||
2312 tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend)
2314 __SS__ <<
"Cannot convert custom storage data to CSV!" << __E__;
2321 for(
int c = 0; includeColumnNames && c < (int)getNumberOfColumns(); ++c)
2324 out << valueDelimeter;
2325 out <<
"\"" << columnsInfo_[c].getStorageName() <<
"\"";
2327 if(includeColumnNames)
2328 out << recordDelimeter;
2330 for(
int r = 0; r < (int)getNumberOfRows(); ++r)
2332 for(
int c = 0; c < (int)getNumberOfColumns(); ++c)
2335 out << valueDelimeter;
2340 out << recordDelimeter;
2348 std::string restoreJSONStringEntities(
const std::string& str)
2350 unsigned int sz = str.size();
2354 std::stringstream retStr;
2356 for(; i < sz - 1; ++i)
2388 retStr << str[sz - 1];
2390 return retStr.str();
2404 std::string tmpCachePrepend = TableBase::GROUP_CACHE_PREPEND;
2406 std::string tmpJsonDocPrepend = TableBase::JSON_DOC_PREPEND;
2410 if(tableName_.substr(0, tmpJsonDocPrepend.length()) == tmpJsonDocPrepend ||
2411 tableName_.substr(0, tmpCachePrepend.length()) == tmpCachePrepend)
2413 __COUTS__(3) <<
"Special JSON doc: " << json << __E__;
2420 bool rawData = getSourceRawData_;
2421 if(getSourceRawData_)
2423 __COUTV__(getSourceRawData_);
2424 getSourceRawData_ =
false;
2425 sourceRawData_ =
"";
2428 std::map<std::string ,
unsigned int > keyEntryCountMap;
2429 std::vector<std::string> keys;
2430 keys.push_back(
"NAME");
2431 keys.push_back(
"COMMENT");
2432 keys.push_back(
"AUTHOR");
2433 keys.push_back(
"CREATION_TIME");
2435 keys.push_back(
"DATA_SET");
2439 CV_JSON_FILL_COMMENT,
2440 CV_JSON_FILL_AUTHOR,
2441 CV_JSON_FILL_CREATION_TIME,
2443 CV_JSON_FILL_DATA_SET
2448 __COUTV__(tableName_);
2449 __COUTTV__(getNumberOfRows());
2453 sourceColumnMismatchCount_ = 0;
2454 sourceColumnMissingCount_ = 0;
2455 sourceColumnNames_.clear();
2456 unsigned int colFoundCount = 0;
2458 unsigned int row = -1;
2459 unsigned int colSpeedup = 0;
2460 unsigned int startString, startNumber = 0, endNumber = -1;
2461 unsigned int bracketCount = 0;
2462 unsigned int sqBracketCount = 0;
2467 bool keyIsMatch, keyIsComment;
2468 unsigned int keyIsMatchIndex, keyIsMatchStorageIndex, keyIsMatchCommentIndex;
2469 const std::string COMMENT_ALT_KEY =
"COMMENT";
2471 std::string extractedString =
"", currKey =
"", currVal =
"";
2472 unsigned int currDepth = 0;
2474 std::vector<std::string> jsonPath;
2475 std::vector<char> jsonPathType;
2476 char lastPopType =
'_';
2478 unsigned int matchedKey = -1;
2479 unsigned int lastCol = -1;
2482 for(; i < json.size(); ++i)
2487 if(i - 1 < json.size() &&
2488 json[i - 1] ==
'\\')
2491 inQuotes = !inQuotes;
2496 extractedString = restoreJSONStringEntities(
2497 json.substr(startString + 1, i - startString - 1));
2506 if(jsonPathType[jsonPathType.size() - 1] !=
'{' ||
2509 __COUT__ <<
"Invalid ':' position" << __E__;
2514 jsonPathType.push_back(
'K');
2515 jsonPath.push_back(extractedString);
2534 if(lastPopType ==
'{')
2537 if(jsonPathType[jsonPathType.size() - 1] ==
'K')
2540 jsonPath.pop_back();
2541 jsonPathType.pop_back();
2547 currVal = extractedString;
2550 if(endNumber == (
unsigned int)-1 ||
2551 endNumber <= startNumber)
2554 if(endNumber <= startNumber)
2557 currVal = json.substr(startNumber + 1, endNumber - startNumber - 1);
2560 currDepth = bracketCount;
2562 if(jsonPathType[jsonPathType.size() - 1] ==
'K')
2564 currKey = jsonPath[jsonPathType.size() - 1];
2569 jsonPath.pop_back();
2570 jsonPathType.pop_back();
2572 else if(jsonPathType[jsonPathType.size() - 1] ==
2576 for(
unsigned int k = jsonPathType.size() - 2; k < jsonPathType.size();
2578 if(jsonPathType[k] ==
'K')
2580 currKey = jsonPath[k];
2585 __COUT__ <<
"Invalid array position" << __E__;
2594 __COUT__ <<
"Invalid ',' position" << __E__;
2605 jsonPathType.push_back(
'{');
2606 jsonPath.push_back(
"{");
2619 if(lastPopType !=
'{' &&
2620 jsonPathType[jsonPathType.size() - 1] ==
'K')
2622 currDepth = bracketCount;
2623 currKey = jsonPath[jsonPathType.size() - 1];
2625 currVal = extractedString;
2628 if(endNumber == (
unsigned int)-1 ||
2629 endNumber <= startNumber)
2632 if(endNumber <= startNumber)
2636 json.substr(startNumber + 1, endNumber - startNumber - 1);
2640 jsonPath.pop_back();
2641 jsonPathType.pop_back();
2644 if(jsonPathType[jsonPathType.size() - 1] !=
'{')
2646 __COUT__ <<
"Invalid '}' position" << __E__;
2650 jsonPath.pop_back();
2651 jsonPathType.pop_back();
2657 jsonPathType.push_back(
'[');
2658 jsonPath.push_back(
"[");
2667 if(jsonPathType[jsonPathType.size() - 1] !=
'[')
2669 __COUT__ <<
"Invalid ']' position" << __E__;
2673 currDepth = bracketCount;
2677 currVal = extractedString;
2680 if(endNumber == (
unsigned int)-1 ||
2681 endNumber <= startNumber)
2684 if(endNumber <= startNumber)
2687 currVal = json.substr(startNumber + 1, endNumber - startNumber - 1);
2692 for(
unsigned int k = jsonPathType.size() - 2; k < jsonPathType.size(); --k)
2693 if(jsonPathType[k] ==
'K')
2695 currKey = jsonPath[k];
2700 __COUT__ <<
"Invalid array position" << __E__;
2705 if(jsonPathType[jsonPathType.size() - 1] !=
'[')
2707 __COUT__ <<
"Invalid ']' position" << __E__;
2711 jsonPath.pop_back();
2712 jsonPathType.pop_back();
2721 if(startNumber != (
unsigned int)-1 && endNumber == (
unsigned int)-1)
2735 std::cout << i <<
":\t" << json[i] <<
" - ";
2745 std::cout <<
"ExtKey=";
2746 for(
unsigned int k = 0; k < jsonPath.size(); ++k)
2747 std::cout << jsonPath[k] <<
"/";
2749 std::cout << lastPopType <<
" ";
2750 std::cout << bracketCount <<
" ";
2751 std::cout << sqBracketCount <<
" ";
2752 std::cout << inQuotes <<
" ";
2753 std::cout << newValue <<
"-";
2754 std::cout << currKey <<
"-{" << currDepth <<
"}:";
2755 std::cout << currVal <<
" ";
2756 std::cout << startNumber <<
"-";
2757 std::cout << endNumber <<
" ";
2759 __COUTTV__(fillWithLooseColumnMatching_);
2760 __COUTTV__(getNumberOfRows());
2769 for(
unsigned int k = 0; k < keys.size(); ++k)
2770 if((currDepth == 1 && keys[k] == currKey) ||
2771 (currDepth > 1 && keys[k] == jsonPath[1]))
2780 if(matchedKey == CV_JSON_FILL_COMMENT)
2781 setComment(currVal);
2782 else if(matchedKey == CV_JSON_FILL_AUTHOR)
2784 else if(matchedKey == CV_JSON_FILL_CREATION_TIME)
2785 setCreationTime(strtol(currVal.c_str(), 0, 10));
2787 else if(currDepth == 2)
2790 sourceRawData_ += StringMacros::encodeURIComponent(currKey) +
"," +
2791 StringMacros::encodeURIComponent(currVal) +
",";
2792 sourceColumnNames_.emplace(currKey);
2795 else if(matchedKey != (
unsigned int)-1)
2798 __COUTT__ <<
"New Data for:: key[" << matchedKey <<
"]-"
2799 << keys[matchedKey] <<
"\n";
2803 case CV_JSON_FILL_NAME:
2809 if(currVal != getTableName() &&
2811 "TABLE_GROUP_METADATA")
2812 __COUT_WARN__ <<
"JSON-fill Table name mismatch: " << currVal
2813 <<
" vs " << getTableName() << __E__;
2816 case CV_JSON_FILL_COMMENT:
2818 setComment(currVal);
2820 case CV_JSON_FILL_AUTHOR:
2824 case CV_JSON_FILL_CREATION_TIME:
2826 setCreationTime(strtol(currVal.c_str(), 0, 10));
2831 case CV_JSON_FILL_DATA_SET:
2833 __COUTT__ <<
"CV_JSON_FILL_DATA_SET New Data for::" << matchedKey
2834 <<
"]-" << keys[matchedKey] <<
"/" << currDepth
2835 <<
".../" << currKey <<
"\n";
2841 unsigned int col, ccnt = 0;
2842 unsigned int noc = getNumberOfColumns();
2843 for(; ccnt < noc; ++ccnt)
2849 if(fillWithLooseColumnMatching_)
2862 if(getNumberOfRows() == 1)
2863 sourceColumnNames_.emplace(currKey);
2867 if(row >= getNumberOfRows())
2869 __SS__ <<
"Invalid row"
2871 std::cout << ss.str();
2876 theDataView_[row][col] =
2884 col = (ccnt + colSpeedup) % noc;
2890 keyIsComment =
true;
2891 for(keyIsMatchIndex = 0,
2892 keyIsMatchStorageIndex = 0,
2893 keyIsMatchCommentIndex = 0;
2894 keyIsMatchIndex < currKey.size();
2897 if(columnsInfo_[col]
2898 .getStorageName()[keyIsMatchStorageIndex] ==
2900 ++keyIsMatchStorageIndex;
2902 if(currKey[keyIsMatchIndex] ==
'_')
2906 if(keyIsMatchStorageIndex >=
2907 columnsInfo_[col].getStorageName().size() ||
2908 currKey[keyIsMatchIndex] !=
2910 .getStorageName()[keyIsMatchStorageIndex])
2920 keyIsMatchCommentIndex < COMMENT_ALT_KEY.size())
2922 if(currKey[keyIsMatchIndex] !=
2923 COMMENT_ALT_KEY[keyIsMatchCommentIndex])
2926 keyIsComment =
false;
2930 ++keyIsMatchStorageIndex;
2935 __COUTTV__(keyIsMatch);
2936 __COUTTV__(keyIsComment);
2937 __COUTTV__(currKey);
2938 __COUTTV__(columnsInfo_[col].getStorageName());
2939 __COUTTV__(getNumberOfRows());
2942 if(keyIsMatch || keyIsComment)
2945 if(keyEntryCountMap.find(currKey) ==
2946 keyEntryCountMap.end())
2947 keyEntryCountMap[currKey] =
2950 ++keyEntryCountMap.at(currKey);
2953 if(keyEntryCountMap.size() == 1 ||
2954 (keyEntryCountMap.at(currKey) &&
2955 keyEntryCountMap.at(currKey) >
2958 if(getNumberOfRows())
2959 sourceColumnMissingCount_ +=
2960 getNumberOfColumns() - colFoundCount;
2968 if(getNumberOfRows() == 1)
2969 sourceColumnNames_.emplace(currKey);
2973 if(row >= getNumberOfRows())
2975 __SS__ <<
"Invalid row"
2977 __COUT__ <<
"\n" << ss.str();
2982 theDataView_[row][col] = currVal;
2988 if(ccnt >= getNumberOfColumns())
2991 <<
"Invalid column in JSON source data: " << currKey
2992 <<
" not found in column names of table named "
2993 << getTableName() <<
"."
2998 ++sourceColumnMismatchCount_;
2999 if(getNumberOfRows() ==
3001 sourceColumnNames_.emplace(currKey);
3004 __COUT_WARN__ <<
"Trying to ignore error, and not populating "
3009 colSpeedup = (colSpeedup + 1) % noc;
3028 __COUTTV__(fillWithLooseColumnMatching_);
3029 __COUTTV__(sourceColumnNames_.size());
3032 if(!fillWithLooseColumnMatching_ && sourceColumnMissingCount_ > 0)
3034 __COUTV__(sourceColumnMissingCount_);
3035 __SS__ <<
"Can not ignore errors because not every column was found in the "
3037 <<
". Please see the details below:\n\n"
3042 if(sourceColumnNames_.size() ==
3045 for(
unsigned int i = 0; i < getNumberOfColumns(); ++i)
3046 sourceColumnNames_.emplace(getColumnsInfo()[i].getStorageName());
3055 std::string TableView::getMismatchColumnInfo(
void)
const
3057 const std::set<std::string>& srcColNames = getSourceColumnNames();
3058 std::set<std::string> destColNames = getColumnStorageNames();
3060 __SS__ <<
"The source column size was found to be " << srcColNames.size()
3061 <<
", and the current number of columns for this table is "
3062 << getNumberOfColumns() <<
". This resulted in a count of "
3063 << getSourceColumnMismatch() <<
" source column mismatches, and a count of "
3064 << getSourceColumnMissing() <<
" table entries missing in "
3065 << getNumberOfRows() <<
" row(s) of data." << __E__;
3068 << srcColNames.size()
3069 <<
" Source column names in ALPHABETICAL order were as follows:\n";
3071 std::string preIndexStr =
"";
3072 for(
auto& srcColName : srcColNames)
3074 if(destColNames.find(srcColName) == destColNames.end())
3075 ss <<
"\n\t*** " << preIndexStr << index <<
". " << srcColName <<
" ***";
3077 ss <<
"\n\t" << preIndexStr << index <<
". " << srcColName;
3090 << destColNames.size()
3091 <<
" Current table column names in ALPHABETICAL order are as follows:\n";
3094 for(
auto& destColName : destColNames)
3096 if(srcColNames.find(destColName) == srcColNames.end())
3097 ss <<
"\n\t*** " << preIndexStr << index <<
". " << destColName <<
" ***";
3099 ss <<
"\n\t" << preIndexStr << index <<
". " << destColName;
3114 bool TableView::isURIEncodedCommentTheSame(
const std::string& comment)
const
3117 return comment_ == compareStr;
3162 const int& dataOffset ,
3163 const std::string& author ,
3164 const char rowDelimter ,
3165 const char colDelimter )
3167 int row = dataOffset;
3169 std::string currentValue =
"";
3170 bool insideQuotes =
false;
3171 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3172 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3174 for(
size_t i = 0; i < data.size(); ++i)
3177 const char nextChar = (i + 1 < data.size() ? data[i + 1] :
' ');
3181 if(insideQuotes && nextChar ==
'"')
3184 currentValue +=
'"';
3190 insideQuotes = !insideQuotes;
3193 else if(c == rowDelimter && !insideQuotes)
3195 if(col == 0 && row >= (
int)getNumberOfRows())
3201 else if((c == colDelimter || c ==
'\r') && !insideQuotes)
3211 __COUT__ <<
"First row detected as column names." << __E__;
3219 setValue(time(0), row, timestampCol);
3243 __COUT__ <<
"First row detected as column names." << __E__;
3251 setValue(time(0), row, timestampCol);
3290 const int& dataOffset,
3291 const std::string& author)
3299 int j = data.find(
',', i);
3300 int k = data.find(
';', i);
3302 bool rowWasModified;
3303 unsigned int countRowsModified = 0;
3304 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3305 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3308 while(k != (
int)(std::string::npos))
3310 rowWasModified =
false;
3311 if(r >= (
int)getNumberOfRows())
3315 rowWasModified =
true;
3318 while(j < k && j != (
int)(std::string::npos))
3323 if(c >= (
int)getNumberOfColumns() - 2)
3326 j = data.find(
',', i);
3332 rowWasModified =
true;
3335 j = data.find(
',', i);
3340 if(author !=
"" && rowWasModified)
3342 __COUTT__ <<
"Row=" << (int)r <<
" was modified!" << __E__;
3344 setValue(time(0), r, timestampCol);
3348 ++countRowsModified;
3354 j = data.find(
',', i);
3355 k = data.find(
';', i);
3359 while(r < (
int)getNumberOfRows())
3362 __COUT__ <<
"Row deleted: " << (int)r << __E__;
3363 ++countRowsModified;
3366 __COUT_INFO__ <<
"countRowsModified=" << countRowsModified << __E__;
3368 if(!countRowsModified)
3373 bool match = getColumnStorageNames().size() == getSourceColumnNames().size();
3376 for(
auto& destColName : getColumnStorageNames())
3377 if(getSourceColumnNames().find(destColName) ==
3378 getSourceColumnNames().end())
3380 __COUT__ <<
"Found column name mismach for '" << destColName
3381 <<
"'... So allowing same data!" << __E__;
3390 __SS__ <<
"No rows were modified! No reason to fill a view with same content."
3392 __COUT__ <<
"\n" << ss.str();
3402 sourceColumnNames_.clear();
3403 for(
unsigned int i = 0; i < getNumberOfColumns(); ++i)
3404 sourceColumnNames_.emplace(getColumnsInfo()[i].getStorageName());
3426 const unsigned int& r,
3427 const unsigned int& c,
3428 const std::string& author)
3430 if(!(c < columnsInfo_.size() && r < getNumberOfRows()))
3432 __SS__ <<
"Invalid row (" << (int)r <<
") col (" << (
int)c <<
") requested!"
3433 <<
"Number of Rows = " << getNumberOfRows()
3434 <<
"Number of Columns = " << columnsInfo_.size() << __E__;
3440 std::string originalValueStr =
3464 theDataView_[r][c] = valueStr;
3468 else if(columnsInfo_[c].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
3480 setValue(time_t(strtol(valueStr.c_str(), 0, 10)), r, c);
3483 theDataView_[r][c] = valueStr;
3485 bool rowWasModified =
3486 (originalValueStr !=
3490 if(author !=
"" && rowWasModified)
3492 __COUT__ <<
"Row=" << (int)r <<
" was modified!" << __E__;
3493 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3494 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3496 setValue(time(0), r, timestampCol);
3499 return rowWasModified;
3503 void TableView::resizeDataView(
unsigned int nRows,
unsigned int nCols)
3507 theDataView_.resize(nRows, std::vector<std::string>(nCols));
3518 const std::string& author,
3520 incrementUniqueData ,
3523 const std::string& baseNameAutoUID ,
3524 unsigned int rowToAdd ,
3525 std::string childLinkIndex ,
3526 std::string groupId )
3529 if(rowToAdd == (
unsigned int)-1)
3530 rowToAdd = getNumberOfRows();
3532 theDataView_.resize(getNumberOfRows() + 1,
3533 std::vector<std::string>(getNumberOfColumns()));
3536 for(
unsigned int r = getNumberOfRows() - 2; r >= rowToAdd; --r)
3538 if(r == (
unsigned int)-1)
3540 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
3541 theDataView_[r + 1][col] = theDataView_[r][col];
3544 std::vector<std::string> defaultRowValues = getDefaultRowValues();
3547 std::string tmpString, baseString;
3551 std::string numString;
3556 for(
unsigned int col = 0; col < getNumberOfColumns(); ++col)
3564 if(incrementUniqueData &&
3565 (col ==
getColUID() || columnsInfo_[col].isChildLinkGroupID() ||
3566 (getNumberOfRows() > 1 &&
3567 (columnsInfo_[col].getType() == TableViewColumnInfo::TYPE_UNIQUE_DATA ||
3568 columnsInfo_[col].getType() ==
3569 TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA))))
3571 if(col ==
getColUID() || columnsInfo_[col].isChildLinkGroupID())
3573 rowToAdd, col, baseNameAutoUID );
3583 theDataView_[rowToAdd][col] = defaultRowValues[col];
3588 __COUT__ <<
"Row=" << rowToAdd <<
" was created!" << __E__;
3590 int authorCol =
findColByType(TableViewColumnInfo::TYPE_AUTHOR);
3591 int timestampCol =
findColByType(TableViewColumnInfo::TYPE_TIMESTAMP);
3592 setValue(author, rowToAdd, authorCol);
3593 setValue(time(0), rowToAdd, timestampCol);
3604 if(r >= (
int)getNumberOfRows())
3607 __SS__ <<
"Row " << (int)r
3608 <<
" is out of bounds (Row Count = " << getNumberOfRows()
3609 <<
") and can not be deleted." << __E__;
3613 theDataView_.erase(theDataView_.begin() + r);
3633 const unsigned int& c,
3635 std::pair<unsigned int /*link col*/, unsigned int /*link id col*/>& linkPair)
const
3637 if(!(c < columnsInfo_.size()))
3639 __SS__ <<
"Invalid col (" << (int)c <<
") requested for child link!" << __E__;
3647 if((isGroup = columnsInfo_[c].isChildLinkGroupID()) ||
3648 columnsInfo_[c].isChildLinkUID())
3652 linkPair.second = c;
3653 std::string index = columnsInfo_[c].getChildLinkIndex();
3658 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
3664 else if(columnsInfo_[col].isChildLink() &&
3665 index == columnsInfo_[col].getChildLinkIndex())
3670 linkPair.first = col;
3676 __SS__ <<
"\tIn view: " << tableName_
3677 <<
", Can't find complete child link for column name "
3678 << columnsInfo_[c].getName() << __E__;
3682 if(!columnsInfo_[c].isChildLink())
3687 std::string index = columnsInfo_[c].getChildLinkIndex();
3692 for(
unsigned int col = 0; col < columnsInfo_.size(); ++col)
3709 if(((columnsInfo_[col].isChildLinkUID() && !(isGroup =
false)) ||
3710 (columnsInfo_[col].isChildLinkGroupID() && (isGroup =
true))) &&
3711 index == columnsInfo_[col].getChildLinkIndex())
3716 linkPair.second = col;
3722 __SS__ <<
"\tIn view: " << tableName_
3723 <<
", Can't find complete child link id for column name "
3724 << 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)
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 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)