evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DataType.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_DATATYPE_H
12 #define EVIO_6_0_DATATYPE_H
13 
14 
15 #include <string>
16 
17 
18 namespace evio {
19 
20 
32  class DataType {
33 
34  public:
35 
36  static const DataType UNKNOWN32;
37  static const DataType UINT32;
38  static const DataType FLOAT32;
39  static const DataType CHARSTAR8;
40  static const DataType SHORT16;
41  static const DataType USHORT16;
42  static const DataType CHAR8;
43  static const DataType UCHAR8;
44  static const DataType DOUBLE64;
45  static const DataType LONG64;
46  static const DataType ULONG64;
47  static const DataType INT32;
48  static const DataType TAGSEGMENT;
49  static const DataType ALSOSEGMENT;
50  static const DataType ALSOBANK;
51  static const DataType COMPOSITE;
52  static const DataType BANK;
53  static const DataType SEGMENT;
54 
55  // These types are only used when dealing with COMPOSITE data.
56  // They are never transported independently and are stored in integers.
57  static const DataType HOLLERIT;
58  static const DataType NVALUE;
59  static const DataType nVALUE;
60  static const DataType mVALUE;
61 
62  // In C++ this seems to be useful on occasion
63  static const DataType NOT_A_VALID_TYPE;
64 
65 
66  private:
67 
69  uint32_t value;
70 
72  std::string name;
73 
75  int bytes;
76 
77  private:
78 
80  static DataType intToType[37]; // min size -> 37 = 0x24 + 1
81 
83  static std::string names[37];
84 
91  DataType(uint32_t val, std::string name, int byteLen = -1) : value(val), name(std::move(name)), bytes(byteLen) {}
92 
93  public:
94 
100  static const DataType & getDataType(uint32_t val) {
101  if (val > 0x24 || (val > 0x10 && val < 0x20)) return UNKNOWN32;
102  return intToType[val];
103  }
104 
110  static std::string getName(uint32_t val) {
111  if (val > 0x24 || (val > 0x10 && val < 0x20)) return "UNKNOWN32";
112  return getDataType(val).names[val];
113  }
114 
121  static DataType valueOf(std::string const & typeName) {
122  int index = 0;
123  for (std::string const & name : names) {
124  if (name == typeName) {
125  return intToType[index];
126  }
127  index++;
128  }
129  return DataType::UNKNOWN32;
130  }
131 
139  static bool isStructure(uint32_t dataType) {
140  return dataType == BANK.value || dataType == ALSOBANK.value ||
141  dataType == SEGMENT.value || dataType == ALSOSEGMENT.value ||
142  dataType == TAGSEGMENT.value;
143  }
144 
150  static bool isBank(uint32_t dataType) {
151  return (BANK.value == dataType || ALSOBANK.value == dataType);
152  }
153 
159  static bool isSegment(uint32_t dataType) {
160  return (SEGMENT.value == dataType || ALSOSEGMENT.value == dataType);
161  }
162 
168  static bool isTagSegment(uint32_t dataType) {
169  return (TAGSEGMENT.value == dataType);
170  }
171 
172 
173 
178  const std::string & getName() const {return name;}
179 
184  uint32_t getValue() const {return value;}
185 
193  std::string toString() const {
194  if (*this == ALSOBANK) return "BANK";
195  else if (*this == ALSOSEGMENT) return "SEGMENT";
196  return name;
197  }
198 
199 
205  bool isStructure() const {
206  return ((*this == BANK) ||
207  (*this == SEGMENT) ||
208  (*this == TAGSEGMENT) ||
209  (*this == ALSOBANK) ||
210  (*this == ALSOSEGMENT));
211  }
212 
217  bool isBank() const {return (*this == BANK || *this == ALSOBANK);}
218 
223  bool isSegment() const {return (*this == SEGMENT || *this == ALSOSEGMENT);}
224 
229  bool isTagSegment() const {return (*this == TAGSEGMENT);}
230 
236  bool isInteger() const {
237  return ((*this == UCHAR8) ||
238  (*this == CHAR8) ||
239  (*this == USHORT16) ||
240  (*this == SHORT16) ||
241  (*this == UINT32) ||
242  (*this == INT32) ||
243  (*this == ULONG64) ||
244  (*this == LONG64));
245  }
246 
251  int getBytes() const {return bytes;}
252 
253  bool operator==(const DataType &rhs) const;
254 
255  bool operator!=(const DataType &rhs) const;
256  };
257 
258 }
259 
260 
261 #endif //EVIO_6_0_DATATYPE_H
static const DataType ALSOBANK
Bank alternate value.
Definition: DataType.h:50
static const DataType LONG64
64 bit int.
Definition: DataType.h:45
static const DataType UCHAR8
Unsigned 8 bit int.
Definition: DataType.h:43
static const DataType INT32
32 bit int.
Definition: DataType.h:47
static const DataType NVALUE
In composite data, N value.
Definition: DataType.h:58
bool isSegment() const
Convenience routine to see if &quot;this&quot; data type is a segment structure.
Definition: DataType.h:223
static const DataType HOLLERIT
In composite data, Hollerit type.
Definition: DataType.h:57
uint32_t getValue() const
Get the integer value associated with this data type.
Definition: DataType.h:184
static const DataType SEGMENT
Segment.
Definition: DataType.h:53
std::string toString() const
Return a string which is usually the same as the name of the enumerated value, except in the cases of...
Definition: DataType.h:193
static const DataType CHARSTAR8
ASCII characters.
Definition: DataType.h:39
bool isStructure() const
Convenience routine to see if &quot;this&quot; data type is a structure (a container.)
Definition: DataType.h:205
bool isBank() const
Convenience routine to see if &quot;this&quot; data type is a bank structure.
Definition: DataType.h:217
static const DataType DOUBLE64
64 bit double.
Definition: DataType.h:44
static const DataType COMPOSITE
Composite data type.
Definition: DataType.h:51
bool isInteger() const
Convenience method to see if &quot;this&quot; data type is an integer of some kind - either 8...
Definition: DataType.h:236
int getBytes() const
Return the number of bytes this data type takes (if relevant).
Definition: DataType.h:251
static const DataType & getDataType(uint32_t val)
Get the object from the integer value.
Definition: DataType.h:100
static const DataType FLOAT32
32 bit float.
Definition: DataType.h:38
static const DataType NOT_A_VALID_TYPE
Not a valid data type.
Definition: DataType.h:63
static const DataType SHORT16
16 bit int.
Definition: DataType.h:40
const std::string & getName() const
Get the name associated with this data type.
Definition: DataType.h:178
static const DataType UINT32
Unsigned 32 bit int.
Definition: DataType.h:37
static const DataType BANK
Bank.
Definition: DataType.h:52
static const DataType CHAR8
8 bit int.
Definition: DataType.h:42
static const DataType ALSOSEGMENT
Segment alternate value.
Definition: DataType.h:49
Numerical values associated with evio data types.
Definition: DataType.h:32
static const DataType mVALUE
In composite data, m value.
Definition: DataType.h:60
static bool isStructure(uint32_t dataType)
Convenience method to see if the given integer arg represents a data type which is a structure (a con...
Definition: DataType.h:139
static bool isBank(uint32_t dataType)
Convenience method to see if the given integer arg represents a BANK.
Definition: DataType.h:150
bool operator!=(const DataType &rhs) const
Definition: DataType.cpp:21
static const DataType UNKNOWN32
Unknown data type.
Definition: DataType.h:36
static bool isTagSegment(uint32_t dataType)
Convenience method to see if the given integer arg represents a TAGSEGMENT.
Definition: DataType.h:168
static const DataType USHORT16
Unsigned 16 bit int.
Definition: DataType.h:41
bool isTagSegment() const
Convenience routine to see if &quot;this&quot; data type is a tagsegment structure.
Definition: DataType.h:229
static const DataType TAGSEGMENT
Tag segment.
Definition: DataType.h:48
static bool isSegment(uint32_t dataType)
Convenience method to see if the given integer arg represents a SEGMENT.
Definition: DataType.h:159
static const DataType nVALUE
In composite data, n value.
Definition: DataType.h:59
static const DataType ULONG64
Unsigned 64 bit int.
Definition: DataType.h:46
static DataType valueOf(std::string const &typeName)
Get the enum constant from a string.
Definition: DataType.h:121
bool operator==(const DataType &rhs) const
Definition: DataType.cpp:17
static std::string getName(uint32_t val)
Get the name from the integer value.
Definition: DataType.h:110