clean up some parts of the code

This commit is contained in:
Christian Zimmermann 2017-03-01 10:41:29 +01:00
parent 27ddea16f6
commit 51dcbe7b92
7 changed files with 32 additions and 34 deletions

View file

@ -17,31 +17,31 @@ namespace MultiArrayTools
size_t IndefinitIndexBase::pos() const size_t IndefinitIndexBase::pos() const
{ {
assert(not virt()); //assert(not virt());
return mPos; return mPos;
} }
const std::string& IndefinitIndexBase::name() const const std::string& IndefinitIndexBase::name() const
{ {
assert(not virt()); //assert(not virt());
return mName; return mName;
} }
void IndefinitIndexBase::name(const std::string& str) void IndefinitIndexBase::name(const std::string& str)
{ {
assert(not virt()); //assert(not virt());
mName = str; mName = str;
} }
void IndefinitIndexBase::name(const Name& nm) void IndefinitIndexBase::name(const Name& nm)
{ {
assert(not virt()); //assert(not virt());
mName = nm.own(); mName = nm.own();
} }
bool IndefinitIndexBase::link(IndefinitIndexBase* toLink) bool IndefinitIndexBase::link(IndefinitIndexBase* toLink)
{ {
assert(not virt()); //assert(not virt());
if(toLink->rangeType() != rangeType() and toLink->name() == name()){ if(toLink->rangeType() != rangeType() and toLink->name() == name()){
assert(0); assert(0);
// throw !! // throw !!
@ -77,13 +77,13 @@ namespace MultiArrayTools
bool IndefinitIndexBase::linked() const bool IndefinitIndexBase::linked() const
{ {
assert(not virt()); //assert(not virt());
return mLinked != nullptr; return mLinked != nullptr;
} }
void IndefinitIndexBase::setPos(size_t pos) void IndefinitIndexBase::setPos(size_t pos)
{ {
assert(not virt()); //assert(not virt());
mPos = pos; mPos = pos;
if(linked()){ if(linked()){
mLinked->setPos(mPos); mLinked->setPos(mPos);
@ -93,26 +93,26 @@ namespace MultiArrayTools
size_t IndefinitIndexBase::max() const size_t IndefinitIndexBase::max() const
{ {
assert(not virt()); //assert(not virt());
return static_cast<size_t>( -1 ); return static_cast<size_t>( -1 );
} }
size_t IndefinitIndexBase::outOfRange() const size_t IndefinitIndexBase::outOfRange() const
{ {
assert(not virt()); //assert(not virt());
int res = pos() - max() + 1; int res = pos() - max() + 1;
return res > 0 ? static_cast<size_t>(res) : 0; return res > 0 ? static_cast<size_t>(res) : 0;
} }
bool IndefinitIndexBase::toNull() const bool IndefinitIndexBase::toNull() const
{ {
assert(not virt()); //assert(not virt());
return true; return true;
} }
void IndefinitIndexBase::evalMajor() void IndefinitIndexBase::evalMajor()
{ {
assert(not virt()); //assert(not virt());
if(not master()){ if(not master()){
mMajor->eval(); mMajor->eval();
} }
@ -120,13 +120,13 @@ namespace MultiArrayTools
bool IndefinitIndexBase::master() bool IndefinitIndexBase::master()
{ {
assert(not virt()); //assert(not virt());
return mMajor == nullptr; return mMajor == nullptr;
} }
void IndefinitIndexBase::subOrd(IndefinitIndexBase* major) void IndefinitIndexBase::subOrd(IndefinitIndexBase* major)
{ {
assert(not virt()); //assert(not virt());
mMajor = major; mMajor = major;
} }
@ -140,31 +140,29 @@ namespace MultiArrayTools
template <class Index> template <class Index>
size_t IndexBase<Index>::max() const size_t IndexBase<Index>::max() const
{ {
assert(not virt()); //assert(not virt());
return mRange->size(); return mRange->size();
} }
template <class Index> template <class Index>
bool IndexBase<Index>::toNull() const bool IndexBase<Index>::toNull() const
{ {
assert(not virt()); //assert(not virt());
return mRange == nullptr; return mRange == nullptr;
} }
template <class Index> template <class Index>
void IndexBase<Index>::assignRange(RangeBase<Index> const* range) void IndexBase<Index>::assignRange(RangeBase<Index> const* range)
{ {
assert(not virt()); //assert(not virt());
if(toNull()){ if(toNull()){
mRange = range; mRange = range;
} }
} }
/*
template <class Index> template <class Index>
void IndexBase<Index>::eval() void IndexBase<Index>::eval()
{ {
CHECK;
setPos( evaluate(*dynamic_cast<Index const*>( this )) ); setPos( evaluate(*dynamic_cast<Index const*>( this )) );
}*/ }
} }

View file

@ -57,7 +57,7 @@ namespace MultiArrayTools
virtual void subOrd(IndefinitIndexBase* major); virtual void subOrd(IndefinitIndexBase* major);
virtual bool virt() const { return true; } //virtual bool virt() const { return true; }
protected: protected:
@ -85,7 +85,7 @@ namespace MultiArrayTools
virtual void assignRange(RangeBase<Index> const* range); virtual void assignRange(RangeBase<Index> const* range);
//virtual void eval() override; virtual void eval() override;
virtual void copyPos(const Index& in) = 0; virtual void copyPos(const Index& in) = 0;
protected: protected:

View file

@ -486,12 +486,13 @@ namespace MultiArrayTools
PositionCopy<sizeof...(Indices)-1>::copyPos(*this, in); PositionCopy<sizeof...(Indices)-1>::copyPos(*this, in);
} }
/*
template <class... Indices> template <class... Indices>
void MultiIndex<Indices...>::eval() void MultiIndex<Indices...>::eval()
{ {
IIB::setPos( evaluate( *this ) ); IIB::setPos( evaluate( *this ) );
} }
*/
/* /*
template <size_t N> template <size_t N>
struct RangeAssigner struct RangeAssigner

View file

@ -80,9 +80,8 @@ namespace MultiArrayTools
virtual void copyPos(const MultiIndex<Indices...>& in) override; virtual void copyPos(const MultiIndex<Indices...>& in) override;
virtual void eval() override; //virtual void eval() override;
//virtual bool virt() const override { return false; }
virtual bool virt() const override { return false; }
//virtual void assignRange(RangeBase<MultiIndex<Indices...> > const* range) override; //virtual void assignRange(RangeBase<MultiIndex<Indices...> > const* range) override;
}; };

View file

@ -155,9 +155,11 @@ namespace MultiArrayTools
IIB::setPos(in.pos()); IIB::setPos(in.pos());
} }
/*
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
void SingleIndex<U,TYPE>::eval() void SingleIndex<U,TYPE>::eval()
{ {
IIB::setPos( evaluate( *this ) ); IIB::setPos( evaluate( *this ) );
} }
*/
} }

View file

@ -50,9 +50,8 @@ namespace MultiArrayTools
virtual void copyPos(const SingleIndex& in) override; virtual void copyPos(const SingleIndex& in) override;
virtual void eval() override; //virtual void eval() override;
//virtual bool virt() const override { return false; }
virtual bool virt() const override { return false; }
protected: protected:
virtual size_t evaluate(const SingleIndex& in) const override; virtual size_t evaluate(const SingleIndex& in) const override;

View file

@ -359,11 +359,11 @@ namespace {
auto i1 = i.template getIndex<0>(); auto i1 = i.template getIndex<0>();
auto i2 = i.template getIndex<1>(); auto i2 = i.template getIndex<1>();
auto i3 = i.template getIndex<2>(); auto i3 = i.template getIndex<2>();
CHECK;
Slice2d3dAny sl(ra); Slice2d3dAny sl(ra);
CHECK;
sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)]; sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)];
EXPECT_EQ(sl.size(), 6); EXPECT_EQ(sl.size(), 6);
Slice2d3dAny sl2(rb); Slice2d3dAny sl2(rb);
sl2("alpha","beta") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 0, i3 = 1)]; sl2("alpha","beta") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 0, i3 = 1)];
EXPECT_EQ(sl2.size(), 12); EXPECT_EQ(sl2.size(), 12);
@ -377,13 +377,12 @@ namespace {
auto i3 = i.template getIndex<2>(); auto i3 = i.template getIndex<2>();
Slice2d3dAny sl(ra); Slice2d3dAny sl(ra);
sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)]; sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)];
CHECK;
auto j = sl.begin(); auto j = sl.begin();
auto j1 = j.template getIndex<0>(); auto j1 = j.template getIndex<0>();
auto j2 = j.template getIndex<1>(); auto j2 = j.template getIndex<1>();
CHECK;
EXPECT_EQ(sl[j(j1 = 0, j2 = 0)], 9); EXPECT_EQ(sl[j(j1 = 0, j2 = 0)], 9);
CHECK;
EXPECT_EQ(sl[j(j1 = 0, j2 = 1)], 54); EXPECT_EQ(sl[j(j1 = 0, j2 = 1)], 54);
EXPECT_EQ(sl[j(j1 = 1, j2 = 0)], -10); EXPECT_EQ(sl[j(j1 = 1, j2 = 0)], -10);