evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvioDictionaryEntry.h
Go to the documentation of this file.
1 //
2 // Copyright 2020, Jefferson Science Associates, LLC.
3 // Subject to the terms in the LICENSE file found in the top-level directory.
4 //
5 // EPSCI Group
6 // Thomas Jefferson National Accelerator Facility
7 // 12000, Jefferson Ave, Newport News, VA 23606
8 // (757)-269-7100
9 
10 
11 #ifndef EVIO_6_0_EVIODICTIONARYENTRY_H
12 #define EVIO_6_0_EVIODICTIONARYENTRY_H
13 
14 
15 #include <sstream>
16 #include <memory>
17 
18 
19 #include "DataType.h"
20 
21 
22 namespace evio {
23 
24 
31 
32  friend class EvioXMLDictionary;
33 
34  public:
35 
42  TAG_NUM = 0,
44  TAG_ONLY = 1,
47  };
48 
49  private:
50 
52  uint16_t tag= 0;
53 
56  uint16_t tagEnd = 0;
57 
59  uint8_t num = 0;
60 
62  bool numValid = false;
63 
66 
68  std::string format = "";
69 
71  std::string description = "";
72 
74  EvioDictionaryEntryType entryType = TAG_NUM;
75 
79  std::shared_ptr<EvioDictionaryEntry> parentEntry = nullptr;
80 
81 
82 
83 
85  EvioDictionaryEntry() = default;
86 
87 
120  EvioDictionaryEntry(uint16_t tag, uint8_t num, uint16_t tagEnd, bool numValid,
121  DataType const & type, std::string const & description, std::string const & format,
122  std::shared_ptr<EvioDictionaryEntry> parent) {
123 
124  bool isRange = true;
125 
126  if (tagEnd == tag || tagEnd == 0) {
127  // If both values equal each other or tagEnd == 0, there is no range.
128  this->tag = tag;
129  this->tagEnd = 0;
130  isRange = false;
131  }
132  else if (tagEnd < tag) {
133  // Switch things so tag < tagEnd for simplicity
134  this->tag = tagEnd;
135  this->tagEnd = tag;
136  }
137  else {
138  this->tag = tag;
139  this->tagEnd = tagEnd;
140  }
141 
142  this->num = num;
143  this->numValid = numValid;
144  this->format = format;
145  this->description = description;
146  this->type = type;
147 
148  if (!isRange) {
149  if (numValid) {
150  entryType = EvioDictionaryEntryType::TAG_NUM;
151  }
152  else {
153  entryType = EvioDictionaryEntryType::TAG_ONLY;
154  }
155  }
156  else {
157  entryType = EvioDictionaryEntryType::TAG_RANGE;
158  }
159 
160  parentEntry = parent;
161  }
162 
163 
164  public:
165 
166 
175  EvioDictionaryEntry(uint16_t tag, uint8_t num, DataType const & type) :
176  EvioDictionaryEntry(tag, num, 0, true, type,
177  "", "", nullptr) {
178  }
179 
180 
196  explicit EvioDictionaryEntry(uint16_t tag, uint16_t tagEnd = 0,
197  DataType const & type = DataType::UNKNOWN32,
198  std::string const & description = "", std::string const & format = "",
199  std::shared_ptr<EvioDictionaryEntry> parent = nullptr) :
200 
201  EvioDictionaryEntry(tag, 0, tagEnd, false, type, description, format, parent) {
202  }
203 
219  explicit EvioDictionaryEntry(uint16_t tag, uint8_t num, uint16_t tagEnd = 0,
220  DataType const & type = DataType::UNKNOWN32,
221  std::string const & description = "", std::string const & format = "",
222  std::shared_ptr<EvioDictionaryEntry> parent = nullptr) :
223 
224  EvioDictionaryEntry(tag, num, tagEnd, true, type, description, format, parent) {
225  }
226 
227 
234  bool inRange(uint16_t tagArg) const {
235  return tagEnd != 0 && tagArg >= tag && tagArg <= tagEnd;
236  }
237 
238 
246  bool inRange(EvioDictionaryEntry & entry) const {
247  return tagEnd != 0 && entry.tag >= tag && entry.tag <= tagEnd;
248  }
249 
250 
251  bool operator==(const EvioDictionaryEntry &other) const {
252 
253  if (&other == this) return true;
254 
255  // Objects equal each other if tag & num & tagEnd are the same
256  auto otherParent = other.getParentEntry();
257 
258  bool match = (tag == other.tag);
259  match = match && (numValid == other.numValid);
260 
261  if (numValid) {
262  match = match && (num == other.num);
263  }
264 
265  // Now check tag range if any
266  match = match && (tagEnd == other.tagEnd);
267 
268  // Now check if same entry type
269  match = match && (entryType == other.entryType);
270 
271  // If both parent containers are defined, use them as well
272  if (parentEntry != nullptr && otherParent != nullptr) {
273  match = match && (parentEntry->getTag() == otherParent->getTag());
274  match = match && (parentEntry->numValid == otherParent->numValid);
275  if (parentEntry->numValid) {
276  match = match && (parentEntry->getNum() == otherParent->getNum());
277  }
278  match = match && (parentEntry->getTagEnd() == otherParent->getTagEnd());
279  if (!match) std::cout << " parents don't match" << std::endl;
280  }
281 
282  return match;
283  }
284 
285  bool operator!=(const EvioDictionaryEntry &rhs) const {
286  return !(rhs == *this);
287  }
288 
289 
294  std::string toString() const {
295  std::stringstream ss;
296 
297  switch (entryType) {
298  case TAG_NUM:
299  ss << "(tag=" << tag << ",num =" << +num << ")" ;
300  break;
301  case TAG_ONLY:
302  ss << "(tag=" << tag << ")" ;
303  break;
304  case TAG_RANGE:
305  ss << "(tag=" << tag << "-" << tagEnd << ")" ;
306  }
307 
308  return ss.str();
309  }
310 
311 
317  uint16_t getTag() const {return tag;}
318 
324  uint16_t getTagEnd() const {return tagEnd;}
325 
330  uint8_t getNum() const {return num;}
331 
336  DataType getType() const {return type;}
337 
342  std::string getFormat() const {return format;}
343 
348  std::string getDescription() const {return description;}
349 
354  EvioDictionaryEntryType getEntryType() const {return entryType;}
355 
360  std::shared_ptr<EvioDictionaryEntry> getParentEntry() const {return parentEntry;}
361 
366  std::string toString() {
367 
368  std::stringstream ss;
369 
370  ss << std::boolalpha;
371 
372  ss << "tag = " << tag << ", tagEnd = " << tagEnd << ", num = " << +num << ", numValid = " << numValid <<
373  ", data type = " << type.toString();
374 
375  if (entryType == TAG_NUM)
376  ss << ", entry type = TAG/NUM";
377  else if (entryType == TAG_ONLY)
378  ss << ", entry type = TAG_ONLY";
379  else if (entryType == TAG_RANGE)
380  ss << ", entry type = TAG_RANGE";
381 
382  ss << std::endl;
383 
384  if (!format.empty()) {
385  ss << " format = " << format << std::endl;
386  }
387 
388  if (!description.empty()) {
389  ss << " description = " << description << std::endl;
390  }
391 
392  if (parentEntry != nullptr) {
393  ss << " parent = " << parentEntry->toString() << std::endl;
394  }
395 
396  return ss.str();
397  }
398 
399  };
400 
401 
402 }
403 
404 #endif //EVIO_6_0_EVIODICTIONARYENTRY_H
std::string toString()
Get the string representation of this object.
Definition: EvioDictionaryEntry.h:366
std::string getDescription() const
Get the CompositeData&#39;s description.
Definition: EvioDictionaryEntry.h:348
DataType getType() const
Get the data&#39;s type.
Definition: EvioDictionaryEntry.h:336
EvioDictionaryEntry(uint16_t tag, uint16_t tagEnd=0, DataType const &type=DataType::UNKNOWN32, std::string const &description="", std::string const &format="", std::shared_ptr< EvioDictionaryEntry > parent=nullptr)
Constructor containing actual implementation.
Definition: EvioDictionaryEntry.h:196
EvioDictionaryEntryType getEntryType() const
Get this entry&#39;s type.
Definition: EvioDictionaryEntry.h:354
EvioDictionaryEntry(uint16_t tag, uint8_t num, DataType const &type)
Constructor.
Definition: EvioDictionaryEntry.h:175
EvioDictionaryEntry(uint16_t tag, uint8_t num, uint16_t tagEnd=0, DataType const &type=DataType::UNKNOWN32, std::string const &description="", std::string const &format="", std::shared_ptr< EvioDictionaryEntry > parent=nullptr)
Constructor containing actual implementation.
Definition: EvioDictionaryEntry.h:219
std::shared_ptr< EvioDictionaryEntry > getParentEntry() const
Get the parent container&#39;s dictionary entry.
Definition: EvioDictionaryEntry.h:360
bool operator==(const EvioDictionaryEntry &other) const
Definition: EvioDictionaryEntry.h:251
Valid tag and tagEnd, but no num.
Definition: EvioDictionaryEntry.h:46
std::string toString() const
Get a string representation of this object.
Definition: EvioDictionaryEntry.h:294
Valid tag &amp; num, with or without a tagEnd.
Definition: EvioDictionaryEntry.h:42
uint8_t getNum() const
Get the num value.
Definition: EvioDictionaryEntry.h:330
bool inRange(EvioDictionaryEntry &entry) const
Is the given dictionary entry&#39;s tag within the specified range (inclusive) of this dictionary entry...
Definition: EvioDictionaryEntry.h:246
Valid tag, but no num or tagEnd.
Definition: EvioDictionaryEntry.h:44
uint16_t getTagEnd() const
Get the tagEnd value (upper end of a tag range).
Definition: EvioDictionaryEntry.h:324
bool inRange(uint16_t tagArg) const
Is the given tag within the specified range (inclusive) of this dictionary entry? ...
Definition: EvioDictionaryEntry.h:234
Numerical values associated with evio data types.
Definition: DataType.h:32
bool operator!=(const EvioDictionaryEntry &rhs) const
Definition: EvioDictionaryEntry.h:285
uint16_t getTag() const
Get the tag value.
Definition: EvioDictionaryEntry.h:317
static const DataType UNKNOWN32
Unknown data type.
Definition: DataType.h:36
This was developed to read the xml dictionary that Maurizio uses for GEMC.
Definition: EvioXMLDictionary.h:55
EvioDictionaryEntryType
Type of dictionary entry.
Definition: EvioDictionaryEntry.h:40
std::string getFormat() const
Get the CompositeData&#39;s format.
Definition: EvioDictionaryEntry.h:342
Class to facilitate use of Evio XML dictionary entry data as a key or value in a hash table...
Definition: EvioDictionaryEntry.h:30