The rationale behind said array is to emulate a 2D/3D pixel matrix.
After doing a fair amount of research and reading, I reckon Boost.MultiArray might come in handy for this. However, I still have to create a neat wrapper on top of it to allow for less verbose coding.
Ultimately, what I want to achieve is the following:
PixMat<u8, 3, {2, 4, 3}> pixMat;
or
PixMat<u8, 3> pixMat(2,3,4);
, which would basically create a 2x4x3 matrix of u8 values.
What I've come up with so far is:
template <typename T, int Dims>
class PixMat {
public:
typedef typename boost::multi_array<T, Dims> PixMatType;
typedef typename PixMatType::index PixMatTypeIdx;
PixMat(int dim1Ext, int dim2Ext) : pixMat(PixMatType(boost::extents[dim1Ext][dim2Ext])) {}
PixMat(int dim1Ext, int dim2Ext, int dim3Ext) : pixMat(PixMatType(boost::extents[dim1Ext][dim2Ext][dim3Ext])) {}
private:
PixMatType pixMat;
};
template <typename T>
class Pix2DMat : PixMat<T, 2> {
public:
Pix2DMat(int dim1Ext, int dim2Ext) : PixMat<DataType, 2>(dim1Ext, dim2Ext) {}
};
template <typename T>
class Pix3DMat : PixMat<T, 3> {
public:
Pix3DMat(int dim1Ext, int dim2Ext, int dim3Ext) : PixMat<DataType, 3>(dim1Ext, dim2Ext, dim3Ext) {}
};
I'm not too keen on this solution. Normally, the matrix won't be either 2D or 3D, but still, I'd like a more generic solution.
Questions:
- Is there a way to provide the extents of the dimensions as template arguments as well instead of via C-TOR?
- Is there a better way than inheritance to achieve this e.g. template specialization, variadic templates? But then how to deal with not duplicating the
typedef
s for boost all over the place?