From ec7e67b5ba152285ffb27ea6f0f1415a1b7aed86 2017-08-24 14:53:03 From: Alexandre Leroux Date: 2017-08-24 14:53:03 Subject: [PATCH] Updates DataSeriesIterator to make an iterator general to SciQlop --- diff --git a/core/include/Data/DataSeriesIterator.h b/core/include/Data/DataSeriesIterator.h index 78c05af..3489d23 100644 --- a/core/include/Data/DataSeriesIterator.h +++ b/core/include/Data/DataSeriesIterator.h @@ -2,6 +2,7 @@ #define SCIQLOP_DATASERIESITERATOR_H #include "CoreGlobal.h" +#include "Data/SqpIterator.h" #include @@ -54,35 +55,6 @@ private: std::unique_ptr m_Impl; }; -/** - * @brief The DataSeriesIterator class represents an iterator used for data series. It defines all - * operators needed for a standard forward iterator - * @sa http://www.cplusplus.com/reference/iterator/ - */ -class SCIQLOP_CORE_EXPORT DataSeriesIterator { -public: - using iterator_category = std::forward_iterator_tag; - using value_type = const DataSeriesIteratorValue; - using difference_type = std::ptrdiff_t; - using pointer = value_type *; - using reference = value_type &; - - explicit DataSeriesIterator(DataSeriesIteratorValue value); - virtual ~DataSeriesIterator() noexcept = default; - DataSeriesIterator(const DataSeriesIterator &) = default; - DataSeriesIterator(DataSeriesIterator &&) = default; - DataSeriesIterator &operator=(const DataSeriesIterator &) = default; - DataSeriesIterator &operator=(DataSeriesIterator &&) = default; - - DataSeriesIterator &operator++(); - DataSeriesIterator &operator--(); - pointer operator->() const { return &m_CurrentValue; } - reference operator*() const { return m_CurrentValue; } - bool operator==(const DataSeriesIterator &other) const; - bool operator!=(const DataSeriesIterator &other) const; - -private: - DataSeriesIteratorValue m_CurrentValue; -}; +using DataSeriesIterator = SqpIterator; #endif // SCIQLOP_DATASERIESITERATOR_H diff --git a/core/include/Data/SqpIterator.h b/core/include/Data/SqpIterator.h new file mode 100644 index 0000000..8b51389 --- /dev/null +++ b/core/include/Data/SqpIterator.h @@ -0,0 +1,54 @@ +#ifndef SCIQLOP_SQPITERATOR_H +#define SCIQLOP_SQPITERATOR_H + +#include "CoreGlobal.h" + +/** + * @brief The SqpIterator class represents an iterator used in SciQlop. It defines all operators + * needed for a standard forward iterator + * @tparam T the type of object handled in iterator + * @sa http://www.cplusplus.com/reference/iterator/ + */ +template +class SCIQLOP_CORE_EXPORT SqpIterator { +public: + using iterator_category = std::forward_iterator_tag; + using value_type = const T; + using difference_type = std::ptrdiff_t; + using pointer = value_type *; + using reference = value_type &; + + explicit SqpIterator(T value) : m_CurrentValue{std::move(value)} {} + + virtual ~SqpIterator() noexcept = default; + SqpIterator(const SqpIterator &) = default; + SqpIterator(SqpIterator &&) = default; + SqpIterator &operator=(const SqpIterator &) = default; + SqpIterator &operator=(SqpIterator &&) = default; + + SqpIterator &operator++() + { + m_CurrentValue.next(); + return *this; + } + + SqpIterator &operator--() + { + m_CurrentValue.prev(); + return *this; + } + + pointer operator->() const { return &m_CurrentValue; } + reference operator*() const { return m_CurrentValue; } + + bool operator==(const SqpIterator &other) const + { + return m_CurrentValue.equals(other.m_CurrentValue); + } + bool operator!=(const SqpIterator &other) const { return !(*this == other); } + +private: + T m_CurrentValue; +}; + +#endif // SCIQLOP_SQPITERATOR_H diff --git a/core/src/Data/DataSeriesIterator.cpp b/core/src/Data/DataSeriesIterator.cpp index 87a2222..03daf1e 100644 --- a/core/src/Data/DataSeriesIterator.cpp +++ b/core/src/Data/DataSeriesIterator.cpp @@ -56,30 +56,3 @@ double DataSeriesIteratorValue::maxValue() const { return m_Impl->maxValue(); } - -DataSeriesIterator::DataSeriesIterator(DataSeriesIteratorValue value) - : m_CurrentValue{std::move(value)} -{ -} - -DataSeriesIterator &DataSeriesIterator::operator++() -{ - m_CurrentValue.next(); - return *this; -} - -DataSeriesIterator &DataSeriesIterator::operator--() -{ - m_CurrentValue.prev(); - return *this; -} - -bool DataSeriesIterator::operator==(const DataSeriesIterator &other) const -{ - return m_CurrentValue.equals(other.m_CurrentValue); -} - -bool DataSeriesIterator::operator!=(const DataSeriesIterator &other) const -{ - return !(*this == other); -}