F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
ExternalString.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // @file ExternalString.hpp
3 // @author Robert Bocchino
4 // @brief A string backed by an external buffer
5 // ======================================================================
6 
7 #ifndef FW_EXTERNAL_STRING_HPP
8 #define FW_EXTERNAL_STRING_HPP
9 
10 #include <FpConfig.hpp>
11 
12 #include "Fw/Types/StringBase.hpp"
13 
14 namespace Fw {
15 
17 class ExternalString final : public Fw::StringBase {
18  public:
19  // ----------------------------------------------------------------------
20  // Construction and destruction
21  // ----------------------------------------------------------------------
22 
24  ExternalString(const ExternalString&) = delete;
25 
27  ExternalString() : StringBase(), m_bufferPtr(nullptr), m_bufferSize(0) {}
28 
30  ExternalString(char* bufferPtr,
31  StringBase::SizeType bufferSize
32  )
33  : StringBase(), m_bufferPtr(bufferPtr), m_bufferSize(bufferSize) {
34  *this = "";
35  }
36 
38  ExternalString(char* bufferPtr,
39  StringBase::SizeType bufferSize,
40  const StringBase& sb
41  )
42  : StringBase(), m_bufferPtr(bufferPtr), m_bufferSize(bufferSize) {
43  *this = sb;
44  }
45 
47  ExternalString(char* bufferPtr,
48  StringBase::SizeType bufferSize,
49  const char* str
50  )
51  : StringBase(), m_bufferPtr(bufferPtr), m_bufferSize(bufferSize) {
52  *this = str;
53  }
54 
57 
58  public:
59  // ----------------------------------------------------------------------
60  // StringBase interface
61  // ----------------------------------------------------------------------
62 
65  const char* toChar() const { return this->m_bufferPtr; }
66 
69  StringBase::SizeType getCapacity() const { return this->m_bufferSize; }
70 
71  public:
72  // ----------------------------------------------------------------------
73  // Public interface
74  // ----------------------------------------------------------------------
75 
77  void setBuffer(char* bufferPtr,
78  StringBase::SizeType bufferSize
79  ) {
80  this->m_bufferPtr = bufferPtr;
81  this->m_bufferSize = bufferSize;
82  *this = "";
83  }
84 
85  public:
86  // ----------------------------------------------------------------------
87  // Operators
88  // ----------------------------------------------------------------------
89 
90  // Operator= (const ExternalString&)
92  (void)StringBase::operator=(src);
93  return *this;
94  }
95 
96  // Operator= (const StringBase&)
98  (void)StringBase::operator=(src);
99  return *this;
100  }
101 
102  // const char* assignment operator
103  ExternalString& operator=(const char* src) {
104  (void)StringBase::operator=(src);
105  return *this;
106  }
107 
108  private:
109  // ----------------------------------------------------------------------
110  // Data members
111  // ----------------------------------------------------------------------
112 
114  char* m_bufferPtr;
115 
119  StringBase::SizeType m_bufferSize;
120 };
121 } // namespace Fw
122 
123 #endif
C++-compatible configuration header for fprime configuration.
Declares F Prime string base class.
A string backed by an external buffer.
ExternalString & operator=(const StringBase &src)
ExternalString(char *bufferPtr, StringBase::SizeType bufferSize, const char *str)
Constructor (bufferPtr, bufferSize, and const char*)
ExternalString(char *bufferPtr, StringBase::SizeType bufferSize)
Constructor (bufferPtr and bufferSize)
StringBase::SizeType getCapacity() const
ExternalString(const ExternalString &)=delete
Deleted copy constructor.
ExternalString()
Constructor (uninitialized buffer)
ExternalString & operator=(const ExternalString &src)
const char * toChar() const
ExternalString & operator=(const char *src)
void setBuffer(char *bufferPtr, StringBase::SizeType bufferSize)
Set the buffer and initialize it to the empty string.
~ExternalString()
Destructor.
ExternalString(char *bufferPtr, StringBase::SizeType bufferSize, const StringBase &sb)
Constructor (bufferPtr, bufferSize, and StringBase)
NATIVE_UINT_TYPE SizeType
Definition: StringBase.hpp:26