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 #include <cstdarg>
19 #ifdef BUILD_UT
20 #include <iostream>
21 #endif
22 
23 namespace Fw {
24 class StringBase : public Serializable {
25  public:
27  virtual const CHAR* toChar() const = 0; //<! Convert to a C-style char*
28  virtual SizeType getCapacity() const = 0;
29  SizeType length() const;
30 
32  SizeType maxLength() const;
36  ) {
37  return static_cast<SizeType>(sizeof(FwSizeStoreType)) + maxLength;
38  }
39 
42  ) {
43  // Reserve one byte for each character plus one for the null terminator
44  return maxLength + 1;
45  }
46 
49  SizeType serializedSize() const;
50 
54  ) const;
55 
56  const CHAR* operator+=(const CHAR* src);
57  const StringBase& operator+=(const StringBase& src);
58  bool operator==(const StringBase& other) const;
59  bool operator==(const CHAR* other) const;
60  bool operator!=(const StringBase& other) const;
61  bool operator!=(const CHAR* other) const;
62  StringBase& operator=(const CHAR* src);
63  StringBase& operator=(const StringBase& src);
64 
65  void format(const CHAR* formatString, ...);
66  void vformat(const CHAR* formatString, va_list args);
67 
68  virtual SerializeStatus serialize(SerializeBufferBase& buffer) const;
69  virtual SerializeStatus serialize(SerializeBufferBase& buffer, SizeType maxLen) const;
71 
72 #ifdef BUILD_UT
73  // to support GoogleTest framework in unit tests
74  friend std::ostream& operator<<(std::ostream& os, const StringBase& str);
75 #endif
76 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
77  void toString(StringBase& text) const;
78 #endif
79 
80  protected:
81  StringBase();
82  virtual ~StringBase();
83 
84  void appendBuff(const CHAR* buff, SizeType size);
85 
86  private:
87  StringBase(const StringBase& src) = delete;
88 };
89 
90 } // namespace Fw
91 
92 #endif
char CHAR
Definition: BasicTypes.h:32
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
U16 FwSizeStoreType
Definition: FpConfig.h:59
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
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:77
NATIVE_UINT_TYPE SizeType
Definition: StringBase.hpp:26
static constexpr SizeType STATIC_SERIALIZED_SIZE(SizeType maxLength)
Definition: StringBase.hpp:35
virtual ~StringBase()
Definition: StringBase.cpp:24
SizeType serializedTruncatedSize(FwSizeType maxLength) const
Definition: StringBase.cpp:142
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
Definition: StringBase.cpp:156
void format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:56
SizeType length() const
Get length of string.
Definition: StringBase.cpp:125
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 (which is capacity - 1)
Definition: StringBase.cpp:132
void appendBuff(const CHAR *buff, SizeType size)
Definition: StringBase.cpp:112
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const
serialization function
Definition: StringBase.cpp:146
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:107
SizeType serializedSize() const
Definition: StringBase.cpp:138
void vformat(const CHAR *formatString, va_list args)
write formatted string to buffer using va_list
Definition: StringBase.cpp:63
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
Definition: StringBase.hpp:41
SerializeStatus
forward declaration for string