tdaq-develop-2025-02-12
TableViewColumnInfo.cc
1 #include "otsdaq/TableCore/TableViewColumnInfo.h"
2 
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/Macros/StringMacros.h"
5 
6 #include <iostream>
7 #include <sstream>
8 #include <stdexcept>
9 
10 #include "otsdaq/TableCore/TableView.h"
11 
12 using namespace ots;
13 
14 // clang-format off
15 
17 const std::string TableViewColumnInfo::TYPE_UID = "UID";
18 
19 const std::string TableViewColumnInfo::TYPE_DATA = "Data";
20 const std::string TableViewColumnInfo::TYPE_UNIQUE_DATA = "UniqueData";
21 const std::string TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA = "UniqueGroupData";
22 const std::string TableViewColumnInfo::TYPE_MULTILINE_DATA = "MultilineData";
23 const std::string TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA = "FixedChoiceData";
24 const std::string TableViewColumnInfo::TYPE_BITMAP_DATA = "BitMap";
25 
26 const std::string TableViewColumnInfo::TYPE_ON_OFF = "OnOff";
27 const std::string TableViewColumnInfo::TYPE_TRUE_FALSE = "TrueFalse";
28 const std::string TableViewColumnInfo::TYPE_YES_NO = "YesNo";
29 
30 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK = "ChildLink";
31 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_UID = "ChildLinkUID";
32 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_GROUP_ID = "ChildLinkGroupID";
33 const std::string TableViewColumnInfo::TYPE_START_GROUP_ID = "GroupID";
34 const std::string TableViewColumnInfo::TYPE_COMMENT = "Comment";
35 const std::string TableViewColumnInfo::TYPE_AUTHOR = "Author";
36 const std::string TableViewColumnInfo::TYPE_TIMESTAMP = "Timestamp";
39 const std::string TableViewColumnInfo::DATATYPE_NUMBER = "NUMBER";
40 const std::string TableViewColumnInfo::DATATYPE_STRING = "STRING";
41 const std::string TableViewColumnInfo::DATATYPE_TIME = "TIMESTAMP WITH TIMEZONE";
42 
43 const std::string TableViewColumnInfo::TYPE_VALUE_YES = "Yes";
44 const std::string TableViewColumnInfo::TYPE_VALUE_NO = "No";
45 const std::string TableViewColumnInfo::TYPE_VALUE_TRUE = "True";
46 const std::string TableViewColumnInfo::TYPE_VALUE_FALSE = "False";
47 const std::string TableViewColumnInfo::TYPE_VALUE_ON = "On";
48 const std::string TableViewColumnInfo::TYPE_VALUE_OFF = "Off";
49 
50 const std::string TableViewColumnInfo::DATATYPE_STRING_DEFAULT = "DEFAULT";
51 const std::string TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT = "No Comment";
52 const std::string TableViewColumnInfo::DATATYPE_BOOL_DEFAULT = "0";
53 const std::string TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT = "0";
54 
55 const std::string TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT = "";
56 const std::string TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT = "";
57 
58 const std::string TableViewColumnInfo::DATATYPE_TIME_DEFAULT = "0";
59 const std::string TableViewColumnInfo::DATATYPE_LINK_DEFAULT = "NO_LINK";
60 
61 const std::string TableViewColumnInfo::COL_NAME_STATUS = "Status";
62 const std::string TableViewColumnInfo::COL_NAME_ENABLED = "Enabled";
63 const std::string TableViewColumnInfo::COL_NAME_PRIORITY = "Priority";
64 const std::string TableViewColumnInfo::COL_NAME_COMMENT = "CommentDescription";
65 const std::string TableViewColumnInfo::COL_NAME_AUTHOR = "Author";
66 const std::string TableViewColumnInfo::COL_NAME_CREATION = "RecordInsertionTime";
67 
68 // clang-format on
69 
70 //==============================================================================
74 TableViewColumnInfo::TableViewColumnInfo(const std::string& type,
75  const std::string& name,
76  const std::string& storageName,
77  const std::string& dataType,
78  const std::string* defaultValue,
79  const std::string& dataChoicesCSV,
80  const std::string* minValue,
81  const std::string* maxValue,
82  std::string* capturedExceptionString)
83  : type_(type)
84  , name_(name)
85  , storageName_(storageName)
86  , dataType_(/*convert antiquated*/ dataType == "VARCHAR2" ? DATATYPE_STRING
87  : dataType)
88  , defaultValue_(defaultValue ? *defaultValue
89  : getDefaultDefaultValue(type_, dataType_))
90  , // if default pointer, take input default value
91  dataChoices_(getDataChoicesFromString(dataChoicesCSV))
92  , minValue_(minValue ? ((*minValue) == "null" ? "" : (*minValue))
93  : getMinDefaultValue(dataType_))
94  , // there was a time during JS GUI development when "null" was being injected into data files rather than empty strings. Because this member variable is
95  // constant, this is the single cleansing point.
96  maxValue_(maxValue ? ((*maxValue) == "null" ? "" : (*maxValue))
97  : getMaxDefaultValue(dataType_))
98  , // there was a time during JS GUI development when "null" was being injected into data files rather than empty strings. Because this member variable is
99  // constant, this is the single cleansing point.
100  bitMapInfoP_(0)
101 {
102  // verify type
103  if((type_ != TYPE_UID) && (type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) &&
104  (type_ != TYPE_UNIQUE_GROUP_DATA) && (type_ != TYPE_MULTILINE_DATA) &&
105  (type_ != TYPE_FIXED_CHOICE_DATA) && (type_ != TYPE_BITMAP_DATA) &&
106  (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
107  (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
109  {
110  __SS__ << "The type for column " << name_ << " is " << type_
111  << ", while the only accepted types are: " << TYPE_DATA << " "
112  << TYPE_UNIQUE_DATA << " " << TYPE_UNIQUE_GROUP_DATA << " "
113  << TYPE_MULTILINE_DATA << " " << TYPE_FIXED_CHOICE_DATA << " " << TYPE_UID
114  << " " << TYPE_ON_OFF << " " << TYPE_TRUE_FALSE << " " << TYPE_YES_NO
115  << " " << TYPE_START_CHILD_LINK << "-* " << TYPE_START_CHILD_LINK_UID
116  << "-* " << TYPE_START_CHILD_LINK_GROUP_ID << "-* " << TYPE_START_GROUP_ID
117  << "-* " << std::endl;
118  if(capturedExceptionString)
119  *capturedExceptionString = ss.str();
120  else
121  __SS_THROW__;
122  }
123  else if(capturedExceptionString)
124  *capturedExceptionString = ""; // indicates no error found
125 
126  // enforce that type only
127  // allows letters, numbers, dash, underscore
128  for(unsigned int i = 0; i < type_.size(); ++i)
129  if(!((type_[i] >= 'A' && type_[i] <= 'Z') ||
130  (type_[i] >= 'a' && type_[i] <= 'z') ||
131  (type_[i] >= '0' && type_[i] <= '9') ||
132  (type_[i] == '-' || type_[i] == '_' || type_[i] == '.' || type_[i] == ' ')))
133  {
134  __SS__ << "The column type for column " << name_ << " is '" << type_
135  << "'. Column types must contain only letters, numbers, "
136  << "dashes, underscores, periods, and spaces." << std::endl;
137  if(capturedExceptionString)
138  *capturedExceptionString += ss.str();
139  else
140  __SS_THROW__;
141  }
142 
143  // verify data type
144  if((dataType_ != DATATYPE_NUMBER) && (dataType_ != DATATYPE_STRING) &&
145  (dataType_ != DATATYPE_TIME))
146  {
147  __SS__ << "The data type for column " << name_ << " is " << dataType_
148  << ", while the only accepted types are: " << DATATYPE_NUMBER << " "
149  << DATATYPE_STRING << " " << DATATYPE_TIME << std::endl;
150  if(capturedExceptionString)
151  *capturedExceptionString += ss.str();
152  else
153  __SS_THROW__;
154  }
155 
156  if(dataType_.size() == 0)
157  {
158  __SS__ << "The data type for column " << name_ << " is '" << dataType_
159  << "'. Data types must contain at least 1 character." << std::endl;
160  if(capturedExceptionString)
161  *capturedExceptionString += ss.str();
162  else
163  __SS_THROW__;
164  }
165 
166  // enforce that data type only
167  // allows letters, numbers, dash, underscore
168  for(unsigned int i = 0; i < dataType_.size(); ++i)
169  if(!((dataType_[i] >= 'A' && dataType_[i] <= 'Z') ||
170  (dataType_[i] >= 'a' && dataType_[i] <= 'z') ||
171  (dataType_[i] >= '0' && dataType_[i] <= '9') ||
172  (dataType_[i] == '-' || dataType_[i] == '_' || dataType_[i] == ' ')))
173  {
174  __SS__ << "The data type for column " << name_ << " is '" << dataType_
175  << "'. Data types must contain only letters, numbers, "
176  << "dashes, underscores, and spaces." << std::endl;
177  if(capturedExceptionString)
178  *capturedExceptionString += ss.str();
179  else
180  __SS_THROW__;
181  }
182 
183  if(name_.size() == 0)
184  {
185  __SS__ << "There is a column named " << name_
186  << "'. Column names must contain at least 1 character." << std::endl;
187  if(capturedExceptionString)
188  *capturedExceptionString += ss.str();
189  else
190  __SS_THROW__;
191  }
192 
193  // enforce that col name only
194  // allows letters, numbers, dash, underscore
195  for(unsigned int i = 0; i < name_.size(); ++i)
196  if(!((name_[i] >= 'A' && name_[i] <= 'Z') ||
197  (name_[i] >= 'a' && name_[i] <= 'z') ||
198  (name_[i] >= '0' && name_[i] <= '9') ||
199  (name_[i] == '-' || name_[i] == '_')))
200  {
201  __SS__ << "There is a column named " << name_
202  << "'. Column names must contain only letters, numbers, "
203  << "dashes, and underscores." << std::endl;
204  if(capturedExceptionString)
205  *capturedExceptionString += ss.str();
206  else
207  __SS_THROW__;
208  }
209 
210  if(storageName_.size() == 0)
211  {
212  __SS__ << "The storage name for column " << name_ << " is '" << storageName_
213  << "'. Storage names must contain at least 1 character." << std::endl;
214  if(capturedExceptionString)
215  *capturedExceptionString += ss.str();
216  else
217  __SS_THROW__;
218  }
219 
220  // enforce that col storage name only
221  // allows capital letters, numbers, dash, underscore
222  for(unsigned int i = 0; i < storageName_.size(); ++i)
223  if(!((storageName_[i] >= 'A' && storageName_[i] <= 'Z') ||
224  (storageName_[i] >= '0' && storageName_[i] <= '9') ||
225  (storageName_[i] == '-' || storageName_[i] == '_')))
226  {
227  __SS__ << "The storage name for column " << name_ << " is '" << storageName_
228  << "'. Storage names must contain only capital letters, numbers,"
229  << "dashes, and underscores." << std::endl;
230  if(capturedExceptionString)
231  *capturedExceptionString += ss.str();
232  else
233  __SS_THROW__;
234  }
235 
236  // RAR moved to call from initialization of constructor!
237 
238  // build data choices vector from URI encoded data
239  //__COUT__ << "dataChoicesCSV " << dataChoicesCSV << std::endl;
240  // {
241  // std::istringstream f(dataChoicesCSV);
242  // std::string s;
243  // while (getline(f, s, ','))
244  // dataChoices_.push_back(StringMacros::decodeURIComponent(s));
245  // // for(const auto &dc: dataChoices_)
246  // // __COUT__ << dc << std::endl;
247  // }
248  // __COUTV__(dataChoicesCSV);
249  // __COUTV__(StringMacros::vectorToString(dataChoices_));
250  // __COUTV__(dataChoices_.size());
251  // __COUTV__ (defaultValue);
252  // __COUTV__ (defaultValue_);
253 
254  try
255  {
256  extractBitMapInfo();
257  }
258  catch(std::runtime_error& e)
259  {
260  if(capturedExceptionString)
261  *capturedExceptionString += e.what();
262  else
263  throw;
264  }
265 
266  //__COUT__ << "dataChoicesCSV " << dataChoicesCSV << std::endl;
267 }
268 
269 //==============================================================================
270 std::vector<std::string> TableViewColumnInfo::getDataChoicesFromString(
271  const std::string& dataChoicesCSV) const
272 {
273  std::vector<std::string> dataChoices;
274  // build data choices vector from URI encoded data
275  //__COUT__ << "dataChoicesCSV " << dataChoicesCSV << std::endl;
276  {
277  std::istringstream f(dataChoicesCSV);
278  std::string s;
279  while(getline(f, s, ','))
280  dataChoices.push_back(StringMacros::decodeURIComponent(s));
281  // for(const auto &dc: dataChoices_)
282  // __COUT__ << dc << std::endl;
283  }
284  return dataChoices;
285 } // end getDataChoicesFromString
286 
287 //==============================================================================
288 void TableViewColumnInfo::extractBitMapInfo()
289 {
290  // create BitMapInfo if this is a bitmap column
291  if(type_ == TYPE_BITMAP_DATA)
292  {
293  if(bitMapInfoP_)
294  delete bitMapInfoP_;
295  bitMapInfoP_ = new BitMapInfo();
296 
297  // extract bitMapInfo parameters:
298  // must match TableEditor js handling:
299 
300  // [ //types => 0:string, 1:bool (default no),
301  // //2:bool (default yes), 3:color
302  //
303  // 0 0,//"Number of Rows",
304  // 1 0,//"Number of Columns",
305  // 2 0,//"Cell Bit-field Size",
306  // 3 0,//"Min-value Allowed",
307  // 4 0,//"Max-value Allowed",
308  // 5 0,//"Value step-size Allowed",
309  // 6 0,//"Display Aspect H:W",
310  // 7 3,//"Min-value Cell Color",
311  // 8 3,//"Mid-value Cell Color",
312  // 9 3,//"Max-value Cell Color",
313  // 10 3,//"Absolute Min-value Cell Color",
314  // 11 3,//"Absolute Max-value Cell Color",
315  // 12 1,//"Display Rows in Ascending Order",
316  // 13 2,//"Display Columns in Ascending Order",
317  // 14 1,//"Snake Double Rows",
318  // 15 1];//"Snake Double Columns"];
319 
320  if(dataChoices_.size() < 16)
321  {
322  __SS__ << "The Bit-Map data parameters for column " << name_
323  << " should be size 16, but is size " << dataChoices_.size()
324  << ". Bit-Map parameters should be rows, cols, cellBitSize, and min, "
325  "mid, max color."
326  << std::endl;
327  __SS_THROW__;
328  }
329 
330  sscanf(dataChoices_[0].c_str(), "%u", &(bitMapInfoP_->numOfRows_));
331  sscanf(dataChoices_[1].c_str(), "%u", &(bitMapInfoP_->numOfColumns_));
332  sscanf(dataChoices_[2].c_str(), "%u", &(bitMapInfoP_->cellBitSize_));
333 
334  sscanf(dataChoices_[3].c_str(), "%lu", &(bitMapInfoP_->minValue_));
335  sscanf(dataChoices_[4].c_str(), "%lu", &(bitMapInfoP_->maxValue_));
336  sscanf(dataChoices_[5].c_str(), "%lu", &(bitMapInfoP_->stepValue_));
337 
338  bitMapInfoP_->aspectRatio_ = dataChoices_[6];
339  bitMapInfoP_->minColor_ = dataChoices_[7];
340  bitMapInfoP_->midColor_ = dataChoices_[8];
341  bitMapInfoP_->maxColor_ = dataChoices_[9];
342  bitMapInfoP_->absMinColor_ = dataChoices_[10];
343  bitMapInfoP_->absMaxColor_ = dataChoices_[11];
344 
345  bitMapInfoP_->rowsAscending_ = dataChoices_[12] == "Yes" ? 1 : 0;
346  bitMapInfoP_->colsAscending_ = dataChoices_[13] == "Yes" ? 1 : 0;
347  bitMapInfoP_->snakeRows_ = dataChoices_[14] == "Yes" ? 1 : 0;
348  bitMapInfoP_->snakeCols_ = dataChoices_[15] == "Yes" ? 1 : 0;
349  }
350 }
351 
352 //==============================================================================
354 TableViewColumnInfo::TableViewColumnInfo(void) {}
355 
356 //==============================================================================
357 TableViewColumnInfo::TableViewColumnInfo(
358  const TableViewColumnInfo& c) // copy constructor because of bitmap pointer
359  : type_(c.type_)
360  , name_(c.name_)
361  , storageName_(c.storageName_)
362  , dataType_(c.dataType_)
363  , defaultValue_(c.defaultValue_)
364  , dataChoices_(c.dataChoices_)
365  , minValue_(c.minValue_)
366  , maxValue_(c.maxValue_)
367  , bitMapInfoP_(0)
368 {
369  // extract bitmap info if necessary
370  extractBitMapInfo();
371 } // end copy constructor
372 
373 //==============================================================================
375  const TableViewColumnInfo&) // assignment operator because of bitmap pointer
376 {
377  __COUT__ << "OPERATOR= COPY CONSTRUCTOR " << std::endl;
378  // Note: Members of the ConfigurationTree are declared constant.
379  // (Refer to comments at top of class declaration for solutions)
380  // So this operator cannot work.. SO I am going to crash just in case it is
381  // called by mistake
382  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
383  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
384  "and initialize another TableViewColumnInfo, rather than assigning to "
385  "an existing TableViewColumnInfo. Crashing now."
386  << std::endl;
387  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
388  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
389  "and initialize another TableViewColumnInfo, rather than assigning to "
390  "an existing TableViewColumnInfo. Crashing now."
391  << std::endl;
392  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
393  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
394  "and initialize another TableViewColumnInfo, rather than assigning to "
395  "an existing TableViewColumnInfo. Crashing now."
396  << std::endl;
397  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
398  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
399  "and initialize another TableViewColumnInfo, rather than assigning to "
400  "an existing TableViewColumnInfo. Crashing now."
401  << std::endl;
402  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
403  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
404  "and initialize another TableViewColumnInfo, rather than assigning to "
405  "an existing TableViewColumnInfo. Crashing now."
406  << std::endl;
407 
408  __COUT__ << StringMacros::stackTrace() << __E__;
409  exit(0);
410  // TableViewColumnInfo* retColInfo = new TableViewColumnInfo();
411  // retColInfo->type_ = c.type_;
412  // retColInfo->name_ = c.name_;
413  // retColInfo->storageName_ = c.storageName_;
414  // retColInfo->dataType_ = c.dataType_;
415  // retColInfo->dataChoices_ = c.dataChoices_;
416  // retColInfo->bitMapInfoP_ = 0;
417 
418  // extract bitmap info if necessary
419  // retColInfo->extractBitMapInfo();
420 
421  extractBitMapInfo();
422  return *this; //*retColInfo;
423 } // end assignment operator
424 
425 //==============================================================================
426 TableViewColumnInfo::~TableViewColumnInfo(void)
427 {
428  if(bitMapInfoP_)
429  delete bitMapInfoP_;
430 }
431 
432 //==============================================================================
433 const std::string& TableViewColumnInfo::getType(void) const { return type_; }
434 
435 //==============================================================================
436 const std::string& TableViewColumnInfo::getDefaultValue(void) const
437 {
438  return defaultValue_;
439 }
440 const std::string& TableViewColumnInfo::getMinValue(void) const { return minValue_; }
441 const std::string& TableViewColumnInfo::getMaxValue(void) const { return maxValue_; }
442 
443 //==============================================================================
444 const std::string& TableViewColumnInfo::getDefaultDefaultValue(
445  const std::string& type, const std::string& dataType)
446 {
447  if(dataType == TableViewColumnInfo::DATATYPE_STRING)
448  {
449  if(type == TableViewColumnInfo::TYPE_ON_OFF ||
450  type == TableViewColumnInfo::TYPE_TRUE_FALSE ||
451  type == TableViewColumnInfo::TYPE_YES_NO)
452  return (
453  TableViewColumnInfo::DATATYPE_BOOL_DEFAULT); // default to OFF, NO, FALSE
454  else if(TableViewColumnInfo::isChildLink(type)) // call static version
455  return (TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
456  else if(type == TableViewColumnInfo::TYPE_COMMENT)
457  return (TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
458  else
459  return (TableViewColumnInfo::DATATYPE_STRING_DEFAULT);
460  }
461  else if(dataType == TableViewColumnInfo::DATATYPE_NUMBER)
462  return (TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
463  else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
464  return (TableViewColumnInfo::DATATYPE_TIME_DEFAULT);
465  else
466  {
467  __SS__ << "\tUnrecognized View data type: " << dataType << std::endl;
468  __COUT_ERR__ << "\n" << ss.str();
469  __SS_THROW__;
470  }
471 } // end getDefaultDefaultValue()
472 
473 //==============================================================================
475 const std::string& TableViewColumnInfo::getMinDefaultValue(const std::string& dataType)
476 {
477  if(dataType == TableViewColumnInfo::DATATYPE_STRING)
478  return (TableViewColumnInfo::
479  DATATYPE_NUMBER_MIN_DEFAULT); // default to OFF, NO, FALSE
480 
481  else if(dataType == TableViewColumnInfo::DATATYPE_NUMBER)
482  {
483  return (TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT);
484  }
485 
486  else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
487  return (TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT);
488  else
489  {
490  __SS__ << "\tUnrecognized View data type: " << dataType << std::endl;
491  __COUT_ERR__ << "\n" << ss.str();
492  __SS_THROW__;
493  }
494 }
495 
496 //==============================================================================
498 const std::string& TableViewColumnInfo::getMaxDefaultValue(const std::string& dataType)
499 {
500  if(dataType == TableViewColumnInfo::DATATYPE_STRING)
501  return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
502 
503  else if(dataType == TableViewColumnInfo::DATATYPE_NUMBER)
504  {
505  return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
506  }
507  else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
508  return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
509  else
510  {
511  __SS__ << "\tUnrecognized View data type: " << dataType << std::endl;
512  __COUT_ERR__ << "\n" << ss.str();
513  __SS_THROW__;
514  }
515 }
516 
517 //==============================================================================
518 std::vector<std::string> TableViewColumnInfo::getAllTypesForGUI(void)
519 {
520  std::vector<std::string> all;
521  all.push_back(TYPE_DATA);
522  all.push_back(TYPE_UNIQUE_DATA);
523  all.push_back(TYPE_UNIQUE_GROUP_DATA);
524  all.push_back(TYPE_FIXED_CHOICE_DATA);
525  all.push_back(TYPE_MULTILINE_DATA);
526  all.push_back(TYPE_BITMAP_DATA);
527  all.push_back(TYPE_ON_OFF);
528  all.push_back(TYPE_TRUE_FALSE);
529  all.push_back(TYPE_YES_NO);
530  all.push_back(TYPE_START_CHILD_LINK_UID);
531  all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
532  all.push_back(TYPE_START_CHILD_LINK);
533  all.push_back(TYPE_START_GROUP_ID);
534  return all;
535 } // end getAllTypesForGUI()
536 
537 //==============================================================================
538 std::vector<std::string> TableViewColumnInfo::getAllDataTypesForGUI(void)
539 {
540  std::vector<std::string> all;
541  all.push_back(DATATYPE_STRING);
542  all.push_back(DATATYPE_NUMBER);
543  all.push_back(DATATYPE_TIME);
544  return all;
545 }
546 
547 //==============================================================================
549 std::map<std::pair<std::string, std::string>, std::string>
551 {
552  std::map<std::pair<std::string, std::string>, std::string> all;
553  all[std::pair<std::string, std::string>(DATATYPE_NUMBER, "*")] =
554  DATATYPE_NUMBER_DEFAULT;
555  all[std::pair<std::string, std::string>(DATATYPE_TIME, "*")] = DATATYPE_TIME_DEFAULT;
556 
557  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_ON_OFF)] =
558  DATATYPE_BOOL_DEFAULT;
559  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_TRUE_FALSE)] =
560  DATATYPE_BOOL_DEFAULT;
561  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_YES_NO)] =
562  DATATYPE_BOOL_DEFAULT;
563 
564  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_START_CHILD_LINK)] =
565  DATATYPE_LINK_DEFAULT;
566  all[std::pair<std::string, std::string>(DATATYPE_STRING, "*")] =
567  DATATYPE_STRING_DEFAULT;
568  return all;
569 }
571 //==============================================================================
574 {
575  return (type_ == TYPE_ON_OFF || type_ == TYPE_TRUE_FALSE || type_ == TYPE_YES_NO);
576 } // end isBoolType()
577 
578 //==============================================================================
581 {
582  return (dataType_ == DATATYPE_NUMBER);
583 } // end isBoolType()
584 
585 //==============================================================================
586 const std::string& TableViewColumnInfo::getName(void) const { return name_; }
587 
588 //==============================================================================
589 const std::string& TableViewColumnInfo::getStorageName(void) const
590 {
591  return storageName_;
592 }
593 
594 //==============================================================================
595 const std::string& TableViewColumnInfo::getDataType(void) const { return dataType_; }
596 
597 //==============================================================================
598 const std::vector<std::string>& TableViewColumnInfo::getDataChoices(void) const
599 {
600  return dataChoices_;
601 }
602 
603 //==============================================================================
607 {
608  if(bitMapInfoP_)
609  return *bitMapInfoP_;
610 
611  // throw error at this point!
612  {
613  __SS__ << "getBitMapInfo request for non-BitMap column of type: " << getType()
614  << std::endl;
615  __COUT_ERR__ << "\n" << ss.str();
616  __SS_THROW__;
617  }
618 }
619 
620 //==============================================================================
624 bool TableViewColumnInfo::isChildLink(const std::string& type)
625 {
626  return (type.find(TYPE_START_CHILD_LINK) == 0 &&
627  type.length() > TYPE_START_CHILD_LINK.length() &&
628  type[TYPE_START_CHILD_LINK.length()] == '-');
629 }
630 
631 //==============================================================================
636 {
637  return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
638  type_.length() > TYPE_START_CHILD_LINK.length() &&
639  type_[TYPE_START_CHILD_LINK.length()] == '-');
640 }
641 
642 //==============================================================================
647 {
648  return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
649  type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
650  type_[TYPE_START_CHILD_LINK_UID.length()] == '-');
651 }
652 
653 //==============================================================================
658 {
659  return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
660  type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
661  type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] == '-');
662 }
663 
664 //==============================================================================
669 {
670  return (type_.find(TYPE_START_GROUP_ID) == 0 &&
671  type_.length() > TYPE_START_GROUP_ID.length() &&
672  type_[TYPE_START_GROUP_ID.length()] == '-');
673 }
674 
675 //==============================================================================
677 bool TableViewColumnInfo::isUID(void) const { return (type_ == TYPE_UID); }
678 
679 //==============================================================================
682 {
683  // note: +1 to skip '-'
684  if(isChildLink())
685  return type_.substr(TYPE_START_CHILD_LINK.length() + 1);
686  else if(isChildLinkUID())
687  return type_.substr(TYPE_START_CHILD_LINK_UID.length() + 1);
688  else if(isChildLinkGroupID())
689  return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length() + 1);
690  else if(isGroupID())
691  return type_.substr(TYPE_START_GROUP_ID.length() + 1);
692  else
693  {
694  __SS__
695  << ("Requesting a Link Index from a column that is not a child link member!")
696  << std::endl;
697  __COUT_ERR__ << ss.str();
698  __SS_THROW__;
699  }
700 }
static const std::string DATATYPE_NUMBER
static std::map< std::pair< std::string, std::string >, std::string > getAllDefaultsForGUI(void)
map of datatype,type to default value
std::string getChildLinkIndex(void) const
getChildLinkIndex
TableViewColumnInfo & operator=(const TableViewColumnInfo &c)
assignment operator because of bitmap pointer
bool isUID(void) const
isUID
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...
static const std::string & getMaxDefaultValue(const std::string &dataType)
function to get max default value
const BitMapInfo & getBitMapInfo(void) const
uses dataChoices CSV fields if type is TYPE_BITMAP_DATA
static const std::string & getMinDefaultValue(const std::string &dataType)
function to get min default value
bool isBoolType(void) const
TODO check if min and max values need a function called getallminmaxforgui or something like that for...
bool isNumberDataType(void) const
isNumberDataType
bool isChildLinkGroupID(void) const
static std::string decodeURIComponent(const std::string &data)
static std::string stackTrace(void)
< uses dataChoices CSV fields if type is TYPE_BITMAP_DATA