2017-02-16 13:12:20 +01:00
|
|
|
|
|
|
|
#include "multi_array.h"
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
/*******************
|
|
|
|
* MultiArray *
|
|
|
|
*******************/
|
|
|
|
|
2017-02-16 16:06:23 +01:00
|
|
|
template <typename T, class Range>
|
2017-02-17 18:10:03 +01:00
|
|
|
MultiArray<T,Range>::MultiArray(const Range& range) : mRange(new Range(range)), mCont(mRange.size())
|
2017-02-16 16:06:23 +01:00
|
|
|
{
|
|
|
|
mInit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
2017-02-17 18:10:03 +01:00
|
|
|
MultiArray<T,Range>::MultiArray(const Range& range, const std::vector<T>& vec) : mRange(new Range(range)),
|
|
|
|
mCont(vec)
|
2017-02-16 16:06:23 +01:00
|
|
|
{
|
|
|
|
mInit = true;
|
2017-02-17 18:10:03 +01:00
|
|
|
if(mCont.size() > mRange->size()){
|
|
|
|
mCont.erase(mCont.begin() + mRange->size(), mCont.end());
|
2017-02-16 16:06:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
2017-02-17 18:10:03 +01:00
|
|
|
MultiArray<T,Range>::MultiArray(const Range& range, std::vector<T>&& vec) : mRange(new Range(range)), mCont(vec)
|
2017-02-16 16:06:23 +01:00
|
|
|
{
|
|
|
|
mInit = true;
|
2017-02-17 18:10:03 +01:00
|
|
|
if(mCont.size() > mRange->size()){
|
|
|
|
mCont.erase(mCont.begin() + mRange->size(), mCont.end());
|
2017-02-16 16:06:23 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-16 13:12:20 +01:00
|
|
|
|
|
|
|
template <typename T, class Range>
|
2017-02-17 18:10:03 +01:00
|
|
|
T& MultiArray<T,Range>::operator[](const typename Range::IndexType& i)
|
2017-02-16 13:12:20 +01:00
|
|
|
{
|
|
|
|
return mCont[ i.pos() ];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
2017-02-17 18:10:03 +01:00
|
|
|
const T& MultiArray<T,Range>::operator[](const typename Range::IndexType& i) const
|
2017-02-16 13:12:20 +01:00
|
|
|
{
|
|
|
|
return mCont[ i.pos() ];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
template <class... NameTypes>
|
2017-02-17 18:10:03 +01:00
|
|
|
MultiArrayOperationBase<T,Range> MultiArray<T,Range>::operator()(const NameTypes&... str)
|
2017-02-16 13:12:20 +01:00
|
|
|
{
|
|
|
|
auto index = mRange->begin();
|
2017-02-16 16:06:23 +01:00
|
|
|
index.name(Name("master", str...));
|
2017-02-17 18:10:03 +01:00
|
|
|
return MultiArrayOperationBase<T,Range>(*this, index);
|
2017-02-16 13:12:20 +01:00
|
|
|
}
|
|
|
|
|
2017-02-17 18:10:03 +01:00
|
|
|
template <typename T, class Range>
|
|
|
|
size_t MultiArray<T,Range>::size() const
|
|
|
|
{
|
|
|
|
return mRange->size();
|
|
|
|
}
|
|
|
|
|
2017-02-16 13:12:20 +01:00
|
|
|
}
|