start building in Access classes + add IsArray trait

This commit is contained in:
Christian Zimmermann 2021-07-01 18:15:12 +02:00
parent bf7853c1b5
commit 33b52c1a70
3 changed files with 57 additions and 20 deletions

View file

@ -513,34 +513,38 @@ namespace MultiArrayTools
OperationRoot<T,Ranges...>::
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mDataPtr(ma.data()),
mOrigDataPtr(ma.data()),
//mDataPtr(ma.data()),
//mOrigDataPtr(ma.data()),
mDataAcc( ma.data(), ma.data() ),
mIndex( ma.begin() )
{
mIndex(indices...);
mDataPtr = mOrigDataPtr + mIndex.pos();
mDataAcc.set( mIndex.pos() );
//mDataPtr = mOrigDataPtr + mIndex.pos();
}
template <typename T, class... Ranges>
OperationRoot<T,Ranges...>::
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::tuple<std::shared_ptr<typename Ranges::IndexType>...>& indices) :
mDataPtr(ma.data()),
mOrigDataPtr(ma.data()),
//mDataPtr(ma.data()),
//mOrigDataPtr(ma.data()),
mIndex( ma.begin() )
{
mIndex(indices);
mDataPtr = mOrigDataPtr + mIndex.pos();
mDataAcc.set( mIndex.pos() );
//mDataPtr = mOrigDataPtr + mIndex.pos();
}
template <typename T, class... Ranges>
OperationRoot<T,Ranges...>::
OperationRoot(T* data, const IndexType& ind) :
mDataPtr(data),
mOrigDataPtr(data),
//mDataPtr(data),
//mOrigDataPtr(data),
mIndex( ind )
{
mDataPtr = mOrigDataPtr + mIndex.pos();
mDataAcc.set( mIndex.pos() );
//mDataPtr = mOrigDataPtr + mIndex.pos();
}
template <typename T, class... Ranges>
@ -672,21 +676,24 @@ namespace MultiArrayTools
template <class ET>
inline T& OperationRoot<T,Ranges...>::get(ET pos) const
{
return mDataPtr[pos.val()];
return *mDataAcc.get(pos.val());
//return mDataPtr[pos.val()];
}
template <typename T, class... Ranges>
template <typename V, class ET>
inline V& OperationRoot<T,Ranges...>::vget(ET pos) const
{
return *(reinterpret_cast<V*>(mDataPtr+pos.val()));
return *(reinterpret_cast<V*>(mDataAcc.get(pos.val())));
//return *(reinterpret_cast<V*>(mDataPtr+pos.val()));
}
template <typename T, class... Ranges>
template <class ET>
inline OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos)
{
mDataPtr = mOrigDataPtr + pos.val();
mDataAcc.set(pos.val());
//mDataPtr = mOrigDataPtr + pos.val();
return *this;
}
@ -706,7 +713,8 @@ namespace MultiArrayTools
template <typename T, class... Ranges>
T* OperationRoot<T,Ranges...>::data() const
{
return mDataPtr;
return mDataAcc.get(0);
//return mDataPtr;
}
template <typename T, class... Ranges>

View file

@ -229,12 +229,14 @@ namespace MultiArrayTools
typedef T in_type;
private:
T* mPtr;
T* mOrigPtr;
public:
PointerAccess(T* ptr) : mPtr(ptr) {}
PointerAccess(T* ptr, T* origPtr) : mPtr(ptr), mOrigPtr(origPtr) {}
T* get(size_t pos) { return mPtr; }
T* get(size_t pos) const { return mPtr; }
T* get(size_t pos) { return mPtr+pos; }
T* get(size_t pos) const { return mPtr+pos; }
PointerAccess<T>& set(size_t pos) { mPtr = mOrigPtr + pos; return *this; }
template <class F, typename Op, class ExtType>
inline void exec(size_t pos, const Op& op, ExtType e) const
@ -255,8 +257,8 @@ namespace MultiArrayTools
public:
ConstPointerAccess(T* ptr) : mPtr(ptr) {}
const T* get(size_t pos) { return mPtr; }
const T* get(size_t pos) const { return mPtr; }
const T* get(size_t pos) { return mPtr+pos; }
const T* get(size_t pos) const { return mPtr+pos; }
template <class F, typename Op, class ExtType>
inline void exec(size_t pos, const Op& op, ExtType e) const { assert(0); }
@ -552,8 +554,9 @@ namespace MultiArrayTools
private:
T* mDataPtr;
T* mOrigDataPtr;
//T* mDataPtr;
//T* mOrigDataPtr;
PointerAccess<T> mDataAcc;
IndexType mIndex;
public:

View file

@ -0,0 +1,26 @@
#include "base_def.h"
namespace MultiArrayTools
{
template <typename T>
struct IsArray
{
static constexpr bool VALUE = false;
};
#define add_array_trait(name) template <typename... X> struct IsArray<##name<X...>> { \
static constexpr bool VALUE = true; \
}
add_array_trait(MultiArrayBase);
add_array_trait(MutableMultiArrayBase);
add_array_trait(MultiArray);
add_array_trait(FunctionalMultiArray);
add_array_trait(Slice);
add_array_trait(ConstSlice);
#undef add_array_trait
}