-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathAArrayAc.ref.cpp
More file actions
215 lines (182 loc) · 4.17 KB
/
AArrayAc.ref.cpp
File metadata and controls
215 lines (182 loc) · 4.17 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
// ======================================================================
// \title AArrayAc.cpp
// \author Generated by fpp-to-cpp
// \brief cpp file for A array
// ======================================================================
#include "AArrayAc.hpp"
#include "Fw/Types/Assert.hpp"
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
A ::
A() :
Serializable(),
elements()
{
}
A ::
A(const ElementType (&a)[SIZE]) :
Serializable()
{
*this = a;
}
A ::
A(const ElementType& e) :
Serializable()
{
*this = e;
}
A ::
A(const std::initializer_list<ElementType>& il) :
Serializable()
{
*this = il;
}
A ::
A(const A& obj) :
Serializable()
{
*this = obj;
}
// ----------------------------------------------------------------------
// Operators
// ----------------------------------------------------------------------
A::ElementType& A ::
operator[](const FwSizeType i)
{
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
return this->elements[i];
}
const A::ElementType& A ::
operator[](const FwSizeType i) const
{
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
return this->elements[i];
}
A& A ::
operator=(const A& obj)
{
if (this != &obj) {
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = obj.elements[index];
}
}
return *this;
}
A& A ::
operator=(const ElementType (&a)[SIZE])
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = a[index];
}
return *this;
}
A& A ::
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;
}
A& A ::
operator=(const ElementType& e)
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = e;
}
return *this;
}
bool A ::
operator==(const A& obj) const
{
for (FwSizeType index = 0; index < SIZE; index++) {
if (!((*this)[index] == obj[index])) {
return false;
}
}
return true;
}
bool A ::
operator!=(const A& obj) const
{
return !(*this == obj);
}
#ifdef BUILD_UT
std::ostream& operator<<(std::ostream& os, const A& obj) {
os << "[";
constexpr auto SIZE = A::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 A ::
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 A ::
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 A ::
serializedSize() const
{
return SERIALIZED_SIZE;
}
#if FW_SERIALIZABLE_TO_STRING
void A ::
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;
tmp.format("%" PRIu32 "", this->elements[index]);
if (index > 0) {
sb += ", ";
}
sb += tmp;
}
// Array suffix
sb += " ]";
}
#endif