mirror of
https://github.com/nasa/fpp.git
synced 2025-12-11 11:16:42 -06:00
222 lines
5.1 KiB
C++
Vendored
222 lines
5.1 KiB
C++
Vendored
// ======================================================================
|
|
// \title PrimitiveF32eArrayAc.cpp
|
|
// \author Generated by fpp-to-cpp
|
|
// \brief cpp file for PrimitiveF32e array
|
|
// ======================================================================
|
|
|
|
#include "Fw/Types/Assert.hpp"
|
|
#include "PrimitiveF32eArrayAc.hpp"
|
|
|
|
namespace M {
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Constructors
|
|
// ----------------------------------------------------------------------
|
|
|
|
PrimitiveF32e ::
|
|
PrimitiveF32e() :
|
|
Serializable(),
|
|
elements{}
|
|
{
|
|
*this = M::PrimitiveF32e(1.0f);
|
|
}
|
|
|
|
PrimitiveF32e ::
|
|
PrimitiveF32e(const ElementType (&a)[SIZE]) :
|
|
Serializable()
|
|
{
|
|
*this = a;
|
|
}
|
|
|
|
PrimitiveF32e ::
|
|
PrimitiveF32e(const ElementType& e) :
|
|
Serializable()
|
|
{
|
|
*this = e;
|
|
}
|
|
|
|
PrimitiveF32e ::
|
|
PrimitiveF32e(const std::initializer_list<ElementType>& il) :
|
|
Serializable()
|
|
{
|
|
*this = il;
|
|
}
|
|
|
|
PrimitiveF32e ::
|
|
PrimitiveF32e(const PrimitiveF32e& obj) :
|
|
Serializable()
|
|
{
|
|
*this = obj;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Operators
|
|
// ----------------------------------------------------------------------
|
|
|
|
PrimitiveF32e::ElementType& PrimitiveF32e ::
|
|
operator[](const FwSizeType i)
|
|
{
|
|
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
|
|
return this->elements[i];
|
|
}
|
|
|
|
const PrimitiveF32e::ElementType& PrimitiveF32e ::
|
|
operator[](const FwSizeType i) const
|
|
{
|
|
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
|
|
return this->elements[i];
|
|
}
|
|
|
|
PrimitiveF32e& PrimitiveF32e ::
|
|
operator=(const PrimitiveF32e& obj)
|
|
{
|
|
if (this != &obj) {
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = obj.elements[index];
|
|
}
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
PrimitiveF32e& PrimitiveF32e ::
|
|
operator=(const ElementType (&a)[SIZE])
|
|
{
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = a[index];
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
PrimitiveF32e& PrimitiveF32e ::
|
|
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;
|
|
}
|
|
|
|
PrimitiveF32e& PrimitiveF32e ::
|
|
operator=(const ElementType& e)
|
|
{
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = e;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
bool PrimitiveF32e ::
|
|
operator==(const PrimitiveF32e& obj) const
|
|
{
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
if (!((*this)[index] == obj[index])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool PrimitiveF32e ::
|
|
operator!=(const PrimitiveF32e& obj) const
|
|
{
|
|
return !(*this == obj);
|
|
}
|
|
|
|
#ifdef BUILD_UT
|
|
|
|
std::ostream& operator<<(std::ostream& os, const PrimitiveF32e& obj) {
|
|
Fw::String s;
|
|
obj.toString(s);
|
|
os << s;
|
|
return os;
|
|
}
|
|
|
|
#endif
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Public member functions
|
|
// ----------------------------------------------------------------------
|
|
|
|
Fw::SerializeStatus PrimitiveF32e ::
|
|
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 PrimitiveF32e ::
|
|
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 PrimitiveF32e ::
|
|
serializedSize() const
|
|
{
|
|
return SERIALIZED_SIZE;
|
|
}
|
|
|
|
#if FW_SERIALIZABLE_TO_STRING
|
|
|
|
void PrimitiveF32e ::
|
|
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("%.3e", 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
|
|
|
|
}
|