GCC Code Coverage Report


Directory: ./
File: Fw/DataStructures/ArrayMap.hpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 10 16 62.5%
Functions: 14 31 45.2%
Branches: 8 13 61.5%

Line Branch Exec Source
1 // ======================================================================
2 // \file ArrayMap.hpp
3 // \author bocchino
4 // \brief An array-based map with internal storage
5 // ======================================================================
6
7 #ifndef Fw_ArrayMap_HPP
8 #define Fw_ArrayMap_HPP
9
10 #include "Fw/DataStructures/ExternalArrayMap.hpp"
11
12 namespace Fw {
13
14 template <typename K, typename V, FwSizeType C>
15 class ArrayMap final : public MapBase<K, V> {
16 // ----------------------------------------------------------------------
17 // Static assertions
18 // ----------------------------------------------------------------------
19
20 static_assert(C > 0, "capacity must be greater than zero");
21
22 // ----------------------------------------------------------------------
23 // Friend class for testing
24 // ----------------------------------------------------------------------
25
26 template <typename KK, typename VV, FwSizeType CC>
27 friend class ArrayMapTester;
28
29 public:
30 // ----------------------------------------------------------------------
31 // Public types
32 // ----------------------------------------------------------------------
33
34 //! The type of a const iterator
35 using ConstIterator = MapConstIterator<K, V>;
36
37 //! The type of an implementation entry
38 using Entry = SetOrMapImplEntry<K, V>;
39
40 //! The type of the implementation entries
41 using Entries = Entry[C];
42
43 public:
44 // ----------------------------------------------------------------------
45 // Public constructors and destructors
46 // ----------------------------------------------------------------------
47
48 //! Zero-argument constructor
49
5/9
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 87 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 50 times.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
91 ArrayMap() : MapBase<K, V>(), m_extMap(m_entries, C) {}
50
51 //! Copy constructor
52 ArrayMap(const ArrayMap<K, V, C>& map) : MapBase<K, V>(), m_extMap(m_entries, C) { *this = map; }
53
54 //! Destructor
55
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87 times.
✓ Branch 3 taken 4 times.
182 ~ArrayMap() override = default;
56
57 public:
58 // ----------------------------------------------------------------------
59 // Public member functions
60 // ----------------------------------------------------------------------
61
62 //! operator=
63 ArrayMap<K, V, C>& operator=(const ArrayMap<K, V, C>& map) {
64 this->m_extMap.copyDataFrom(map);
65 return *this;
66 }
67
68 //! Get the begin iterator
69 //! \return The iterator
70 ConstIterator begin() const override { return this->m_extMap.begin(); }
71
72 //! Clear the map
73 2 void clear() override { this->m_extMap.clear(); }
74
75 //! Get the end iterator
76 //! \return The iterator
77 ConstIterator end() const override { return this->m_extMap.end(); }
78
79 //! Find a value associated with a key in the map
80 //! \return SUCCESS if the item was found
81 823 Success find(const K& key, //!< The key
82 V& value //!< The value
83 ) const override {
84 823 return this->m_extMap.find(key, value);
85 }
86
87 //! Get the capacity of the map (max number of entries)
88 //! \return The capacity
89 FwSizeType getCapacity() const override { return this->m_extMap.getCapacity(); }
90
91 //! Get the size (number of entries)
92 //! \return The size
93 8 FwSizeType getSize() const override { return this->m_extMap.getSize(); }
94
95 //! Insert a (key, value) pair in the map
96 //! \return SUCCESS if there is room in the map
97 963 Success insert(const K& key, //!< The key
98 const V& value //!< The value
99 ) override {
100 963 return this->m_extMap.insert(key, value);
101 }
102
103 //! Remove a (key, value) pair from the map
104 //! \return SUCCESS if the key was there
105 145 Success remove(const K& key, //!< The key
106 V& value //!< The value
107 ) override {
108 145 return this->m_extMap.remove(key, value);
109 }
110
111 private:
112 // ----------------------------------------------------------------------
113 // Private member variables
114 // ----------------------------------------------------------------------
115
116 //! The external map implementation
117 ExternalArrayMap<K, V> m_extMap = {};
118
119 //! The array providing the backing memory for m_extMap
120 Entries m_entries = {};
121 };
122
123 } // namespace Fw
124
125 #endif
126