-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathPrimitiveArrayArrayAc.ref.cpp
More file actions
219 lines (186 loc) · 4.74 KB
/
PrimitiveArrayArrayAc.ref.cpp
File metadata and controls
219 lines (186 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// ======================================================================
// \title PrimitiveArrayArrayAc.cpp
// \author Generated by fpp-to-cpp
// \brief cpp file for PrimitiveArray array
// ======================================================================
#include "Fw/Types/Assert.hpp"
#include "PrimitiveArrayArrayAc.hpp"
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
PrimitiveArray ::
PrimitiveArray() :
Serializable(),
elements()
{
}
PrimitiveArray ::
PrimitiveArray(const ElementType (&a)[SIZE]) :
Serializable()
{
*this = a;
}
PrimitiveArray ::
PrimitiveArray(const ElementType& e) :
Serializable()
{
*this = e;
}
PrimitiveArray ::
PrimitiveArray(const std::initializer_list<ElementType>& il) :
Serializable()
{
*this = il;
}
PrimitiveArray ::
PrimitiveArray(const PrimitiveArray& obj) :
Serializable()
{
*this = obj;
}
// ----------------------------------------------------------------------
// Operators
// ----------------------------------------------------------------------
PrimitiveArray::ElementType& PrimitiveArray ::
operator[](const FwSizeType i)
{
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
return this->elements[i];
}
const PrimitiveArray::ElementType& PrimitiveArray ::
operator[](const FwSizeType i) const
{
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
return this->elements[i];
}
PrimitiveArray& PrimitiveArray ::
operator=(const PrimitiveArray& obj)
{
if (this != &obj) {
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = obj.elements[index];
}
}
return *this;
}
PrimitiveArray& PrimitiveArray ::
operator=(const ElementType (&a)[SIZE])
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = a[index];
}
return *this;
}
PrimitiveArray& PrimitiveArray ::
operator=(const std::initializer_list<ElementType>& il)
{
// Check that the initializer has the expected size
FW_ASSERT(il.size() == SIZE, static_cast<FwAssertArgType>(il.size()), static_cast<FwAssertArgType>(SIZE));
FwSizeType i = 0;
for (const auto& e : il) {
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
this->elements[i] = e;
i++;
}
return *this;
}
PrimitiveArray& PrimitiveArray ::
operator=(const ElementType& e)
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = e;
}
return *this;
}
bool PrimitiveArray ::
operator==(const PrimitiveArray& obj) const
{
for (FwSizeType index = 0; index < SIZE; index++) {
if (!((*this)[index] == obj[index])) {
return false;
}
}
return true;
}
bool PrimitiveArray ::
operator!=(const PrimitiveArray& obj) const
{
return !(*this == obj);
}
#ifdef BUILD_UT
std::ostream& operator<<(std::ostream& os, const PrimitiveArray& obj) {
os << "[";
constexpr auto SIZE = PrimitiveArray::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}
os << obj.elements[index];
}
os << "]";
return os;
}
#endif
// ----------------------------------------------------------------------
// Public member functions
// ----------------------------------------------------------------------
Fw::SerializeStatus PrimitiveArray ::
serializeTo(
Fw::SerialBufferBase& buffer,
Fw::Endianness mode
) const
{
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
for (FwSizeType index = 0; index < SIZE; index++) {
status = buffer.serializeFrom((*this)[index], mode);
if (status != Fw::FW_SERIALIZE_OK) {
return status;
}
}
return status;
}
Fw::SerializeStatus PrimitiveArray ::
deserializeFrom(
Fw::SerialBufferBase& buffer,
Fw::Endianness mode
)
{
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
for (FwSizeType index = 0; index < SIZE; index++) {
status = buffer.deserializeTo((*this)[index], mode);
if (status != Fw::FW_SERIALIZE_OK) {
return status;
}
}
return status;
}
FwSizeType PrimitiveArray ::
serializedSize() const
{
FwSizeType size = 0;
for (FwSizeType index = 0; index < SIZE; index++) {
size += this->elements[index].serializedSize();
}
return size;
}
#if FW_SERIALIZABLE_TO_STRING
void PrimitiveArray ::
toString(Fw::StringBase& sb) const
{
// Clear the output string
sb = "";
// Array prefix
sb += "[ ";
for (FwSizeType index = 0; index < SIZE; index++) {
// Array data
Fw::String tmp;
this->elements[index].toString(tmp);
if (index > 0) {
sb += ", ";
}
sb += tmp;
}
// Array suffix
sb += " ]";
}
#endif