some corrections (still have to fix comile errors)

This commit is contained in:
Christian Zimmermann 2017-07-28 14:02:44 +02:00
parent 230ca490d5
commit e8ad0f1b03
9 changed files with 58 additions and 53 deletions

View file

@ -1,7 +1,7 @@
// -*- C++ -*-
#include "container_range.h"
#include "numpack.h"
#include "pack_num.h"
namespace MultiArrayTools
{

View file

@ -4,7 +4,12 @@
#define __container_range_h__
#include <cstdlib>
#include <tuple>
#include <memory>
#include "base_def.h"
#include "range_base.h"
#include "index_base.h"
namespace MultiArrayTools
{

View file

@ -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<M3Range,SRange> CRF;
typedef CRF::oType CRange;
ConnectionTest()
IndexTest()
{
rfbptr.swap( std::make_shared<SRF>( { 'e', 'b', 'n' } ) );
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr.create() );
@ -53,9 +53,30 @@ namespace {
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

View file

@ -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<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,4>, RangeType::MOMENTUM> LinMom4dR;
// ...
*/
}
#endif

View file

@ -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<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;
}

View file

@ -121,11 +121,6 @@ namespace MultiArrayTools
}
template <typename... Ts>
std::ostream& operator<<(std::ostream& os,
const std::tuple<Ts...>& meta);
#include "multi_range.cc"
#endif

View file

@ -1,7 +1,9 @@
// -*- C++ -*-
#include <cstdlib>
#include <type_traits>
#include <tuple>
#include <memory>
namespace MultiArrayHelper
{
@ -118,13 +120,6 @@ namespace MultiArrayHelper
return std::get<N>(iPtrTup)->pos() +
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>
static void swapIndices(Pack& ipack, const std::shared_ptr<Indices>&... ninds,
@ -225,12 +220,6 @@ namespace MultiArrayHelper
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>
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind)
{

View file

@ -120,21 +120,13 @@ namespace MultiArrayTools
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>
SingleIndex<U> SingleRange<U,TYPE>::begin() const
{
SingleIndex<U> i(mThis);
return i = 0;
}
template <typename U, RangeType TYPE>
SingleIndex<U> SingleRange<U,TYPE>::end() const
{
@ -142,6 +134,15 @@ namespace MultiArrayTools
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!!!)
SingleRange<int,RangeType::SPACE>::SingleRange(size_t ext) :
@ -338,5 +339,5 @@ namespace MultiArrayTools
{
return SingleIndex<size_t,RangeType::LORENTZ>(this, size());
}
*/
}

View file

@ -61,7 +61,8 @@ namespace MultiArrayTools
virtual SingleIndex<U> begin() const override;
virtual SingleIndex<U> end() const override;
virtual std::shared_ptr<IndexBase> index() const override;
friend SingleRangeFactory<U,TYPE>;
protected:
@ -73,7 +74,7 @@ namespace MultiArrayTools
std::vector<U> mSpace;
};
/*
// specializaions
template <>
@ -197,7 +198,7 @@ namespace MultiArrayTools
SingleIndex<size_t,RangeType::LORENTZ> begin() const override;
SingleIndex<size_t,RangeType::LORENTZ> end() const override;
};
*/
}
#include "single_range.cc"