F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
PolyType.hpp
Go to the documentation of this file.
1 #ifndef FW_POLY_TYPE_HPP
2 #define FW_POLY_TYPE_HPP
3 
5 #include <Fw/Types/SerIds.hpp>
8 
9 namespace Fw {
10 
11 class PolyType : public Serializable {
12  public:
13  PolyType(U8 val);
14  operator U8();
15  void get(U8& val);
16  bool isU8();
17  PolyType& operator=(U8 val);
18 
19  PolyType(I8 val);
20  operator I8();
21  void get(I8& val);
22  bool isI8();
23  PolyType& operator=(I8 val);
24 
25 #if FW_HAS_16_BIT
26  PolyType(U16 val);
27  operator U16();
28  void get(U16& val);
29  bool isU16();
30  PolyType& operator=(U16 val);
31 
32  PolyType(I16 val);
33  operator I16();
34  void get(I16& val);
35  bool isI16();
36  PolyType& operator=(I16 val);
37 #endif
38 #if FW_HAS_32_BIT
39  PolyType(U32 val);
40  operator U32();
41  void get(U32& val);
42  bool isU32();
43  PolyType& operator=(U32 val);
44 
45  PolyType(I32 val);
46  operator I32();
47  void get(I32& val);
48  bool isI32();
49  PolyType& operator=(I32 val);
50 #endif
51 #if FW_HAS_64_BIT
52  PolyType(U64 val);
53  operator U64();
54  void get(U64& val);
55  bool isU64();
56  PolyType& operator=(U64 val);
57 
58  PolyType(I64 val);
59  operator I64();
60  void get(I64& val);
61  bool isI64();
62  PolyType& operator=(I64 val);
63 #endif
64 
65  PolyType(F64 val);
66  operator F64();
67  void get(F64& val);
68  bool isF64();
69  PolyType& operator=(F64 val);
70 
71  PolyType(F32 val);
72  operator F32();
73  void get(F32& val);
74  bool isF32();
75  PolyType& operator=(F32 val);
76 
77  PolyType(bool val);
78  operator bool();
79  void get(bool& val);
80  bool isBool();
81  PolyType& operator=(bool val);
82 
83  PolyType(void* val);
84  operator void*();
85  void get(void*& val);
86  bool isPtr();
87  PolyType& operator=(void* val);
88 
89  PolyType();
90  PolyType(const PolyType& original);
91  virtual ~PolyType();
92 
93 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
94  void toString(StringBase& dest, bool append) const;
95  void toString(StringBase& dest) const;
96 #endif
97 
98  PolyType& operator=(const PolyType& src);
99  bool operator<(const PolyType& other) const;
100  bool operator>(const PolyType& other) const;
101  bool operator>=(const PolyType& other) const;
102  bool operator<=(const PolyType& other) const;
103  bool operator==(const PolyType& other) const;
104  bool operator!=(const PolyType& other) const;
107 
108  PRIVATE:
109  typedef enum {
110  TYPE_NOTYPE, // !< No type stored yet
111  TYPE_U8, // !< U8 type stored
112  TYPE_I8, // !< I8 type stored
113 #if FW_HAS_16_BIT
114  TYPE_U16, // !< U16 type stored
115  TYPE_I16, // !< I16 type stored
116 #endif
117 #if FW_HAS_32_BIT
118  TYPE_U32, // !< U32 type stored
119  TYPE_I32, // !< I32 type stored
120 #endif
121 #if FW_HAS_64_BIT
122  TYPE_U64, // !< U64 type stored
123  TYPE_I64, // !< I64 type stored
124 #endif
125  TYPE_F32, // !< F32 type stored
126  TYPE_F64, // !< F64 type stored
127  TYPE_BOOL, // !< bool type stored
128  TYPE_PTR // !< pointer type stored
129  } Type;
130 
131  Type m_dataType;
132 
133  union PolyVal {
134  U8 u8Val;
135  I8 i8Val;
136 #if FW_HAS_16_BIT
137  U16 u16Val;
138  I16 i16Val;
139 #endif
140 #if FW_HAS_32_BIT
141  U32 u32Val;
142  I32 i32Val;
143 #endif
144 #if FW_HAS_64_BIT
145  U64 u64Val;
146  I64 i64Val;
147 #endif
148  F64 f64Val;
149  F32 f32Val; // !< F32 data storage
150  void* ptrVal; // !< pointer data storage
151  bool boolVal; // !< bool data storage
152  } m_val; // !< stores data value
153 
154  public:
155  enum {
157  SERIALIZED_SIZE = sizeof(FwEnumStoreType) + sizeof(PolyVal)
158  };
159 };
160 
161 } // namespace Fw
162 
163 #endif
bool isBool()
bool checker
Definition: PolyType.cpp:303
PolyType serialized type id.
Definition: SerIds.hpp:41
SerializeStatus serialize(SerializeBufferBase &buffer) const
Serialize function.
Definition: PolyType.cpp:483
I32 FwEnumStoreType
bool isI8()
I8 checker.
Definition: PolyType.cpp:55
PolyType()
default constructor
Definition: PolyType.cpp:9
bool isPtr()
void* checker
Definition: PolyType.cpp:328
int8_t I8
8-bit signed integer
Definition: BasicTypes.h:53
typeid for PolyType
Definition: PolyType.hpp:156
bool operator>=(const PolyType &other) const
PolyType operator>=.
Definition: PolyType.cpp:475
bool operator>(const PolyType &other) const
PolyType operator>
Definition: PolyType.cpp:471
Definitions for ISF type serial IDs.
SerializeStatus
forward declaration for string
float F32
32-bit floating point
Definition: BasicTypes.h:86
stored serialized size
Definition: PolyType.hpp:157
bool isU8()
U8 checker.
Definition: PolyType.cpp:28
bool operator<(const PolyType &other) const
PolyType operator<.
Definition: PolyType.cpp:412
bool operator<=(const PolyType &other) const
PolyType operator<=.
Definition: PolyType.cpp:479
virtual ~PolyType()
destructor
Definition: PolyType.cpp:343
bool isF64()
F64 checker.
Definition: PolyType.cpp:253
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:56
PolyType & operator=(U8 val)
U8 operator=.
Definition: PolyType.cpp:32
double F64
64-bit floating point (double). Required for compiler-supplied double promotion.
Definition: BasicTypes.h:88
forward declaration
SerializeStatus deserialize(SerializeBufferBase &buffer)
Deserialize function.
Definition: PolyType.cpp:542
bool isF32()
F32 checker.
Definition: PolyType.cpp:278
bool operator!=(const PolyType &other) const
PolyType operator!=.
Definition: PolyType.cpp:351
bool operator==(const PolyType &other) const
PolyType operator==.
Definition: PolyType.cpp:355
#define U64(C)
Definition: sha.h:180