F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
InternalInterfaceString.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* InternalInterfaceString::toChar(void) const {
35  return this->m_buf;
36  }
37 
38  void InternalInterfaceString::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  NATIVE_UINT_TYPE strSize = strnlen(this->m_buf,sizeof(this->m_buf));
50  // serialize string as buffer
51  return buffer.serialize((U8*)this->m_buf,strSize);
52  }
53 
55  NATIVE_UINT_TYPE maxSize = sizeof(this->m_buf);
56  // deserialize string
57  SerializeStatus stat = buffer.deserialize((U8*)this->m_buf,maxSize);
58  // make sure it is null-terminated
59  this->terminate(maxSize);
60 
61  return stat;
62  }
63 
64  NATIVE_UINT_TYPE InternalInterfaceString::getCapacity(void) const {
66  }
67 
69  this->copyBuff(other.m_buf,this->getCapacity());
70  return *this;
71  }
72 
73  void InternalInterfaceString::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 }
Fw::InternalInterfaceString
Definition: InternalInterfaceString.hpp:11
StringType.hpp
Declares ISF string base class.
Fw::InternalInterfaceString::serialize
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialization function
Definition: InternalInterfaceString.cpp:48
Fw::InternalInterfaceString::deserialize
SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
Definition: InternalInterfaceString.cpp:54
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::InternalInterfaceString::length
NATIVE_UINT_TYPE length(void) const
returns length of stored string
Definition: InternalInterfaceString.cpp:30
Assert.hpp
Fw::StringBase::toChar
virtual const char * toChar(void) const =0
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Fw::InternalInterfaceString::~InternalInterfaceString
~InternalInterfaceString(void)
destructor
Definition: InternalInterfaceString.cpp:27
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::InternalInterfaceString::operator=
const InternalInterfaceString & operator=(const InternalInterfaceString &other)
equal operator
Definition: InternalInterfaceString.cpp:68
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:290
Fw::InternalInterfaceString::toChar
const char * toChar(void) const
gets char buffer
Definition: InternalInterfaceString.cpp:34
BasicTypes.hpp
Declares ISF basic types.
FW_INTERNAL_INTERFACE_STRING_MAX_SIZE
#define FW_INTERNAL_INTERFACE_STRING_MAX_SIZE
Max size of interface string parameter type.
Definition: FpConfig.hpp:281
InternalInterfaceString.hpp
Fw
Definition: Buffer.cpp:21
Fw::InternalInterfaceString::InternalInterfaceString
InternalInterfaceString(void)
default constructor
Definition: InternalInterfaceString.cpp:23