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/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  "Use serializeTo(SerializeBufferBase& buffer) instead") {
75  return this->serializeTo(buffer);
76  }
77 
78  DEPRECATED(SerializeStatus serialize(SerializeBufferBase& buffer, SizeType maxLen) const,
79  "Use serializeTo(SerializeBufferBase& buffer, SizeType maxLen) instead") {
80  return this->serializeTo(buffer, maxLen);
81  }
82 
83 #ifdef BUILD_UT
84  // to support GoogleTest framework in unit tests
85  friend std::ostream& operator<<(std::ostream& os, const StringBase& str);
86 #endif
87 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
88  void toString(StringBase& text) const override;
89 #endif
90 
91  protected:
92  StringBase();
93  virtual ~StringBase();
94 
95  void appendBuff(const CHAR* buff, SizeType size);
96 
97  private:
98  StringBase(const StringBase& src) = delete;
99 };
100 
101 } // namespace Fw
102 
103 #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:152
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
DEPRECATED(SerializeStatus serialize(SerializeBufferBase &buffer) const, "Use serializeTo(SerializeBufferBase& buffer) instead")
Definition: StringBase.hpp:73
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
DEPRECATED(SerializeStatus serialize(SerializeBufferBase &buffer, SizeType maxLen) const, "Use serializeTo(SerializeBufferBase& buffer, SizeType maxLen) instead")
Definition: StringBase.hpp:78
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
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