| 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 | 112 | SetBase() : SizedContainer() {} | |
| 48 | |||
| 49 | //! Destructor | ||
| 50 | 224 | 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 | 16 | void copyDataFrom(const SetBase<T>& set) { | |
| 67 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (&set != this) { |
| 68 |
1/1✓ Branch 10 taken 16 times.
|
16 | this->clear(); |
| 69 |
6/6✓ Branch 11 taken 16 times.
✓ Branch 23 taken 16 times.
✓ Branch 25 taken 8 times.
✓ Branch 26 taken 8 times.
✓ Branch 38 taken 8 times.
✓ Branch 50 taken 8 times.
|
16 | const FwSizeType size = FW_MIN(set.getSize(), this->getCapacity()); |
| 70 |
1/1✓ Branch 5 taken 16 times.
|
16 | auto it = set.begin(); |
| 71 |
2/2✓ Branch 3 taken 4140 times.
✓ Branch 4 taken 16 times.
|
8296 | for (FwSizeType i = 0; i < size; i++) { |
| 72 |
2/2✓ Branch 5 taken 4140 times.
✓ Branch 8 taken 4140 times.
|
4140 | const auto status = this->insert(*it); |
| 73 | 4140 | FW_ASSERT(status == Success::SUCCESS, static_cast<FwAssertArgType>(status)); | |
| 74 |
1/1✓ Branch 2 taken 4140 times.
|
4140 | it++; |
| 75 | } | ||
| 76 | 16 | } | |
| 77 | 16 | } | |
| 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 |