diff --git a/src/container_range.cc b/src/container_range.cc index a8cf1b9..75a4a5a 100644 --- a/src/container_range.cc +++ b/src/container_range.cc @@ -1,7 +1,7 @@ // -*- C++ -*- #include "container_range.h" -#include "numpack.h" +#include "pack_num.h" namespace MultiArrayTools { diff --git a/src/container_range.h b/src/container_range.h index a5d009f..e6cd1b3 100644 --- a/src/container_range.h +++ b/src/container_range.h @@ -4,7 +4,12 @@ #define __container_range_h__ #include +#include +#include + #include "base_def.h" +#include "range_base.h" +#include "index_base.h" namespace MultiArrayTools { diff --git a/src/index_unit_test.cc b/src/index_unit_test.cc index bdfa45c..7f85253 100644 --- a/src/index_unit_test.cc +++ b/src/index_unit_test.cc @@ -12,7 +12,7 @@ namespace { using namespace MAT; - class ConnectionTest : public ::testing::Test + class IndexTest : public ::testing::Test { protected: @@ -28,7 +28,7 @@ namespace { typedef ContainerRangeFactory CRF; typedef CRF::oType CRange; - ConnectionTest() + IndexTest() { rfbptr.swap( std::make_shared( { 'e', 'b', 'n' } ) ); sr1ptr = std::dynamic_pointer_cast( rfbptr.create() ); @@ -53,9 +53,30 @@ namespace { std::shared_ptr m3rptr; }; - TEST_F(ConnectionTest, UnlinkedIteration) + TEST_F(IndexTest, SingleIndex_SimpleCall) { - EXPECT_EQ(i3d.pos(), 0); + auto si = sr1ptr->begin(); + EXPECT_EQ(si.max(), 3); + EXPECT_EQ(si.pos(), 0); + EXPECT_EQ(si.first(), true); + EXPECT_EQ(si.last(), false); + EXPECT_EQ(si.meta(), 'e'); + si.at('n'); + EXPECT_EQ(si.pos(), si.max()-1); + EXPECT_EQ(si.first(), false); + EXPECT_EQ(si.last(), true); + si = 1; + EXPECT_EQ(si.meta(), 'b'); + ++si; + EXPECT_EQ(si.meta(), 'n'); + auto si2 = sr1ptr->end(); + --si2; + EXPECT_EQ(si == si2, true); + EXPECT_EQ(si != si2, false); + auto si3 = sr2ptr->end(); + --si3; + EXPECT_EQ(si == si3, false); + EXPECT_EQ(si != si3, true); } } // end namespace diff --git a/src/multi_array_header.h b/src/multi_array_header.h index a4cbc50..97c072b 100644 --- a/src/multi_array_header.h +++ b/src/multi_array_header.h @@ -9,12 +9,13 @@ #include "index_base.h" #include "single_range.h" #include "multi_range.h" -#include "multi_array_operation.h" -#include "multi_array.h" -#include "slice.h" -#include "manipulator.h" -#include "range_transformer.h" -#include "ma_functional.h" +#include "container_range.h" +//#include "multi_array_operation.h" +//#include "multi_array.h" +//#include "slice.h" +//#include "manipulator.h" +//#include "range_transformer.h" +//#include "ma_functional.h" namespace MultiArrayTools { @@ -22,7 +23,7 @@ namespace MultiArrayTools /********************************* * Some standard definitions * *********************************/ - + /* // ===== Index Types ===== typedef SingleIndex GenericNI; @@ -50,7 +51,7 @@ namespace MultiArrayTools typedef SingleRange, RangeType::MOMENTUM> LinMomR; typedef SingleRange, RangeType::MOMENTUM> LinMom4dR; // ... - + */ } #endif diff --git a/src/multi_range.cc b/src/multi_range.cc index 8aa5fa6..1c0f658 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -1,6 +1,6 @@ #include "multi_range.h" -#include "packnum.h" +#include "pack_num.h" namespace MultiArrayTools { @@ -197,11 +197,3 @@ namespace MultiArrayTools ( std::dynamic_pointer_cast >( mThis ) ); } } - -template -std::ostream& operator<<(std::ostream& os, - const std::tuple& meta) -{ - MultiArrayTools::PackNum::print(os, meta); - return os; -} diff --git a/src/multi_range.h b/src/multi_range.h index 877c563..d71bef8 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -121,11 +121,6 @@ namespace MultiArrayTools } -template -std::ostream& operator<<(std::ostream& os, - const std::tuple& meta); - - #include "multi_range.cc" #endif diff --git a/src/pack_num.h b/src/pack_num.h index 7822390..a346e6b 100644 --- a/src/pack_num.h +++ b/src/pack_num.h @@ -1,7 +1,9 @@ // -*- C++ -*- #include +#include #include +#include namespace MultiArrayHelper { @@ -118,13 +120,6 @@ namespace MultiArrayHelper return std::get(iPtrTup)->pos() + PackNum::makePos(iPtrTup) * std::get(iPtrTup)->max(); } - - template - static void print(std::ostream& os, const std::tuple& meta) - { - PackNum::print(os, meta); - os << std::get(meta) << '\t'; - } template static void swapIndices(Pack& ipack, const std::shared_ptr&... ninds, @@ -225,12 +220,6 @@ namespace MultiArrayHelper return std::get<0>(iPtrTup)->pos(); } - template - static void print(std::ostream& os, const std::tuple& meta) - { - os << std::get<0>(meta) << '\t'; - } - template static void swapIndices(Pack& ipack, const std::shared_ptr& nind) { diff --git a/src/single_range.cc b/src/single_range.cc index b4c0a6d..1b47dc5 100644 --- a/src/single_range.cc +++ b/src/single_range.cc @@ -120,21 +120,13 @@ namespace MultiArrayTools return 1; } - // put this in the interface class !!! - template - std::shared_ptr SingleRange::index() const - { - return std::make_shared > - ( std::dynamic_pointer_cast >( mThis ) ); - } - template SingleIndex SingleRange::begin() const { SingleIndex i(mThis); return i = 0; } - + template SingleIndex SingleRange::end() const { @@ -142,6 +134,15 @@ namespace MultiArrayTools return i = size(); } + // put this in the interface class !!! + template + std::shared_ptr SingleRange::index() const + { + return std::make_shared > + ( std::dynamic_pointer_cast >( mThis ) ); + } + + /* // specializations (not updated!!!) SingleRange::SingleRange(size_t ext) : @@ -338,5 +339,5 @@ namespace MultiArrayTools { return SingleIndex(this, size()); } - + */ } diff --git a/src/single_range.h b/src/single_range.h index 1093439..b55cc22 100644 --- a/src/single_range.h +++ b/src/single_range.h @@ -61,7 +61,8 @@ namespace MultiArrayTools virtual SingleIndex begin() const override; virtual SingleIndex end() const override; - + virtual std::shared_ptr index() const override; + friend SingleRangeFactory; protected: @@ -73,7 +74,7 @@ namespace MultiArrayTools std::vector mSpace; }; - + /* // specializaions template <> @@ -197,7 +198,7 @@ namespace MultiArrayTools SingleIndex begin() const override; SingleIndex end() const override; }; - + */ } #include "single_range.cc"