Nsound  0.9.4
Public Member Functions | Private Attributes | List of all members
Nsound::circular_iterator Class Reference

A circulator iterator for class Buffer. More...

#include <Nsound/CircularIterators.h>

Public Member Functions

 circular_iterator (FloatVector &v)
 
 circular_iterator (const circular_iterator &copy)
 
circular_iteratoroperator= (const circular_iterator &rhs)
 
void reset ()
 
bool operator== (const circular_iterator &rhs) const
 
bool operator!= (const circular_iterator &rhs) const
 
circular_iteratoroperator++ ()
 
circular_iteratoroperator-- ()
 
circular_iterator operator++ (int)
 
circular_iteratoroperator+= (int32 i)
 
circular_iteratoroperator-= (int32 i)
 
FloatVector::value_type & operator* ()
 
float64 __float__ () const
 
std::string __str__ () const
 

Private Attributes

FloatVector::const_iterator end_
 
FloatVector::iterator itor_
 
FloatVectordata_
 

Detailed Description

A circulator iterator for class Buffer.

This iterator should behave like a normal std::vector::iterator, but when the iterator reaches the end of the vector, it will automatically wrap around back to the front.

Example:
// C++
Buffer b1("california.wav");
Buffer b2;
Buffer::circular_iterator ctor = b1.cbegin();
for(i = 0; i < 1e6; ++i) b2 << *ctor;
// Python, not currently supported.

Definition at line 63 of file CircularIterators.h.

Constructor & Destructor Documentation

Nsound::circular_iterator::circular_iterator ( FloatVector v)
inline

Definition at line 68 of file CircularIterators.h.

69  :
70  end_(v.end()),
71  itor_(v.begin()),
72  data_(&v)
73  {}
FloatVector::const_iterator end_
FloatVector::iterator itor_
Nsound::circular_iterator::circular_iterator ( const circular_iterator copy)
inline

Definition at line 75 of file CircularIterators.h.

76  :
77  end_(copy.end_),
78  itor_(copy.itor_),
79  data_(copy.data_)
80  {}
FloatVector::const_iterator end_
FloatVector::iterator itor_

Member Function Documentation

circular_iterator& Nsound::circular_iterator::operator= ( const circular_iterator rhs)
inline

Definition at line 82 of file CircularIterators.h.

References data_, end_, and itor_.

83  {
84  if(this == &rhs) return *this;
85 
86  end_ = rhs.end_;
87  itor_ = rhs.itor_;
88  data_ = rhs.data_;
89 
90  return *this;
91  }
FloatVector::const_iterator end_
FloatVector::iterator itor_
void Nsound::circular_iterator::reset ( )
inline

Definition at line 93 of file CircularIterators.h.

References data_, and itor_.

Referenced by Buffer_UnitTest().

93 { itor_ = data_->begin(); }
FloatVector::iterator itor_
bool Nsound::circular_iterator::operator== ( const circular_iterator rhs) const
inline

Definition at line 95 of file CircularIterators.h.

References data_, and itor_.

96  {
97  return
98  data_ == rhs.data_ &&
99  itor_ == rhs.itor_;
100  }
FloatVector::iterator itor_
bool Nsound::circular_iterator::operator!= ( const circular_iterator rhs) const
inline

Definition at line 102 of file CircularIterators.h.

References data_, and itor_.

103  {
104  return
105  data_ != rhs.data_ ||
106  itor_ != rhs.itor_;
107  }
FloatVector::iterator itor_
circular_iterator& Nsound::circular_iterator::operator++ ( )
inline

Definition at line 109 of file CircularIterators.h.

References data_, end_, and itor_.

Referenced by operator++().

110  {
111  ++itor_;
112 
113  if(itor_ >= end_) itor_ = data_->begin();
114 
115  return *this;
116  }
FloatVector::const_iterator end_
FloatVector::iterator itor_
circular_iterator& Nsound::circular_iterator::operator-- ( )
inline

Definition at line 118 of file CircularIterators.h.

References data_, and itor_.

119  {
120  if(itor_ == data_->begin()) itor_ = data_->end() - 1;
121  else --itor_;
122 
123  return *this;
124  }
FloatVector::iterator itor_
circular_iterator Nsound::circular_iterator::operator++ ( int  )
inline

Definition at line 126 of file CircularIterators.h.

References operator++().

127  {
128  circular_iterator tmp(*this);
129  operator++();
130  return tmp;
131  }
circular_iterator(FloatVector &v)
circular_iterator & operator++()
circular_iterator& Nsound::circular_iterator::operator+= ( int32  i)
inline

Definition at line 133 of file CircularIterators.h.

References data_, and itor_.

134  {
135  if(i < 0) return *this -= -i;
136  auto pos = std::distance(data_->begin(), itor_);
137  pos = (pos + i) % data_->size();
138  itor_ = data_->begin() + pos;
139  return *this;
140  }
FloatVector::iterator itor_
circular_iterator& Nsound::circular_iterator::operator-= ( int32  i)
inline

Definition at line 142 of file CircularIterators.h.

References data_, and itor_.

143  {
144  if(i < 0) return *this += -i;
145  auto pos = std::distance(data_->begin(), itor_);
146  pos -= (i % data_->size());
147  if(pos < 0) pos += data_->size();
148  itor_ = data_->begin() + pos;
149  return *this;
150  }
FloatVector::iterator itor_
FloatVector::value_type& Nsound::circular_iterator::operator* ( )
inline

Definition at line 152 of file CircularIterators.h.

References itor_.

153  {
154  return *itor_;
155  }
FloatVector::iterator itor_
float64 Nsound::circular_iterator::__float__ ( ) const
inline

Definition at line 157 of file CircularIterators.h.

References itor_.

158  {
159  return *itor_;
160  }
FloatVector::iterator itor_
std::string Nsound::circular_iterator::__str__ ( ) const
inline

Definition at line 162 of file CircularIterators.h.

References data_, and itor_.

163  {
164  std::stringstream ss;
165 
166  ss
167  << "Nsound::Buffer::circular_iterator(vector at 0x0"
168  << std::hex
169  << reinterpret_cast<uint64>(data_)
170  << ", index = ";
171 
172  uint64 pos = itor_ - data_->begin();
173 
174  ss << std::dec << pos << ")";
175 
176  return ss.str();
177  }
FloatVector::iterator itor_
unsigned long long uint64
Definition: Nsound.h:154

Member Data Documentation

FloatVector::const_iterator Nsound::circular_iterator::end_
private

Definition at line 181 of file CircularIterators.h.

Referenced by operator++(), and operator=().

FloatVector::iterator Nsound::circular_iterator::itor_
private
FloatVector* Nsound::circular_iterator::data_
private

The documentation for this class was generated from the following file: