F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FixedLengthString.cpp
Go to the documentation of this file.
4 #include <Fw/Types/Assert.hpp>
5 #include <string.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 namespace Fw {
10 
12  this->copyBuff(src, sizeof(this->m_buf));
13  }
14 
16  this->copyBuff(src.toChar(), sizeof(this->m_buf));
17  }
18 
20  this->copyBuff(src.m_buf, sizeof(this->m_buf));
21  }
22 
24  this->m_buf[0] = 0;
25  }
26 
28  }
29 
31  return strnlen(this->m_buf,sizeof(this->m_buf));
32  }
33 
34  const char* FixedLengthString::toChar(void) const {
35  return this->m_buf;
36  }
37 
38  void FixedLengthString::copyBuff(const char* buff, NATIVE_UINT_TYPE size) {
39  FW_ASSERT(buff);
40  // check for self copy
41  if (buff != this->m_buf) {
42  (void)strncpy(this->m_buf,buff,size);
43  // NULL terminate
44  this->terminate(sizeof(this->m_buf));
45  }
46  }
47 
49  this->copyBuff(other.m_buf,sizeof(this->m_buf));
50  return *this;
51  }
52 
54  NATIVE_UINT_TYPE strSize = strnlen(this->m_buf,sizeof(this->m_buf));
55  // serialize string as buffer
56  return buffer.serialize((U8*)this->m_buf,strSize);
57  }
58 
60  NATIVE_UINT_TYPE maxSize = sizeof(this->m_buf);
61  // deserialize string
62  SerializeStatus stat = buffer.deserialize((U8*)this->m_buf,maxSize);
63  // make sure it is null-terminated
64  this->terminate(maxSize);
65 
66  return stat;
67  }
68 
69  NATIVE_UINT_TYPE FixedLengthString::getCapacity(void) const {
70  return STRING_SIZE;
71  }
72 
73  void FixedLengthString::terminate(NATIVE_UINT_TYPE size) {
74  // null terminate the string
75  this->m_buf[size < sizeof(this->m_buf)?size:sizeof(this->m_buf)-1] = 0;
76  }
77 
78 }
StringType.hpp
Declares ISF string base class.
FixedLengthString.hpp
Fw::FixedLengthString::operator=
const FixedLengthString & operator=(const FixedLengthString &other)
equal operator
Definition: FixedLengthString.cpp:48
Fw::SerializeBufferBase
Definition: Serializable.hpp:43
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Fw::SerializeBufferBase::serialize
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
Definition: Serializable.cpp:67
Fw::StringBase
Definition: StringType.hpp:23
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::FixedLengthString::~FixedLengthString
~FixedLengthString(void)
destructor
Definition: FixedLengthString.cpp:27
Assert.hpp
Fw::FixedLengthString::FixedLengthString
FixedLengthString(void)
default constructor
Definition: FixedLengthString.cpp:23
Fw::FixedLengthString::STRING_SIZE
@ STRING_SIZE
Storage for string.
Definition: FixedLengthString.hpp:15
Fw::StringBase::toChar
virtual const char * toChar(void) const =0
Fw::FixedLengthString::deserialize
SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
Definition: FixedLengthString.cpp:59
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:290
Fw::FixedLengthString::toChar
const char * toChar(void) const
gets char buffer
Definition: FixedLengthString.cpp:34
Fw::FixedLengthString::length
NATIVE_UINT_TYPE length(void) const
returns length of stored string
Definition: FixedLengthString.cpp:30
BasicTypes.hpp
Declares ISF basic types.
Fw::FixedLengthString::serialize
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialization function
Definition: FixedLengthString.cpp:53
Fw::FixedLengthString
Definition: FixedLengthString.hpp:10
Fw
Definition: Buffer.cpp:21