CARMA C++
DataType.h
Go to the documentation of this file.
1 // $Id: DataType.h,v 1.4 2013/07/09 17:12:00 eml Exp $
2 
3 #ifndef SZA_UTIL_DATATYPE_H
4 #define SZA_UTIL_DATATYPE_H
5 
15 #include "carma/szaarrayutils/regmap.h"
16 #include "carma/szaarrayutils/regtemplate.h"
17 
18 #include "carma/szautil/Complex.h"
19 #include "carma/szautil/RegDate.h"
20 #include <ostream>
21 
22 namespace sza {
23  namespace util {
24 
28  class DataType {
29  public:
30 
31  enum Type {
32  NONE = 0x0,
33  UNKNOWN = 0x0,
34  UCHAR = 0x1,
35  CHAR = 0x2,
36  BOOL = 0x4,
37  USHORT = 0x8,
38  SHORT = 0x10,
39  UINT = 0x20,
40  INT = 0x40,
41  ULONG = 0x80,
42  LONG = 0x100,
43  FLOAT = 0x200,
44  DOUBLE = 0x400,
45  DATE = 0x800,
46  COMPLEX_FLOAT = 0x1000,
47 
48  // Not handled yet in this object, but included for
49  // compatibility with FITS format types
50 
51  COMPLEX_DOUBLE= 0x2000,
52  STRING = 0x4000,
53  CARMASTRING = 0x8000,
54  BITMASK = 0x10000,
55  };
56 
57 
58  DataType();
59  DataType(bool b);
60  DataType(unsigned char uc);
61  DataType(char ch);
62  DataType(unsigned short us);
63  DataType(short s);
64  DataType(unsigned int ui);
65  DataType(int i);
66  DataType(unsigned long ul);
67  DataType(long l);
68  DataType(float f);
69  DataType(double d);
70  DataType(sza::util::RegDate date);
71  DataType(sza::util::Complex<float> cf);
72 
73  virtual ~DataType();
74 
78  static unsigned sizeOf(Type type);
79 
84  static unsigned sizeOf(RegMapBlock* blk);
85 
89  static Type typeOf(RegMapBlock* blk);
90  static Type typeOf(RegBlockTemp* blk);
91 
96  static std::string carmaTypeString(RegMapBlock* blk);
97 
98  // Take the stored value and convert to the type corresponding
99  // to a register block
100 
101  void convertToTypeOf(RegMapBlock* blk);
102  double getValAsDouble();
103 
107  void operator=(bool b);
108  void operator=(unsigned char uc);
109  void operator=(char ch);
110  void operator=(unsigned short us);
111  void operator=(short s);
112  void operator=(unsigned int ui);
113  void operator=(int i);
114  void operator=(unsigned long ul);
115  void operator=(long l);
116  void operator=(float f);
117  void operator=(double d);
118  void operator=(sza::util::RegDate date);
119  void operator=(sza::util::Complex<float> cf);
120 
124  void operator=(bool* b);
125  void operator=(unsigned char* uc);
126  void operator=(char* ch);
127  void operator=(unsigned short* us);
128  void operator=(short* s);
129  void operator=(unsigned int* ui);
130  void operator=(int* i);
131  void operator=(unsigned long* ul);
132  void operator=(long* l);
133  void operator=(float* f);
134  void operator=(double* d);
135  void operator=(sza::util::RegDate* date);
136  void operator=(sza::util::Complex<float>* cf);
137 
138  void operator=(DataType& dataType);
139  void operator=(const DataType& dataType);
140 
141  void operator-=(DataType& dataType);
142 
143  bool operator==(DataType& dataType);
144  bool operator>(DataType& dataType);
145  bool operator>=(DataType& dataType);
146  bool operator<(DataType& dataType);
147  bool operator<=(DataType& dataType);
148 
149  void operator++();
150 
151  void convertToAbs();
152 
153  friend std::ostream& operator<<(std::ostream& os, DataType& dataType);
154  friend std::ostream& operator<<(std::ostream& os, DataType::Type type);
155 
159  void* data();
160 
161  // The actual data in this DataType will be stored as a union
162 
163  union {
164  bool b;
165  unsigned char uc;
166  char c;
167  unsigned short us;
168  short s;
169  unsigned int ui;
170  int i;
171  unsigned long ul;
172  long l;
173  float f;
174  double d;
175  sza::util::RegDate::Data date;
176  sza::util::Complex<float>::Data cf;
177  } data_;
178 
179  Type type_;
180 
181  void checkType(DataType& dataType);
182 
183  // True if we are indexing an array of data
184 
185  bool isArray_;
186 
187  // A void ptr to the array
188 
189  void* ptr_;
190 
191  // Overloaded utility methods
192 
193  static Type typeOf(bool* obj);
194  static Type typeOf(unsigned char* obj);
195  static Type typeOf(char* obj);
196  static Type typeOf(unsigned short* obj);
197  static Type typeOf(short* obj);
198  static Type typeOf(unsigned int* obj);
199  static Type typeOf(int* obj);
200  static Type typeOf(unsigned long* obj);
201  static Type typeOf(long* obj);
202  static Type typeOf(float* obj);
203  static Type typeOf(double* obj);
204  static Type typeOf(sza::util::RegDate* obj);
205  static Type typeOf(sza::util::Complex<float>* obj);
206  static Type typeOf(sza::util::RegDate::Data* obj);
207  static Type typeOf(sza::util::Complex<float>::Data* obj);
208 
209  }; // End class DataType
210 
211  } // End namespace util
212 } // End namespace sza
213 
214 
215 
216 
217 #endif // End #ifndef SZA_UTIL_DATATYPE_H
static Type typeOf(RegMapBlock *blk)
Return the data type of a block.
static unsigned sizeOf(Type type)
Return the size, in bytes, of the requested type.
static std::string carmaTypeString(RegMapBlock *blk)
Return the data type of a block as a string appropriate for the CARMA monitor system.
Tagged: Tue Oct 12 09:13:47 PDT 2004.
void * data()
Return a void ptr to the data for this data type.
void operator=(bool b)
Assignment operators.
Tagged: Tue Oct 12 10:25:49 PDT 2004.
Enumerate data types.
Definition: DataType.h:28