F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
String.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // @file String.hpp
3 // @author F Prime
4 // @brief A general purpose string backed by a fixed-size buffer
5 // ======================================================================
6 
7 #ifndef FW_STRING_HPP
8 #define FW_STRING_HPP
9 
10 #include <FpConfig.hpp>
11 
12 #include "Fw/Cfg/SerIds.hpp"
13 #include "Fw/Types/StringBase.hpp"
14 
15 namespace Fw {
16 
17 class String final : public StringBase {
18  public:
19  enum {
23  };
24 
25  String() : StringBase() { *this = ""; }
26 
27  explicit String(const String& src) : StringBase() { *this = src; }
28 
29  explicit String(const StringBase& src) : StringBase() { *this = src; }
30 
31  String(const char* src) : StringBase() { *this = src; }
32 
33  ~String() {}
34 
35  String& operator=(const String& src) {
36  (void)StringBase::operator=(src);
37  return *this;
38  }
39 
40  String& operator=(const StringBase& src) {
41  (void)StringBase::operator=(src);
42  return *this;
43  }
44 
45  String& operator=(const char* src) {
46  (void)StringBase::operator=(src);
47  return *this;
48  }
49 
50  const char* toChar() const { return this->m_buf; }
51 
52  StringBase::SizeType getCapacity() const { return sizeof this->m_buf; }
53 
54  private:
55  char m_buf[BUFFER_SIZE(STRING_SIZE)];
56 };
57 } // namespace Fw
58 
59 #endif
#define FW_FIXED_LENGTH_STRING_SIZE
Character array size for Fw::String.
Definition: FpConfig.h:387
C++-compatible configuration header for fprime configuration.
Definitions for ISF type serial IDs.
Declares F Prime string base class.
NATIVE_UINT_TYPE SizeType
Definition: StringBase.hpp:26
static constexpr SizeType STATIC_SERIALIZED_SIZE(SizeType maxLength)
Definition: StringBase.hpp:35
static constexpr SizeType BUFFER_SIZE(SizeType maxLength)
Get the size of a null-terminated string buffer.
Definition: StringBase.hpp:41
String & operator=(const char *src)
Definition: String.hpp:45
String & operator=(const StringBase &src)
Definition: String.hpp:40
String & operator=(const String &src)
Definition: String.hpp:35
@ STRING_SIZE
Definition: String.hpp:21
@ SERIALIZED_TYPE_ID
Definition: String.hpp:20
@ SERIALIZED_SIZE
Definition: String.hpp:22
String(const StringBase &src)
Definition: String.hpp:29
const char * toChar() const
Definition: String.hpp:50
String(const String &src)
Definition: String.hpp:27
String(const char *src)
Definition: String.hpp:31
StringBase::SizeType getCapacity() const
return size of buffer
Definition: String.hpp:52
@ FW_TYPEID_FIXED_LENGTH_STRING
256 char string Buffer type id
Definition: SerIds.hpp:59