2017-02-26 18:14:58 +01:00
|
|
|
// -*- C++ -*-
|
2017-02-16 13:12:20 +01:00
|
|
|
|
|
|
|
#include "multi_array.h"
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
2017-02-26 18:14:58 +01:00
|
|
|
/**********************
|
|
|
|
* MultiArrayBase *
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
MultiArrayBase<T,Range>::MultiArrayBase(const Range& range) : mRange(new Range(range)) {}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
size_t MultiArrayBase<T,Range>::size() const
|
|
|
|
{
|
|
|
|
return mRange->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
auto MultiArrayBase<T,Range>::begin() -> decltype(Range().begin())
|
|
|
|
{
|
|
|
|
return mRange->begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
auto MultiArrayBase<T,Range>::end() -> decltype(Range().end())
|
|
|
|
{
|
|
|
|
return mRange->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
|
|
|
const Range& MultiArrayBase<T,Range>::range() const
|
|
|
|
{
|
|
|
|
return *mRange;
|
|
|
|
}
|
|
|
|
|
2017-02-27 11:23:40 +01:00
|
|
|
template <typename T, class Range>
|
|
|
|
template <class... NameTypes>
|
|
|
|
MultiArrayOperationRoot<T,Range> MultiArrayBase<T,Range>::operator()(const NameTypes&... str)
|
|
|
|
{
|
|
|
|
return MultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
|
|
|
|
}
|
|
|
|
|
2017-02-16 13:12:20 +01:00
|
|
|
/*******************
|
|
|
|
* MultiArray *
|
|
|
|
*******************/
|
|
|
|
|
2017-02-16 16:06:23 +01:00
|
|
|
template <typename T, class Range>
|
2017-02-26 18:14:58 +01:00
|
|
|
MultiArray<T,Range>::MultiArray(const Range& range) :
|
|
|
|
MultiArrayBase<T,Range>(range),
|
|
|
|
mCont(MAB::mRange->size()) {}
|
2017-02-16 16:06:23 +01:00
|
|
|
|
|
|
|
template <typename T, class Range>
|
2017-02-26 18:14:58 +01:00
|
|
|
MultiArray<T,Range>::MultiArray(const Range& range, const std::vector<T>& vec) :
|
|
|
|
MultiArrayBase<T,Range>(range),
|
|
|
|
mCont(vec)
|
2017-02-16 16:06:23 +01:00
|
|
|
{
|
2017-02-26 18:14:58 +01:00
|
|
|
if(mCont.size() > MAB::mRange->size()){
|
|
|
|
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
2017-02-16 16:06:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Range>
|
2017-02-26 18:14:58 +01:00
|
|
|
MultiArray<T,Range>::MultiArray(const Range& range, std::vector<T>&& vec) :
|
|
|
|
MultiArrayBase<T,Range>(range),
|
|
|
|
mCont(vec)
|
2017-02-16 16:06:23 +01:00
|
|
|
{
|
2017-02-26 18:14:58 +01:00
|
|
|
if(mCont.size() > MAB::mRange->size()){
|
|
|
|
mCont.erase(mCont.begin() + MAB::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() ];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|