F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ExternalArraySet.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \file ExternalArraySet.hpp
3 // \author bocchino
4 // \brief An array-based set with external storage
5 // ======================================================================
6 
7 #ifndef Fw_ExternalArraySet_HPP
8 #define Fw_ExternalArraySet_HPP
9 
13 #include "Fw/Types/Assert.hpp"
14 
15 namespace Fw {
16 
17 template <typename T>
18 class ExternalArraySet final : public SetBase<T> {
19  // ----------------------------------------------------------------------
20  // Friend class for testing
21  // ----------------------------------------------------------------------
22 
23  template <typename TT>
24  friend class ExternalArraySetTester;
25 
26  public:
27  // ----------------------------------------------------------------------
28  // Public types
29  // ----------------------------------------------------------------------
30 
33 
36 
37  public:
38  // ----------------------------------------------------------------------
39  // Public constructors and destructors
40  // ----------------------------------------------------------------------
41 
43  ExternalArraySet() = default;
44 
48  FwSizeType capacity
49  )
50  : SetBase<T>() {
51  this->setStorage(entries, capacity);
52  }
53 
58  FwSizeType capacity
59  )
60  : SetBase<T>() {
61  this->setStorage(data, capacity);
62  }
63 
65  ExternalArraySet(const ExternalArraySet<T>& set) : SetBase<T>() { *this = set; }
66 
68  ~ExternalArraySet() override = default;
69 
70  public:
71  // ----------------------------------------------------------------------
72  // Public member functions
73  // ----------------------------------------------------------------------
74 
77  if (&set != this) {
78  this->m_impl = set.m_impl;
79  }
80  return *this;
81  }
82 
85  ConstIterator begin() const override { return ConstIterator(this->m_impl.begin()); }
86 
88  void clear() override { this->m_impl.clear(); }
89 
92  ConstIterator end() const override { return ConstIterator(this->m_impl.end()); }
93 
96  Success find(const T& element
97  ) const override {
98  Nil nil = {};
99  return this->m_impl.find(element, nil);
100  }
101 
104  FwSizeType getCapacity() const override { return this->m_impl.getCapacity(); }
105 
108  FwSizeType getSize() const override { return this->m_impl.getSize(); }
109 
112  Success insert(const T& element
113  ) override {
114  return this->m_impl.insert(element, Nil());
115  }
116 
119  Success remove(const T& element
120  ) override {
121  Nil nil = {};
122  return this->m_impl.remove(element, nil);
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<T, Nil> m_impl = {};
166 };
167 
168 } // namespace Fw
169 
170 #endif
SetConstIterator< T > ConstIterator
The type of a const iterator.
PlatformSizeType FwSizeType
Success find(const T &element) const override
ConstIterator begin() const
Get the begin iterator.
void clear() override
Clear the set.
friend class ExternalArraySetTester
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
void setStorage(Entry *entries, FwSizeType capacity)
static constexpr U8 getByteArrayAlignment()
ConstIterator end() const
Get the end iterator.
Success insert(const T &element) override
ExternalArraySet(const ExternalArraySet< T > &set)
Copy constructor.
Success remove(const KE &keyOrElement, VN &valueOrNil)
void setStorage(ByteArray data, FwSizeType capacity)
void clear()
Clear the set or map.
void setStorage(Entry *entries, FwSizeType capacity)
A variable-length byte array.
Definition: ByteArray.hpp:23
FwSizeType getSize() const override
~ExternalArraySet() override=default
Destructor.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
ConstIterator begin() const override
Success find(const KE &keyOrElement, VN &valueOrNil) const
FwSizeType getCapacity() const
ExternalArraySet()=default
Zero-argument constructor.
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
static constexpr U8 getByteArrayAlignment()
FwSizeType getSize() const
Definition: Nil.hpp:12
ExternalArraySet(ByteArray data, FwSizeType capacity)
ConstIterator end() const override
ExternalArraySet(Entry *entries, FwSizeType capacity)
Success/Failure.
Success insert(const KE &keyOrElement, const VN &valueOrNil)
FwSizeType getCapacity() const override
ExternalArraySet< T > & operator=(const ExternalArraySet< T > &set)
operator=