F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
StringBase.hpp
Go to the documentation of this file.
1 
13 #ifndef FW_STRING_BASE_HPP
14 #define FW_STRING_BASE_HPP
15 #include <Fw/Types/format.hpp>
16 #include <FpConfig.hpp>
18 #include <cstdarg>
19 #ifdef BUILD_UT
20 #include <iostream>
21 #endif
22 
23 namespace Fw {
24 
25 class StringBase : public Serializable {
26  public:
28  virtual const CHAR* toChar() const = 0; //<! Convert to a C-style char*
29  virtual SizeType getCapacity() const = 0;
30  SizeType length() const;
31 
33  SizeType maxLength() const;
37  ) {
38  return static_cast<SizeType>(sizeof(FwSizeStoreType)) + maxLength;
39  }
40 
43  ) {
44  // Reserve one byte for each character plus one for the null terminator
45  return maxLength + 1;
46  }
47 
50  SizeType serializedSize() const;
51 
55  ) const;
56 
57  const CHAR* operator+=(const CHAR* src);
58  const StringBase& operator+=(const StringBase& src);
59  bool operator==(const StringBase& other) const;
60  bool operator==(const CHAR* other) const;
61  bool operator!=(const StringBase& other) const;
62  bool operator!=(const CHAR* other) const;
63  StringBase& operator=(const CHAR* src);
64  StringBase& operator=(const StringBase& src);
65 
66  FormatStatus format(const CHAR* formatString, ...);
67  FormatStatus vformat(const CHAR* formatString, va_list args);
68 
69  virtual SerializeStatus serialize(SerializeBufferBase& buffer) const;
70  virtual SerializeStatus serialize(SerializeBufferBase& buffer, SizeType maxLen) const;
72 
73 #ifdef BUILD_UT
74  // to support GoogleTest framework in unit tests
75  friend std::ostream& operator<<(std::ostream& os, const StringBase& str);
76 #endif
77 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
78  void toString(StringBase& text) const;
79 #endif
80 
81  protected:
82  StringBase();
83  virtual ~StringBase();
84 
85  void appendBuff(const CHAR* buff, SizeType size);
86 
87  private:
88  StringBase(const StringBase& src) = delete;
89 };
90 
91 } // namespace Fw
92 
93 #endif
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
NATIVE_UINT_TYPE SizeType
Definition: StringBase.hpp:27
NATIVE_UINT_TYPE SizeType
const CHAR * operator+=(const CHAR *src)
Concatenate a CHAR*.
Definition: StringBase.cpp:25
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
FormatStatus vformat(const CHAR *formatString, va_list args)
write formatted string to buffer using va_list
Definition: StringBase.cpp:63
SizeType serializedTruncatedSize(FwSizeType maxLength) const
Definition: StringBase.cpp:138
char CHAR
Definition: BasicTypes.h:32
SerializeStatus
forward declaration for string
SizeType maxLength() const
Get the maximum length of a string that the buffer can hold (which is capacity - 1) ...
Definition: StringBase.cpp:128
bool operator!=(const StringBase &other) const
Inequality with StringBase.
Definition: StringBase.cpp:73
virtual ~StringBase()
Definition: StringBase.cpp:23
U16 FwSizeStoreType
Definition: FpConfig.h:59
bool operator==(const StringBase &other) const
Check for equality with StringBase.
Definition: StringBase.cpp:35
SizeType length() const
Get length of string.
Definition: StringBase.cpp:121
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:55
C++-compatible configuration header for fprime configuration.
SizeType serializedSize() const
Definition: StringBase.cpp:134
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
Definition: StringBase.hpp:42
void appendBuff(const CHAR *buff, SizeType size)
Definition: StringBase.cpp:108
StringBase & operator=(const CHAR *src)
Assign CHAR*.
Definition: StringBase.cpp:103
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
Definition: StringBase.cpp:152
forward declaration
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const
serialization function
Definition: StringBase.cpp:142
virtual SizeType getCapacity() const =0
return size of buffer
static constexpr SizeType STATIC_SERIALIZED_SIZE(SizeType maxLength)
Definition: StringBase.hpp:36
virtual const CHAR * toChar() const =0
FormatStatus
status of string format calls
Definition: format.hpp:18