diff --git a/src/base_def.h b/src/base_def.h index 98ab87c..bddb0a6 100644 --- a/src/base_def.h +++ b/src/base_def.h @@ -49,42 +49,59 @@ namespace MultiArrayTools enum class RangeType; // range_base.h - class MultiRangeType; - - // range_base.h - class IndefinitRangeBase; - - // range_base.h - template class RangeBase; + // range_base.h + class RangeFactoryBase; + // range_base.h template - class SubRangeBase; + class RangeInterface; // index_base.h - class IndefinitIndexBase; - - // index_base.h - template class IndexBase; - // single_range.h - template - class SingleIndex; + // index_base.h + template + class IndexInterface; // single_range.h template class SingleRange; - // multi_range.h - template - class MultiIndex; + // single_range.h + template + class SingleRangeFactory; + // single_range.h + template + class SingleIndex; + + // multi_range.h + template + class MultiRangeFactory; + // multi_range.h template class MultiRange; + // multi_range.h + template + class MultiIndex; + + // container_range.h + template + class ContainerRangeFactory; + + // container_range.h + template + class ContainerRange; + + // container_range.h + template + class ContainerIndex; + + /* // multi_array.h template class MultiArrayBase; @@ -153,6 +170,7 @@ namespace MultiArrayTools // ma_functional.h class pyProjNoSymFunction; + */ } #endif diff --git a/src/container_range.h b/src/container_range.h index a31b969..a5d009f 100644 --- a/src/container_range.h +++ b/src/container_range.h @@ -14,6 +14,8 @@ namespace MultiArrayTools { public: + typedef ContainerRange oType; + ContainerRangeFactory() = delete; ContainerRangeFactory(const std::shared_ptr&... rs); ContainerRangeFactory(const ContainerRange::SpaceType& space); diff --git a/src/index_unit_test.cc b/src/index_unit_test.cc index 2c27147..bdfa45c 100644 --- a/src/index_unit_test.cc +++ b/src/index_unit_test.cc @@ -10,37 +10,52 @@ namespace MAT = MultiArrayTools; namespace { + using namespace MAT; + class ConnectionTest : public ::testing::Test { protected: - typedef MAT::SingleRange SingleRc; - typedef MAT::SingleRange SingleRi; - typedef MAT::MultiRange MultiR3d; - typedef MAT::MultiRange MultiR2d; + typedef SingleRangeFactory SRF; + typedef SRF::oType SRange; - 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; + typedef MultiRangeFactory M3RF; + typedef M3RF::oType M3Range; + + typedef MultiRangeFactory MasterRF; + typedef MasterRF::oType MasterRange; + + typedef ContainerRangeFactory CRF; + typedef CRF::oType CRange; + + ConnectionTest() + { + rfbptr.swap( std::make_shared( { 'e', 'b', 'n' } ) ); + sr1ptr = std::dynamic_pointer_cast( rfbptr.create() ); + + rfbptr.swap( std::make_shared( { 'x', 'y', 'l', 'f' } ) ); + sr2ptr = std::dynamic_pointer_cast( rfbptr.create() ); + + rfbptr.swap( std::make_shared( { 'a', 'b' } ) ); + std::shared_ptr temp1 = std::dynamic_pointer_cast( rfbptr.create() ); + rfbptr.swap( std::make_shared( { '1' } ) ); + std::shared_ptr temp2 = std::dynamic_pointer_cast( rfbptr.create() ); + rfbptr.swap( std::make_shared( { '0', '7' } ) ); + std::shared_ptr temp3 = std::dynamic_pointer_cast( rfbptr.create() ); + + rfbptr.swap( std::make_shared( temp1, temp2, temp3 ) ); + m3rptr = std::dynamic_pointer_cast( rfbptr.create() ); + } + + std::shared_ptr rfbptr; + std::shared_ptr sr1ptr; + std::shared_ptr sr2ptr; + std::shared_ptr m3rptr; }; 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 diff --git a/src/multi_range.h b/src/multi_range.h index 2de8e70..877c563 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -68,6 +68,8 @@ namespace MultiArrayTools class MultiRangeFactory : public RangeFactoryBase { public: + typedef MultiRange oType; + MultiRangeFactory() = delete; MultiRangeFactory(const std::shared_ptr&... rs); MultiRangeFactory(const MultiRange::SpaceType& space); diff --git a/src/single_range.cc b/src/single_range.cc index 02a1f79..b4c0a6d 100644 --- a/src/single_range.cc +++ b/src/single_range.cc @@ -63,6 +63,23 @@ namespace MultiArrayTools { return mPos == 0; } + + /******************** + * SingleRange * + ********************/ + + template + SingleRangeFactory::SingleRangeFactory(const std::vector& space) + { + mProd = std::make_shared( space ); + } + + template + std::shared_ptr SingleRangeFactory::create() + { + setSelf(); + return mProd; + } /******************** * SingleRange * diff --git a/src/single_range.h b/src/single_range.h index 3e9ee85..1093439 100644 --- a/src/single_range.h +++ b/src/single_range.h @@ -35,6 +35,19 @@ namespace MultiArrayTools virtual bool first() const override; }; + template + class SingleRangeFactory : public RangeFactoryBase + { + public: + + typedef SingleRange oType; + + SingleRangeFactory() = delete; + SingleRangeFactory(const std::vector& space); + std::shared_ptr create(); + + }; + template class SingleRange : public RangeInterface > {