F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
SetBase.hpp
Go to the documentation of this file.
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 
12 #include "Fw/Types/Assert.hpp"
14 
15 namespace Fw {
16 
17 template <typename T>
18 class SetBase : public SizedContainer {
19  private:
20  // ----------------------------------------------------------------------
21  // Deleted elements
22  // ----------------------------------------------------------------------
23 
26  SetBase(const SetBase<T>&) = delete;
27 
31  SetBase<T>& operator=(const SetBase<T>&) = delete;
32 
33  public:
34  // ----------------------------------------------------------------------
35  // Public types
36  // ----------------------------------------------------------------------
37 
40 
41  protected:
42  // ----------------------------------------------------------------------
43  // Protected constructors and destructors
44  // ----------------------------------------------------------------------
45 
48 
50  virtual ~SetBase() = default;
51 
52  public:
53  // ----------------------------------------------------------------------
54  // Public member functions
55  // ----------------------------------------------------------------------
56 
59  virtual ConstIterator begin() const = 0;
60 
63  virtual ConstIterator end() const = 0;
64 
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 
81  virtual Success find(const T& element
82  ) const = 0;
83 
86  virtual Success insert(const T& element
87  ) = 0;
88 
91  virtual Success remove(const T& element
92  ) = 0;
93 };
94 
95 } // namespace Fw
96 
97 #endif
virtual ~SetBase()=default
Destructor.
virtual Success insert(const T &element)=0
Representing success.
PlatformSizeType FwSizeType
virtual FwSizeType getSize() const =0
#define FW_MIN(a, b)
MIN macro.
Definition: BasicTypes.h:92
virtual FwSizeType getCapacity() const =0
SetConstIterator< T > ConstIterator
The type of a set const iterator.
Definition: SetBase.hpp:39
virtual Success find(const T &element) const =0
void copyDataFrom(const SetBase< T > &set)
Copy data from another set.
Definition: SetBase.hpp:66
virtual ConstIterator begin() const =0
SetBase()
Zero-argument constructor.
Definition: SetBase.hpp:47
virtual ConstIterator end() const =0
virtual void clear()=0
Clear the container.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.