F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ExternalArrayMap.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \file ExternalArrayMap.hpp
3 // \author bocchino
4 // \brief An array-based map with external storage
5 // ======================================================================
6 
7 #ifndef Fw_ExternalArrayMap_HPP
8 #define Fw_ExternalArrayMap_HPP
9 
12 #include "Fw/Types/Assert.hpp"
13 
14 namespace Fw {
15 
16 template <typename K, typename V>
17 class ExternalArrayMap final : public MapBase<K, V> {
18  // ----------------------------------------------------------------------
19  // Friend class for testing
20  // ----------------------------------------------------------------------
21 
22  template <typename KK, typename VV>
23  friend class ExternalArrayMapTester;
24 
25  public:
26  // ----------------------------------------------------------------------
27  // Public types
28  // ----------------------------------------------------------------------
29 
32 
35 
36  public:
37  // ----------------------------------------------------------------------
38  // Public constructors and destructors
39  // ----------------------------------------------------------------------
40 
42  ExternalArrayMap() = default;
43 
47  FwSizeType capacity
48  )
49  : MapBase<K, V>() {
50  this->setStorage(entries, capacity);
51  }
52 
57  FwSizeType capacity
58  )
59  : MapBase<K, V>() {
60  this->setStorage(data, capacity);
61  }
62 
64  ExternalArrayMap(const ExternalArrayMap<K, V>& map) : MapBase<K, V>() { *this = map; }
65 
67  ~ExternalArrayMap() override = default;
68 
69  public:
70  // ----------------------------------------------------------------------
71  // Public member functions
72  // ----------------------------------------------------------------------
73 
76  if (&map != this) {
77  this->m_impl = map.m_impl;
78  }
79  return *this;
80  }
81 
84  ConstIterator begin() const override { return ConstIterator(this->m_impl.begin()); }
85 
87  void clear() override { this->m_impl.clear(); }
88 
91  ConstIterator end() const override { return ConstIterator(this->m_impl.end()); }
92 
95  Success find(const K& key,
96  V& value
97  ) const override {
98  return this->m_impl.find(key, value);
99  }
100 
103  FwSizeType getCapacity() const override { return this->m_impl.getCapacity(); }
104 
107  FwSizeType getSize() const override { return this->m_impl.getSize(); }
108 
111  Success insert(const K& key,
112  const V& value
113  ) override {
114  return this->m_impl.insert(key, value);
115  }
116 
119  Success remove(const K& key,
120  V& value
121  ) override {
122  return this->m_impl.remove(key, value);
123  }
124 
127  void setStorage(Entry* entries,
128  FwSizeType capacity
129  ) {
130  this->m_impl.setStorage(entries, capacity);
131  }
132 
136  void setStorage(ByteArray data,
137  FwSizeType capacity
138  ) {
139  this->m_impl.setStorage(data, capacity);
140  }
141 
142  public:
143  // ----------------------------------------------------------------------
144  // Public static functions
145  // ----------------------------------------------------------------------
146 
150 
154  static constexpr FwSizeType getByteArraySize(FwSizeType capacity
155  ) {
157  }
158 
159  private:
160  // ----------------------------------------------------------------------
161  // Private member variables
162  // ----------------------------------------------------------------------
163 
165  ArraySetOrMapImpl<K, V> m_impl = {};
166 };
167 
168 } // namespace Fw
169 
170 #endif
static constexpr U8 getByteArrayAlignment()
PlatformSizeType FwSizeType
ConstIterator begin() const
Get the begin iterator.
void clear() override
Clear the map.
ExternalArrayMap(const ExternalArrayMap< K, V > &map)
Copy constructor.
~ExternalArrayMap() override=default
Destructor.
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
friend class ExternalArrayMapTester
ConstIterator end() const override
void setStorage(Entry *entries, FwSizeType capacity)
ConstIterator end() const
Get the end iterator.
ExternalArrayMap()=default
Zero-argument constructor.
Success remove(const KE &keyOrElement, VN &valueOrNil)
void clear()
Clear the set or map.
A variable-length byte array.
Definition: ByteArray.hpp:23
Success insert(const K &key, const V &value) override
MapConstIterator< K, V > ConstIterator
The type of a const iterator.
ConstIterator begin() const override
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
void setStorage(Entry *entries, FwSizeType capacity)
Success find(const KE &keyOrElement, VN &valueOrNil) const
Success find(const K &key, V &value) const override
FwSizeType getCapacity() const
void setStorage(ByteArray data, FwSizeType capacity)
ExternalArrayMap(Entry *entries, FwSizeType capacity)
static constexpr U8 getByteArrayAlignment()
FwSizeType getSize() const override
ExternalArrayMap(ByteArray data, FwSizeType capacity)
FwSizeType getSize() const
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
ExternalArrayMap< K, V > & operator=(const ExternalArrayMap< K, V > &map)
operator=
FwSizeType getCapacity() const override
Success/Failure.
Success insert(const KE &keyOrElement, const VN &valueOrNil)