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