otsdaq  3.07.00
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_STRING_ALT_DEFAULT = "Default";
52 const std::string TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT = "No comment.";
53 const std::string TableViewColumnInfo::DATATYPE_COMMENT_OLD_DEFAULT = "No Comment";
54 const std::string TableViewColumnInfo::DATATYPE_BOOL_DEFAULT = "0";
55 const std::string TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT = "0";
56 
57 const std::string TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT = "";
58 const std::string TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT = "";
59 
60 const std::string TableViewColumnInfo::DATATYPE_TIME_DEFAULT = "0";
61 const std::string TableViewColumnInfo::DATATYPE_LINK_DEFAULT = "NO_LINK";
62 
63 const std::string TableViewColumnInfo::COL_NAME_STATUS = "Status";
64 const std::string TableViewColumnInfo::COL_NAME_ENABLED = "Enabled";
65 const std::string TableViewColumnInfo::COL_NAME_PRIORITY = "Priority";
66 const std::string TableViewColumnInfo::COL_NAME_COMMENT = "CommentDescription";
67 const std::string TableViewColumnInfo::COL_NAME_AUTHOR = "Author";
68 const std::string TableViewColumnInfo::COL_NAME_CREATION = "RecordInsertionTime";
69 
70 // clang-format on
71 
72 //==============================================================================
76 TableViewColumnInfo::TableViewColumnInfo(const std::string& type,
77  const std::string& name,
78  const std::string& storageName,
79  const std::string& dataType,
80  const std::string* defaultValue,
81  const std::string& dataChoicesCSV,
82  const std::string* minValue,
83  const std::string* maxValue,
84  std::string* capturedExceptionString)
85  : type_(type)
86  , name_(name)
87  , storageName_(storageName)
88  , dataType_(/*convert antiquated*/ dataType == "VARCHAR2" ? DATATYPE_STRING
89  : dataType)
90  , defaultValue_(defaultValue ? *defaultValue
91  : getDefaultDefaultValue(type_, dataType_))
92  , // if default pointer, take input default value
93  dataChoices_(getDataChoicesFromString(dataChoicesCSV))
94  , minValue_(minValue ? ((*minValue) == "null" ? "" : (*minValue))
95  : getMinDefaultValue(dataType_))
96  , // 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
97  // constant, this is the single cleansing point.
98  maxValue_(maxValue ? ((*maxValue) == "null" ? "" : (*maxValue))
99  : getMaxDefaultValue(dataType_))
100  , // 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
101  // constant, this is the single cleansing point.
102  bitMapInfoP_(nullptr)
103 {
104  //keep lightweight because tables+columns get copied around a lot
105 
106  // verify type
107  if((type_ != TYPE_UID) && (type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) &&
108  (type_ != TYPE_UNIQUE_GROUP_DATA) && (type_ != TYPE_MULTILINE_DATA) &&
109  (type_ != TYPE_FIXED_CHOICE_DATA) && (type_ != TYPE_BITMAP_DATA) &&
110  (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
111  (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
113  {
114  __SS__ << "The type for column " << name_ << " is " << type_
115  << ", while the only accepted types are: " << TYPE_DATA << " "
116  << TYPE_UNIQUE_DATA << " " << TYPE_UNIQUE_GROUP_DATA << " "
117  << TYPE_MULTILINE_DATA << " " << TYPE_FIXED_CHOICE_DATA << " " << TYPE_UID
118  << " " << TYPE_ON_OFF << " " << TYPE_TRUE_FALSE << " " << TYPE_YES_NO
119  << " " << TYPE_START_CHILD_LINK << "-* " << TYPE_START_CHILD_LINK_UID
120  << "-* " << TYPE_START_CHILD_LINK_GROUP_ID << "-* " << TYPE_START_GROUP_ID
121  << "-* " << std::endl;
122  if(capturedExceptionString)
123  *capturedExceptionString = ss.str();
124  else
125  __SS_THROW__;
126  }
127  else if(capturedExceptionString)
128  *capturedExceptionString = ""; // indicates no error found
129 
130  // enforce that type only
131  // allows letters, numbers, dash, underscore
132  for(unsigned int i = 0; i < type_.size(); ++i)
133  if(!((type_[i] >= 'A' && type_[i] <= 'Z') ||
134  (type_[i] >= 'a' && type_[i] <= 'z') ||
135  (type_[i] >= '0' && type_[i] <= '9') ||
136  (type_[i] == '-' || type_[i] == '_' || type_[i] == '.' || type_[i] == ' ')))
137  {
138  __SS__ << "The column type for column " << name_ << " is '" << type_
139  << "'. Column types must contain only letters, numbers, "
140  << "dashes, underscores, periods, and spaces." << std::endl;
141  if(capturedExceptionString)
142  *capturedExceptionString += ss.str();
143  else
144  __SS_THROW__;
145  }
146 
147  // verify data type
148  if((dataType_ != DATATYPE_NUMBER) && (dataType_ != DATATYPE_STRING) &&
149  (dataType_ != DATATYPE_TIME))
150  {
151  __SS__ << "The data type for column " << name_ << " is " << dataType_
152  << ", while the only accepted types are: " << DATATYPE_NUMBER << " "
153  << DATATYPE_STRING << " " << DATATYPE_TIME << std::endl;
154  if(capturedExceptionString)
155  *capturedExceptionString += ss.str();
156  else
157  __SS_THROW__;
158  }
159 
160  if(type_ == TYPE_BITMAP_DATA && dataType_ != DATATYPE_STRING)
161  {
162  __SS__ << "The data type for column " << name_ << " is '" << dataType_
163  << "'. Bitmap columns must have a data type of '" << DATATYPE_STRING
164  << "'." << std::endl;
165  if(capturedExceptionString)
166  *capturedExceptionString += ss.str();
167  else
168  __SS_THROW__;
169  }
170 
171  if(dataType_.size() == 0)
172  {
173  __SS__ << "The data type for column " << name_ << " is '" << dataType_
174  << "'. Data types must contain at least 1 character." << std::endl;
175  if(capturedExceptionString)
176  *capturedExceptionString += ss.str();
177  else
178  __SS_THROW__;
179  }
180 
181  // enforce that data type only
182  // allows letters, numbers, dash, underscore
183  for(unsigned int i = 0; i < dataType_.size(); ++i)
184  if(!((dataType_[i] >= 'A' && dataType_[i] <= 'Z') ||
185  (dataType_[i] >= 'a' && dataType_[i] <= 'z') ||
186  (dataType_[i] >= '0' && dataType_[i] <= '9') ||
187  (dataType_[i] == '-' || dataType_[i] == '_' || dataType_[i] == ' ')))
188  {
189  __SS__ << "The data type for column " << name_ << " is '" << dataType_
190  << "'. Data types must contain only letters, numbers, "
191  << "dashes, underscores, and spaces." << std::endl;
192  if(capturedExceptionString)
193  *capturedExceptionString += ss.str();
194  else
195  __SS_THROW__;
196  }
197 
198  if(name_.size() == 0)
199  {
200  __SS__ << "There is a column named " << name_
201  << "'. Column names must contain at least 1 character." << std::endl;
202  if(capturedExceptionString)
203  *capturedExceptionString += ss.str();
204  else
205  __SS_THROW__;
206  }
207 
208  // enforce that col name only
209  // allows letters, numbers, dash, underscore
210  for(unsigned int i = 0; i < name_.size(); ++i)
211  if(!((name_[i] >= 'A' && name_[i] <= 'Z') ||
212  (name_[i] >= 'a' && name_[i] <= 'z') ||
213  (name_[i] >= '0' && name_[i] <= '9') ||
214  (name_[i] == '-' || name_[i] == '_')))
215  {
216  __SS__ << "There is a column named " << name_
217  << "'. Column names must contain only letters, numbers, "
218  << "dashes, and underscores." << std::endl;
219  if(capturedExceptionString)
220  *capturedExceptionString += ss.str();
221  else
222  __SS_THROW__;
223  }
224 
225  if(storageName_.size() == 0)
226  {
227  __SS__ << "The storage name for column " << name_ << " is '" << storageName_
228  << "'. Storage names must contain at least 1 character." << std::endl;
229  if(capturedExceptionString)
230  *capturedExceptionString += ss.str();
231  else
232  __SS_THROW__;
233  }
234 
235  // enforce that col storage name only
236  // allows capital letters, numbers, dash, underscore
237  for(unsigned int i = 0; i < storageName_.size(); ++i)
238  if(!((storageName_[i] >= 'A' && storageName_[i] <= 'Z') ||
239  (storageName_[i] >= '0' && storageName_[i] <= '9') ||
240  (storageName_[i] == '-' || storageName_[i] == '_')))
241  {
242  __SS__ << "The storage name for column " << name_ << " is '" << storageName_
243  << "'. Storage names must contain only capital letters, numbers,"
244  << "dashes, and underscores." << std::endl;
245  if(capturedExceptionString)
246  *capturedExceptionString += ss.str();
247  else
248  __SS_THROW__;
249  }
250 
251  try
252  {
253  extractBitMapInfo();
254  }
255  catch(std::runtime_error& e)
256  {
257  if(capturedExceptionString)
258  *capturedExceptionString += e.what();
259  else
260  throw;
261  }
262 } //end TableViewColumnInfo() constructor
263 
264 //==============================================================================
265 std::vector<std::string> TableViewColumnInfo::getDataChoicesFromString(
266  const std::string& dataChoicesCSV) const
267 {
268  std::vector<std::string> dataChoices;
269  // build data choices vector from URI encoded data
270  //__COUT__ << "dataChoicesCSV " << dataChoicesCSV << std::endl;
271  {
272  std::istringstream f(dataChoicesCSV);
273  std::string s;
274  while(getline(f, s, ','))
275  dataChoices.push_back(StringMacros::decodeURIComponent(s));
276  // for(const auto &dc: dataChoices_)
277  // __COUT__ << dc << std::endl;
278  }
279  return dataChoices;
280 } // end getDataChoicesFromString()
281 
282 //==============================================================================
283 void TableViewColumnInfo::extractBitMapInfo()
284 {
285  // create BitMapInfo if this is a bitmap column
286  if(type_ == TYPE_BITMAP_DATA)
287  {
288  if(bitMapInfoP_)
289  delete bitMapInfoP_;
290  bitMapInfoP_ = new BitMapInfo();
291 
292  // extract bitMapInfo parameters:
293  // must match TableEditor js handling:
294 
295  // [ //types => 0:string, 1:bool (default no),
296  // //2:bool (default yes), 3:color
297  //
298  // 0 0,//"Number of Rows",
299  // 1 0,//"Number of Columns",
300  // 2 0,//"Cell Bit-field Size",
301  // 3 0,//"Min-value Allowed",
302  // 4 0,//"Max-value Allowed",
303  // 5 0,//"Value step-size Allowed",
304  // 6 0,//"Display Aspect H:W",
305  // 7 3,//"Min-value Cell Color",
306  // 8 3,//"Mid-value Cell Color",
307  // 9 3,//"Max-value Cell Color",
308  // 10 3,//"Absolute Min-value Cell Color",
309  // 11 3,//"Absolute Max-value Cell Color",
310  // 12 1,//"Display Rows in Ascending Order",
311  // 13 2,//"Display Columns in Ascending Order",
312  // 14 1,//"Snake Double Rows",
313  // 15 1,//"Snake Double Columns",
314  // 16 1,//"Allow Floating Point",
315  // 17 0 //"Value Map to Strings"
316  // ];
317 
318  if(dataChoices_.size() < 16)
319  {
320  __SS__ << "The Bit-Map data parameters for column " << name_
321  << " should be size 16, but is size " << dataChoices_.size()
322  << ". Bit-Map parameters should be e.g. rows, cols, cellBitSize, and "
323  "min, "
324  "mid, max color, etc."
325  << std::endl;
326  __SS_THROW__;
327  }
328  if(dataChoices_.size() > 18)
329  {
330  __SS__ << "The Bit-Map data parameters for column " << name_
331  << " should be size 18, but is size " << dataChoices_.size()
332  << ". Bit-Map parameters should be e.g. rows, cols, cellBitSize, and "
333  "min, "
334  "mid, max color, etc."
335  << std::endl;
336  __SS_THROW__;
337  }
338 
339  sscanf(dataChoices_[0].c_str(), "%u", &(bitMapInfoP_->numOfRows_));
340  sscanf(dataChoices_[1].c_str(), "%u", &(bitMapInfoP_->numOfColumns_));
341  sscanf(dataChoices_[2].c_str(), "%u", &(bitMapInfoP_->cellBitSize_));
342 
343  sscanf(dataChoices_[3].c_str(), "%lf", &(bitMapInfoP_->minValue_));
344  sscanf(dataChoices_[4].c_str(), "%lf", &(bitMapInfoP_->maxValue_));
345  sscanf(dataChoices_[5].c_str(), "%lf", &(bitMapInfoP_->stepValue_));
346 
347  bitMapInfoP_->aspectRatio_ = dataChoices_[6];
348  bitMapInfoP_->minColor_ = dataChoices_[7];
349  bitMapInfoP_->midColor_ = dataChoices_[8];
350  bitMapInfoP_->maxColor_ = dataChoices_[9];
351  bitMapInfoP_->absMinColor_ = dataChoices_[10];
352  bitMapInfoP_->absMaxColor_ = dataChoices_[11];
353 
354  bitMapInfoP_->rowsAscending_ = dataChoices_[12] == "Yes" ? 1 : 0;
355  bitMapInfoP_->colsAscending_ = dataChoices_[13] == "Yes" ? 1 : 0;
356  bitMapInfoP_->snakeRows_ = dataChoices_[14] == "Yes" ? 1 : 0;
357  bitMapInfoP_->snakeCols_ = dataChoices_[15] == "Yes" ? 1 : 0;
358 
359  bitMapInfoP_->snakeCols_ = dataChoices_[15] == "Yes" ? 1 : 0;
360  if(dataChoices_.size() > 16)
361  bitMapInfoP_->floatingPoint_ = dataChoices_[16] == "Yes" ? 1 : 0;
362  if(dataChoices_.size() > 17)
363  bitMapInfoP_->mapToStrings_ = dataChoices_[17];
364 
365  if(bitMapInfoP_->floatingPoint_ &&
366  bitMapInfoP_->cellBitSize_ != 32) //check floating point
367  {
368  __SS__ << "Illegal Bit-Map data parameters for column " << name_
369  << " - if floating point is allowed, the Bit-field size must be 32."
370  << std::endl;
371  __SS_THROW__;
372  }
373 
374  if(bitMapInfoP_->mapToStrings_ != "" &&
375  bitMapInfoP_->mapToStrings_ != TableViewColumnInfo::DATATYPE_STRING_DEFAULT &&
376  bitMapInfoP_->mapToStrings_ !=
377  TableViewColumnInfo::DATATYPE_STRING_ALT_DEFAULT)
378  {
379  if(bitMapInfoP_->floatingPoint_)
380  {
381  __SS__ << "Illegal Bit-Map data parameters for column " << name_
382  << " - if floating point is allowed, then Value Map to Strings "
383  "must be empty or set to '"
384  << TableViewColumnInfo::DATATYPE_STRING_DEFAULT << ".' "
385  << "Please disable floating point or clear the Value Map to "
386  "Strings value."
387  << std::endl;
388  __SS_THROW__;
389  }
390  bitMapInfoP_->mapsToStrings_ = true;
391  }
392  else
393  bitMapInfoP_->mapsToStrings_ = false;
394  }
395 } //end extractBitMapInfo()
396 
397 //==============================================================================
399 TableViewColumnInfo::TableViewColumnInfo(void) {}
400 
401 //==============================================================================
402 TableViewColumnInfo::TableViewColumnInfo(
403  const TableViewColumnInfo& c) // copy constructor because of bitmap pointer
404  : type_(c.type_)
405  , name_(c.name_)
406  , storageName_(c.storageName_)
407  , dataType_(c.dataType_)
408  , defaultValue_(c.defaultValue_)
409  , dataChoices_(c.dataChoices_)
410  , minValue_(c.minValue_)
411  , maxValue_(c.maxValue_)
412  , bitMapInfoP_(nullptr)
413 {
414  // extract bitmap info if necessary
415  extractBitMapInfo();
416 } // end copy constructor
417 
418 //==============================================================================
420  const TableViewColumnInfo&) // assignment operator because of bitmap pointer
421 {
422  __COUT__ << "OPERATOR= COPY CONSTRUCTOR " << std::endl;
423  // Note: Members of the ConfigurationTree are declared constant.
424  // (Refer to comments at top of class declaration for solutions)
425  // So this operator cannot work.. SO I am going to crash just in case it is
426  // called by mistake
427  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
428  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
429  "and initialize another TableViewColumnInfo, rather than assigning to "
430  "an existing TableViewColumnInfo. Crashing now."
431  << std::endl;
432  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
433  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
434  "and initialize another TableViewColumnInfo, rather than assigning to "
435  "an existing TableViewColumnInfo. Crashing now."
436  << std::endl;
437  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
438  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
439  "and initialize another TableViewColumnInfo, rather than assigning to "
440  "an existing TableViewColumnInfo. Crashing now."
441  << std::endl;
442  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
443  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
444  "and initialize another TableViewColumnInfo, rather than assigning to "
445  "an existing TableViewColumnInfo. Crashing now."
446  << std::endl;
447  __COUT__ << "OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
448  "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
449  "and initialize another TableViewColumnInfo, rather than assigning to "
450  "an existing TableViewColumnInfo. Crashing now."
451  << std::endl;
452 
453  __COUT__ << StringMacros::stackTrace() << __E__;
454  exit(0);
455  // TableViewColumnInfo* retColInfo = new TableViewColumnInfo();
456  // retColInfo->type_ = c.type_;
457  // retColInfo->name_ = c.name_;
458  // retColInfo->storageName_ = c.storageName_;
459  // retColInfo->dataType_ = c.dataType_;
460  // retColInfo->dataChoices_ = c.dataChoices_;
461  // retColInfo->bitMapInfoP_ = 0;
462 
463  // extract bitmap info if necessary
464  // retColInfo->extractBitMapInfo();
465 
466  extractBitMapInfo();
467  return *this; //*retColInfo;
468 } // end assignment operator
469 
470 //==============================================================================
471 TableViewColumnInfo::~TableViewColumnInfo(void)
472 {
473  if(bitMapInfoP_)
474  delete bitMapInfoP_;
475 } //end destructor
476 
477 //==============================================================================
478 const std::string& TableViewColumnInfo::getType(void) const { return type_; }
479 
480 //==============================================================================
482 const std::string& TableViewColumnInfo::getDefaultValue(void) const
483 {
484  return defaultValue_;
485 }
486 const std::string& TableViewColumnInfo::getMinValue(void) const { return minValue_; }
487 const std::string& TableViewColumnInfo::getMaxValue(void) const { return maxValue_; }
488 
489 //==============================================================================
493  const std::string& type, const std::string& dataType)
494 {
495  if(dataType == TableViewColumnInfo::DATATYPE_STRING)
496  {
497  if(type == TableViewColumnInfo::TYPE_ON_OFF ||
498  type == TableViewColumnInfo::TYPE_TRUE_FALSE ||
499  type == TableViewColumnInfo::TYPE_YES_NO)
500  return (
501  TableViewColumnInfo::DATATYPE_BOOL_DEFAULT); // default to OFF, NO, FALSE
502  else if(TableViewColumnInfo::isChildLink(type)) // call static version
503  return (TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
504  else if(type == TableViewColumnInfo::TYPE_COMMENT)
505  return (TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
506  else
507  return (TableViewColumnInfo::DATATYPE_STRING_DEFAULT);
508  }
509  else if(dataType == TableViewColumnInfo::DATATYPE_NUMBER)
510  return (TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
511  else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
512  return (TableViewColumnInfo::DATATYPE_TIME_DEFAULT);
513  else
514  {
515  __SS__ << "\tUnrecognized View data type: " << dataType << std::endl;
516  __COUT_ERR__ << "\n" << ss.str();
517  __SS_THROW__;
518  }
519 } // end getDefaultDefaultValue()
520 
521 //==============================================================================
523 const std::string& TableViewColumnInfo::getMinDefaultValue(const std::string& dataType)
524 {
525  if(dataType == TableViewColumnInfo::DATATYPE_STRING)
526  return (TableViewColumnInfo::
527  DATATYPE_NUMBER_MIN_DEFAULT); // default to OFF, NO, FALSE
528 
529  else if(dataType == TableViewColumnInfo::DATATYPE_NUMBER)
530  {
531  return (TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT);
532  }
533 
534  else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
535  return (TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT);
536  else
537  {
538  __SS__ << "\tUnrecognized View data type: " << dataType << std::endl;
539  __COUT_ERR__ << "\n" << ss.str();
540  __SS_THROW__;
541  }
542 }
543 
544 //==============================================================================
546 const std::string& TableViewColumnInfo::getMaxDefaultValue(const std::string& dataType)
547 {
548  if(dataType == TableViewColumnInfo::DATATYPE_STRING)
549  return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
550 
551  else if(dataType == TableViewColumnInfo::DATATYPE_NUMBER)
552  {
553  return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
554  }
555  else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
556  return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
557  else
558  {
559  __SS__ << "\tUnrecognized View data type: " << dataType << std::endl;
560  __COUT_ERR__ << "\n" << ss.str();
561  __SS_THROW__;
562  }
563 }
564 
565 //==============================================================================
566 std::vector<std::string> TableViewColumnInfo::getAllTypesForGUI(void)
567 {
568  std::vector<std::string> all;
569  all.push_back(TYPE_DATA);
570  all.push_back(TYPE_UNIQUE_DATA);
571  all.push_back(TYPE_UNIQUE_GROUP_DATA);
572  all.push_back(TYPE_FIXED_CHOICE_DATA);
573  all.push_back(TYPE_MULTILINE_DATA);
574  all.push_back(TYPE_BITMAP_DATA);
575  all.push_back(TYPE_ON_OFF);
576  all.push_back(TYPE_TRUE_FALSE);
577  all.push_back(TYPE_YES_NO);
578  all.push_back(TYPE_START_CHILD_LINK_UID);
579  all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
580  all.push_back(TYPE_START_CHILD_LINK);
581  all.push_back(TYPE_START_GROUP_ID);
582  return all;
583 } // end getAllTypesForGUI()
584 
585 //==============================================================================
586 std::vector<std::string> TableViewColumnInfo::getAllDataTypesForGUI(void)
587 {
588  std::vector<std::string> all;
589  all.push_back(DATATYPE_STRING);
590  all.push_back(DATATYPE_NUMBER);
591  all.push_back(DATATYPE_TIME);
592  return all;
593 }
594 
595 //==============================================================================
597 std::map<std::pair<std::string, std::string>, std::string>
599 {
600  std::map<std::pair<std::string, std::string>, std::string> all;
601  all[std::pair<std::string, std::string>(DATATYPE_NUMBER, "*")] =
602  DATATYPE_NUMBER_DEFAULT;
603  all[std::pair<std::string, std::string>(DATATYPE_TIME, "*")] = DATATYPE_TIME_DEFAULT;
604 
605  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_ON_OFF)] =
606  DATATYPE_BOOL_DEFAULT;
607  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_TRUE_FALSE)] =
608  DATATYPE_BOOL_DEFAULT;
609  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_YES_NO)] =
610  DATATYPE_BOOL_DEFAULT;
611 
612  all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_START_CHILD_LINK)] =
613  DATATYPE_LINK_DEFAULT;
614  all[std::pair<std::string, std::string>(DATATYPE_STRING, "*")] =
615  DATATYPE_STRING_DEFAULT;
616  return all;
617 }
619 //==============================================================================
622 {
623  return (type_ == TYPE_ON_OFF || type_ == TYPE_TRUE_FALSE || type_ == TYPE_YES_NO);
624 } // end isBoolType()
625 
626 //==============================================================================
629 {
630  return (dataType_ == DATATYPE_NUMBER);
631 } // end isBoolType()
632 
633 //==============================================================================
634 const std::string& TableViewColumnInfo::getName(void) const { return name_; }
635 
636 //==============================================================================
637 const std::string& TableViewColumnInfo::getStorageName(void) const
638 {
639  return storageName_;
640 }
641 
642 //==============================================================================
643 const std::string& TableViewColumnInfo::getDataType(void) const { return dataType_; }
644 
645 //==============================================================================
646 const std::vector<std::string>& TableViewColumnInfo::getDataChoices(void) const
647 {
648  return dataChoices_;
649 }
650 
651 //==============================================================================
655 {
656  if(bitMapInfoP_)
657  return *bitMapInfoP_;
658 
659  // throw error at this point!
660  {
661  __SS__ << "getBitMapInfo request for non-BitMap column of type: " << getType()
662  << std::endl;
663  __COUT_ERR__ << "\n" << ss.str();
664  __SS_THROW__;
665  }
666 }
667 
668 //==============================================================================
672 bool TableViewColumnInfo::isChildLink(const std::string& type)
673 {
674  return (type.find(TYPE_START_CHILD_LINK) == 0 &&
675  type.length() > TYPE_START_CHILD_LINK.length() &&
676  type[TYPE_START_CHILD_LINK.length()] == '-');
677 }
678 
679 //==============================================================================
684 {
685  return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
686  type_.length() > TYPE_START_CHILD_LINK.length() &&
687  type_[TYPE_START_CHILD_LINK.length()] == '-');
688 }
689 
690 //==============================================================================
695 {
696  return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
697  type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
698  type_[TYPE_START_CHILD_LINK_UID.length()] == '-');
699 }
700 
701 //==============================================================================
706 {
707  return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
708  type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
709  type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] == '-');
710 }
711 
712 //==============================================================================
717 {
718  return (type_.find(TYPE_START_GROUP_ID) == 0 &&
719  type_.length() > TYPE_START_GROUP_ID.length() &&
720  type_[TYPE_START_GROUP_ID.length()] == '-');
721 }
722 
723 //==============================================================================
725 bool TableViewColumnInfo::isUID(void) const { return (type_ == TYPE_UID); }
726 
727 //==============================================================================
730 {
731  // note: +1 to skip '-'
732  if(isChildLink())
733  return type_.substr(TYPE_START_CHILD_LINK.length() + 1);
734  else if(isChildLinkUID())
735  return type_.substr(TYPE_START_CHILD_LINK_UID.length() + 1);
736  else if(isChildLinkGroupID())
737  return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length() + 1);
738  else if(isGroupID())
739  return type_.substr(TYPE_START_GROUP_ID.length() + 1);
740  else
741  {
742  __SS__
743  << ("Requesting a Link Index from a column that is not a child link member!")
744  << std::endl;
745  __COUT_ERR__ << ss.str();
746  __SS_THROW__;
747  }
748 }
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 & getDefaultDefaultValue(const std::string &type, const std::string &dataType)
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
const std::string & getDefaultValue(void) const
returns the configued default value value for this particular column
defines used also by OtsConfigurationWizardSupervisor
static std::string decodeURIComponent(const std::string &data)
static std::string stackTrace(void)
< uses dataChoices CSV fields if type is TYPE_BITMAP_DATA