fpp/compiler/tools/fpp-to-cpp/test/array/PrimitiveF32fArrayAc.ref.cpp
Rob Bocchino 597935d1cc Revise array code gen
Use FwSizeType instead of U32 for indices
Add operator= with initializer list
2025-08-19 08:38:09 -07:00

230 lines
5.4 KiB
C++
Vendored

// ======================================================================
// \title PrimitiveF32fArrayAc.cpp
// \author Generated by fpp-to-cpp
// \brief cpp file for PrimitiveF32f array
// ======================================================================
#include "Fw/Types/Assert.hpp"
#include "PrimitiveF32fArrayAc.hpp"
namespace M {
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
PrimitiveF32f ::
PrimitiveF32f() :
Serializable()
{
*this = M::PrimitiveF32f(0.0f, 0.0f, 0.0f);
}
PrimitiveF32f ::
PrimitiveF32f(const ElementType (&a)[SIZE]) :
Serializable()
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = a[index];
}
}
PrimitiveF32f ::
PrimitiveF32f(const ElementType& e) :
Serializable()
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = e;
}
}
PrimitiveF32f ::
PrimitiveF32f(
const ElementType& e1,
const ElementType& e2,
const ElementType& e3
) :
Serializable()
{
this->elements[0] = e1;
this->elements[1] = e2;
this->elements[2] = e3;
}
PrimitiveF32f ::
PrimitiveF32f(const PrimitiveF32f& obj) :
Serializable()
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = obj.elements[index];
}
}
// ----------------------------------------------------------------------
// Operators
// ----------------------------------------------------------------------
PrimitiveF32f::ElementType& PrimitiveF32f ::
operator[](const FwSizeType i)
{
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
return this->elements[i];
}
const PrimitiveF32f::ElementType& PrimitiveF32f ::
operator[](const FwSizeType i) const
{
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
return this->elements[i];
}
PrimitiveF32f& PrimitiveF32f ::
operator=(const PrimitiveF32f& obj)
{
if (this == &obj) {
return *this;
}
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = obj.elements[index];
}
return *this;
}
PrimitiveF32f& PrimitiveF32f ::
operator=(const ElementType (&a)[SIZE])
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = a[index];
}
return *this;
}
PrimitiveF32f& PrimitiveF32f ::
operator=(const std::initializer_list<ElementType>& il)
{
// Since we are required to use C++11, this has to be a runtime check
// In C++14, it can be a static check
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);
this->elements[i] = e;
i++;
}
return *this;
}
PrimitiveF32f& PrimitiveF32f ::
operator=(const ElementType& e)
{
for (FwSizeType index = 0; index < SIZE; index++) {
this->elements[index] = e;
}
return *this;
}
bool PrimitiveF32f ::
operator==(const PrimitiveF32f& obj) const
{
for (FwSizeType index = 0; index < SIZE; index++) {
if (!((*this)[index] == obj[index])) {
return false;
}
}
return true;
}
bool PrimitiveF32f ::
operator!=(const PrimitiveF32f& obj) const
{
return !(*this == obj);
}
#ifdef BUILD_UT
std::ostream& operator<<(std::ostream& os, const PrimitiveF32f& obj) {
Fw::String s;
obj.toString(s);
os << s;
return os;
}
#endif
// ----------------------------------------------------------------------
// Public member functions
// ----------------------------------------------------------------------
Fw::SerializeStatus PrimitiveF32f ::
serializeTo(Fw::SerializeBufferBase& buffer) const
{
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
for (FwSizeType index = 0; index < SIZE; index++) {
status = buffer.serializeFrom((*this)[index]);
if (status != Fw::FW_SERIALIZE_OK) {
return status;
}
}
return status;
}
Fw::SerializeStatus PrimitiveF32f ::
deserializeFrom(Fw::SerializeBufferBase& buffer)
{
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
for (FwSizeType index = 0; index < SIZE; index++) {
status = buffer.deserializeTo((*this)[index]);
if (status != Fw::FW_SERIALIZE_OK) {
return status;
}
}
return status;
}
FwSizeType PrimitiveF32f ::
serializedSize() const
{
return SERIALIZED_SIZE;
}
#if FW_SERIALIZABLE_TO_STRING
void PrimitiveF32f ::
toString(Fw::StringBase& sb) const
{
// Clear the output string
sb = "";
// Array prefix
if (sb.length() + 2 <= sb.maxLength()) {
sb += "[ ";
} else {
return;
}
for (FwSizeType index = 0; index < SIZE; index++) {
Fw::String tmp;
tmp.format("%.1f", static_cast<F64>(this->elements[index]));
FwSizeType size = tmp.length() + (index > 0 ? 2 : 0);
if ((size + sb.length()) <= sb.maxLength()) {
if (index > 0) {
sb += ", ";
}
sb += tmp;
} else {
break;
}
}
// Array suffix
if (sb.length() + 2 <= sb.maxLength()) {
sb += " ]";
}
}
#endif
}