GCC Code Coverage Report


Directory: ./
File: Fw/Types/ExternalString.hpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 9 9 100.0%
Branches: 3 3 100.0%

Line Branch Exec Source
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 <Fw/FPrimeBasicTypes.hpp>
11
12 #include "Fw/Types/StringBase.hpp"
13
14 namespace Fw {
15
16 //! A string backed by an external buffer
17 class ExternalString final : public Fw::StringBase {
18 public:
19 // ----------------------------------------------------------------------
20 // Construction and destruction
21 // ----------------------------------------------------------------------
22
23 //! Deleted copy constructor
24 ExternalString(const ExternalString&) = delete;
25
26 //! Constructor (uninitialized buffer)
27 ExternalString() : StringBase(), m_bufferPtr(nullptr), m_bufferSize(0) {}
28
29 //! Constructor (bufferPtr and bufferSize)
30 1071741 ExternalString(char* bufferPtr, //!< The buffer pointer
31 StringBase::SizeType bufferSize //!< The buffer size
32 )
33 1071741 : StringBase(), m_bufferPtr(bufferPtr), m_bufferSize(bufferSize) {
34
1/1
✓ Branch 4 taken 1071741 times.
1071741 *this = "";
35 1071741 }
36
37 //! Constructor (bufferPtr, bufferSize, and StringBase)
38 60610 ExternalString(char* bufferPtr, //!< The buffer pointer
39 StringBase::SizeType bufferSize, //!< The buffer size
40 const StringBase& sb //!< The source string
41 )
42 60610 : StringBase(), m_bufferPtr(bufferPtr), m_bufferSize(bufferSize) {
43
1/1
✓ Branch 7 taken 60610 times.
60610 *this = sb;
44 60610 }
45
46 //! Constructor (bufferPtr, bufferSize, and const char*)
47 2 ExternalString(char* bufferPtr, //!< The buffer pointer
48 StringBase::SizeType bufferSize, //!< The buffer size
49 const char* str //!< The source string
50 )
51 2 : StringBase(), m_bufferPtr(bufferPtr), m_bufferSize(bufferSize) {
52
1/1
✓ Branch 4 taken 2 times.
2 *this = str;
53 2 }
54
55 //! Destructor
56 2264706 ~ExternalString() {}
57
58 public:
59 // ----------------------------------------------------------------------
60 // StringBase interface
61 // ----------------------------------------------------------------------
62
63 //! Gets the char buffer
64 //! @return The char buffer
65 1257849 const char* toChar() const { return this->m_bufferPtr; }
66
67 //! Returns the buffer size
68 //! @return The buffer size
69 1200229 StringBase::SizeType getCapacity() const { return this->m_bufferSize; }
70
71 public:
72 // ----------------------------------------------------------------------
73 // Public interface
74 // ----------------------------------------------------------------------
75
76 //! Set the buffer and initialize it to the empty string
77 void setBuffer(char* bufferPtr, //!< The buffer pointer
78 StringBase::SizeType bufferSize //!< The buffer size
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&)
91 12663 ExternalString& operator=(const ExternalString& src) {
92 12663 (void)StringBase::operator=(src);
93 12663 return *this;
94 }
95
96 // Operator= (const ConstStringBase&)
97 110647 ExternalString& operator=(const ConstStringBase& src) {
98 110647 (void)StringBase::operator=(src);
99 110647 return *this;
100 }
101
102 // const char* assignment operator
103 1071743 ExternalString& operator=(const char* src) {
104 1071743 (void)StringBase::operator=(src);
105 1071743 return *this;
106 }
107
108 private:
109 // ----------------------------------------------------------------------
110 // Data members
111 // ----------------------------------------------------------------------
112
113 //! Pointer to string buffer
114 char* m_bufferPtr;
115
116 //! Size of string buffer
117 //! F Prime strings are null-terminated, so this is one more than
118 //! the length of the largest string that the buffer can hold
119 StringBase::SizeType m_bufferSize;
120 };
121 } // namespace Fw
122
123 #endif
124