My old project for strange attractors, new approach
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

133 lines
2.5 KiB

//
// Vectors.hpp
// AwesomeAttractorND
//
// Created by Joshua Moerman on 11/5/11.
// Copyright 2011 Vadovas. All rights reserved.
//
#ifndef AwesomeAttractorND_Vectors_hpp
#define AwesomeAttractorND_Vectors_hpp
#include <iterator>
typedef double* VectorRef;
typedef double const * VectorConstRef;
struct VectorIterator : public std::iterator<std::random_access_iterator_tag, double> {
template <size_t N>
static VectorIterator begin(std::array<double, N> & arr, size_t dimension){
return VectorIterator(arr.data(), dimension);
}
template <size_t N>
static VectorIterator end(std::array<double, N> & arr, size_t dimension){
size_t offset = N - (N % dimension);
return VectorIterator(arr.data() + offset, dimension);
}
VectorIterator(VectorIterator const & rh)
: data(rh.data)
, dimension(rh.dimension)
{}
VectorIterator & operator=(VectorIterator const & rh){
data = rh.data;
dimension = rh.dimension;
return *this;
}
bool operator==(VectorIterator const & rh) const {
return data == rh.data && dimension == rh.dimension;
}
bool operator!=(VectorIterator const & rh) const {
return data != rh.data || dimension != rh.dimension;
}
bool operator<(VectorIterator const & rh) const {
return data < rh.data;
}
bool operator<=(VectorIterator const & rh) const {
return data <= rh.data;
}
bool operator>(VectorIterator const & rh) const {
return data > rh.data;
}
bool operator>=(VectorIterator const & rh) const {
return data >= rh.data;
}
VectorRef operator*(){
return data;
}
VectorRef operator->(){
return data;
}
VectorIterator & operator++(){
data += dimension;
return *this;
}
VectorIterator operator++(int){
VectorIterator temp(*this);
++(*this);
return temp;
}
VectorIterator & operator--(){
data -= dimension;
return *this;
}
VectorIterator operator--(int){
VectorIterator temp(*this);
++(*this);
return temp;
}
VectorIterator & operator+=(int n){
data += n*dimension;
return *this;
}
VectorIterator operator+(int n){
VectorIterator temp(*this);
temp += n;
return temp;
}
VectorIterator & operator-=(int n){
data -= n*dimension;
return *this;
}
VectorIterator operator-(int n){
VectorIterator temp(*this);
temp -= n;
return temp;
}
VectorRef operator[](int n){
VectorIterator temp(*this);
return *(temp += n);
}
private:
VectorIterator(double * data, size_t dimension)
: data(data)
, dimension(dimension)
{}
VectorIterator();
double * data;
size_t dimension;
};
#endif