F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
MapBase.hpp
Go to the documentation of this file.
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 
12 #include "Fw/Types/Assert.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 
26  MapBase(const MapBase<K, V>&) = delete;
27 
31  MapBase<K, V>& operator=(const MapBase<K, V>&) = delete;
32 
33  public:
34  // ----------------------------------------------------------------------
35  // Public types
36  // ----------------------------------------------------------------------
37 
40 
41  protected:
42  // ----------------------------------------------------------------------
43  // Protected constructors and destructors
44  // ----------------------------------------------------------------------
45 
48 
50  virtual ~MapBase() = default;
51 
52  public:
53  // ----------------------------------------------------------------------
54  // Public member functions
55  // ----------------------------------------------------------------------
56 
59  virtual ConstIterator begin() const = 0;
60 
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 
77  virtual ConstIterator end() const = 0;
78 
81  virtual Success find(const K& key,
82  V& value
83  ) const = 0;
84 
87  virtual Success insert(const K& key,
88  const V& value
89  ) = 0;
93  virtual Success remove(const K& key,
94  V& value
95  ) = 0;
96 };
97 
98 } // namespace Fw
99 
100 #endif
Representing success.
void copyDataFrom(const MapBase< K, V > &map)
Copy data from another map.
Definition: MapBase.hpp:62
PlatformSizeType FwSizeType
virtual ConstIterator begin() const =0
virtual FwSizeType getSize() const =0
MapConstIterator< K, V > ConstIterator
The type of a map const iterator.
Definition: MapBase.hpp:39
virtual Success find(const K &key, V &value) const =0
MapBase()
Zero-argument constructor.
Definition: MapBase.hpp:47
#define FW_MIN(a, b)
MIN macro.
Definition: BasicTypes.h:92
virtual FwSizeType getCapacity() const =0
virtual ~MapBase()=default
Destructor.
virtual ConstIterator end() const =0
virtual void clear()=0
Clear the container.
virtual Success insert(const K &key, const V &value)=0
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.