GCC Code Coverage Report


Directory: ./
File: Fw/DataStructures/ExternalArrayMap.hpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 16 19 84.2%
Functions: 17 33 51.5%
Branches: 2 6 33.3%

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