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