+ClassicRange, changes in anonymous stuff (still not fixed completely -> AnonymousIndex missing)

This commit is contained in:
Christian Zimmermann 2018-02-14 21:37:18 +01:00
parent ddc1a518d2
commit 31de87229d
8 changed files with 246 additions and 58 deletions

View file

@ -6,7 +6,7 @@
#include <cstdlib>
//#include "base_def.h"
#include "ranges/range_base.h"
#include "ranges/single_range.h"
#include "ranges/rpheader.h"
namespace MultiArrayTools
{
@ -88,12 +88,6 @@ namespace MultiArrayTools
{
mProd = std::shared_ptr<oType>( new AnonymousRange( origs... ) );
}
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
{
setSelf();
return mProd;
}
/***********************
* AnonymousRange *
@ -114,55 +108,15 @@ namespace MultiArrayTools
{
auto rst = std::make_tuple(origs...);
mOrig.resize(sizeof...(RangeTypes));
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
}
size_t AnonymousRange::get(size_t pos) const
{
return pos;
}
size_t AnonymousRange::getMeta(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
{
AnonymousIndex i( std::dynamic_pointer_cast<AnonymousRange>
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename AnonymousRange::IndexType AnonymousRange::end() const
{
AnonymousIndex i( std::dynamic_pointer_cast<AnonymousRange>
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;
//RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
//RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
}
// put this in the interface class !!!
std::shared_ptr<VIWB> AnonymousRange::index() const
{
typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW>
(std::make_shared<IndexType>
( std::dynamic_pointer_cast<AnonymousRange>
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
}
/*****************
* Functions *
*****************/
std::shared_ptr<AnonymousRange> defaultRange(size_t size = 0);
}
#endif

View file

@ -0,0 +1,70 @@
#ifdef include_range_type
//include_range_type(NONE,0)
#else
#ifdef __ranges_header__
// assert, that this is only used within range_types/header.h
namespace MultiArrayTools
{
typedef SingleIndex<size_t,SpaceType::NONE> ClassicIndex;
template <>
class SingleRangeFactory<size_t,SpaceType::NONE> : public RangeFactoryBase
{
public:
typedef SingleRange<size_t,SpaceType::NONE> oType;
SingleRangeFactory(size_t size = 0);
std::shared_ptr<RangeBase> create();
};
template <>
class SingleRange<size_t,SpaceType::NONE> : public RangeInterface<ClassicIndex>
{
public:
typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<size_t,SpaceType::NONE> >::IndexType IndexType;
virtual size_t size() const override;
virtual size_t dim() const override;
size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const;
virtual IndexType begin() const override;
virtual IndexType end() const override;
virtual std::shared_ptr<VIWB> index() const override;
friend SingleRangeFactory<size_t,SpaceType::NONE>;
static constexpr bool defaultable = true;
static constexpr size_t ISSTATIC = 0;
static constexpr size_t SIZE = -1;
static SingleRangeFactory<size_t, SpaceType::NONE> factory(size_t size = 0)
{ return SingleRangeFactory<size_t, SpaceType::NONE>(size); }
protected:
size_t mSize = 0;
SingleRange() = default;
SingleRange(const SingleRange& in) = delete;
SingleRange(size_t size);
};
typedef SingleRange<size_t,SpaceType::NONE> ClassicRange;
typedef SingleRangeFactory<size_t,SpaceType::NONE> ClassicRF;
}
//#endif // #ifndef __spin_range_h__
#endif // #ifdef __ranges_header__
#endif // #ifdef include_range_type

View file

@ -15,6 +15,7 @@
//#define __ranges_header__
#include "spin_range.h"
#include "classic_range.h"
#undef __ranges_header__
//#endif

View file

@ -1,5 +1,3 @@
#include "single_range.h"
#include "multi_range.h"
#include "container_range.h"
//#include "anonymous_range.h" have to fix bug !!
#include "rpheader.h"
#include "anonymous_range.h"

View file

@ -0,0 +1,5 @@
#include "single_range.h"
#include "multi_range.h"
#include "container_range.h"
#include "anonymous_range.h"

View file

@ -2,6 +2,7 @@
set(libmultiarray_a_SOURCES
${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc
${CMAKE_SOURCE_DIR}/src/lib/ranges/index_info.cc
${CMAKE_SOURCE_DIR}/src/lib/ranges/anonymous_range.cc
)
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc")

View file

@ -0,0 +1,82 @@
#include "ranges/anonymous_range.h"
namespace MultiArrayTools
{
/******************************
* AnonymousRangeFactory *
******************************/
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
{
setSelf();
return mProd;
}
/***********************
* AnonymousRange *
***********************/
size_t AnonymousRange::get(size_t pos) const
{
return pos;
}
size_t AnonymousRange::getMeta(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
{
AnonymousIndex i
(std::dynamic_pointer_cast<ClassicRange>
( ClassicRange::factory(size()).create() ) ); // !!!
i = 0;
return i;
}
typename AnonymousRange::IndexType AnonymousRange::end() const
{
AnonymousIndex i
( std::dynamic_pointer_cast<ClassicRange>
( ClassicRange::factory(size()).create() ));// !!!
i = size();
return i;
}
// put this in the interface class !!!
std::shared_ptr<VIWB> AnonymousRange::index() const
{
//typedef IndexWrapper<IndexType> IW;
return std::shared_ptr<VIWB>();
/* std::make_shared<IW>
(std::make_shared<IndexType>
( std::dynamic_pointer_cast<AnonymousRange>
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) ); */ //!!!!
}
/*****************
* Functions *
*****************/
std::shared_ptr<AnonymousRange> defaultRange(size_t size )
{
AnonymousRangeFactory arf
( std::dynamic_pointer_cast<ClassicRange>
(ClassicRange::factory(size).create() ) );
return std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
}
} // end namespace MultiArrayTools

View file

@ -0,0 +1,77 @@
#include "ranges/rheader.h"
namespace MultiArrayTools
{
/********************
* SingleRange *
********************/
SingleRangeFactory<size_t,SpaceType::NONE>::SingleRangeFactory(size_t size)
{
// Quasi Singleton
if(not mProd){
mProd = std::shared_ptr<oType>( new SingleRange<size_t,SpaceType::NONE>(size) );
setSelf();
}
}
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,SpaceType::NONE>::create()
{
return mProd;
}
/********************
* SingleRange *
********************/
SingleRange<size_t,SpaceType::NONE>::SingleRange(size_t size) : mSize(size) {}
size_t SingleRange<size_t,SpaceType::NONE>::get(size_t pos) const
{
return pos;
}
size_t SingleRange<size_t,SpaceType::NONE>::getMeta(size_t metaPos) const
{
return metaPos;
}
size_t SingleRange<size_t,SpaceType::NONE>::size() const
{
return mSize;
}
size_t SingleRange<size_t,SpaceType::NONE>::dim() const
{
return 1;
}
typename SingleRange<size_t,SpaceType::NONE>::IndexType SingleRange<size_t,SpaceType::NONE>::begin() const
{
SingleIndex<size_t,SpaceType::NONE> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NONE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename SingleRange<size_t,SpaceType::NONE>::IndexType SingleRange<size_t,SpaceType::NONE>::end() const
{
SingleIndex<size_t,SpaceType::NONE> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NONE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;
}
// put this in the interface class !!!
std::shared_ptr<VIWB> SingleRange<size_t,SpaceType::NONE>::index() const
{
typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW>
( std::make_shared<IndexType>
( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NONE> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
}
}