From 294b109a05632239eb4c87f85e256d4604bc65c2 2017-08-24 14:53:08 From: Alexandre Leroux Date: 2017-08-24 14:53:08 Subject: [PATCH] Creates general iterator for ArrayData --- diff --git a/core/include/Data/ArrayDataIterator.h b/core/include/Data/ArrayDataIterator.h new file mode 100644 index 0000000..af46ede --- /dev/null +++ b/core/include/Data/ArrayDataIterator.h @@ -0,0 +1,56 @@ +#ifndef SCIQLOP_ARRAYDATAITERATOR_H +#define SCIQLOP_ARRAYDATAITERATOR_H + +#include "CoreGlobal.h" +#include "Data/SqpIterator.h" + +#include + +/** + * @brief The ArrayDataIteratorValue class represents the current value of an array data iterator. + * It offers standard access methods for the data in the series (at(), first()), but it is up to + * each array data to define its own implementation of how to retrieve this data (one-dim or two-dim + * array), by implementing the ArrayDataIteratorValue::Impl interface + * @sa ArrayDataIterator + */ +class SCIQLOP_CORE_EXPORT ArrayDataIteratorValue { +public: + struct Impl { + virtual ~Impl() noexcept = default; + virtual std::unique_ptr clone() const = 0; + virtual bool equals(const Impl &other) const = 0; + virtual void next() = 0; + virtual void prev() = 0; + virtual double at(int componentIndex) const = 0; + virtual double first() const = 0; + virtual double min() const = 0; + virtual double max() const = 0; + }; + + explicit ArrayDataIteratorValue(std::unique_ptr impl); + ArrayDataIteratorValue(const ArrayDataIteratorValue &other); + ArrayDataIteratorValue(ArrayDataIteratorValue &&other) = default; + ArrayDataIteratorValue &operator=(ArrayDataIteratorValue other); + + bool equals(const ArrayDataIteratorValue &other) const; + + /// Advances to the next value + void next(); + /// Moves back to the previous value + void prev(); + /// Gets value of a specified component + double at(int componentIndex) const; + /// Gets value of first component + double first() const; + /// Gets min value among all components + double min() const; + /// Gets max value among all components + double max() const; + +private: + std::unique_ptr m_Impl; +}; + +using ArrayDataIterator = SqpIterator; + +#endif // SCIQLOP_ARRAYDATAITERATOR_H diff --git a/core/src/Data/ArrayDataIterator.cpp b/core/src/Data/ArrayDataIterator.cpp new file mode 100644 index 0000000..fb13181 --- /dev/null +++ b/core/src/Data/ArrayDataIterator.cpp @@ -0,0 +1,52 @@ +#include "Data/ArrayDataIterator.h" + +ArrayDataIteratorValue::ArrayDataIteratorValue(std::unique_ptr impl) + : m_Impl{std::move(impl)} +{ +} + +ArrayDataIteratorValue::ArrayDataIteratorValue(const ArrayDataIteratorValue &other) + : m_Impl{other.m_Impl->clone()} +{ +} + +ArrayDataIteratorValue &ArrayDataIteratorValue::operator=(ArrayDataIteratorValue other) +{ + std::swap(m_Impl, other.m_Impl); + return *this; +} + +bool ArrayDataIteratorValue::equals(const ArrayDataIteratorValue &other) const +{ + return m_Impl->equals(*other.m_Impl); +} + +void ArrayDataIteratorValue::next() +{ + m_Impl->next(); +} + +void ArrayDataIteratorValue::prev() +{ + m_Impl->prev(); +} + +double ArrayDataIteratorValue::at(int componentIndex) const +{ + return m_Impl->at(componentIndex); +} + +double ArrayDataIteratorValue::first() const +{ + return m_Impl->first(); +} + +double ArrayDataIteratorValue::min() const +{ + return m_Impl->min(); +} + +double ArrayDataIteratorValue::max() const +{ + return m_Impl->max(); +}