almost finished operation templates

This commit is contained in:
Christian Zimmermann 2017-02-15 22:39:36 +01:00
parent 211c731273
commit f94f758c16
2 changed files with 87 additions and 5 deletions

View file

@ -476,13 +476,17 @@ namespace ME
/********************************* /*********************************
* MultiArrayOperationBase * * MultiArrayOperationBase *
*********************************/ *********************************/
template <typename T, class Range> template <typename T, class Range>
template <class Range2> template <class Range2>
MultiArrayOperationBase<T,Range>& MultiArrayOperationBase<T,Range>&
MultiArrayOperationBase<T,Range>::operator=(const MultiArrayOperationBase<T, Range2>& in) MultiArrayOperationBase<T,Range>::operator=(const MultiArrayOperationBase<T, Range2>& in)
{ {
// perform operation (iterate head index) in.linkIndicesTo(mIibPtr);
for(*mIibPtr = mArrayRef.begin(); *mIibPtr != mArrayRef.end(); ++(*mIibPtr)){
// build in vectorization later
get() = in.get();
}
} }
template <typename T, class Range> template <typename T, class Range>
@ -490,9 +494,7 @@ namespace ME
MultiArrayOperation<Operation> MultiArrayOperation<Operation>
MultiArrayOperationBase<T,Range>::operator()(Operation& op, MultiArrayOperationBase<T,Ranges>&... secs) MultiArrayOperationBase<T,Range>::operator()(Operation& op, MultiArrayOperationBase<T,Ranges>&... secs)
{ {
// set operation return MultiArrayOperationBase<T,Range>(op, secs);
// set mSecs
// link Indices
} }
template <typename T, class Range> template <typename T, class Range>
@ -501,15 +503,81 @@ namespace ME
return 1; return 1;
} }
template <typename T, class Range>
IndefinitIndexBase* MultiArrayOperationBase<T,Range>::index()
{
return mIibPtr;
}
template <typename T, class Range>
void MultiArrayOperationBase<T,Range>::linkIndicesTo(IndefinitIndexBase* target)
{
mIibPtr->linkTo(target);
}
template <typename T, class Range>
T& MultiArrayOperationBase<T,Range>::get()
{
return mArrayRef(*mIibPtr);
}
template <typename T, class Range>
const T& MultiArrayOperationBase<T,Range>::get() const
{
return mArrayRef(*mIibPtr);
}
/***************************** /*****************************
* MultiArrayOperation * * MultiArrayOperation *
*****************************/ *****************************/
template <class IndexTuple, size_t N>
void linkTupleIndicesTo(IndexTuple& itp, IndefinitIndexBase* target)
{
std::get<N>(itp).linkTo(target);
linkTupleIndicesTo<N-1>(itp, target);
}
template <class IndexTuple>
void linkTupleIndicesTo<0>(IndexTuple& itp, IndefinitIndexBase* target)
{
std::get<0>(itp).linkTo(target);
}
template <typename T, class Operation, class Tuple, class... MBases>
T callOperation(Operation& op, Tuple& tp, MBases&... secs)
{
return callOperation(op, tp, std::get</*!!!*/>(tp), secs...);
}
// spezialization for termination !!!
template <typename T, class Range, class Operation, class... Ranges> template <typename T, class Range, class Operation, class... Ranges>
size_t MultiArrayOperation<T,Range,Operation,Ranges...>::argNum() const size_t MultiArrayOperation<T,Range,Operation,Ranges...>::argNum() const
{ {
return sizeof...(Ranges) + 1; return sizeof...(Ranges) + 1;
} }
template <typename T, class Range, class Operation, class... Ranges>
void MultiArrayOperation<T,Range,Operation,Ranges...>::linkIndicesTo(IndefinitIndexBase* target)
{
mIibPtr->linkTo(target);
linkTupleIndicesTo<sizeof...(Ranges)>(mSecs, target);
}
template <typename T, class Range, class Operation, class... Ranges>
T& MultiArrayOperation<T,Range,Operation,Ranges...>::get()
{
mVal = mOp();
return mVal;
}
template <typename T, class Range, class Operation, class... Ranges>
const T& MultiArrayOperation<T,Range,Operation,Ranges...>::get() const
{
mVal = mOp()
return mVal;
}
} // end namespace ME } // end namespace ME

View file

@ -356,6 +356,13 @@ namespace ME
MultiArrayOperation<std::divides<T>,Range2> operator/(MultiArrayOperationBase<T,Range2>& sec); MultiArrayOperation<std::divides<T>,Range2> operator/(MultiArrayOperationBase<T,Range2>& sec);
virtual size_t argNum() const; virtual size_t argNum() const;
IndefinitIndexBase* index();
virtual void linkIndicesTo(IndefinitIndexBase* target);
virtual T& get();
virtual const T& get() const;
protected: protected:
@ -369,10 +376,17 @@ namespace ME
{ {
public: public:
MultiArrayOperation(Operation& op, MultiArrayOperationBase<T,Ranges>&... secs);
virtual size_t argNum() const override; virtual size_t argNum() const override;
virtual void linkIndicesTo(IndefinitIndexBase* target) override;
virtual T& get() override;
virtual const T& get() const override;
protected: protected:
T mVal;
Operation mOp; Operation mOp;
std::tuple<MultiArrayOperationBase<T,Ranges>... > mSecs; std::tuple<MultiArrayOperationBase<T,Ranges>... > mSecs;
}; };