im com (a-range not finished)

This commit is contained in:
Christian Zimmermann 2017-12-05 17:31:57 +01:00
parent c5053b02cb
commit 1347615cb3
4 changed files with 110 additions and 28 deletions

View file

@ -16,7 +16,7 @@ namespace MultiArrayTools
{
public:
typedef SingleRange<U,TYPE> oType;
typedef AnonymousRange oType;
AnonymousRangeFactory() = delete;
AnonymousRangeFactory(const std::shared_ptr<Ranges>... origs);
@ -33,8 +33,8 @@ namespace MultiArrayTools
virtual size_t size() const override;
virtual size_t dim() const override;
const size_t& get(size_t pos) const;
size_t getMeta(const size_t& metaPos) const;
size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const;
virtual IndexType begin() const override;
virtual IndexType end() const override;
@ -64,9 +64,9 @@ namespace MultiArrayTools
namespace MultiArrayTools
{
/********************
/***********************
* AnonymousRange *
********************/
***********************/
AnonymousRangeFactory::AnonymousRangeFactory(const std::shared_ptr<Ranges>... origs)
{
@ -79,25 +79,26 @@ namespace MultiArrayTools
return mProd;
}
/********************
/***********************
* AnonymousRange *
********************/
***********************/
template <class... Ranges>
AnonymousRange::AnonymousRange(const std::shared_ptr<Ranges>... origs) :
RangeInterface<AnonymousIndex>()
{
mOrig.resize(sizeof...(Ranges));
PackNum<sizeof...(Ranges)-1>::RangesToVec();
// mOrig !!!!
// mSize !!! = (prod origs.size...)
}
const size_t& AnonymousRange::get(size_t pos) const
size_t AnonymousRange::get(size_t pos) const
{
static size_t x;
x = pos;
return x;
return pos;
}
size_t AnonymousRange::getMeta(const size_t& metaPos) const
size_t AnonymousRange::getMeta(size_t metaPos) const
{
return metaPos;
}

View file

@ -244,7 +244,14 @@ namespace MultiArrayHelper
out << std::get<sizeof...(T)-N-1>(tp) << ", ";
PackNum<N-1>::printTuple(out, tp);
}
template <class RangeType, class... Ranges>
static void RangesToVec(const std::shared_ptr<RangeType> r,
const std::shared_ptr<Ranges>... rs,
std::vector<RangeBase> v)
{
}
};
template<>

View file

@ -14,15 +14,11 @@ namespace MultiArrayTools
enum class RangeType
{
NIL = 0,
NONE = 0,
ANY = 1,
SPACE = 2,
MOMENTUM = 3,
LORENTZ = 4,
SPIN = 5,
ENSEMBLE = 6,
VALUE_ERROR = 7,
DISTANCE = 8
#define include_range_type(x,n) x = n,
#include "range_types/header.h"
#undef include_range_type
};
class RangeFactoryBase

View file

@ -1,4 +1,9 @@
#ifdef include_range_type
include_range_type(SPIN,2)
#else
#ifdef __ranges_header__
// assert, that this is only used within range_types/header.h
@ -32,8 +37,8 @@ namespace MultiArrayTools
virtual size_t size() const override;
virtual size_t dim() const override;
const U& get(size_t pos) const;
size_t getMeta(const U& metaPos) const;
size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const;
virtual IndexType begin() const override;
virtual IndexType end() const override;
@ -43,13 +48,16 @@ namespace MultiArrayTools
protected:
SingleRange() = delete;
SingleRange() = default;
SingleRange(const SingleRange& in) = delete;
SingleRange(size_t spinNum);
size_t mSpinNum = 4;
};
typedef SingleRange<size_t,RangeType::SPIN> SpinRange;
typedef SingleRangeFactory<size_t,RangeType::SPIN> SpinRF;
}
/* ========================= *
@ -58,8 +66,78 @@ namespace MultiArrayTools
namespace MultiArrayTools
{
// ... !!!!
/********************
* SingleRange *
********************/
SingleRangeFactory<size_t,RangeType::SPIN>::SingleRangeFactory(const std::vector<U>& space)
{
mProd = std::shared_ptr<oType>( new SingleRange<size_t,RangeType::SPIN>( space ) );
}
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,RangeType::SPIN>::create()
{
setSelf();
return mProd;
}
/********************
* SingleRange *
********************/
SingleRange<size_t,RangeType::SPIN>::SingleRange(size_t spinNum) :
RangeInterface<SingleIndex<size_t,RangeType::SPIN> >()
{
mSpinNum = spinNum;
}
size_t SingleRange<size_t,RangeType::SPIN>::get(size_t pos) const
{
return pos;
}
size_t SingleRange<size_t,RangeType::SPIN>::getMeta(size_t metaPos) const
{
return metaPos;
}
size_t SingleRange<size_t,RangeType::SPIN>::size() const
{
return mSpinNum;
}
size_t SingleRange<size_t,RangeType::SPIN>::dim() const
{
return 1;
}
typename SingleRange<size_t,RangeType::SPIN>::IndexType SingleRange<size_t,RangeType::SPIN>::begin() const
{
SingleIndex<size_t,RangeType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,RangeType::SPIN> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename SingleRange<size_t,RangeType::SPIN>::IndexType SingleRange<size_t,RangeType::SPIN>::end() const
{
SingleIndex<size_t,RangeType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,RangeType::SPIN> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;
}
// put this in the interface class !!!
std::shared_ptr<IndexBase> SingleRange<size_t,RangeType::SPIN>::index() const
{
return std::make_shared<SingleIndex<size_t,RangeType::SPIN> >
( std::dynamic_pointer_cast<SingleRange<size_t,RangeType::SPIN> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
}
}
#endif
#endif
#endif // #ifndef __spin_range_h__
#endif // #ifdef __ranges_header__
#endif // #ifdef include_range_type