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-21 21:47:40 +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
|
|
|
{
|
2017-02-21 21:47:40 +01:00
|
|
|
return MultiArrayOperationBase<T,Range>(*this, Name("master", str...));
|
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-20 17:18:53 +01:00
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
auto MultiArray<T,Range>::begin() -> decltype(Range().begin())
|
|
|
|
{
|
|
|
|
return mRange->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
auto MultiArray<T,Range>::end() -> decltype(Range().end())
|
|
|
|
{
|
|
|
|
return mRange->end();
|
|
|
|
}
|
|
|
|
|
2017-02-23 19:33:46 +01:00
|
|
|
template <typename T, class Range>
|
|
|
|
bool MultiArray<T,Range>::isSlice() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-17 18:10:03 +01:00
|
|
|
|
2017-02-16 13:12:20 +01:00
|
|
|
}
|