F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/FPrimeBasicTypes.hpp>
17 #include <Fw/Types/format.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  SerializeStatus serializeTo(SerializeBufferBase& buffer) const override;
70  virtual SerializeStatus serializeTo(SerializeBufferBase& buffer, SizeType maxLen) const;
72 
74  virtual SerializeStatus serialize(SerializeBufferBase& buffer, SizeType maxLen) const;
75 
76 #ifdef BUILD_UT
77  // to support GoogleTest framework in unit tests
78  friend std::ostream& operator<<(std::ostream& os, const StringBase& str);
79 #endif
80 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
81  void toString(StringBase& text) const override;
82 #endif
83 
84  protected:
85  StringBase();
86  virtual ~StringBase();
87 
88  void appendBuff(const CHAR* buff, SizeType size);
89 
90  private:
91  StringBase(const StringBase& src) = delete;
92 };
93 
94 } // namespace Fw
95 
96 #endif
PlatformSizeType FwSizeType
const CHAR * operator+=(const CHAR *src)
Concatenate a CHAR*.
Definition: StringBase.cpp:25
SerializeStatus deserializeFrom(SerializeBufferBase &buffer) override
deserialize contents from buffer
Definition: StringBase.cpp:162
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:59
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
U16 FwSizeStoreType
The type used to serialize a size value.
bool operator!=(const StringBase &other) const
Inequality with StringBase.
Definition: StringBase.cpp:73
virtual ~StringBase()
Definition: StringBase.cpp:23
bool operator==(const StringBase &other) const
Check for equality with StringBase.
Definition: StringBase.cpp:35
FwSizeType SizeType
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
FwSizeType SizeType
Definition: StringBase.hpp:27
SerializeStatus serializeTo(SerializeBufferBase &buffer) const override
serialize contents to buffer
Definition: StringBase.cpp:142
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
forward declaration
SerializeStatus serialize(SerializeBufferBase &buffer) const
Definition: StringBase.cpp:153
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