| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title SizedContainer | ||
| 3 | // \author bocchino | ||
| 4 | // \brief An abstract base class representing a sized container | ||
| 5 | // ====================================================================== | ||
| 6 | |||
| 7 | #ifndef Fw_SizedContainer_HPP | ||
| 8 | #define Fw_SizedContainer_HPP | ||
| 9 | |||
| 10 | #include "Fw/FPrimeBasicTypes.hpp" | ||
| 11 | |||
| 12 | namespace Fw { | ||
| 13 | |||
| 14 | class SizedContainer { | ||
| 15 | private: | ||
| 16 | // ---------------------------------------------------------------------- | ||
| 17 | // Private constructors | ||
| 18 | // ---------------------------------------------------------------------- | ||
| 19 | |||
| 20 | //! Copy constructor deleted in the base class | ||
| 21 | //! Behavior depends on the implementation | ||
| 22 | SizedContainer(const SizedContainer&) = delete; | ||
| 23 | |||
| 24 | protected: | ||
| 25 | // ---------------------------------------------------------------------- | ||
| 26 | // Protected constructors and destructors | ||
| 27 | // ---------------------------------------------------------------------- | ||
| 28 | |||
| 29 | //! Zero-argument constructor | ||
| 30 | 2231 | SizedContainer() {} | |
| 31 | |||
| 32 | //! Destructor | ||
| 33 | 4462 | virtual ~SizedContainer() = default; | |
| 34 | |||
| 35 | private: | ||
| 36 | // ---------------------------------------------------------------------- | ||
| 37 | // Private member functions | ||
| 38 | // ---------------------------------------------------------------------- | ||
| 39 | |||
| 40 | //! operator= deleted in the base class | ||
| 41 | //! Behavior depends on the implementation | ||
| 42 | //! We avoid virtual user-defined operators | ||
| 43 | SizedContainer& operator=(const SizedContainer&) = delete; | ||
| 44 | |||
| 45 | public: | ||
| 46 | // ---------------------------------------------------------------------- | ||
| 47 | // Public member functions | ||
| 48 | // ---------------------------------------------------------------------- | ||
| 49 | |||
| 50 | //! Clear the container | ||
| 51 | virtual void clear() = 0; | ||
| 52 | |||
| 53 | //! Get the size (number of items stored in the container) | ||
| 54 | //! \return The size | ||
| 55 | virtual FwSizeType getSize() const = 0; | ||
| 56 | |||
| 57 | //! Get the capacity (maximum number of items storable in the container) | ||
| 58 | //! \return The capacity | ||
| 59 | virtual FwSizeType getCapacity() const = 0; | ||
| 60 | |||
| 61 | //! Check whether the container is empty | ||
| 62 | //! \return True if the container is empty | ||
| 63 | 18665 | bool isEmpty() const { return this->getSize() == 0; } | |
| 64 | |||
| 65 | //! Check whether the container is full | ||
| 66 | //! \return True if the container is full | ||
| 67 | 20762 | bool isFull() const { return this->getSize() >= this->getCapacity(); } | |
| 68 | }; | ||
| 69 | |||
| 70 | } // namespace Fw | ||
| 71 | |||
| 72 | #endif | ||
| 73 |