fix multi_index bugs...

This commit is contained in:
Christian Zimmermann 2017-08-07 11:22:42 +02:00
parent 7a16f22f78
commit 40864ace00
6 changed files with 43 additions and 10 deletions

View file

@ -21,7 +21,7 @@ include_directories(src)
add_executable(iutest src/index_unit_test.cc) add_executable(iutest src/index_unit_test.cc)
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES}) target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES})
add_test(NAME iutest COMMAND utest) add_test(NAME iutest COMMAND iutest)
#install(TARGETS testm DESTINATION install) #install(TARGETS testm DESTINATION install)

View file

@ -175,7 +175,8 @@ namespace MultiArrayTools
ContainerIndex<typename Ranges::IndexType...> ContainerIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> > i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = 0; i = 0;
return i;
} }
template <class... Ranges> template <class... Ranges>
@ -184,7 +185,8 @@ namespace MultiArrayTools
ContainerIndex<typename Ranges::IndexType...> ContainerIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> > i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = size(); i = size();
return i;
} }
template <class... Ranges> template <class... Ranges>

View file

@ -93,7 +93,33 @@ namespace {
EXPECT_EQ(si == si3, false); EXPECT_EQ(si == si3, false);
EXPECT_EQ(si != si3, true); EXPECT_EQ(si != si3, true);
} }
TEST_F(IndexTest, MultiIndex_SimpleCall)
{
auto mi = m3rptr->begin();
EXPECT_EQ(mi.max(), 4);
EXPECT_EQ(mi.pos(), 0);
EXPECT_EQ(mi.first(), true);
EXPECT_EQ(mi.last(), false);
EXPECT_EQ(mi.meta() == std::make_tuple('a','1','0'), true);
mi.at(std::make_tuple('b','1','7'));
EXPECT_EQ(mi.pos(), mi.max()-1);
EXPECT_EQ(mi.first(), false);
EXPECT_EQ(mi.last(), true);
mi = 1;
EXPECT_EQ(mi.meta() == std::make_tuple('a','1','7'), true);
++mi;
EXPECT_EQ(mi.meta() == std::make_tuple('b','1','0'), true);
++mi;
auto mi2 = m3rptr->end();
--mi2;
EXPECT_EQ(mi == mi2, true);
EXPECT_EQ(mi != mi2, false);
--mi2;
EXPECT_EQ(mi == mi2, false);
EXPECT_EQ(mi != mi2, true);
}
} // end namespace } // end namespace
int main(int argc, char** argv) int main(int argc, char** argv)

View file

@ -120,6 +120,7 @@ namespace MultiArrayTools
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MultiIndex<Indices...>::MetaType& metaPos) MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MultiIndex<Indices...>::MetaType& metaPos)
{ {
PackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos); PackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
return *this; return *this;
} }
@ -206,7 +207,8 @@ namespace MultiArrayTools
MultiIndex<typename Ranges::IndexType...> MultiIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MultiRange<Ranges...> > i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = 0; i = 0;
return i;
} }
template <class... Ranges> template <class... Ranges>
@ -215,7 +217,8 @@ namespace MultiArrayTools
MultiIndex<typename Ranges::IndexType...> MultiIndex<typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MultiRange<Ranges...> > i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )) ); ( std::shared_ptr<RangeBase>( RB::mThis )) );
return i = size(); i = size();
return i;
} }
template <class... Ranges> template <class... Ranges>

View file

@ -89,7 +89,7 @@ namespace MultiArrayHelper
template <class IndexPack> template <class IndexPack>
static void setIndexPack(IndexPack& iPack, size_t pos) static void setIndexPack(IndexPack& iPack, size_t pos)
{ {
auto i = *std::get<N>(iPack).get(); auto& i = *std::get<N>(iPack).get();
const size_t ownPos = pos % i.max(); const size_t ownPos = pos % i.max();
i = ownPos; i = ownPos;
if(ownPos == pos){ if(ownPos == pos){
@ -195,7 +195,7 @@ namespace MultiArrayHelper
template <class IndexPack> template <class IndexPack>
static void setIndexPack(IndexPack& iPack, size_t pos) static void setIndexPack(IndexPack& iPack, size_t pos)
{ {
auto i = *std::get<0>(iPack); auto& i = *std::get<0>(iPack);
const size_t ownPos = pos % i.max(); const size_t ownPos = pos % i.max();
i = ownPos; i = ownPos;
} }

View file

@ -124,7 +124,8 @@ namespace MultiArrayTools
{ {
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> > SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = 0; i = 0;
return i;
} }
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
@ -132,7 +133,8 @@ namespace MultiArrayTools
{ {
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> > SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
return i = size(); i = size();
return i;
} }
// put this in the interface class !!! // put this in the interface class !!!