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;
39  SizeType maxLength(SizeType capacity) const;
40 
44  ) {
45  return static_cast<SizeType>(sizeof(FwSizeStoreType)) + maxLength;
46  }
47 
50  ) {
51  // Reserve one byte for each character plus one for the null terminator
52  return maxLength + 1;
53  }
54 
57  SizeType serializedSize() const;
58 
62  ) const;
63 
64  bool operator==(const ConstStringBase& other) const;
65  bool operator==(const CHAR* other) const;
66  bool operator!=(const ConstStringBase& other) const;
67  bool operator!=(const CHAR* other) const;
68 
71  SizeType maxLen,
72  Endianness mode = Endianness::BIG) const;
73  // NOTE: all derived classes should override this function; it will always return an error
74  // status since ConstStringBase is immutable and deserializeFrom is not a read-only operation
76 
77  DEPRECATED(SerializeStatus serialize(SerialBufferBase& buffer) const,
78  "Use serializeTo(LinearBufferBase& buffer) instead") {
79  return this->serializeTo(buffer);
80  }
81 
82  DEPRECATED(SerializeStatus serialize(SerialBufferBase& buffer, SizeType maxLen) const,
83  "Use serializeTo(LinearBufferBase& buffer, SizeType maxLen) instead") {
84  return this->serializeTo(buffer, maxLen);
85  }
86 
87 #ifdef BUILD_UT
88  // to support GoogleTest framework in unit tests
89  friend std::ostream& operator<<(std::ostream& os, const ConstStringBase& str);
90 #endif
91 
92 #if FW_SERIALIZABLE_TO_STRING || BUILD_UT
93  void toString(StringBase& text) const override;
94 #endif
95 
96  protected:
98  virtual ~ConstStringBase();
99 
100  private:
102  ConstStringBase(const ConstStringBase& src) = delete;
103 };
104 
105 } // namespace Fw
106 
107 #endif
PlatformSizeType FwSizeType
bool operator!=(const ConstStringBase &other) const
Inequality with ConstStringBase.
DEPRECATED(SerializeStatus serialize(SerialBufferBase &buffer) const, "Use serializeTo(LinearBufferBase& buffer) instead")
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
char CHAR
Definition: BasicTypes.h:60
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.
DEPRECATED(SerializeStatus serialize(SerialBufferBase &buffer, SizeType maxLen) const, "Use serializeTo(LinearBufferBase& buffer, SizeType maxLen) instead")
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.