F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ConstStringBase.hpp
Go to the documentation of this file.
1 
12 #ifndef FW_CONST_STRING_BASE_HPP
13 #define FW_CONST_STRING_BASE_HPP
14 
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 
26 class ConstStringBase : public Serializable {
27  public:
29 
31  virtual const CHAR* toChar() const = 0;
33  virtual SizeType getCapacity() const = 0;
35  virtual SizeType length() const;
37  SizeType maxLength() const;
38 
42  ) {
43  return static_cast<SizeType>(sizeof(FwSizeStoreType)) + maxLength;
44  }
45 
48  ) {
49  // Reserve one byte for each character plus one for the null terminator
50  return maxLength + 1;
51  }
52 
55  SizeType serializedSize() const;
56 
60  ) const;
61 
62  bool operator==(const ConstStringBase& other) const;
63  bool operator==(const CHAR* other) const;
64  bool operator!=(const ConstStringBase& other) const;
65  bool operator!=(const CHAR* other) const;
66 
69  SizeType maxLen,
70  Endianness mode = Endianness::BIG) const;
71  // NOTE: all derived classes should override this function; it will always return an error
72  // status since ConstStringBase is immutable and deserializeFrom is not a read-only operation
74 
75  DEPRECATED(SerializeStatus serialize(SerialBufferBase& buffer) const,
76  "Use serializeTo(SerializeBufferBase& buffer) instead") {
77  return this->serializeTo(buffer);
78  }
79 
80  DEPRECATED(SerializeStatus serialize(SerialBufferBase& buffer, SizeType maxLen) const,
81  "Use serializeTo(SerializeBufferBase& buffer, SizeType maxLen) instead") {
82  return this->serializeTo(buffer, maxLen);
83  }
84 
85 #ifdef BUILD_UT
86  // to support GoogleTest framework in unit tests
87  friend std::ostream& operator<<(std::ostream& os, const ConstStringBase& str);
88 #endif
89 
90 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
91  void toString(StringBase& text) const override;
92 #endif
93 
94  protected:
96  virtual ~ConstStringBase();
97 
98  private:
100  ConstStringBase(const ConstStringBase& src) = delete;
101 };
102 
103 } // namespace Fw
104 
105 #endif
PlatformSizeType FwSizeType
bool operator!=(const ConstStringBase &other) const
Inequality with ConstStringBase.
DEPRECATED(SerializeStatus serialize(SerialBufferBase &buffer) const, "Use serializeTo(SerializeBufferBase& buffer) instead")
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
DEPRECATED(SerializeStatus serialize(SerialBufferBase &buffer, SizeType maxLen) const, "Use serializeTo(SerializeBufferBase& buffer, SizeType maxLen) instead")
char CHAR
Definition: BasicTypes.h:59
SerializeStatus
forward declaration for string
SizeType serializedSize() const
U16 FwSizeStoreType
The type used to serialize a size value.
bool operator==(const ConstStringBase &other) const
Check for equality with ConstStringBase.
SizeType serializedTruncatedSize(FwSizeType maxLength) const
virtual SizeType getCapacity() const =0
Return the size of the buffer.
SizeType maxLength() const
Get the maximum length of a string that the buffer can hold (which is capacity - 1) ...
A read-only abstract superclass for StringBase.
virtual SizeType length() const
Get the length of the string.
static constexpr SizeType STATIC_SERIALIZED_SIZE(SizeType maxLength)
Implementation of malloc based allocator.
Endianness
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
SerializeStatus deserializeFrom(SerialBufferBase &buffer, Endianness mode=Endianness::BIG) override
Deserialize the contents of this object from a buffer.
Big endian serialization.
SerializeStatus serializeTo(SerialBufferBase &buffer, Endianness mode=Endianness::BIG) const override
Serialize the contents of this object to a buffer.