some corrections (still have to fix comile errors)
This commit is contained in:
parent
230ca490d5
commit
e8ad0f1b03
9 changed files with 58 additions and 53 deletions
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#include "container_range.h"
|
#include "container_range.h"
|
||||||
#include "numpack.h"
|
#include "pack_num.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,12 @@
|
||||||
#define __container_range_h__
|
#define __container_range_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <tuple>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
|
#include "range_base.h"
|
||||||
|
#include "index_base.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace {
|
||||||
|
|
||||||
using namespace MAT;
|
using namespace MAT;
|
||||||
|
|
||||||
class ConnectionTest : public ::testing::Test
|
class IndexTest : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace {
|
||||||
typedef ContainerRangeFactory<M3Range,SRange> CRF;
|
typedef ContainerRangeFactory<M3Range,SRange> CRF;
|
||||||
typedef CRF::oType CRange;
|
typedef CRF::oType CRange;
|
||||||
|
|
||||||
ConnectionTest()
|
IndexTest()
|
||||||
{
|
{
|
||||||
rfbptr.swap( std::make_shared<SRF>( { 'e', 'b', 'n' } ) );
|
rfbptr.swap( std::make_shared<SRF>( { 'e', 'b', 'n' } ) );
|
||||||
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
|
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
|
||||||
|
@ -53,9 +53,30 @@ namespace {
|
||||||
std::shared_ptr<M3Range> m3rptr;
|
std::shared_ptr<M3Range> 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
|
} // end namespace
|
||||||
|
|
|
@ -9,12 +9,13 @@
|
||||||
#include "index_base.h"
|
#include "index_base.h"
|
||||||
#include "single_range.h"
|
#include "single_range.h"
|
||||||
#include "multi_range.h"
|
#include "multi_range.h"
|
||||||
#include "multi_array_operation.h"
|
#include "container_range.h"
|
||||||
#include "multi_array.h"
|
//#include "multi_array_operation.h"
|
||||||
#include "slice.h"
|
//#include "multi_array.h"
|
||||||
#include "manipulator.h"
|
//#include "slice.h"
|
||||||
#include "range_transformer.h"
|
//#include "manipulator.h"
|
||||||
#include "ma_functional.h"
|
//#include "range_transformer.h"
|
||||||
|
//#include "ma_functional.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
@ -22,7 +23,7 @@ namespace MultiArrayTools
|
||||||
/*********************************
|
/*********************************
|
||||||
* Some standard definitions *
|
* Some standard definitions *
|
||||||
*********************************/
|
*********************************/
|
||||||
|
/*
|
||||||
// ===== Index Types =====
|
// ===== Index Types =====
|
||||||
|
|
||||||
typedef SingleIndex<size_t,RangeType::ANY> GenericNI;
|
typedef SingleIndex<size_t,RangeType::ANY> GenericNI;
|
||||||
|
@ -50,7 +51,7 @@ namespace MultiArrayTools
|
||||||
typedef SingleRange<std::array<int,3>, RangeType::MOMENTUM> LinMomR;
|
typedef SingleRange<std::array<int,3>, RangeType::MOMENTUM> LinMomR;
|
||||||
typedef SingleRange<std::array<int,4>, RangeType::MOMENTUM> LinMom4dR;
|
typedef SingleRange<std::array<int,4>, RangeType::MOMENTUM> LinMom4dR;
|
||||||
// ...
|
// ...
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#include "multi_range.h"
|
#include "multi_range.h"
|
||||||
#include "packnum.h"
|
#include "pack_num.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
|
@ -197,11 +197,3 @@ namespace MultiArrayTools
|
||||||
( std::dynamic_pointer_cast<MultiRange<Ranges...> >( mThis ) );
|
( std::dynamic_pointer_cast<MultiRange<Ranges...> >( mThis ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
std::ostream& operator<<(std::ostream& os,
|
|
||||||
const std::tuple<Ts...>& meta)
|
|
||||||
{
|
|
||||||
MultiArrayTools::PackNum<sizeof...(Ts)-1>::print(os, meta);
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
|
@ -121,11 +121,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
std::ostream& operator<<(std::ostream& os,
|
|
||||||
const std::tuple<Ts...>& meta);
|
|
||||||
|
|
||||||
|
|
||||||
#include "multi_range.cc"
|
#include "multi_range.cc"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <type_traits>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
|
@ -118,13 +120,6 @@ namespace MultiArrayHelper
|
||||||
return std::get<N>(iPtrTup)->pos() +
|
return std::get<N>(iPtrTup)->pos() +
|
||||||
PackNum<N-1>::makePos(iPtrTup) * std::get<N-1>(iPtrTup)->max();
|
PackNum<N-1>::makePos(iPtrTup) * std::get<N-1>(iPtrTup)->max();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
static void print(std::ostream& os, const std::tuple<Ts...>& meta)
|
|
||||||
{
|
|
||||||
PackNum<N-1>::print(os, meta);
|
|
||||||
os << std::get<N>(meta) << '\t';
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class IndexType, class... Indices>
|
template <class Pack, class IndexType, class... Indices>
|
||||||
static void swapIndices(Pack& ipack, const std::shared_ptr<Indices>&... ninds,
|
static void swapIndices(Pack& ipack, const std::shared_ptr<Indices>&... ninds,
|
||||||
|
@ -225,12 +220,6 @@ namespace MultiArrayHelper
|
||||||
return std::get<0>(iPtrTup)->pos();
|
return std::get<0>(iPtrTup)->pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
static void print(std::ostream& os, const std::tuple<Ts...>& meta)
|
|
||||||
{
|
|
||||||
os << std::get<0>(meta) << '\t';
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class IndexType>
|
template <class Pack, class IndexType>
|
||||||
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind)
|
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind)
|
||||||
{
|
{
|
||||||
|
|
|
@ -120,21 +120,13 @@ namespace MultiArrayTools
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// put this in the interface class !!!
|
|
||||||
template <typename U, RangeType TYPE>
|
|
||||||
std::shared_ptr<IndexBase> SingleRange<U,TYPE>::index() const
|
|
||||||
{
|
|
||||||
return std::make_shared<SingleIndex<U> >
|
|
||||||
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( mThis ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
SingleIndex<U> SingleRange<U,TYPE>::begin() const
|
SingleIndex<U> SingleRange<U,TYPE>::begin() const
|
||||||
{
|
{
|
||||||
SingleIndex<U> i(mThis);
|
SingleIndex<U> i(mThis);
|
||||||
return i = 0;
|
return i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, RangeType TYPE>
|
template <typename U, RangeType TYPE>
|
||||||
SingleIndex<U> SingleRange<U,TYPE>::end() const
|
SingleIndex<U> SingleRange<U,TYPE>::end() const
|
||||||
{
|
{
|
||||||
|
@ -142,6 +134,15 @@ namespace MultiArrayTools
|
||||||
return i = size();
|
return i = size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// put this in the interface class !!!
|
||||||
|
template <typename U, RangeType TYPE>
|
||||||
|
std::shared_ptr<IndexBase> SingleRange<U,TYPE>::index() const
|
||||||
|
{
|
||||||
|
return std::make_shared<SingleIndex<U> >
|
||||||
|
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( mThis ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// specializations (not updated!!!)
|
// specializations (not updated!!!)
|
||||||
|
|
||||||
SingleRange<int,RangeType::SPACE>::SingleRange(size_t ext) :
|
SingleRange<int,RangeType::SPACE>::SingleRange(size_t ext) :
|
||||||
|
@ -338,5 +339,5 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return SingleIndex<size_t,RangeType::LORENTZ>(this, size());
|
return SingleIndex<size_t,RangeType::LORENTZ>(this, size());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
virtual SingleIndex<U> begin() const override;
|
virtual SingleIndex<U> begin() const override;
|
||||||
virtual SingleIndex<U> end() const override;
|
virtual SingleIndex<U> end() const override;
|
||||||
|
virtual std::shared_ptr<IndexBase> index() const override;
|
||||||
|
|
||||||
friend SingleRangeFactory<U,TYPE>;
|
friend SingleRangeFactory<U,TYPE>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -73,7 +74,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
std::vector<U> mSpace;
|
std::vector<U> mSpace;
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
// specializaions
|
// specializaions
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -197,7 +198,7 @@ namespace MultiArrayTools
|
||||||
SingleIndex<size_t,RangeType::LORENTZ> begin() const override;
|
SingleIndex<size_t,RangeType::LORENTZ> begin() const override;
|
||||||
SingleIndex<size_t,RangeType::LORENTZ> end() const override;
|
SingleIndex<size_t,RangeType::LORENTZ> end() const override;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "single_range.cc"
|
#include "single_range.cc"
|
||||||
|
|
Loading…
Reference in a new issue