Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move string copyBuff from implmentation to string base class #695

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##
## Template to stamp out serializable arrays .cpp file
##
// ======================================================================
// ======================================================================
// \title ${name}
// \author Auto-generated
// \brief cpp file for ${name}
Expand All @@ -11,7 +11,7 @@
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged. Any commercial use must be negotiated with the Office
// of Technology Transfer at the California Institute of Technology.
//
//
// This software may be subject to U.S. export control laws and
// regulations. By accepting this document, the user agrees to comply
// with all U.S. export laws and regulations. User has the
Expand Down Expand Up @@ -64,16 +64,6 @@ namespace ${namespace} {
return this->m_buf;
}

void ${name}::${name}String::copyBuff(const char* buff, NATIVE_UINT_TYPE size) {
FW_ASSERT(buff);
// check for self copy
if (buff != this->m_buf) {
(void)strncpy(this->m_buf,buff,size);
// NULL terminate
this->terminate(sizeof(this->m_buf));
}
}

Fw::SerializeStatus ${name}::${name}String::serialize(Fw::SerializeBufferBase& buffer) const {
NATIVE_UINT_TYPE strSize = strnlen(this->m_buf,sizeof(this->m_buf));
// serialize string
Expand Down Expand Up @@ -127,8 +117,8 @@ namespace ${namespace} {
#set $i = $i + 1
#end for
}
${name} ::

${name} ::
${name}(const ElementType (&a)[SIZE]) :
Serializable()
{
Expand All @@ -137,9 +127,9 @@ namespace ${namespace} {
this->elements[index] = a[index];
}
}

#if $size != 1:
${name} ::
${name} ::
${name}(const ElementType& e) :
Serializable()
{
Expand All @@ -149,8 +139,8 @@ namespace ${namespace} {
}
}
#end if
${name} ::

${name} ::
${name}(
#for $i in $range(1, $size + 1)
#if $i != $size:
Expand All @@ -168,7 +158,7 @@ namespace ${namespace} {
#set $k = $k + 1
#end for
}

${name} ::
${name}(const ${name}& other) :
Serializable()
Expand All @@ -178,27 +168,27 @@ namespace ${namespace} {
this->elements[index] = other.elements[index];
}
}

// ----------------------------------------------------------------------
// Public functions
// ----------------------------------------------------------------------


${name}::ElementType& ${name} ::
operator[](const U32 i)
{
FW_ASSERT(i < SIZE);
return this->elements[i];
}

const ${name}::ElementType& ${name} ::
operator[](const U32 i) const
{
FW_ASSERT(i < SIZE);
return this->elements[i];
}


const ${name}& ${name} ::
operator=(const ${name}& other)
{
Expand All @@ -207,7 +197,7 @@ namespace ${namespace} {
}
return *this;
}

const ${name}& ${name} ::
operator=(const ElementType (&a)[SIZE])
{
Expand All @@ -216,7 +206,7 @@ namespace ${namespace} {
}
return *this;
}

const ${name}& ${name} ::
operator=(const ElementType& e)
{
Expand All @@ -225,9 +215,9 @@ namespace ${namespace} {
}
return *this;
}

bool ${name} ::
operator==(const ${name}& other) const
operator==(const ${name}& other) const
{
for (U32 i = 0; i < SIZE; ++i) {
if (!((*this)[i] == other[i])) {
Expand All @@ -236,9 +226,9 @@ namespace ${namespace} {
}
return true;
}

bool ${name} ::
operator!=(const ${name}& other) const
operator!=(const ${name}& other) const
{
return !(*this == other);
}
Expand Down Expand Up @@ -288,7 +278,7 @@ void ${name}::toString(Fw::StringBase& text) const {
}

\#endif

\#ifdef BUILD_UT
std::ostream& operator<<(std::ostream& os, const ${name}& obj) {
Fw::EightyCharString temp;
Expand All @@ -298,7 +288,7 @@ void ${name}::toString(Fw::StringBase& text) const {
return os;
}
\#endif

Fw::SerializeStatus ${name} ::
serialize(Fw::SerializeBufferBase& buffer) const
{
Expand All @@ -311,7 +301,7 @@ void ${name}::toString(Fw::StringBase& text) const {
}
return status;
}

Fw::SerializeStatus ${name} ::
deserialize(Fw::SerializeBufferBase& buffer)
{
Expand All @@ -327,4 +317,4 @@ void ${name}::toString(Fw::StringBase& text) const {

#if $namespace
}
#end if
#end if
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Template to stamp out serializable arrays .hpp file
##
#import re
// ======================================================================
// ======================================================================
// \title ${name}.hpp
// \author Auto-generated
// \brief hpp file for ${name}
Expand All @@ -12,7 +12,7 @@
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged. Any commercial use must be negotiated with the Office
// of Technology Transfer at the California Institute of Technology.
//
//
// This software may be subject to U.S. export control laws and
// regulations. By accepting this document, the user agrees to comply
// with all U.S. export laws and regulations. User has the
Expand Down Expand Up @@ -73,7 +73,6 @@ namespace ${namespace} {
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& buffer); //!< deserialization function

private:
void copyBuff(const char* buff, NATIVE_UINT_TYPE size); //!< copy a buffer, overwriting current contents
NATIVE_UINT_TYPE getCapacity(void) const ;
void terminate(NATIVE_UINT_TYPE size); //!< terminate the string

Expand All @@ -92,7 +91,7 @@ namespace ${namespace} {
#else:
typedef ${type} ElementType;
#end if

enum {
SIZE=${size},
SERIALIZED_SIZE = SIZE *
Expand All @@ -106,28 +105,28 @@ namespace ${namespace} {
sizeof($type)
#end if
}; //!< serializable size of ${name}

public:

// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------

//! Construct a ${name} with default initialization
${name}(void);

//! Construct a ${name} and initialize its elements from an array
${name}(
const ElementType (&a)[SIZE] //!< The array
);

#if $size != 1:
#if $size != 1:
//! Construct a ${name} and initialize its elements from a single element
${name}(
const ElementType& e //!< The element
);
#end if

//! Construct a ${name} and initialize its elements from elements
${name}(
#for $i in $range(1, $size + 1):
Expand All @@ -138,72 +137,72 @@ namespace ${namespace} {
#end if
#end for
);

//! Copy constructor
${name}(
const ${name}& other //!< The other object
);

public:

// ----------------------------------------------------------------------
// Public operators
// ----------------------------------------------------------------------

//! Subscript operator
ElementType& operator[](
const U32 i //!< The subscript index
);

//! Const subscript operator
const ElementType& operator[](
const U32 i //!< The subscript index
) const;

//! Assignment operator
const ${name}& operator=(
const ${name}& other //!< The other object
);

//! Assignment operator from array
const ${name}& operator=(
const ElementType (&a)[SIZE] //!< The array
);

//! Assignment operator from element
const ${name}& operator=(
const ElementType& e //!< The element
);

//! Equality operator
bool operator==(
const ${name}& other //!< The other object
) const;

//! Inequality operator
bool operator!=(
const ${name}& other //!< The other object
) const;

\#ifdef BUILD_UT
//! Ostream operator
friend std::ostream& operator<<(
std::ostream& os, //!< The ostream
const ${name}& obj //!< The object
);
\#endif

public:

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------

//! Serialization
Fw::SerializeStatus serialize(
Fw::SerializeBufferBase& buffer //!< The serial buffer
) const;

//! Deserialization
Fw::SerializeStatus deserialize(
Fw::SerializeBufferBase& buffer //!< The serial buffer
Expand All @@ -218,20 +217,20 @@ namespace ${namespace} {
enum {
TYPE_ID = ${uuid} //!< type id
};

private:

// ----------------------------------------------------------------------
// Private member variables
// ----------------------------------------------------------------------

//! The array elements
ElementType elements[SIZE];

};

#if $namespace
}
#end if

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ namespace ${n} {
return this->m_buf;
}

void ${argname}String::copyBuff(const char* buff, NATIVE_UINT_TYPE size) {
FW_ASSERT(buff);
// check for self copy
if (buff != this->m_buf) {
(void)strncpy(this->m_buf,buff,size);
// NULL terminate
this->terminate(sizeof(this->m_buf));
}
}

Fw::SerializeStatus ${argname}String::serialize(Fw::SerializeBufferBase& buffer) const {
NATIVE_UINT_TYPE strSize = strnlen(this->m_buf,sizeof(this->m_buf));
// serialize string as buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace ${namespace} {
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& buffer); //!< serialization method

private:
void copyBuff(const char* buff, NATIVE_UINT_TYPE size); //!< copy buffer, overwriting old string
NATIVE_UINT_TYPE getCapacity(void) const ;
void terminate(NATIVE_UINT_TYPE size); //!< terminate the string

Expand Down
Loading