cnorxz/src/multi_array.cc

76 lines
1.9 KiB
C++
Raw Normal View History

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>
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>
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;
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>
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;
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>
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>
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>
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...));
return MultiArrayOperationBase<T,Range>(*this, index);
2017-02-16 13:12:20 +01:00
}
template <typename T, class Range>
size_t MultiArray<T,Range>::size() const
{
return mRange->size();
}
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-16 13:12:20 +01:00
}