GCC Code Coverage Report


Directory: ./
File: Fw/DataStructures/MapBase.hpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 2 13 15.4%
Functions: 8 11 72.7%
Branches: 0 18 0.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title MapBase
3 // \author bocchino
4 // \brief An abstract base class template for a map
5 // ======================================================================
6
7 #ifndef Fw_MapBase_HPP
8 #define Fw_MapBase_HPP
9
10 #include "Fw/DataStructures/MapConstIterator.hpp"
11 #include "Fw/DataStructures/SizedContainer.hpp"
12 #include "Fw/Types/Assert.hpp"
13 #include "Fw/Types/SuccessEnumAc.hpp"
14
15 namespace Fw {
16
17 template <typename K, typename V>
18 class MapBase : public SizedContainer {
19 private:
20 // ----------------------------------------------------------------------
21 // Deleted elements
22 // ----------------------------------------------------------------------
23
24 //! Copy constructor deleted in the base class
25 //! Behavior depends on the implementation
26 MapBase(const MapBase<K, V>&) = delete;
27
28 //! operator= deleted in the base class
29 //! Behavior depends on the implementation
30 //! We avoid virtual user-defined operators
31 MapBase<K, V>& operator=(const MapBase<K, V>&) = delete;
32
33 public:
34 // ----------------------------------------------------------------------
35 // Public types
36 // ----------------------------------------------------------------------
37
38 //! The type of a map const iterator
39 using ConstIterator = MapConstIterator<K, V>;
40
41 protected:
42 // ----------------------------------------------------------------------
43 // Protected constructors and destructors
44 // ----------------------------------------------------------------------
45
46 //! Zero-argument constructor
47 14 MapBase() : SizedContainer() {}
48
49 //! Destructor
50 20 virtual ~MapBase() = default;
51
52 public:
53 // ----------------------------------------------------------------------
54 // Public member functions
55 // ----------------------------------------------------------------------
56
57 //! Get the begin value of the iterator
58 //! \return The iterator
59 virtual ConstIterator begin() const = 0;
60
61 //! Copy data from another map
62 void copyDataFrom(const MapBase<K, V>& map) {
63 if (&map != this) {
64 this->clear();
65 const FwSizeType size = FW_MIN(map.getSize(), this->getCapacity());
66 auto it = map.begin();
67 for (FwSizeType i = 0; i < size; i++) {
68 const auto status = this->insert(it->getKey(), it->getValue());
69 FW_ASSERT(status == Success::SUCCESS, static_cast<FwAssertArgType>(status));
70 it++;
71 }
72 }
73 }
74
75 //! Get the end value of the iterator
76 //! \return The iterator
77 virtual ConstIterator end() const = 0;
78
79 //! Find the value associated with a key in the map
80 //! SUCCESS if the item was found
81 virtual Success find(const K& key, //!< The key (input)
82 V& value //!< The value (output)
83 ) const = 0;
84
85 //! Insert a (key, value) pair in the map
86 //! \return SUCCESS if there is room in the map
87 virtual Success insert(const K& key, //!< The key
88 const V& value //!< The value
89 ) = 0;
90 //! Remove a (key, value) pair from the map
91 //! Store the value into the value parameter if the key was there
92 //! \return SUCCESS if the key was there
93 virtual Success remove(const K& key, //!< The key (input)
94 V& value //!< The value (output)
95 ) = 0;
96 };
97
98 } // namespace Fw
99
100 #endif
101