start building in Access classes + add IsArray trait
This commit is contained in:
parent
bf7853c1b5
commit
33b52c1a70
3 changed files with 57 additions and 20 deletions
|
@ -513,34 +513,38 @@ namespace MultiArrayTools
|
||||||
OperationRoot<T,Ranges...>::
|
OperationRoot<T,Ranges...>::
|
||||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||||
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
|
||||||
mDataPtr(ma.data()),
|
//mDataPtr(ma.data()),
|
||||||
mOrigDataPtr(ma.data()),
|
//mOrigDataPtr(ma.data()),
|
||||||
|
mDataAcc( ma.data(), ma.data() ),
|
||||||
mIndex( ma.begin() )
|
mIndex( ma.begin() )
|
||||||
{
|
{
|
||||||
mIndex(indices...);
|
mIndex(indices...);
|
||||||
mDataPtr = mOrigDataPtr + mIndex.pos();
|
mDataAcc.set( mIndex.pos() );
|
||||||
|
//mDataPtr = mOrigDataPtr + mIndex.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
OperationRoot<T,Ranges...>::
|
OperationRoot<T,Ranges...>::
|
||||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||||
const std::tuple<std::shared_ptr<typename Ranges::IndexType>...>& indices) :
|
const std::tuple<std::shared_ptr<typename Ranges::IndexType>...>& indices) :
|
||||||
mDataPtr(ma.data()),
|
//mDataPtr(ma.data()),
|
||||||
mOrigDataPtr(ma.data()),
|
//mOrigDataPtr(ma.data()),
|
||||||
mIndex( ma.begin() )
|
mIndex( ma.begin() )
|
||||||
{
|
{
|
||||||
mIndex(indices);
|
mIndex(indices);
|
||||||
mDataPtr = mOrigDataPtr + mIndex.pos();
|
mDataAcc.set( mIndex.pos() );
|
||||||
|
//mDataPtr = mOrigDataPtr + mIndex.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
OperationRoot<T,Ranges...>::
|
OperationRoot<T,Ranges...>::
|
||||||
OperationRoot(T* data, const IndexType& ind) :
|
OperationRoot(T* data, const IndexType& ind) :
|
||||||
mDataPtr(data),
|
//mDataPtr(data),
|
||||||
mOrigDataPtr(data),
|
//mOrigDataPtr(data),
|
||||||
mIndex( ind )
|
mIndex( ind )
|
||||||
{
|
{
|
||||||
mDataPtr = mOrigDataPtr + mIndex.pos();
|
mDataAcc.set( mIndex.pos() );
|
||||||
|
//mDataPtr = mOrigDataPtr + mIndex.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
|
@ -672,21 +676,24 @@ namespace MultiArrayTools
|
||||||
template <class ET>
|
template <class ET>
|
||||||
inline T& OperationRoot<T,Ranges...>::get(ET pos) const
|
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 T, class... Ranges>
|
||||||
template <typename V, class ET>
|
template <typename V, class ET>
|
||||||
inline V& OperationRoot<T,Ranges...>::vget(ET pos) const
|
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 <typename T, class... Ranges>
|
||||||
template <class ET>
|
template <class ET>
|
||||||
inline OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos)
|
inline OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::set(ET pos)
|
||||||
{
|
{
|
||||||
mDataPtr = mOrigDataPtr + pos.val();
|
mDataAcc.set(pos.val());
|
||||||
|
//mDataPtr = mOrigDataPtr + pos.val();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,7 +713,8 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
T* OperationRoot<T,Ranges...>::data() const
|
T* OperationRoot<T,Ranges...>::data() const
|
||||||
{
|
{
|
||||||
return mDataPtr;
|
return mDataAcc.get(0);
|
||||||
|
//return mDataPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
|
|
|
@ -229,12 +229,14 @@ namespace MultiArrayTools
|
||||||
typedef T in_type;
|
typedef T in_type;
|
||||||
private:
|
private:
|
||||||
T* mPtr;
|
T* mPtr;
|
||||||
|
T* mOrigPtr;
|
||||||
|
|
||||||
public:
|
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) { return mPtr+pos; }
|
||||||
T* get(size_t pos) const { return mPtr; }
|
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>
|
template <class F, typename Op, class ExtType>
|
||||||
inline void exec(size_t pos, const Op& op, ExtType e) const
|
inline void exec(size_t pos, const Op& op, ExtType e) const
|
||||||
|
@ -255,8 +257,8 @@ namespace MultiArrayTools
|
||||||
public:
|
public:
|
||||||
ConstPointerAccess(T* ptr) : mPtr(ptr) {}
|
ConstPointerAccess(T* ptr) : mPtr(ptr) {}
|
||||||
|
|
||||||
const T* get(size_t pos) { return mPtr; }
|
const T* get(size_t pos) { return mPtr+pos; }
|
||||||
const T* get(size_t pos) const { return mPtr; }
|
const T* get(size_t pos) const { return mPtr+pos; }
|
||||||
|
|
||||||
template <class F, typename Op, class ExtType>
|
template <class F, typename Op, class ExtType>
|
||||||
inline void exec(size_t pos, const Op& op, ExtType e) const { assert(0); }
|
inline void exec(size_t pos, const Op& op, ExtType e) const { assert(0); }
|
||||||
|
@ -552,8 +554,9 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
T* mDataPtr;
|
//T* mDataPtr;
|
||||||
T* mOrigDataPtr;
|
//T* mOrigDataPtr;
|
||||||
|
PointerAccess<T> mDataAcc;
|
||||||
IndexType mIndex;
|
IndexType mIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
26
src/include/statics/traits.h
Normal file
26
src/include/statics/traits.h
Normal 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
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue