2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-04-30 10:41:24 +00:00
|
|
|
#ifndef SPROUT_ITERATOR_SINUSOID_ITERATOR_HPP
|
|
|
|
#define SPROUT_ITERATOR_SINUSOID_ITERATOR_HPP
|
|
|
|
|
|
|
|
#include <iterator>
|
|
|
|
#include <utility>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2012-04-30 10:41:24 +00:00
|
|
|
#include <sprout/iterator/next.hpp>
|
|
|
|
#include <sprout/iterator/prev.hpp>
|
|
|
|
#include <sprout/iterator/distance.hpp>
|
2012-10-05 15:58:56 +00:00
|
|
|
#include <sprout/utility/swap.hpp>
|
2014-04-20 06:25:25 +00:00
|
|
|
#include <sprout/numeric/dft/detail/sinusoid.hpp>
|
2012-04-30 10:41:24 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// sinusoid_iterator
|
|
|
|
//
|
|
|
|
template<typename Value>
|
|
|
|
class sinusoid_iterator
|
|
|
|
: public std::iterator<
|
|
|
|
std::random_access_iterator_tag,
|
|
|
|
Value,
|
|
|
|
std::ptrdiff_t,
|
|
|
|
Value*,
|
|
|
|
Value
|
|
|
|
>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::random_access_iterator_tag iterator_category;
|
|
|
|
typedef Value value_type;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
typedef value_type* pointer;
|
|
|
|
typedef value_type reference;
|
|
|
|
private:
|
2012-04-30 13:18:45 +00:00
|
|
|
difference_type index_;
|
2012-04-30 10:41:24 +00:00
|
|
|
value_type frequency_;
|
|
|
|
value_type amplitude_;
|
2012-05-01 02:32:48 +00:00
|
|
|
value_type phase_;
|
2012-04-30 10:41:24 +00:00
|
|
|
value_type d_;
|
|
|
|
private:
|
|
|
|
explicit SPROUT_CONSTEXPR sinusoid_iterator(sinusoid_iterator const& other, difference_type index)
|
2012-04-30 13:18:45 +00:00
|
|
|
: index_(index)
|
|
|
|
, frequency_(other.frequency_)
|
2012-04-30 10:41:24 +00:00
|
|
|
, amplitude_(other.amplitude_)
|
2012-05-01 02:32:48 +00:00
|
|
|
, phase_(other.phase_)
|
2012-04-30 10:41:24 +00:00
|
|
|
, d_(other.d_)
|
|
|
|
{}
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR sinusoid_iterator()
|
2012-04-30 13:18:45 +00:00
|
|
|
: index_()
|
|
|
|
, frequency_(1)
|
2012-04-30 10:41:24 +00:00
|
|
|
, amplitude_(1)
|
2012-05-01 02:32:48 +00:00
|
|
|
, phase_(0)
|
2014-04-20 06:25:25 +00:00
|
|
|
, d_(sprout::detail::sinusoid_value_d(frequency_))
|
2012-04-30 10:41:24 +00:00
|
|
|
{}
|
|
|
|
sinusoid_iterator(sinusoid_iterator const&) = default;
|
|
|
|
explicit SPROUT_CONSTEXPR sinusoid_iterator(
|
2012-04-30 13:18:45 +00:00
|
|
|
difference_type index,
|
|
|
|
value_type const& frequency = 1,
|
2012-05-01 02:32:48 +00:00
|
|
|
value_type const& amplitude = 1,
|
|
|
|
value_type const& phase = 0
|
2012-04-30 10:41:24 +00:00
|
|
|
)
|
2012-04-30 13:18:45 +00:00
|
|
|
: index_(index)
|
|
|
|
, frequency_(frequency)
|
2012-04-30 10:41:24 +00:00
|
|
|
, amplitude_(amplitude)
|
2012-05-01 02:32:48 +00:00
|
|
|
, phase_(phase)
|
2014-04-20 06:25:25 +00:00
|
|
|
, d_(sprout::detail::sinusoid_value_d(frequency_))
|
2012-04-30 10:41:24 +00:00
|
|
|
{}
|
|
|
|
template<typename U>
|
|
|
|
SPROUT_CONSTEXPR sinusoid_iterator(sinusoid_iterator<U> const& it)
|
2012-04-30 13:18:45 +00:00
|
|
|
: index_(it.index_)
|
|
|
|
, frequency_(it.frequency_)
|
2012-04-30 10:41:24 +00:00
|
|
|
, amplitude_(it.amplitude_)
|
2012-05-01 02:32:48 +00:00
|
|
|
, phase_(it.phase_)
|
2012-04-30 10:41:24 +00:00
|
|
|
, d_(it.d_)
|
|
|
|
{}
|
|
|
|
template<typename U>
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR sinusoid_iterator& operator=(sinusoid_iterator<U> const& it) {
|
2012-04-30 10:41:24 +00:00
|
|
|
sinusoid_iterator temp(it);
|
|
|
|
temp.swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR difference_type index() const {
|
|
|
|
return index_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR value_type const& frequency() const {
|
|
|
|
return frequency_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR value_type const& amplitude() const {
|
|
|
|
return amplitude_;
|
|
|
|
}
|
2012-05-01 02:32:48 +00:00
|
|
|
SPROUT_CONSTEXPR value_type const& phase() const {
|
|
|
|
return phase_;
|
|
|
|
}
|
2012-04-30 10:41:24 +00:00
|
|
|
SPROUT_CONSTEXPR reference operator*() const {
|
2012-12-06 17:31:16 +00:00
|
|
|
return amplitude_ == 0 ? 0
|
2014-04-20 06:25:25 +00:00
|
|
|
: sprout::detail::sinusoid_value(amplitude_, phase_, d_, index_)
|
2012-12-06 17:31:16 +00:00
|
|
|
;
|
2012-04-30 10:41:24 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR pointer operator->() const {
|
|
|
|
return &operator*()();
|
|
|
|
}
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR sinusoid_iterator& operator++() {
|
2012-04-30 10:41:24 +00:00
|
|
|
++index_;
|
|
|
|
return *this;
|
|
|
|
}
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR sinusoid_iterator operator++(int) {
|
2012-04-30 10:41:24 +00:00
|
|
|
sinusoid_iterator result(*this);
|
|
|
|
++index_;
|
|
|
|
return result;
|
|
|
|
}
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR sinusoid_iterator& operator--() {
|
2012-04-30 10:41:24 +00:00
|
|
|
--index_;
|
|
|
|
return *this;
|
|
|
|
}
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR sinusoid_iterator operator--(int) {
|
2012-04-30 10:41:24 +00:00
|
|
|
sinusoid_iterator temp(*this);
|
|
|
|
--index_;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR sinusoid_iterator operator+(difference_type n) const {
|
|
|
|
return sinusoid_iterator(*this, index_ + n);
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR sinusoid_iterator operator-(difference_type n) const {
|
|
|
|
return sinusoid_iterator(*this, index_ - n);
|
|
|
|
}
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR sinusoid_iterator& operator+=(difference_type n) {
|
2012-04-30 10:41:24 +00:00
|
|
|
sinusoid_iterator temp(*this, index_ + n);
|
|
|
|
temp.swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR sinusoid_iterator& operator-=(difference_type n) {
|
2012-04-30 10:41:24 +00:00
|
|
|
sinusoid_iterator temp(*this, index_ - n);
|
|
|
|
temp.swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
2012-12-06 17:31:16 +00:00
|
|
|
return amplitude_ == 0 ? 0
|
2014-04-20 06:25:25 +00:00
|
|
|
: sprout::detail::sinusoid_value(amplitude_, phase_, d_, index_ + n)
|
2012-12-06 17:31:16 +00:00
|
|
|
;
|
2012-04-30 10:41:24 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR sinusoid_iterator next() const {
|
|
|
|
return sinusoid_iterator(*this, index_ + 1);
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR sinusoid_iterator prev() const {
|
|
|
|
return sinusoid_iterator(*this, index_ - 1);
|
|
|
|
}
|
2013-10-09 14:44:25 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void swap(sinusoid_iterator& other) SPROUT_NOEXCEPT {
|
2012-10-05 15:58:56 +00:00
|
|
|
sprout::swap(index_, other.index_);
|
|
|
|
sprout::swap(frequency_, other.frequency_);
|
|
|
|
sprout::swap(amplitude_, other.amplitude_);
|
|
|
|
sprout::swap(phase_, other.phase_);
|
|
|
|
sprout::swap(d_, other.d_);
|
2012-04-30 10:41:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Value1, typename Value2>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
operator==(sprout::sinusoid_iterator<Value1> const& lhs, sprout::sinusoid_iterator<Value2> const& rhs) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return lhs.index() == rhs.index();
|
|
|
|
}
|
|
|
|
template<typename Value1, typename Value2>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
operator!=(sprout::sinusoid_iterator<Value1> const& lhs, sprout::sinusoid_iterator<Value2> const& rhs) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
template<typename Value1, typename Value2>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
operator<(sprout::sinusoid_iterator<Value1> const& lhs, sprout::sinusoid_iterator<Value2> const& rhs) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return lhs.index() < rhs.index();
|
|
|
|
}
|
|
|
|
template<typename Value1, typename Value2>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
operator>(sprout::sinusoid_iterator<Value1> const& lhs, sprout::sinusoid_iterator<Value2> const& rhs) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return rhs < lhs;
|
|
|
|
}
|
|
|
|
template<typename Value1, typename Value2>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
operator<=(sprout::sinusoid_iterator<Value1> const& lhs, sprout::sinusoid_iterator<Value2> const& rhs) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return !(rhs < lhs);
|
|
|
|
}
|
|
|
|
template<typename Value1, typename Value2>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
operator>=(sprout::sinusoid_iterator<Value1> const& lhs, sprout::sinusoid_iterator<Value2> const& rhs) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return !(lhs < rhs);
|
|
|
|
}
|
|
|
|
template<typename Value1, typename Value2>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::sinusoid_iterator<Value1>::difference_type
|
|
|
|
operator-(sprout::sinusoid_iterator<Value1> const& lhs, sprout::sinusoid_iterator<Value2> const& rhs) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return lhs.index() - rhs.index();
|
|
|
|
}
|
|
|
|
template<typename Value>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value>
|
|
|
|
operator+(typename sprout::sinusoid_iterator<Value>::difference_type n, sprout::sinusoid_iterator<Value> const& it) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return it + n;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// swap
|
|
|
|
//
|
|
|
|
template<typename Value>
|
2013-10-09 14:44:25 +00:00
|
|
|
inline SPROUT_CXX14_CONSTEXPR void
|
2012-10-05 15:58:56 +00:00
|
|
|
swap(sprout::sinusoid_iterator<Value>& lhs, sprout::sinusoid_iterator<Value>& rhs)
|
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
|
|
|
{
|
2012-04-30 10:41:24 +00:00
|
|
|
lhs.swap(rhs);
|
|
|
|
}
|
|
|
|
|
2012-09-26 07:31:11 +00:00
|
|
|
//
|
|
|
|
// iterator_next
|
2012-04-30 10:41:24 +00:00
|
|
|
//
|
|
|
|
template<typename Value>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value>
|
|
|
|
iterator_next(sprout::sinusoid_iterator<Value> const& it) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return it.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-09-26 07:31:11 +00:00
|
|
|
// iterator_prev
|
2012-04-30 10:41:24 +00:00
|
|
|
//
|
|
|
|
template<typename Value>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::sinusoid_iterator<Value>
|
|
|
|
iterator_prev(sprout::sinusoid_iterator<Value> const& it) {
|
2012-04-30 10:41:24 +00:00
|
|
|
return it.prev();
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ITERATOR_SINUSOID_ITERATOR_HPP
|