F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
23namespace Fw {
24class 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
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
bool operator!=(const StringBase &other) const
Inequality with StringBase.
NATIVE_UINT_TYPE SizeType
static constexpr SizeType STATIC_SERIALIZED_SIZE(SizeType maxLength)
virtual ~StringBase()
SizeType serializedTruncatedSize(FwSizeType maxLength) const
virtual SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialization function
void format(const CHAR *formatString,...)
write formatted string to buffer
SizeType length() const
Get length of string.
bool operator==(const StringBase &other) const
Check for equality with StringBase.
SizeType maxLength() const
Get the maximum length of a string that the buffer can hold (which is capacity - 1)
void appendBuff(const CHAR *buff, SizeType size)
virtual SerializeStatus serialize(SerializeBufferBase &buffer) const
serialization function
virtual SizeType getCapacity() const =0
return size of buffer
virtual const CHAR * toChar() const =0
const CHAR * operator+=(const CHAR *src)
Concatenate a CHAR*.
StringBase & operator=(const CHAR *src)
Assign CHAR*.
SizeType serializedSize() const
void vformat(const CHAR *formatString, va_list args)
write formatted string to buffer using va_list
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
SerializeStatus
forward declaration for string