F´ Flight Software - C/C++ Documentation  devel
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 
16 #include <FpConfig.hpp>
18 #ifdef BUILD_UT
19 #include <iostream>
20 #endif
21 
22 namespace Fw {
23 class StringBase : public Serializable {
24  public:
26  virtual const CHAR* toChar() const = 0; //<! Convert to a C-style char*
27  virtual SizeType getCapacity() const = 0;
28  SizeType length() const;
29 
31  SizeType maxLength() const;
35  ) {
36  return static_cast<SizeType>(sizeof(FwSizeStoreType)) + maxLength;
37  }
38 
41  ) {
42  // Reserve one byte for each character plus one for the null terminator
43  return maxLength + 1;
44  }
45 
48  SizeType serializedSize() const;
49 
53  ) const;
54 
55  const CHAR* operator+=(const CHAR* src);
56  const StringBase& operator+=(const StringBase& src);
57  bool operator==(const StringBase& other) const;
58  bool operator==(const CHAR* other) const;
59  bool operator!=(const StringBase& other) const;
60  bool operator!=(const CHAR* other) const;
61  StringBase& operator=(const CHAR* src);
62  StringBase& operator=(const StringBase& src);
63 
64  void format(const CHAR* formatString, ...);
65 
66  virtual SerializeStatus serialize(SerializeBufferBase& buffer) const;
67  virtual SerializeStatus serialize(SerializeBufferBase& buffer, SizeType maxLen) const;
69 
70 #ifdef BUILD_UT
71  // to support GoogleTest framework in unit tests
72  friend std::ostream& operator<<(std::ostream& os, const StringBase& str);
73 #endif
74 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
75  void toString(StringBase& text) const;
76 #endif
77 
78  protected:
79  StringBase();
80  virtual ~StringBase();
81 
82  void appendBuff(const CHAR* buff, SizeType size);
83 
84  private:
85  StringBase(const StringBase& src) = delete;
86 };
87 
88 } // namespace Fw
89 
90 #endif
char CHAR
Definition: BasicTypes.h:28
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
U16 FwSizeStoreType
Definition: FpConfig.h:46
PlatformSizeType FwSizeType
Definition: FpConfig.h:30
C++-compatible configuration header for fprime configuration.
forward declaration
NATIVE_UINT_TYPE SizeType
virtual const CHAR * toChar() const =0
bool operator!=(const StringBase &other) const
Inequality with StringBase.
Definition: StringBase.cpp:68
NATIVE_UINT_TYPE SizeType
Definition: StringBase.hpp:25
static constexpr SizeType STATIC_SERIALIZED_SIZE(SizeType maxLength)
Definition: StringBase.hpp:34
virtual ~StringBase()
Definition: StringBase.cpp:24
SizeType serializedTruncatedSize(FwSizeType maxLength) const
Definition: StringBase.cpp:133
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
Definition: StringBase.cpp:147
void format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:56
SizeType length() const
Get length of string.
Definition: StringBase.cpp:116
bool operator==(const StringBase &other) const
Check for equality with StringBase.
Definition: StringBase.cpp:36
SizeType maxLength() const
Get the maximum length of a string that the buffer can hold.
Definition: StringBase.cpp:123
void appendBuff(const CHAR *buff, SizeType size)
Definition: StringBase.cpp:103
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const
serialization function
Definition: StringBase.cpp:137
virtual SizeType getCapacity() const =0
return size of buffer
const CHAR * operator+=(const CHAR *src)
Concatenate a CHAR*.
Definition: StringBase.cpp:26
StringBase & operator=(const CHAR *src)
Assign CHAR*.
Definition: StringBase.cpp:98
SizeType serializedSize() const
Definition: StringBase.cpp:129
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
Definition: StringBase.hpp:40
SerializeStatus
forward declaration for string