GCC Code Coverage Report


Directory: ./
File: Fw/DataStructures/SetBase.hpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 4 4 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // ======================================================================
2 // \title SetBase
3 // \author bocchino
4 // \brief An abstract base class template for a set
5 // ======================================================================
6
7 #ifndef Fw_SetBase_HPP
8 #define Fw_SetBase_HPP
9
10 #include "Fw/DataStructures/SetConstIterator.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 T>
18 class SetBase : 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 SetBase(const SetBase<T>&) = delete;
27
28 //! operator= deleted in the base class
29 //! Behavior depends on the implementation
30 //! We avoid virtual user-defined operators
31 SetBase<T>& operator=(const SetBase<T>&) = delete;
32
33 public:
34 // ----------------------------------------------------------------------
35 // Public types
36 // ----------------------------------------------------------------------
37
38 //! The type of a set const iterator
39 using ConstIterator = SetConstIterator<T>;
40
41 protected:
42 // ----------------------------------------------------------------------
43 // Protected constructors and destructors
44 // ----------------------------------------------------------------------
45
46 //! Zero-argument constructor
47 4 SetBase() : SizedContainer() {}
48
49 //! Destructor
50 8 virtual ~SetBase() = default;
51
52 public:
53 // ----------------------------------------------------------------------
54 // Public member functions
55 // ----------------------------------------------------------------------
56
57 //! Get the begin iterator
58 //! \return The iterator
59 virtual ConstIterator begin() const = 0;
60
61 //! Get the end iterator
62 //! \return The iterator
63 virtual ConstIterator end() const = 0;
64
65 //! Copy data from another set
66 void copyDataFrom(const SetBase<T>& set) {
67 if (&set != this) {
68 this->clear();
69 const FwSizeType size = FW_MIN(set.getSize(), this->getCapacity());
70 auto it = set.begin();
71 for (FwSizeType i = 0; i < size; i++) {
72 const auto status = this->insert(*it);
73 FW_ASSERT(status == Success::SUCCESS, static_cast<FwAssertArgType>(status));
74 it++;
75 }
76 }
77 }
78
79 //! Find an element in a set
80 //! SUCCESS if the item was found
81 virtual Success find(const T& element //!< The element
82 ) const = 0;
83
84 //! Insert an element in the set
85 //! \return SUCCESS if there is room in the set
86 virtual Success insert(const T& element //!< The element
87 ) = 0;
88
89 //! Remove an element from the set
90 //! \return SUCCESS if the element was there
91 virtual Success remove(const T& element //!< The element
92 ) = 0;
93 };
94
95 } // namespace Fw
96
97 #endif
98