mirror of
https://github.com/nasa/fpp.git
synced 2025-12-12 04:41:37 -06:00
253 lines
5.5 KiB
C++
Vendored
253 lines
5.5 KiB
C++
Vendored
// ======================================================================
|
|
// \title String2ArrayAc.cpp
|
|
// \author Generated by fpp-to-cpp
|
|
// \brief cpp file for String2 array
|
|
// ======================================================================
|
|
|
|
#include "Fw/Types/Assert.hpp"
|
|
#include "String2ArrayAc.hpp"
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Constructors
|
|
// ----------------------------------------------------------------------
|
|
|
|
String2 ::
|
|
String2() :
|
|
Serializable()
|
|
{
|
|
this->initElements();
|
|
*this = String2(Fw::String("\"\\"), Fw::String("abc\ndef\n"));
|
|
}
|
|
|
|
String2 ::
|
|
String2(const ElementType (&a)[SIZE]) :
|
|
Serializable()
|
|
{
|
|
this->initElements();
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = a[index];
|
|
}
|
|
}
|
|
|
|
String2 ::
|
|
String2(const Fw::StringBase& e) :
|
|
Serializable()
|
|
{
|
|
this->initElements();
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = e;
|
|
}
|
|
}
|
|
|
|
String2 ::
|
|
String2(const std::initializer_list<ElementType>& il) :
|
|
Serializable()
|
|
{
|
|
this->initElements();
|
|
*this = il;
|
|
}
|
|
|
|
String2 ::
|
|
String2(
|
|
const Fw::StringBase& e1,
|
|
const Fw::StringBase& e2
|
|
) :
|
|
Serializable()
|
|
{
|
|
this->initElements();
|
|
this->elements[0] = e1;
|
|
this->elements[1] = e2;
|
|
}
|
|
|
|
String2 ::
|
|
String2(const String2& obj) :
|
|
Serializable()
|
|
{
|
|
this->initElements();
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = obj.elements[index];
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Operators
|
|
// ----------------------------------------------------------------------
|
|
|
|
String2::ElementType& String2 ::
|
|
operator[](const FwSizeType i)
|
|
{
|
|
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
|
|
return this->elements[i];
|
|
}
|
|
|
|
const String2::ElementType& String2 ::
|
|
operator[](const FwSizeType i) const
|
|
{
|
|
FW_ASSERT(i < SIZE, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(SIZE));
|
|
return this->elements[i];
|
|
}
|
|
|
|
String2& String2 ::
|
|
operator=(const String2& obj)
|
|
{
|
|
if (this == &obj) {
|
|
return *this;
|
|
}
|
|
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = obj.elements[index];
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
String2& String2 ::
|
|
operator=(const ElementType (&a)[SIZE])
|
|
{
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = a[index];
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
String2& String2 ::
|
|
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;
|
|
}
|
|
|
|
String2& String2 ::
|
|
operator=(const ElementType& e)
|
|
{
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index] = e;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
bool String2 ::
|
|
operator==(const String2& obj) const
|
|
{
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
if (!((*this)[index] == obj[index])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool String2 ::
|
|
operator!=(const String2& obj) const
|
|
{
|
|
return !(*this == obj);
|
|
}
|
|
|
|
#ifdef BUILD_UT
|
|
|
|
std::ostream& operator<<(std::ostream& os, const String2& obj) {
|
|
Fw::String s;
|
|
obj.toString(s);
|
|
os << s;
|
|
return os;
|
|
}
|
|
|
|
#endif
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Public member functions
|
|
// ----------------------------------------------------------------------
|
|
|
|
Fw::SerializeStatus String2 ::
|
|
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 String2 ::
|
|
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 String2 ::
|
|
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 String2 ::
|
|
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("a %s b", this->elements[index].toChar());
|
|
|
|
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
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Private member functions
|
|
// ----------------------------------------------------------------------
|
|
|
|
void String2 ::
|
|
initElements()
|
|
{
|
|
for (FwSizeType index = 0; index < SIZE; index++) {
|
|
this->elements[index].setBuffer(&this->buffers[index][0], sizeof this->buffers[index]);
|
|
}
|
|
}
|