anonymous range + im com while implementing first spec of srange (spin)

This commit is contained in:
Christian Zimmermann 2017-12-04 18:29:18 +01:00
parent b9152a3ae7
commit c5053b02cb
4 changed files with 197 additions and 5 deletions

View file

@ -9,11 +9,50 @@
namespace MultiArrayTools
{
typedef SingleIndex<size_t,NONE> AnonymousIndex;
class AnonymousRange : public RangeBase<AnonymousIndex>
{
typedef SingleIndex<size_t,RangeType::NONE> AnonymousIndex;
template <typename U, RangeType TYPE>
class AnonymousRangeFactory : public RangeFactoryBase
{
public:
typedef SingleRange<U,TYPE> oType;
AnonymousRangeFactory() = delete;
AnonymousRangeFactory(const std::shared_ptr<Ranges>... origs);
std::shared_ptr<RangeBase> create();
};
class AnonymousRange : public RangeInterface<AnonymousIndex>
{
typedef RangeBase RB;
typedef typename RangeInterface<AnonymousIndex>::IndexType IndexType;
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;
virtual IndexType begin() const override;
virtual IndexType end() const override;
virtual std::shared_ptr<IndexBase> index() const override;
friend AnonymousRangeFactory;
protected:
AnonymousRange() = delete;
AnonymousRange(const AnonymousRange& in) = delete;
template <class Ranges...>
AnonymousRange(const std::shared_ptr<Ranges>... origs);
size_t mSize;
std::vector<std::shared_ptr<RangeBase> > mOrig;
};
}
@ -22,6 +61,80 @@ namespace MultiArrayTools
* --- TEMPLATE CODE --- *
* ========================= */
// ...
namespace MultiArrayTools
{
/********************
* AnonymousRange *
********************/
AnonymousRangeFactory::AnonymousRangeFactory(const std::shared_ptr<Ranges>... origs)
{
mProd = std::shared_ptr<oType>( new AnonymousRange( space ) );
}
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
{
setSelf();
return mProd;
}
/********************
* AnonymousRange *
********************/
AnonymousRange::AnonymousRange(const std::shared_ptr<Ranges>... origs) :
RangeInterface<AnonymousIndex>()
{
// mOrig !!!!
// mSize !!! = (prod origs.size...)
}
const size_t& AnonymousRange::get(size_t pos) const
{
static size_t x;
x = pos;
return x;
}
size_t AnonymousRange::getMeta(const size_t& metaPos) const
{
return metaPos;
}
size_t AnonymousRange::size() const
{
return mSize;
}
size_t AnonymousRange::dim() const
{
return 1;
}
typename AnonymousRange::IndexType AnonymousRange::begin() const
{
SingleIndex i( std::dynamic_pointer_cast<AnonymousRange>
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename AnonymousRange::IndexType AnonymousRange::end() const
{
SingleIndex i( std::dynamic_pointer_cast<AnonymousRange>
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;
}
// put this in the interface class !!!
std::shared_ptr<IndexBase> AnonymousRange::index() const
{
return std::make_shared<SingleIndex >
( std::dynamic_pointer_cast<AnonymousRange>
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
}
}
#endif

12
src/range_types/header.h Normal file
View file

@ -0,0 +1,12 @@
#ifdef __single_range_h__
// singel_range is template which is specialized here
// therefore it must be defined before...
#ifndef __ranges_header__
#define __ranges_header__
#include "spin_range.h"
#endif
#endif

View file

@ -0,0 +1,65 @@
#ifdef __ranges_header__
// assert, that this is only used within range_types/header.h
#ifndef __spin_range_h__
#define __spin_range_h__
namespace MultiArrayTools
{
typedef SingleIndex<size_t,RangeType::SPIN> SpinIndex;
template <>
class SingleRangeFactory<size_t,RangeType::SPIN> : public RangeFactoryBase
{
public:
typedef SingleRange<U,TYPE> oType;
SingleRangeFactory() = delete;
SingleRangeFactory(size_t spinNum); // = 4 :)
std::shared_ptr<RangeBase> create();
};
template <>
class SingleRange<size_t,RangeType::SPIN> : public RangeInterface<SpinIndex>
{
public:
typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<U,TYPE> >::IndexType IndexType;
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;
virtual IndexType begin() const override;
virtual IndexType end() const override;
virtual std::shared_ptr<IndexBase> index() const override;
friend SingleRangeFactory<size_t,RangeType::SPIN>;
protected:
SingleRange() = delete;
SingleRange(const SingleRange& in) = delete;
SingleRange(size_t spinNum);
size_t mSpinNum = 4;
};
}
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
namespace MultiArrayTools
{
// ... !!!!
}
#endif
#endif

View file

@ -276,4 +276,6 @@ namespace MultiArrayTools
}
#include "range_types/header.h"
#endif