simple 1dim multi array call works again (without operation stuff)
This commit is contained in:
parent
16e8e588cb
commit
1652e122ea
7 changed files with 379 additions and 309 deletions
|
@ -23,6 +23,11 @@ add_executable(iutest src/index_unit_test.cc)
|
|||
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES})
|
||||
add_test(NAME iutest COMMAND iutest)
|
||||
|
||||
add_executable(mautest src/ma_unit_test.cc)
|
||||
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES})
|
||||
add_test(NAME mautest COMMAND mautest)
|
||||
|
||||
|
||||
#install(TARGETS testm DESTINATION install)
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX ..)
|
||||
|
|
|
@ -101,7 +101,6 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
class ContainerIndex;
|
||||
|
||||
/*
|
||||
// multi_array.h
|
||||
template <typename T, class Range>
|
||||
class MultiArrayBase;
|
||||
|
@ -113,7 +112,7 @@ namespace MultiArrayTools
|
|||
// multi_array.h
|
||||
template <typename T, class Range>
|
||||
class MultiArray;
|
||||
|
||||
/*
|
||||
// multi_array_operation.h
|
||||
template <typename T>
|
||||
class MultiArrayOperationBase;
|
||||
|
|
|
@ -84,6 +84,7 @@ namespace MultiArrayTools
|
|||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::at(const MetaType& metaPos)
|
||||
{
|
||||
PackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
79
src/ma_unit_test.cc
Normal file
79
src/ma_unit_test.cc
Normal file
|
@ -0,0 +1,79 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#include <cstdlib>
|
||||
#include "gtest/gtest.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "multi_array_header.h"
|
||||
|
||||
namespace MAT = MultiArrayTools;
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace MAT;
|
||||
|
||||
template <class Factory, typename T>
|
||||
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
|
||||
{
|
||||
std::vector<T> tmp = ilist;
|
||||
auto nptr = std::make_shared<Factory>( tmp );
|
||||
fptr = nptr;
|
||||
}
|
||||
|
||||
template <class Factory, class... Rs>
|
||||
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
|
||||
{
|
||||
auto nptr = std::make_shared<Factory>( rs... );
|
||||
fptr = nptr;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
|
||||
{
|
||||
return std::make_tuple(ts...);
|
||||
}
|
||||
|
||||
|
||||
class MATest_1Dim : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||||
typedef SRF::oType SRange;
|
||||
|
||||
typedef ContainerRangeFactory<SRange> CRF;
|
||||
typedef CRF::oType CRange;
|
||||
|
||||
MATest_1Dim()
|
||||
{
|
||||
swapFactory<SRF>(rfbptr, {'x', 'y', 'l', 'f', 'g'} );
|
||||
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||
|
||||
swapMFactory<CRF>(rfbptr, srptr);
|
||||
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||||
std::shared_ptr<SRange> srptr;
|
||||
std::shared_ptr<CRange> crptr;
|
||||
std::vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 };
|
||||
};
|
||||
|
||||
TEST_F(MATest_1Dim, SimpleCall)
|
||||
{
|
||||
MultiArray<double,MATest_1Dim::CRange> ma(crptr, vv);
|
||||
auto i = ma.beginIndex();
|
||||
EXPECT_EQ( ma[ i.at('x') ], 3.141);
|
||||
EXPECT_EQ( ma[ i.at('y') ], 2.718);
|
||||
EXPECT_EQ( ma[ i.at('l') ], 1.618);
|
||||
EXPECT_EQ( ma[ i.at('f') ], 0.693);
|
||||
EXPECT_EQ( ma[ i.at('g') ], 0.577);
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
|
@ -8,225 +8,212 @@ namespace MultiArrayTools
|
|||
* MultiArrayBase::const_iterator *
|
||||
**************************************/
|
||||
|
||||
template <typename T, class Range>
|
||||
MultiArrayBase<T,Range>::const_iterator::const_iterator(const MultiArrayBase<T,Range>& ma):
|
||||
mMAPtr(&ma), mIndex(mMAPtr->beginIndex())
|
||||
{ }
|
||||
template <typename T, class CRange>
|
||||
MultiArrayBase<T,CRange>::const_iterator::const_iterator(const MultiArrayBase<T,CRange>& ma):
|
||||
mMAPtr(&ma), mPos(0) { }
|
||||
|
||||
template <typename T, class Range>
|
||||
MultiArrayBase<T,Range>::const_iterator::const_iterator(const MultiArrayBase<T,Range>& ma,
|
||||
const typename Range::IndexType& index):
|
||||
mMAPtr(&ma), mIndex(index)
|
||||
{ }
|
||||
template <typename T, class CRange>
|
||||
MultiArrayBase<T,CRange>::const_iterator::const_iterator(const MultiArrayBase<T,CRange>& ma,
|
||||
const typename CRange::IndexType& index):
|
||||
mMAPtr(&ma), mPos(index.pos()) { }
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::const_iterator::operator==(const const_iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator==(const const_iterator& it) const
|
||||
{
|
||||
return mMAPtr == it.mMAPtr and mIndex.pos() == it.mIndex.pos();
|
||||
return mMAPtr == it.mMAPtr and mPos == it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::const_iterator::operator!=(const const_iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator!=(const const_iterator& it) const
|
||||
{
|
||||
return mMAPtr != it.mMAPtr or mIndex.pos() != it.mIndex.pos();
|
||||
return mMAPtr != it.mMAPtr or mPos != it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MultiArrayBase<T,Range>::const_iterator::operator*() const
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArrayBase<T,CRange>::const_iterator::operator*() const
|
||||
{
|
||||
return (*mMAPtr)[mIndex];
|
||||
return mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
T const* MultiArrayBase<T,Range>::const_iterator::operator->() const
|
||||
template <typename T, class CRange>
|
||||
T const* MultiArrayBase<T,CRange>::const_iterator::operator->() const
|
||||
{
|
||||
return &(*mMAPtr)[mIndex];
|
||||
return &mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator& MultiArrayBase<T,Range>::const_iterator::operator++()
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator++()
|
||||
{
|
||||
++mIndex;
|
||||
++mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator MultiArrayBase<T,Range>::const_iterator::operator++(int)
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
++mIndex;
|
||||
++mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator& MultiArrayBase<T,Range>::const_iterator::operator--()
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator--()
|
||||
{
|
||||
--mIndex;
|
||||
--mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator MultiArrayBase<T,Range>::const_iterator::operator--(int)
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator--(int)
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
--mIndex;
|
||||
--mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator& MultiArrayBase<T,Range>::const_iterator::operator+=(int diff)
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator+=(int diff)
|
||||
{
|
||||
mIndex += diff;
|
||||
mPos += diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator& MultiArrayBase<T,Range>::const_iterator::operator-=(int diff)
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator& MultiArrayBase<T,CRange>::const_iterator::operator-=(int diff)
|
||||
{
|
||||
mIndex -= diff;
|
||||
mPos -= diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator MultiArrayBase<T,Range>::const_iterator::operator+(int num) const
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator+(int num) const
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
tmp += num;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator MultiArrayBase<T,Range>::const_iterator::operator-(int num) const
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::const_iterator::operator-(int num) const
|
||||
{
|
||||
const_iterator tmp(*this);
|
||||
tmp -= num;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
int MultiArrayBase<T,Range>::const_iterator::operator-(const const_iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
int MultiArrayBase<T,CRange>::const_iterator::operator-(const const_iterator& it) const
|
||||
{
|
||||
return mIndex.pos() - it.mIndex.pos();
|
||||
return mPos - it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MultiArrayBase<T,Range>::const_iterator::operator[](int num) const
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArrayBase<T,CRange>::const_iterator::operator[](int num) const
|
||||
{
|
||||
return *(operator+(num));
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::const_iterator::operator<(const const_iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator<(const const_iterator& it) const
|
||||
{
|
||||
return mIndex.pos() < it.mIndex.pos();
|
||||
return mPos < it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::const_iterator::operator>(const const_iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator>(const const_iterator& it) const
|
||||
{
|
||||
return mIndex.pos() > it.mIndex.pos();
|
||||
return mPos > it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::const_iterator::operator<=(const const_iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator<=(const const_iterator& it) const
|
||||
{
|
||||
return mIndex.pos() <= it.mIndex.pos();
|
||||
return mPos <= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::const_iterator::operator>=(const const_iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::const_iterator::operator>=(const const_iterator& it) const
|
||||
{
|
||||
return mIndex.pos() >= it.mIndex.pos();
|
||||
return mPos >= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const typename Range::IndexType& MultiArrayBase<T,Range>::const_iterator::index() const
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MultiArrayBase<T,CRange>::const_iterator::index() const
|
||||
{
|
||||
return mIndex;
|
||||
auto i = mMAPtr->beginIndex();
|
||||
i = mPos;
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename Range::IndexType& MultiArrayBase<T,Range>::const_iterator::index()
|
||||
{
|
||||
return mIndex;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* MultiArrayBase *
|
||||
**********************/
|
||||
|
||||
template <typename T, class Range>
|
||||
MultiArrayBase<T,Range>::MultiArrayBase(const Range& range) : mRange(new Range(range)) {}
|
||||
template <typename T, class CRange>
|
||||
MultiArrayBase<T,CRange>::MultiArrayBase(const std::shared_ptr<CRange>& range) : mRange(range) {}
|
||||
|
||||
template <typename T, class Range>
|
||||
void MultiArrayBase<T,Range>::link(IndefinitIndexBase* iibPtr) const
|
||||
{ }
|
||||
|
||||
template <typename T, class Range>
|
||||
size_t MultiArrayBase<T,Range>::size() const
|
||||
template <typename T, class CRange>
|
||||
size_t MultiArrayBase<T,CRange>::size() const
|
||||
{
|
||||
return mRange->size();
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator MultiArrayBase<T,Range>::begin() const
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::begin() const
|
||||
{
|
||||
return const_iterator(*this, beginIndex());
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MultiArrayBase<T,Range>::const_iterator MultiArrayBase<T,Range>::end() const
|
||||
template <typename T, class CRange>
|
||||
typename MultiArrayBase<T,CRange>::const_iterator MultiArrayBase<T,CRange>::end() const
|
||||
{
|
||||
return const_iterator(*this, endIndex());
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
auto MultiArrayBase<T,Range>::beginIndex() const -> decltype(Range().begin())
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MultiArrayBase<T,CRange>::beginIndex() const
|
||||
{
|
||||
//CHECK;
|
||||
return mRange->begin();
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
auto MultiArrayBase<T,Range>::endIndex() const -> decltype(Range().end())
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MultiArrayBase<T,CRange>::endIndex() const
|
||||
{
|
||||
return mRange->end();
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const Range& MultiArrayBase<T,Range>::range() const
|
||||
template <typename T, class CRange>
|
||||
const CRange& MultiArrayBase<T,CRange>::range() const
|
||||
{
|
||||
return *mRange;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::isConst() const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::isConst() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
/*
|
||||
template <typename T, class CRange>
|
||||
template <class... NameTypes>
|
||||
ConstMultiArrayOperationRoot<T,Range> MultiArrayBase<T,Range>::operator()(const NameTypes&... str) const
|
||||
ConstMultiArrayOperationRoot<T,CRange> MultiArrayBase<T,CRange>::operator()(const NameTypes&... str) const
|
||||
{
|
||||
return ConstMultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
|
||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, Name("master", str...));
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
template <typename T, class CRange>
|
||||
template <class NameType>
|
||||
ConstMultiArrayOperationRoot<T,Range> MultiArrayBase<T,Range>::operator()(const NameType& name, bool master) const
|
||||
ConstMultiArrayOperationRoot<T,CRange> MultiArrayBase<T,CRange>::operator()(const NameType& name, bool master) const
|
||||
{
|
||||
//CHECK;
|
||||
if(master){
|
||||
return ConstMultiArrayOperationRoot<T,Range>(*this, name);
|
||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, name);
|
||||
}
|
||||
else {
|
||||
return operator()(name);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArrayBase<T,Range>::isInit() const
|
||||
*/
|
||||
template <typename T, class CRange>
|
||||
bool MultiArrayBase<T,CRange>::isInit() const
|
||||
{
|
||||
return mInit;
|
||||
}
|
||||
|
@ -235,246 +222,243 @@ namespace MultiArrayTools
|
|||
* MutableMultiArrayBase::iterator *
|
||||
****************************************/
|
||||
|
||||
template <typename T, class Range>
|
||||
MutableMultiArrayBase<T,Range>::iterator::iterator(MutableMultiArrayBase<T,Range>& ma):
|
||||
mMAPtr(&ma), mIndex(mMAPtr->beginIndex())
|
||||
template <typename T, class CRange>
|
||||
MutableMultiArrayBase<T,CRange>::iterator::iterator(MutableMultiArrayBase<T,CRange>& ma):
|
||||
mMAPtr(&ma), mPos(0)
|
||||
{ }
|
||||
|
||||
template <typename T, class Range>
|
||||
MutableMultiArrayBase<T,Range>::iterator::iterator(MutableMultiArrayBase<T,Range>& ma,
|
||||
const typename Range::IndexType& index):
|
||||
mMAPtr(&ma), mIndex(index)
|
||||
template <typename T, class CRange>
|
||||
MutableMultiArrayBase<T,CRange>::iterator::iterator(MutableMultiArrayBase<T,CRange>& ma,
|
||||
const typename CRange::IndexType& index):
|
||||
mMAPtr(&ma), mPos(index.pos())
|
||||
{ }
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MutableMultiArrayBase<T,Range>::iterator::operator==(const iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator==(const iterator& it) const
|
||||
{
|
||||
return mMAPtr == it.mMAPtr and mIndex.pos() == it.mIndex.pos();
|
||||
return mMAPtr == it.mMAPtr and mPos == it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MutableMultiArrayBase<T,Range>::iterator::operator!=(const iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator!=(const iterator& it) const
|
||||
{
|
||||
return mMAPtr != it.mMAPtr or mIndex.pos() != it.mIndex.pos();
|
||||
return mMAPtr != it.mMAPtr or mPos != it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MutableMultiArrayBase<T,Range>::iterator::operator*() const
|
||||
template <typename T, class CRange>
|
||||
const T& MutableMultiArrayBase<T,CRange>::iterator::operator*() const
|
||||
{
|
||||
return (*mMAPtr)[mIndex];
|
||||
return mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
T const* MutableMultiArrayBase<T,Range>::iterator::operator->() const
|
||||
template <typename T, class CRange>
|
||||
T const* MutableMultiArrayBase<T,CRange>::iterator::operator->() const
|
||||
{
|
||||
return &(*mMAPtr)[mIndex];
|
||||
return &mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
T& MutableMultiArrayBase<T,Range>::iterator::operator*()
|
||||
template <typename T, class CRange>
|
||||
T& MutableMultiArrayBase<T,CRange>::iterator::operator*()
|
||||
{
|
||||
return (*mMAPtr)[mIndex];
|
||||
return mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
T* MutableMultiArrayBase<T,Range>::iterator::operator->()
|
||||
template <typename T, class CRange>
|
||||
T* MutableMultiArrayBase<T,CRange>::iterator::operator->()
|
||||
{
|
||||
return &(*mMAPtr)[mIndex];
|
||||
return &mMAPtr->data()[mPos];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator& MutableMultiArrayBase<T,Range>::iterator::operator++()
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator++()
|
||||
{
|
||||
++mIndex;
|
||||
++mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator MutableMultiArrayBase<T,Range>::iterator::operator++(int)
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator++(int)
|
||||
{
|
||||
iterator tmp(*this);
|
||||
++mIndex;
|
||||
++mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator& MutableMultiArrayBase<T,Range>::iterator::operator--()
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator--()
|
||||
{
|
||||
--mIndex;
|
||||
--mPos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator MutableMultiArrayBase<T,Range>::iterator::operator--(int)
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator--(int)
|
||||
{
|
||||
iterator tmp(*this);
|
||||
--mIndex;
|
||||
--mPos;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator& MutableMultiArrayBase<T,Range>::iterator::operator+=(int diff)
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator+=(int diff)
|
||||
{
|
||||
mIndex += diff;
|
||||
mPos += diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator& MutableMultiArrayBase<T,Range>::iterator::operator-=(int diff)
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator& MutableMultiArrayBase<T,CRange>::iterator::operator-=(int diff)
|
||||
{
|
||||
mIndex -= diff;
|
||||
mPos -= diff;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator MutableMultiArrayBase<T,Range>::iterator::operator+(int num) const
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator+(int num) const
|
||||
{
|
||||
iterator tmp(*this);
|
||||
tmp += num;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator MutableMultiArrayBase<T,Range>::iterator::operator-(int num) const
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::iterator::operator-(int num) const
|
||||
{
|
||||
iterator tmp(*this);
|
||||
tmp -= num;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
int MutableMultiArrayBase<T,Range>::iterator::operator-(const iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
int MutableMultiArrayBase<T,CRange>::iterator::operator-(const iterator& it) const
|
||||
{
|
||||
return mIndex.pos() - it.mIndex.pos();
|
||||
return mPos - it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MutableMultiArrayBase<T,Range>::iterator::operator[](int num) const
|
||||
template <typename T, class CRange>
|
||||
const T& MutableMultiArrayBase<T,CRange>::iterator::operator[](int num) const
|
||||
{
|
||||
return *(operator+(num));
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
T& MutableMultiArrayBase<T,Range>::iterator::operator[](int num)
|
||||
template <typename T, class CRange>
|
||||
T& MutableMultiArrayBase<T,CRange>::iterator::operator[](int num)
|
||||
{
|
||||
return *(operator+(num));
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MutableMultiArrayBase<T,Range>::iterator::operator<(const iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator<(const iterator& it) const
|
||||
{
|
||||
return mIndex.pos() < it.mIndex.pos();
|
||||
return mPos < it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MutableMultiArrayBase<T,Range>::iterator::operator>(const iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator>(const iterator& it) const
|
||||
{
|
||||
return mIndex.pos() > it.mIndex.pos();
|
||||
return mPos > it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MutableMultiArrayBase<T,Range>::iterator::operator<=(const iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator<=(const iterator& it) const
|
||||
{
|
||||
return mIndex.pos() <= it.mIndex.pos();
|
||||
return mPos <= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MutableMultiArrayBase<T,Range>::iterator::operator>=(const iterator& it) const
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::iterator::operator>=(const iterator& it) const
|
||||
{
|
||||
return mIndex.pos() >= it.mIndex.pos();
|
||||
return mPos >= it.mPos;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const typename Range::IndexType& MutableMultiArrayBase<T,Range>::iterator::index() const
|
||||
template <typename T, class CRange>
|
||||
typename CRange::IndexType MutableMultiArrayBase<T,CRange>::iterator::index() const
|
||||
{
|
||||
return mIndex;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename Range::IndexType& MutableMultiArrayBase<T,Range>::iterator::index()
|
||||
{
|
||||
return mIndex;
|
||||
auto i = mMAPtr->beginIndex();
|
||||
i = mPos;
|
||||
return i;
|
||||
}
|
||||
|
||||
/******************************
|
||||
* MutableMultiArrayBase *
|
||||
******************************/
|
||||
|
||||
template <typename T, class Range>
|
||||
MutableMultiArrayBase<T,Range>::MutableMultiArrayBase(const Range& range) : MultiArrayBase<T,Range>(range) {}
|
||||
template <typename T, class CRange>
|
||||
MutableMultiArrayBase<T,CRange>::MutableMultiArrayBase(const std::shared_ptr<CRange>& range) :
|
||||
MultiArrayBase<T,CRange>(range) {}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator MutableMultiArrayBase<T,Range>::begin()
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::begin()
|
||||
{
|
||||
return iterator(*this, MAB::beginIndex());
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
typename MutableMultiArrayBase<T,Range>::iterator MutableMultiArrayBase<T,Range>::end()
|
||||
template <typename T, class CRange>
|
||||
typename MutableMultiArrayBase<T,CRange>::iterator MutableMultiArrayBase<T,CRange>::end()
|
||||
{
|
||||
return iterator(*this, MAB::endIndex());
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MutableMultiArrayBase<T,Range>::isConst() const
|
||||
template <typename T, class CRange>
|
||||
bool MutableMultiArrayBase<T,CRange>::isConst() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
/*
|
||||
template <typename T, class CRange>
|
||||
template <class... NameTypes>
|
||||
MultiArrayOperationRoot<T,Range> MutableMultiArrayBase<T,Range>::operator()(const NameTypes&... str)
|
||||
MultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameTypes&... str)
|
||||
{
|
||||
return MultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
|
||||
return MultiArrayOperationRoot<T,CRange>(*this, Name("master", str...));
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
template <typename T, class CRange>
|
||||
template <class NameType>
|
||||
MultiArrayOperationRoot<T,Range> MutableMultiArrayBase<T,Range>::operator()(const NameType& name, bool master)
|
||||
MultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameType& name, bool master)
|
||||
{
|
||||
//CHECK;
|
||||
if(master){
|
||||
return MultiArrayOperationRoot<T,Range>(*this, name);
|
||||
return MultiArrayOperationRoot<T,CRange>(*this, name);
|
||||
}
|
||||
else {
|
||||
return operator()(name);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
template <typename T, class CRange>
|
||||
template <class... NameTypes>
|
||||
ConstMultiArrayOperationRoot<T,Range> MutableMultiArrayBase<T,Range>::operator()(const NameTypes&... str) const
|
||||
ConstMultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameTypes&... str) const
|
||||
{
|
||||
return ConstMultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
|
||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, Name("master", str...));
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
template <typename T, class CRange>
|
||||
template <class NameType>
|
||||
ConstMultiArrayOperationRoot<T,Range> MutableMultiArrayBase<T,Range>::operator()(const NameType& name, bool master) const
|
||||
ConstMultiArrayOperationRoot<T,CRange> MutableMultiArrayBase<T,CRange>::operator()(const NameType& name, bool master) const
|
||||
{
|
||||
//CHECK;
|
||||
if(master){
|
||||
return ConstMultiArrayOperationRoot<T,Range>(*this, name);
|
||||
return ConstMultiArrayOperationRoot<T,CRange>(*this, name);
|
||||
}
|
||||
else {
|
||||
return operator()(name);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/*******************
|
||||
* MultiArray *
|
||||
*******************/
|
||||
|
||||
template <typename T, class Range>
|
||||
MultiArray<T,Range>::MultiArray(const Range& range) :
|
||||
MutableMultiArrayBase<T,Range>(range),
|
||||
template <typename T, class CRange>
|
||||
MultiArray<T,CRange>::MultiArray(const std::shared_ptr<CRange>& range) :
|
||||
MutableMultiArrayBase<T,CRange>(range),
|
||||
mCont(MAB::mRange->size())
|
||||
{
|
||||
MAB::mInit = true;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
MultiArray<T,Range>::MultiArray(const Range& range, const std::vector<T>& vec) :
|
||||
MutableMultiArrayBase<T,Range>(range),
|
||||
template <typename T, class CRange>
|
||||
MultiArray<T,CRange>::MultiArray(const std::shared_ptr<CRange>& range, const std::vector<T>& vec) :
|
||||
MutableMultiArrayBase<T,CRange>(range),
|
||||
mCont(vec)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -483,9 +467,9 @@ namespace MultiArrayTools
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
MultiArray<T,Range>::MultiArray(const Range& range, std::vector<T>&& vec) :
|
||||
MutableMultiArrayBase<T,Range>(range),
|
||||
template <typename T, class CRange>
|
||||
MultiArray<T,CRange>::MultiArray(const std::shared_ptr<CRange>& range, std::vector<T>&& vec) :
|
||||
MutableMultiArrayBase<T,CRange>(range),
|
||||
mCont(vec)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -494,10 +478,10 @@ namespace MultiArrayTools
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
template <typename T, class CRange>
|
||||
template <class Range2, class Range3>
|
||||
MultiArray<T,Range>::MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in) :
|
||||
MutableMultiArrayBase<T,Range>(merge(in.range(), in[ in.beginIndex() ].range()))
|
||||
MultiArray<T,CRange>::MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in) :
|
||||
MutableMultiArrayBase<T,CRange>(merge(in.range(), in[ in.beginIndex() ].range()))
|
||||
// assert that Range2 has always same extension
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -508,9 +492,10 @@ namespace MultiArrayTools
|
|||
assert(mCont.size() == MAB::mRange->size());
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
/*
|
||||
template <typename T, class CRange>
|
||||
template <class Range2, class Range3>
|
||||
MultiArray<T,Range>& MultiArray<T,Range>::operator=(const MultiArray<MultiArray<T,Range2>,Range3> in)
|
||||
MultiArray<T,CRange>& MultiArray<T,CRange>::operator=(const MultiArray<MultiArray<T,Range2>,Range3> in)
|
||||
{
|
||||
MAB::mRange.reset(new Range(merge(in.range(), in[ in.beginIndex() ].range())));
|
||||
// assert that Range2 has always same extension
|
||||
|
@ -520,41 +505,47 @@ namespace MultiArrayTools
|
|||
}
|
||||
assert(mCont.size() == MAB::mRange->size());
|
||||
return *this;
|
||||
}
|
||||
} */
|
||||
|
||||
template <typename T, class Range>
|
||||
T& MultiArray<T,Range>::operator[](const typename Range::IndexType& i)
|
||||
template <typename T, class CRange>
|
||||
T& MultiArray<T,CRange>::operator[](const typename CRange::IndexType& i)
|
||||
{
|
||||
return mCont[ i.pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MultiArray<T,Range>::operator[](const typename Range::IndexType& i) const
|
||||
template <typename T, class CRange>
|
||||
const T& MultiArray<T,CRange>::operator[](const typename CRange::IndexType& i) const
|
||||
{
|
||||
return mCont[ i.pos() ];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArray<T,Range>::isConst() const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArray<T,CRange>::isConst() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArray<T,Range>::isSlice() const
|
||||
template <typename T, class CRange>
|
||||
bool MultiArray<T,CRange>::isSlice() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T* MultiArray<T,Range>::data() const
|
||||
template <typename T, class CRange>
|
||||
const T* MultiArray<T,CRange>::data() const
|
||||
{
|
||||
return mCont.data();
|
||||
}
|
||||
|
||||
template <typename T, class CRange>
|
||||
T* MultiArray<T,CRange>::data()
|
||||
{
|
||||
return mCont.data();
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename T, class Range>
|
||||
void MultiArray<T,Range>::manipulate(ManipulatorBase<T>& mb,
|
||||
template <typename T, class CRange>
|
||||
void MultiArray<T,CRange>::manipulate(ManipulatorBase<T>& mb,
|
||||
const typename Range::IndexType& manBegin,
|
||||
const typename Range::IndexType& manEnd)
|
||||
{
|
||||
|
@ -571,28 +562,28 @@ namespace MultiArrayTools
|
|||
/*
|
||||
template <typename T, class Range, class Function>
|
||||
FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range) :
|
||||
MultiArrayBase<T,Range>(range), mFunc() {}
|
||||
MultiArrayBase<T,CRange>(range), mFunc() {}
|
||||
*/
|
||||
template <typename T, class Range, class Function>
|
||||
FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range,
|
||||
const Function& func) :
|
||||
MultiArrayBase<T,Range>(range), mFunc(func) { /*CHECK;*/ }
|
||||
template <typename T, class CRange, class Function>
|
||||
FunctionalMultiArray<T,CRange,Function>::FunctionalMultiArray(const std::shared_ptr<CRange>& range,
|
||||
const Function& func) :
|
||||
MultiArrayBase<T,CRange>(range), mFunc(func) { /*CHECK;*/ }
|
||||
|
||||
template <typename T, class Range, class Function>
|
||||
const T& FunctionalMultiArray<T,Range,Function>::operator[](const typename Range::IndexType& i) const
|
||||
template <typename T, class CRange, class Function>
|
||||
const T& FunctionalMultiArray<T,CRange,Function>::operator[](const typename CRange::IndexType& i) const
|
||||
{
|
||||
mVal = mFunc(i);
|
||||
return mVal;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class Function>
|
||||
bool FunctionalMultiArray<T,Range,Function>::isConst() const
|
||||
template <typename T, class CRange, class Function>
|
||||
bool FunctionalMultiArray<T,CRange,Function>::isConst() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class Range, class Function>
|
||||
bool FunctionalMultiArray<T,Range,Function>::isSlice() const
|
||||
template <typename T, class CRange, class Function>
|
||||
bool FunctionalMultiArray<T,CRange,Function>::isSlice() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -11,22 +11,18 @@
|
|||
|
||||
#include "base_def.h"
|
||||
#include "multi_range.h"
|
||||
#include "multi_array_operation.h"
|
||||
#include "manipulator.h"
|
||||
#include "name.h"
|
||||
//#include "multi_array_operation.h"
|
||||
//#include "manipulator.h"
|
||||
//#include "name.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class... Ranges>
|
||||
using TopRange = MultiRange<Ranges...>;
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
template <typename T, class CRange>
|
||||
class MultiArrayBase
|
||||
{
|
||||
public:
|
||||
|
||||
typedef TopRange<Ranges...> TopRangeType
|
||||
typedef T value_type;
|
||||
|
||||
class const_iterator : public std::iterator<std::random_access_iterator_tag,T>
|
||||
|
@ -36,7 +32,7 @@ namespace MultiArrayTools
|
|||
DEFAULT_MEMBERS(const_iterator);
|
||||
|
||||
const_iterator(const MultiArrayBase& ma);
|
||||
const_iterator(const MultiArrayBase& ma, const typename TopRangeType::IndexType& index);
|
||||
const_iterator(const MultiArrayBase& ma, const typename CRange::IndexType& index);
|
||||
virtual ~const_iterator() = default;
|
||||
|
||||
// Requirements:
|
||||
|
@ -66,24 +62,21 @@ namespace MultiArrayTools
|
|||
bool operator>=(const const_iterator& it) const;
|
||||
|
||||
// Multi Array specific:
|
||||
|
||||
const typename TopRangeType::IndexType& index() const;
|
||||
typename TopRangeType::IndexType& index();
|
||||
typename CRange::IndexType index() const;
|
||||
|
||||
protected:
|
||||
MultiArrayBase const* mMAPtr = nullptr;
|
||||
typename TopRangeType::IndexType mIndex;
|
||||
size_t mPos;
|
||||
};
|
||||
|
||||
DEFAULT_MEMBERS(MultiArrayBase);
|
||||
MultiArrayBase(const TopRangeType& range);
|
||||
MultiArrayBase(const std::shared_ptr<CRange>& range);
|
||||
|
||||
virtual ~MultiArrayBase() = default;
|
||||
|
||||
// only relevant for slices... has no effect for usual multiarrays
|
||||
virtual void link(IndefinitIndexBase* iibPtr) const;
|
||||
virtual const T& operator[](const typename CRange::IndexType& i) const = 0;
|
||||
|
||||
virtual const T& operator[](const typename TopRangeType::IndexType& i) const = 0;
|
||||
virtual const T* data() const = 0;
|
||||
|
||||
virtual size_t size() const;
|
||||
virtual bool isSlice() const = 0;
|
||||
|
@ -91,36 +84,35 @@ namespace MultiArrayTools
|
|||
virtual const_iterator begin() const;
|
||||
virtual const_iterator end() const;
|
||||
|
||||
virtual auto beginIndex() const -> decltype(Range().begin());
|
||||
virtual auto endIndex() const -> decltype(Range().end());
|
||||
virtual typename CRange::IndexType beginIndex() const;
|
||||
virtual typename CRange::IndexType endIndex() const;
|
||||
|
||||
virtual const TopRangeType& range() const;
|
||||
virtual const CRange& range() const;
|
||||
|
||||
virtual bool isConst() const;
|
||||
|
||||
/*
|
||||
template <class... NameTypes>
|
||||
ConstMultiArrayOperationRoot<T,TopRangeType> operator()(const NameTypes&... str) const;
|
||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameTypes&... str) const;
|
||||
|
||||
template <class NameType>
|
||||
ConstMultiArrayOperationRoot<T,TopRangeType> operator()(const NameType& name, bool master) const;
|
||||
|
||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameType& name, bool master) const;
|
||||
*/
|
||||
virtual bool isInit() const;
|
||||
|
||||
protected:
|
||||
bool mInit = false;
|
||||
std::shared_ptr<TopRangeType> mRange;
|
||||
std::shared_ptr<CRange> mRange;
|
||||
|
||||
};
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
class MutableMultiArrayBase : public MultiArrayBase<T,Ranges...>
|
||||
template <typename T, class CRange>
|
||||
class MutableMultiArrayBase : public MultiArrayBase<T,CRange>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename MultiArrayBase<T,Ranges...>::const_iterator const_iterator;
|
||||
typedef MultiArrayBase<T,Ranges...> MAB;
|
||||
typedef typename MAB::TopRangeType TopRangeType;
|
||||
typedef typename TopRangeType::IndexType IndexType;
|
||||
typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
|
||||
typedef MultiArrayBase<T,CRange> MAB;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
class iterator : public std::iterator<std::random_access_iterator_tag,T>,
|
||||
public std::iterator<std::output_iterator_tag,T>
|
||||
|
@ -163,69 +155,68 @@ namespace MultiArrayTools
|
|||
bool operator>=(const iterator& it) const;
|
||||
|
||||
// Multi Array specific:
|
||||
|
||||
const IndexType& index() const;
|
||||
IndexType& index();
|
||||
typename CRange::IndexType index() const;
|
||||
|
||||
protected:
|
||||
MutableMultiArrayBase* mMAPtr = nullptr;
|
||||
IndexType mIndex;
|
||||
size_t mPos;
|
||||
};
|
||||
|
||||
|
||||
DEFAULT_MEMBERS(MutableMultiArrayBase);
|
||||
MutableMultiArrayBase(const TopRangeType& range);
|
||||
MutableMultiArrayBase(const std::shared_ptr<CRange>& range);
|
||||
|
||||
virtual T& operator[](const IndexType& i) = 0;
|
||||
|
||||
virtual T* data() = 0;
|
||||
|
||||
virtual iterator begin();
|
||||
virtual iterator end();
|
||||
|
||||
virtual bool isConst() const override;
|
||||
|
||||
/*
|
||||
template <class... NameTypes>
|
||||
ConstMultiArrayOperationRoot<T,Ranges...> operator()(bool x, const NameTypes&... str) const
|
||||
ConstMultiArrayOperationRoot<T,CRange> operator()(bool x, const NameTypes&... str) const
|
||||
{
|
||||
return MAB::operator()(str...);
|
||||
}
|
||||
|
||||
template <class... NameTypes>
|
||||
ConstMultiArrayOperationRoot<T,Ranges...> operator()(const NameTypes&... str) const;
|
||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameTypes&... str) const;
|
||||
|
||||
template <class NameType>
|
||||
ConstMultiArrayOperationRoot<T,Ranges...> operator()(const NameType& name, bool master) const;
|
||||
ConstMultiArrayOperationRoot<T,CRange> operator()(const NameType& name, bool master) const;
|
||||
|
||||
template <class... NameTypes>
|
||||
MultiArrayOperationRoot<T,Ranges...> operator()(const NameTypes&... str);
|
||||
MultiArrayOperationRoot<T,CRange> operator()(const NameTypes&... str);
|
||||
|
||||
template <class NameType>
|
||||
MultiArrayOperationRoot<T,Ranges...> operator()(const NameType& name, bool master);
|
||||
|
||||
MultiArrayOperationRoot<T,CRange> operator()(const NameType& name, bool master);
|
||||
*/
|
||||
};
|
||||
|
||||
template <typename T, class Ranges...>
|
||||
class MultiArray : public MutableMultiArrayBase<T,Ranges...>
|
||||
template <typename T, class CRange>
|
||||
class MultiArray : public MutableMultiArrayBase<T,CRange>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef MultiArrayBase<T,Ranges...> MAB;
|
||||
typedef typename MultiArrayBase<T,Ranges...>::const_iterator const_iterator;
|
||||
typedef typename MutableMultiArrayBase<T,Ranges...>::iterator iterator;
|
||||
typedef typename MAB::TopRangeType TopRangeType;
|
||||
typedef typename TopRangeType::IndexType IndexType;
|
||||
typedef MultiArrayBase<T,CRange> MAB;
|
||||
typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
|
||||
typedef typename MutableMultiArrayBase<T,CRange>::iterator iterator;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
DEFAULT_MEMBERS(MultiArray);
|
||||
MultiArray(const TopRangeType& range);
|
||||
MultiArray(const TopRangeType& range, const std::vector<T>& vec);
|
||||
MultiArray(const TopRangeType& range, std::vector<T>&& vec);
|
||||
MultiArray(const std::shared_ptr<CRange>& range);
|
||||
MultiArray(const std::shared_ptr<CRange>& range, const std::vector<T>& vec);
|
||||
MultiArray(const std::shared_ptr<CRange>& range, std::vector<T>&& vec);
|
||||
|
||||
template <class Range2, class Range3>
|
||||
MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
|
||||
// implement contstructor using FunctionalMultiArray as Input !!!
|
||||
|
||||
template <class Range2, class Range3>
|
||||
MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
//template <class Range2, class Range3>
|
||||
//MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
|
||||
T& operator[](const IndexType& i) override;
|
||||
const T& operator[](const IndexType& i) const override;
|
||||
|
@ -233,11 +224,16 @@ namespace MultiArrayTools
|
|||
virtual bool isConst() const override;
|
||||
virtual bool isSlice() const override;
|
||||
|
||||
const T* data() const;
|
||||
template <class Range2>
|
||||
MultiArray& operator()(const std::shared_ptr<Range2>& nr); // reformat array using 'nr' which in
|
||||
// total must have the same size as mRange
|
||||
|
||||
const T* data() const override;
|
||||
T* data() override;
|
||||
|
||||
// virtual void manipulate(ManipulatorBase<T>& mb,
|
||||
// const typename Ranges...::IndexType& manBegin,
|
||||
// const typename Ranges...::IndexType& manEnd);
|
||||
// const typename CRange::IndexType& manBegin,
|
||||
// const typename CRange::IndexType& manEnd);
|
||||
|
||||
template <typename U, class RangeX>
|
||||
friend class MultiArray;
|
||||
|
@ -246,18 +242,17 @@ namespace MultiArrayTools
|
|||
std::vector<T> mCont;
|
||||
};
|
||||
|
||||
template <typename T, class Ranges..., class Function>
|
||||
class FunctionalMultiArray : public MultiArrayBase<T,Ranges...>
|
||||
template <typename T, class CRange, class Function>
|
||||
class FunctionalMultiArray : public MultiArrayBase<T,CRange>
|
||||
{
|
||||
public:
|
||||
typedef MultiArrayBase<T,Ranges...> MAB;
|
||||
typedef typename MultiArrayBase<T,Ranges...>::const_iterator const_iterator;
|
||||
typedef typename MAB::TopRangeType TopRangeType;
|
||||
typedef typename TopRangeType::IndexType IndexType;
|
||||
typedef MultiArrayBase<T,CRange> MAB;
|
||||
typedef typename MultiArrayBase<T,CRange>::const_iterator const_iterator;
|
||||
typedef typename CRange::IndexType IndexType;
|
||||
|
||||
DEFAULT_MEMBERS(FunctionalMultiArray);
|
||||
//FunctionalMultiArray(const Ranges...& range);
|
||||
FunctionalMultiArray(const TopRangeType& range, const Function& func);
|
||||
//FunctionalMultiArray(const CRange& range);
|
||||
FunctionalMultiArray(const std::shared_ptr<CRange>& range, const Function& func);
|
||||
|
||||
virtual const T& operator[](const IndexType& i) const override;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "multi_range.h"
|
||||
#include "container_range.h"
|
||||
//#include "multi_array_operation.h"
|
||||
//#include "multi_array.h"
|
||||
#include "multi_array.h"
|
||||
//#include "slice.h"
|
||||
//#include "manipulator.h"
|
||||
//#include "range_transformer.h"
|
||||
|
|
Loading…
Reference in a new issue