Skip to content

Instantly share code, notes, and snippets.

@ignisan
Created February 13, 2014 14:31
Show Gist options
  • Save ignisan/8976004 to your computer and use it in GitHub Desktop.
Save ignisan/8976004 to your computer and use it in GitHub Desktop.
#ifndef __IGNIS_ARRAY__
#define __IGNIS_ARRAY__
#include<vector>
#include<array>
#include<iostream>
namespace ignis {
template<class ValueType>
struct Array {
typedef ValueType value_type;
typedef std::vector<value_type> vector_type;
vector_type data;
const size_t size;
const size_t NX,NY,NZ;
const size_t NXNY;
Array(const size_t NX, const size_t NY, const size_t NZ) :
size(NX*NY*NZ),NX(NX),NY(NY),NZ(NZ),NXNY(NX*NY),data(size) {}
const int index(const int i, const int j, const int k) const {
return NXNY*i + NX*j + k;
}
const value_type operator()(const int i, const int j, const int k) const {
return data[index(i,j,k)];
}
value_type& operator()(const int i, const int j, const int k) {
return data[index(i,j,k)];
}
const std::array<size_t,3> shape() {
return std::array<size_t,3>{NX,NY,NZ};
}
typename vector_type::iterator begin() {
return data.begin();
}
typename vector_type::iterator end() {
return data.end();
}
};
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment