F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextLogString.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 (NATIVE_UINT_TYPE) strnlen(this->m_buf,sizeof(this->m_buf));
32  }
33 
34  const char* TextLogString::toChar(void) const {
35  return this->m_buf;
36  }
37 
38  void TextLogString::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
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 TextLogString::getCapacity(void) const {
66  }
67 
68  void TextLogString::terminate(NATIVE_UINT_TYPE size) {
69  // null terminate the string
70  this->m_buf[size < sizeof(this->m_buf)?size:sizeof(this->m_buf)-1] = 0;
71  }
72 
74  this->copyBuff(other.m_buf,this->getCapacity());
75  return *this;
76  }
77 
78 }
StringType.hpp
Declares ISF string base class.
Fw::TextLogString
Definition: TextLogString.hpp:11
Fw::TextLogString::serialize
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialize contents
Definition: TextLogString.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
TextLogString.hpp
Assert.hpp
Fw::TextLogString::length
NATIVE_UINT_TYPE length(void) const
Get length of string.
Definition: TextLogString.cpp:30
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::TextLogString::toChar
const char * toChar(void) const
Definition: TextLogString.cpp:34
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::TextLogString::TextLogString
TextLogString(void)
Definition: TextLogString.cpp:23
Fw::TextLogString::operator=
const TextLogString & operator=(const TextLogString &other)
equal operator for other strings
Definition: TextLogString.cpp:73
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:292
BasicTypes.hpp
Declares ISF basic types.
Fw::TextLogString::~TextLogString
~TextLogString(void)
Definition: TextLogString.cpp:27
Fw
Definition: BufferGetPortAc.cpp:6
Fw::TextLogString::deserialize
SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialize to contents
Definition: TextLogString.cpp:54
FW_LOG_TEXT_BUFFER_SIZE
#define FW_LOG_TEXT_BUFFER_SIZE
Max size of string for text log message.
Definition: FpConfig.hpp:291