diff --git a/CMakeLists.txt b/CMakeLists.txt index 271052f..e52e5ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,9 +15,13 @@ endif() include_directories(src) -add_executable(utest src/unit_test.cc) -target_link_libraries(utest ${GTEST_BOTH_LIBRARIES}) -add_test(NAME utest COMMAND utest) +#add_executable(utest src/unit_test.cc) +#target_link_libraries(utest ${GTEST_BOTH_LIBRARIES}) +#add_test(NAME utest COMMAND utest) + +add_executable(iutest src/index_unit_test.cc) +target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES}) +add_test(NAME iutest COMMAND utest) #install(TARGETS testm DESTINATION install) diff --git a/src/index_unit_test.cc b/src/index_unit_test.cc new file mode 100644 index 0000000..2c27147 --- /dev/null +++ b/src/index_unit_test.cc @@ -0,0 +1,52 @@ +// -*- C++ -*- + +#include +#include "gtest/gtest.h" +#include + +#include "multi_array_header.h" + +namespace MAT = MultiArrayTools; + +namespace { + + class ConnectionTest : public ::testing::Test + { + protected: + + typedef MAT::SingleRange SingleRc; + typedef MAT::SingleRange SingleRi; + typedef MAT::MultiRange MultiR3d; + typedef MAT::MultiRange MultiR2d; + + ConnectionTest() : sri1({0,1,2,3}), + src1({'a','b'}), + src2({'a','b','c'}), + mr3d1(src1,src2,sri1) {} + + SingleRi sri1; + SingleRc src1; + SingleRc src2; + MultiR3d mr3d1; + }; + + TEST_F(ConnectionTest, UnlinkedIteration) + { + auto i3d = mr3d1.begin(); + auto& ii1 = i3d.template getIndex<2>(); + EXPECT_EQ(i3d.pos(), 0); + ++ii1; + EXPECT_EQ(i3d.pos(), 1); + ++ii1; + EXPECT_EQ(i3d.pos(), 2); + ++ii1; + EXPECT_EQ(i3d.pos(), 3); + } + +} // end namespace + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/multi_range.cc b/src/multi_range.cc index 6d996dc..4e310d5 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -324,6 +324,18 @@ namespace MultiArrayTools } } + template + static auto setFromPointerList(IndexPack& ipack, + std::vector >& ptrList, + std::shared_ptr&... inds) + -> decltype(IndexPackSetter::setFromPointerList(ipack, + std::shared_ptr(ipack))>, + newPtr, inds...)) + { + typedef std::shared_ptr(ipack))> NewIndexPtrType; + NewIndexPtrType newPtr = dynamic_pointer_cast(ptrList.at(N)); + return IndexPackSetter::setFromPointerList(ipack, ptrList, newPtr, inds...); + } }; template <> @@ -336,9 +348,20 @@ namespace MultiArrayTools const size_t ownPos = pos % i.max(); i = ownPos; } + + template + static auto setFromPointerList(IndexPack& ipack, + std::vector >& ptrList, + std::shared_ptr&... inds) + -> decltype(std::make_tuple(std::shared_ptr(ipack))>, inds...)) + { + typedef std::shared_ptr(ipack))> NewIndexPtrType; + NewIndexPtrType newPtr = dynamic_pointer_cast(ptrList.at(0)); + return std::make_tuple(newPtr, inds...); + } }; - + } template @@ -391,8 +414,11 @@ namespace MultiArrayTools } template - MultiIndex::MultiIndex(std::vector >& indexList) : - // !!!! + MultiIndex::MultiIndex(std::vector >& indexList) + { + mIPack = IndexPackSetter::setFromPointerList(mIPack, indexList); + IndexSubOrder::subOrd(mIPack, this); + } template MultiIndex& MultiIndex::operator++()