mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl docs * Revise RedBlackTree impl * Revise RedBlackTree impl * Fix typo * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl * Revise RedBlackTreeImpl docs * Revise Fw/DataStructures Reformat code * Revise Fw/DataStructures Fix compile errors on Linux * Revise Fw/DataStructures Fix compile errors on Linux * Revise Fw/DataStructures Fix compile errors on Linux * Revise Fw/DataStructures Fix compile errors on Linux * Fix comments * Revise Fw/DataStructures Fix compile errors on Linux * Revise ArrayMap docs * Remove helper scripts * Revise tests for Fw/DataStructures * Fix spelling * Fix Markdown link * Fix uninitialized variable in test * Fix uninitialized variable in test * Fix "spelling" Why is the spelling check enforcing arbitrary rules of style? * Fix comments * Revise RedBlackTree impl docs * Start adding RedBlackTree impl * Revise tests for ArraySetOrMapImpl * Revise RedBlackTree impl * Revise comment * Revise comment * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise ArraySetOrMap impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Add RedBlackTree impl tester * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Fix comments * Revise RedBlackTree impl * Fix comments * Revise comments * Revise comments * Revise comments * Revise statement order for clarity * Revise unit tests for RedBlackTree impl * Revise RedBlackTree impl tests * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Add build and clean scripts Working around regressions in the F Prime build system * Revise build Fix warnings * Revise RedBlackTree impl and tests * Revise tests for RedBlackTree impl * Revise RedBlackTree impl and tests * Revise RedBlackTree tests Remove debug print statements * Revise RedBlackTree impl tester * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise build script * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl test * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise comment * Revise RedBlackTree impl and tests * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl * Revise RedBlackTree impl tests * Revise formatting * Format code * Revise docs * Revise docs for Fw/DataStructures * Revise Array and ExternalArray Add static assertions * Revise FifoQueue and Stack Add static assertions * Revise ArraySet and ArrayMap Add static assertions * Revise docs for ExternalRedBlackTreeMap * Revise docs for ExternalRedBlackTreeSet * Revise docs for RedBlackTreeMap * Revise docs for RedBlackTreeSet * Revise ExternalRedBlackTreeMap tests * Refactor ExternalStackTester * Revise ArrayMap tests * Add RedBlackTreeMap * Revise RedBlackTreeMap tests * Revise RedBlackTreeMap * Add ExternalRedBlackTreeSet * Add missing file * Revise SetConstIterator * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTree tests * Revise ExternalArraySet tests * Revise ExternalArraySet tests * Add RedBlackTreeSet * Revise RedBlackTreeSet tests * Refactor ArraySetTest * Revise RedBlackTreeSetOrMapImpl docs * Revise array initialization * Revise comments * Revise Array initialization * Revise Array design and implementation * Revert changes to Fw/DataStructures * Revise Array * Revise Array * Revise Array * Fix formatting * Add SizedContainer base class * Revise StackBase Make it inherit from SizedContainer Revise stack tests * Revise MapBase Make it inherit from SizedContainer Revise tests * Revise SetBase Make it inherit from SizedContainer Revise tests * Revise DataStructures design Add SizedContainer * Revise SDD for DataStructures * Revise DataStructures design * Revise DataStructures design * Revise DataStructures design * Revise DataStructures design * Fix spelling * Revise zero-arg constructor for Array * Revise Array interface Make it consistent with the arrays generated by FPP * Fix to assertion * Format code * Fix spelling * Fix spelling * Add -Wno-comment to suppress warnings for now * Revise comments * Revise diagrams * Fix comment warnings on gcc * Eliminate tabs * Remove utility scripts * Revise placement of break statements * Rename function getParentDirection --> getDirectionFromParent * Add comment * Add svg diagram * Add svg diagram * Add svg files * Revise diagram * Replace png with svg * Replace png with svg * Replace png with svg * Revise comment * Revise SDD for red-black tree * Revise SDD for red-black tree
172 lines
5.8 KiB
C++
172 lines
5.8 KiB
C++
// ======================================================================
|
|
// \title SetConstIterator
|
|
// \author bocchino
|
|
// \brief An abstract class template representing a const iterator for a set
|
|
// ======================================================================
|
|
|
|
#ifndef Fw_SetConstIterator_HPP
|
|
#define Fw_SetConstIterator_HPP
|
|
|
|
#include <new>
|
|
|
|
#include "Fw/DataStructures/ArraySetOrMapImpl.hpp"
|
|
#include "Fw/DataStructures/Nil.hpp"
|
|
#include "Fw/DataStructures/RedBlackTreeSetOrMapImpl.hpp"
|
|
#include "Fw/FPrimeBasicTypes.hpp"
|
|
|
|
namespace Fw {
|
|
|
|
template <typename T>
|
|
class SetConstIterator {
|
|
public:
|
|
// ----------------------------------------------------------------------
|
|
// Public types
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! The type of an array iterator
|
|
using ArrayIterator = typename ArraySetOrMapImpl<T, Nil>::ConstIterator;
|
|
|
|
//! The type of a red-black tree iterator
|
|
using RedBlackTreeIterator = typename RedBlackTreeSetOrMapImpl<T, Nil>::ConstIterator;
|
|
|
|
private:
|
|
// ----------------------------------------------------------------------
|
|
// Private types
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! The type of an implementation kind
|
|
using ImplKind = typename SetOrMapImplConstIterator<T, Nil>::ImplKind;
|
|
|
|
//! The type of an implementation
|
|
union Impl {
|
|
//! Default constructor
|
|
Impl() {}
|
|
//! Array constructor
|
|
Impl(const ArrayIterator& it) : array(it) {}
|
|
//! Red-black tree constructor
|
|
Impl(const RedBlackTreeIterator& it) : redBlackTree(it) {}
|
|
//! An array iterator
|
|
ArrayIterator array;
|
|
//! A red-black tree iterator
|
|
RedBlackTreeIterator redBlackTree;
|
|
// ! Destructor
|
|
~Impl() {}
|
|
};
|
|
|
|
public:
|
|
// ----------------------------------------------------------------------
|
|
// Constructors and destructors
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! Constructor providing an array implementation
|
|
SetConstIterator(const ArrayIterator& it) : m_impl(it), m_implIterator(&m_impl.array) {}
|
|
|
|
//! Constructor providing a red-black tree implementation
|
|
SetConstIterator(const RedBlackTreeIterator& it) : m_impl(it), m_implIterator(&m_impl.redBlackTree) {}
|
|
|
|
//! Copy constructor
|
|
SetConstIterator(const SetConstIterator& it) : m_impl(), m_implIterator() {
|
|
const auto implKind = it.getImplIterator().implKind();
|
|
switch (implKind) {
|
|
case ImplKind::ARRAY:
|
|
this->m_implIterator = new (&this->m_impl.array) ArrayIterator(it.m_impl.array);
|
|
break;
|
|
case ImplKind::RED_BLACK_TREE:
|
|
this->m_implIterator = new (&this->m_impl.redBlackTree) RedBlackTreeIterator(it.m_impl.redBlackTree);
|
|
break;
|
|
default:
|
|
FW_ASSERT(0, static_cast<FwAssertArgType>(implKind));
|
|
break;
|
|
}
|
|
}
|
|
|
|
//! Destructor
|
|
~SetConstIterator() {}
|
|
|
|
public:
|
|
// ----------------------------------------------------------------------
|
|
// Public member functions
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! Copy assignment operator
|
|
SetConstIterator& operator=(const SetConstIterator&) = default;
|
|
|
|
//! Equality comparison operator
|
|
bool operator==(const SetConstIterator& it) {
|
|
bool result = false;
|
|
const auto implKind1 = this->getImplIterator().implKind();
|
|
const auto implKind2 = it.getImplIterator().implKind();
|
|
if (implKind1 == implKind2) {
|
|
switch (implKind1) {
|
|
case ImplKind::ARRAY:
|
|
result = this->m_impl.array.compareEqual(it.m_impl.array);
|
|
break;
|
|
case ImplKind::RED_BLACK_TREE:
|
|
result = this->m_impl.redBlackTree.compareEqual(it.m_impl.redBlackTree);
|
|
break;
|
|
default:
|
|
FW_ASSERT(0, static_cast<FwAssertArgType>(implKind1));
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
//! Inequality comparison operator
|
|
bool operator!=(const SetConstIterator& it) { return !(*this == it); };
|
|
|
|
//! Prefix increment
|
|
SetConstIterator& operator++() {
|
|
this->getImplIterator().increment();
|
|
return *this;
|
|
}
|
|
|
|
//! Postfix increment
|
|
SetConstIterator operator++(int) {
|
|
SetConstIterator tmp = *this;
|
|
++(*this);
|
|
return tmp;
|
|
}
|
|
|
|
//! Check whether the iterator is in range
|
|
bool isInRange() const { return this->getImplIterator().isInRange(); }
|
|
|
|
//! Dereference
|
|
const T& operator*() const { return this->getImplIterator().getEntry().getKeyOrElement(); }
|
|
|
|
//! Pointer
|
|
const T* operator->() const { return &this->getImplIterator().getEntry().getKeyOrElement(); }
|
|
|
|
private:
|
|
// ----------------------------------------------------------------------
|
|
// Private helper functions
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! Assert and get the impl iterator
|
|
SetOrMapImplConstIterator<T, Nil>& getImplIterator() {
|
|
FW_ASSERT(this->m_implIterator != nullptr);
|
|
return *this->m_implIterator;
|
|
}
|
|
|
|
//! Assert and get the impl iterator (const)
|
|
const SetOrMapImplConstIterator<T, Nil>& getImplIterator() const {
|
|
FW_ASSERT(this->m_implIterator != nullptr);
|
|
return *this->m_implIterator;
|
|
}
|
|
|
|
private:
|
|
// ----------------------------------------------------------------------
|
|
// Private member variables
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! The implementation
|
|
Impl m_impl;
|
|
|
|
//! The impl iterator
|
|
SetOrMapImplConstIterator<T, Nil>* m_implIterator = nullptr;
|
|
};
|
|
|
|
} // namespace Fw
|
|
|
|
#endif
|