// ====================================================================== // \title PrimitiveU8ArrayAc.cpp // \author Generated by fpp-to-cpp // \brief cpp file for PrimitiveU8 array // ====================================================================== #include "Fw/Types/Assert.hpp" #include "PrimitiveU8ArrayAc.hpp" namespace M { // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- PrimitiveU8 :: PrimitiveU8() : Serializable() { *this = M::PrimitiveU8(0); } PrimitiveU8 :: PrimitiveU8(const ElementType (&a)[SIZE]) : Serializable() { *this = a; } PrimitiveU8 :: PrimitiveU8(const ElementType& e) : Serializable() { *this = e; } PrimitiveU8 :: PrimitiveU8(const std::initializer_list& il) : Serializable() { *this = il; } PrimitiveU8 :: PrimitiveU8(const PrimitiveU8& obj) : Serializable() { *this = obj; } // ---------------------------------------------------------------------- // Operators // ---------------------------------------------------------------------- PrimitiveU8::ElementType& PrimitiveU8 :: operator[](const FwSizeType i) { FW_ASSERT(i < SIZE, static_cast(i), static_cast(SIZE)); return this->elements[i]; } const PrimitiveU8::ElementType& PrimitiveU8 :: operator[](const FwSizeType i) const { FW_ASSERT(i < SIZE, static_cast(i), static_cast(SIZE)); return this->elements[i]; } PrimitiveU8& PrimitiveU8 :: operator=(const PrimitiveU8& obj) { if (this != &obj) { for (FwSizeType index = 0; index < SIZE; index++) { this->elements[index] = obj.elements[index]; } } return *this; } PrimitiveU8& PrimitiveU8 :: operator=(const ElementType (&a)[SIZE]) { for (FwSizeType index = 0; index < SIZE; index++) { this->elements[index] = a[index]; } return *this; } PrimitiveU8& PrimitiveU8 :: operator=(const std::initializer_list& 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(il.size()), static_cast(SIZE)); FwSizeType i = 0; for (const auto& e : il) { FW_ASSERT(i < SIZE, static_cast(i), static_cast(SIZE)); this->elements[i] = e; i++; } return *this; } PrimitiveU8& PrimitiveU8 :: operator=(const ElementType& e) { for (FwSizeType index = 0; index < SIZE; index++) { this->elements[index] = e; } return *this; } bool PrimitiveU8 :: operator==(const PrimitiveU8& obj) const { for (FwSizeType index = 0; index < SIZE; index++) { if (!((*this)[index] == obj[index])) { return false; } } return true; } bool PrimitiveU8 :: operator!=(const PrimitiveU8& obj) const { return !(*this == obj); } #ifdef BUILD_UT std::ostream& operator<<(std::ostream& os, const PrimitiveU8& obj) { Fw::String s; obj.toString(s); os << s; return os; } #endif // ---------------------------------------------------------------------- // Public member functions // ---------------------------------------------------------------------- Fw::SerializeStatus PrimitiveU8 :: serializeTo( Fw::SerializeBufferBase& 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 PrimitiveU8 :: deserializeFrom( Fw::SerializeBufferBase& 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 PrimitiveU8 :: serializedSize() const { return SERIALIZED_SIZE; } #if FW_SERIALIZABLE_TO_STRING void PrimitiveU8 :: 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("%" PRIu8 "", 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 }