GCC Code Coverage Report


Directory: ./
File: Fw/DataStructures/ExternalArraySet.hpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 34 34 100.0%
Functions: 16 16 100.0%
Branches: 15 16 93.8%

Line Branch Exec Source
1 // ======================================================================
2 // \file ExternalArraySet.hpp
3 // \author bocchino
4 // \brief An array-based set with external storage
5 // ======================================================================
6
7 #ifndef Fw_ExternalArraySet_HPP
8 #define Fw_ExternalArraySet_HPP
9
10 #include "Fw/DataStructures/ArraySetOrMapImpl.hpp"
11 #include "Fw/DataStructures/Nil.hpp"
12 #include "Fw/DataStructures/SetBase.hpp"
13 #include "Fw/Types/Assert.hpp"
14
15 namespace Fw {
16
17 template <typename T>
18 class ExternalArraySet final : public SetBase<T> {
19 // ----------------------------------------------------------------------
20 // Friend class for testing
21 // ----------------------------------------------------------------------
22
23 template <typename TT>
24 friend class ExternalArraySetTester;
25
26 public:
27 // ----------------------------------------------------------------------
28 // Public types
29 // ----------------------------------------------------------------------
30
31 //! The type of a const iterator
32 using ConstIterator = SetConstIterator<T>;
33
34 //! The type of a set entry
35 using Entry = SetOrMapImplEntry<T, Nil>;
36
37 public:
38 // ----------------------------------------------------------------------
39 // Public constructors and destructors
40 // ----------------------------------------------------------------------
41
42 //! Zero-argument constructor
43
1/1
✓ Branch 18 taken 2 times.
2 ExternalArraySet() = default;
44
45 //! Constructor providing typed backing storage.
46 //! entries must point to at least capacity elements of type ImplEntry.
47 41 ExternalArraySet(Entry* entries, //!< The entries
48 FwSizeType capacity //!< The capacity
49 )
50
1/1
✓ Branch 18 taken 41 times.
41 : SetBase<T>() {
51
1/1
✓ Branch 4 taken 41 times.
41 this->setStorage(entries, capacity);
52 41 }
53
54 //! Constructor providing untyped backing storage.
55 //! data must be aligned according to getByteArrayAlignment().
56 //! data must contain at least getByteArraySize(capacity) bytes.
57 1 ExternalArraySet(ByteArray data, //!< The data,
58 FwSizeType capacity //!< The capacity
59 )
60
1/1
✓ Branch 18 taken 1 times.
1 : SetBase<T>() {
61
1/1
✓ Branch 4 taken 1 times.
1 this->setStorage(data, capacity);
62 1 }
63
64 //! Copy constructor
65
2/2
✓ Branch 19 taken 1 times.
✓ Branch 25 taken 1 times.
1 ExternalArraySet(const ExternalArraySet<T>& set) : SetBase<T>() { *this = set; }
66
67 //! Destructor
68 90 ~ExternalArraySet() override = default;
69
70 public:
71 // ----------------------------------------------------------------------
72 // Public member functions
73 // ----------------------------------------------------------------------
74
75 //! operator=
76 2 ExternalArraySet<T>& operator=(const ExternalArraySet<T>& set) {
77
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (&set != this) {
78 2 this->m_impl = set.m_impl;
79 }
80 2 return *this;
81 }
82
83 //! Get the begin iterator
84 //! \return The iterator
85
2/2
✓ Branch 4 taken 497 times.
✓ Branch 8 taken 497 times.
497 ConstIterator begin() const override { return ConstIterator(this->m_impl.begin()); }
86
87 //! Clear the set
88 191 void clear() override { this->m_impl.clear(); }
89
90 //! Get the end iterator
91 //! \return The iterator
92
2/2
✓ Branch 4 taken 163 times.
✓ Branch 8 taken 163 times.
163 ConstIterator end() const override { return ConstIterator(this->m_impl.end()); }
93
94 //! Find a value associated with an element in the set
95 //! \return SUCCESS if the item was found
96 2839 Success find(const T& element //!< The element
97 ) const override {
98 2839 Nil nil = {};
99
1/1
✓ Branch 4 taken 2839 times.
5678 return this->m_impl.find(element, nil);
100 }
101
102 //! Get the capacity of the set (max number of entries)
103 //! \return The capacity
104 3319 FwSizeType getCapacity() const override { return this->m_impl.getCapacity(); }
105
106 //! Get the size (number of entries)
107 //! \return The size
108 12907 FwSizeType getSize() const override { return this->m_impl.getSize(); }
109
110 //! Insert an element in the set
111 //! \return SUCCESS if there is room in the set
112 7386 Success insert(const T& element //!< The element
113 ) override {
114
1/1
✓ Branch 5 taken 7386 times.
14772 return this->m_impl.insert(element, Nil());
115 }
116
117 //! Remove an element from the set
118 //! \return SUCCESS if the element was there
119 657 Success remove(const T& element //!< The element
120 ) override {
121 657 Nil nil = {};
122
1/1
✓ Branch 4 taken 657 times.
1314 return this->m_impl.remove(element, nil);
123 }
124
125 //! Set the backing storage (typed data)
126 //! entries must point to at least capacity elements of type ImplEntry.
127 41 void setStorage(Entry* entries, //!< The entries
128 FwSizeType capacity //!< The capacity
129 ) {
130 41 this->m_impl.setStorage(entries, capacity);
131 41 }
132
133 //! Set the backing storage (untyped data)
134 //! data must be aligned according to getByteArrayAlignment().
135 //! data must contain at least getByteArraySize(capacity) bytes.
136 1 void setStorage(ByteArray data, //!< The data
137 FwSizeType capacity //!< The capacity
138 ) {
139 1 this->m_impl.setStorage(data, capacity);
140 1 }
141
142 public:
143 // ----------------------------------------------------------------------
144 // Public static functions
145 // ----------------------------------------------------------------------
146
147 //! Get the alignment of the storage for an ArraySetOrMapImpl
148 //! \return The alignment
149 static constexpr U8 getByteArrayAlignment() { return ArraySetOrMapImpl<T, Nil>::getByteArrayAlignment(); }
150
151 //! Get the size of the storage for an ExternalArray of the specified capacity,
152 //! as a byte array
153 //! \return The byte array size
154 static constexpr FwSizeType getByteArraySize(FwSizeType capacity //!< The capacity
155 ) {
156 return ArraySetOrMapImpl<T, Nil>::getByteArraySize(capacity);
157 }
158
159 private:
160 // ----------------------------------------------------------------------
161 // Private member variables
162 // ----------------------------------------------------------------------
163
164 //! The set implementation
165 ArraySetOrMapImpl<T, Nil> m_impl = {};
166 };
167
168 } // namespace Fw
169
170 #endif
171