F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ArrayMap.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \file ArrayMap.hpp
3 // \author bocchino
4 // \brief An array-based map with internal storage
5 // ======================================================================
6 
7 #ifndef Fw_ArrayMap_HPP
8 #define Fw_ArrayMap_HPP
9 
11 
12 namespace Fw {
13 
14 template <typename K, typename V, FwSizeType C>
15 class ArrayMap final : public MapBase<K, V> {
16  // ----------------------------------------------------------------------
17  // Static assertions
18  // ----------------------------------------------------------------------
19 
20  static_assert(C > 0, "capacity must be greater than zero");
21 
22  // ----------------------------------------------------------------------
23  // Friend class for testing
24  // ----------------------------------------------------------------------
25 
26  template <typename KK, typename VV, FwSizeType CC>
27  friend class ArrayMapTester;
28 
29  public:
30  // ----------------------------------------------------------------------
31  // Public types
32  // ----------------------------------------------------------------------
33 
36 
39 
41  using Entries = Entry[C];
42 
43  public:
44  // ----------------------------------------------------------------------
45  // Public constructors and destructors
46  // ----------------------------------------------------------------------
47 
49  ArrayMap() : MapBase<K, V>(), m_extMap(m_entries, C) {}
50 
52  ArrayMap(const ArrayMap<K, V, C>& map) : MapBase<K, V>(), m_extMap(m_entries, C) { *this = map; }
53 
55  ~ArrayMap() override = default;
56 
57  public:
58  // ----------------------------------------------------------------------
59  // Public member functions
60  // ----------------------------------------------------------------------
61 
64  this->m_extMap.copyDataFrom(map);
65  return *this;
66  }
67 
70  ConstIterator begin() const override { return this->m_extMap.begin(); }
71 
73  void clear() override { this->m_extMap.clear(); }
74 
77  ConstIterator end() const override { return this->m_extMap.end(); }
78 
81  Success find(const K& key,
82  V& value
83  ) const override {
84  return this->m_extMap.find(key, value);
85  }
86 
89  FwSizeType getCapacity() const override { return this->m_extMap.getCapacity(); }
90 
93  FwSizeType getSize() const override { return this->m_extMap.getSize(); }
94 
97  Success insert(const K& key,
98  const V& value
99  ) override {
100  return this->m_extMap.insert(key, value);
101  }
102 
105  Success remove(const K& key,
106  V& value
107  ) override {
108  return this->m_extMap.remove(key, value);
109  }
110 
111  private:
112  // ----------------------------------------------------------------------
113  // Private member variables
114  // ----------------------------------------------------------------------
115 
117  ExternalArrayMap<K, V> m_extMap = {};
118 
120  Entries m_entries = {};
121 };
122 
123 } // namespace Fw
124 
125 #endif
ConstIterator end() const override
Definition: ArrayMap.hpp:77
PlatformSizeType FwSizeType
ArrayMap< K, V, C > & operator=(const ArrayMap< K, V, C > &map)
operator=
Definition: ArrayMap.hpp:63
ArrayMap(const ArrayMap< K, V, C > &map)
Copy constructor.
Definition: ArrayMap.hpp:52
Success insert(const K &key, const V &value) override
Definition: ArrayMap.hpp:97
void clear() override
Clear the map.
Definition: ArrayMap.hpp:73
ConstIterator begin() const override
Definition: ArrayMap.hpp:70
FwSizeType getCapacity() const override
Definition: ArrayMap.hpp:89
ArrayMap()
Zero-argument constructor.
Definition: ArrayMap.hpp:49
Success find(const K &key, V &value) const override
Definition: ArrayMap.hpp:81
~ArrayMap() override=default
Destructor.
Entry[C] Entries
The type of the implementation entries.
Definition: ArrayMap.hpp:41
FwSizeType getSize() const override
Definition: ArrayMap.hpp:93
friend class ArrayMapTester
Definition: ArrayMap.hpp:20
Success/Failure.