F´ Flight Software - C/C++ Documentation  devel
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 
4 #include <FpConfig.hpp>
5 #include <Fw/Cfg/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 #if FW_HAS_F64
66  PolyType(F64 val);
67  operator F64();
68  void get(F64& val);
69  bool isF64();
70  PolyType& operator=(F64 val);
71 #endif
72  PolyType(F32 val);
73  operator F32();
74  void get(F32& val);
75  bool isF32();
76  PolyType& operator=(F32 val);
77 
78  PolyType(bool val);
79  operator bool();
80  void get(bool& val);
81  bool isBool();
82  PolyType& operator=(bool val);
83 
84  PolyType(void* val);
85  operator void*();
86  void get(void*& val);
87  bool isPtr();
88  PolyType& operator=(void* val);
89 
90  PolyType();
91  PolyType(const PolyType& original);
92  virtual ~PolyType();
93 
94 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
95  void toString(StringBase& dest, bool append) const;
96  void toString(StringBase& dest) const;
97 #endif
98 
99  PolyType& operator=(const PolyType& src);
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;
105  bool operator!=(const PolyType& other) const;
108 
109  PRIVATE:
110  typedef enum {
111  TYPE_NOTYPE, // !< No type stored yet
112  TYPE_U8, // !< U8 type stored
113  TYPE_I8, // !< I8 type stored
114 #if FW_HAS_16_BIT
115  TYPE_U16, // !< U16 type stored
116  TYPE_I16, // !< I16 type stored
117 #endif
118 #if FW_HAS_32_BIT
119  TYPE_U32, // !< U32 type stored
120  TYPE_I32, // !< I32 type stored
121 #endif
122 #if FW_HAS_64_BIT
123  TYPE_U64, // !< U64 type stored
124  TYPE_I64, // !< I64 type stored
125 #endif
126  TYPE_F32, // !< F32 type stored
127 #if FW_HAS_F64
128  TYPE_F64, // !< F64 type stored
129 #endif
130  TYPE_BOOL, // !< bool type stored
131  TYPE_PTR // !< pointer type stored
132  } Type;
133 
134  Type m_dataType;
135 
136  union PolyVal {
137  U8 u8Val;
138  I8 i8Val;
139 #if FW_HAS_16_BIT
140  U16 u16Val;
141  I16 i16Val;
142 #endif
143 #if FW_HAS_32_BIT
144  U32 u32Val;
145  I32 i32Val;
146 #endif
147 #if FW_HAS_64_BIT
148  U64 u64Val;
149  I64 i64Val;
150 #endif
151 #if FW_HAS_F64
152  F64 f64Val;
153 #endif
154  F32 f32Val; // !< F32 data storage
155  void* ptrVal; // !< pointer data storage
156  bool boolVal; // !< bool data storage
157  } m_val; // !< stores data value
158 
159  public:
160  enum {
162  SERIALIZED_SIZE = sizeof(FwEnumStoreType) + sizeof(PolyVal)
163  };
164 };
165 
166 } // namespace Fw
167 
168 #endif
int8_t I8
8-bit signed integer
Definition: BasicTypes.h:25
float F32
32-bit floating point
Definition: BasicTypes.h:45
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
I32 FwEnumStoreType
Definition: FpConfig.h:51
C++-compatible configuration header for fprime configuration.
Definitions for ISF type serial IDs.
bool isBool()
bool checker
Definition: PolyType.cpp:307
bool operator<(const PolyType &other) const
PolyType operator<.
Definition: PolyType.cpp:418
bool operator>=(const PolyType &other) const
PolyType operator>=.
Definition: PolyType.cpp:483
bool isPtr()
void* checker
Definition: PolyType.cpp:332
bool operator>(const PolyType &other) const
PolyType operator>
Definition: PolyType.cpp:479
@ SERIALIZED_SIZE
stored serialized size
Definition: PolyType.hpp:162
@ SERIALIZED_TYPE_ID
typeid for PolyType
Definition: PolyType.hpp:161
bool operator==(const PolyType &other) const
PolyType operator==.
Definition: PolyType.cpp:359
PolyType()
default constructor
Definition: PolyType.cpp:10
SerializeStatus deserialize(SerializeBufferBase &buffer)
Deserialize function.
Definition: PolyType.cpp:552
SerializeStatus serialize(SerializeBufferBase &buffer) const
Serialize function.
Definition: PolyType.cpp:491
bool operator<=(const PolyType &other) const
PolyType operator<=.
Definition: PolyType.cpp:487
bool operator!=(const PolyType &other) const
PolyType operator!=.
Definition: PolyType.cpp:355
PolyType & operator=(U8 val)
U8 operator=.
Definition: PolyType.cpp:33
bool isU8()
U8 checker.
Definition: PolyType.cpp:29
virtual ~PolyType()
destructor
Definition: PolyType.cpp:347
bool isI8()
I8 checker.
Definition: PolyType.cpp:56
bool isF32()
F32 checker.
Definition: PolyType.cpp:282
void get(U8 &val)
U8 accessor.
Definition: PolyType.cpp:24
forward declaration
@ FW_TYPEID_POLY
PolyType serialized type id.
Definition: SerIds.hpp:41
SerializeStatus
forward declaration for string
#define U64(C)
Definition: sha.h:176