6 #ifndef MYRAMATH_UTILITY_ARRAY2_H 7 #define MYRAMATH_UTILITY_ARRAY2_H 14 #include <myramath/utility/detail/ssize.h> 19 #include <myramath/io/detail/vector.h> 43 contents.resize(I*J,filler);
46 #ifdef MYRAMATH_ENABLE_CPP11 49 Array2(
int II,
int JJ, std::initializer_list<T> list)
55 throw eprintf(
"Array2(I,J,initializer_list<T>), size mismatch I*J != size [%d*%d != %d]", I, J, IJ);
56 contents.resize(IJ,T());
57 const T* p = list.begin();
58 for (
int i = 0; i < I; ++i)
59 for (
int j = 0; j < J; ++j)
67 { in >> I >> J >> contents; }
71 { out << I << J << contents; }
75 {
return contents[offset(i,j)]; }
77 {
return contents[offset(i,j)]; }
82 std::swap(this->I, that.I);
83 std::swap(this->J, that.J);
84 this->contents.swap(that.contents);
88 std::pair<int,int>
size()
const 89 {
return std::pair<int,int>(I,J); }
94 int offset(
int i,
int j)
const 102 typedef std::vector<T> Contents;
108 template<
class T> std::ostream& operator << (std::ostream& out, const Array2<T>& a)
110 int I = a.size().first;
111 int J = a.size().second;
112 out << I <<
" by " << J <<
":" << std::endl;
113 for (
int i = 0; i < I; ++i)
116 for (
int j = 0; j < J; ++j)
117 out << a(i,j) <<
" ";
118 out <<
"]" << std::endl;
Container of values, allows random (i,j) access.
Definition: Array2.h:30
Returns a std::runtime_error() whose message has been populated using printf()-style formatting...
Array2(InputStream &in)
InputStream constructor.
Definition: Array2.h:66
const T & operator()(int i, int j) const
Random accessor/mutator.
Definition: Array2.h:74
ReaderWriter<T>, encapsulates a read()/write() pair for type T.
Abstraction layer, serializable objects write themselves to these.
Definition: Streams.h:39
std::pair< int, int > size() const
Size inspector.
Definition: Array2.h:88
void write(OutputStream &out) const
Writes to OutputStream.
Definition: Array2.h:70
Array2(int in_I, int in_J, T filler)
Constructs with specified size and filler.
Definition: Array2.h:39
void swap(Array2 &that)
Member swap.
Definition: Array2.h:80
Array2()
Default constructs to 0x0 size.
Definition: Array2.h:35
Array2(int II, int JJ, std::initializer_list< T > list)
Constructs from std::initializer_list<T> in row-major order.
Definition: Array2.h:49
Bases classes for binary input/output streams.