first draft of multi/anonymous range meta stream parsing + spaceType() in Ranges

This commit is contained in:
Christian Zimmermann 2018-07-28 15:27:11 +02:00
parent a3ac073975
commit 56cc0bf05c
14 changed files with 95 additions and 11 deletions

View file

@ -75,6 +75,8 @@ namespace MultiArrayTools
virtual IndexType begin() const final;
virtual IndexType end() const final;
virtual SpaceType spaceType() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;

View file

@ -182,6 +182,8 @@ namespace MultiArrayTools
virtual size_t dim() const final;
virtual size_t size() const final;
virtual SpaceType spaceType() const final;
virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final;
@ -215,6 +217,9 @@ namespace MultiArrayTools
using namespace MultiArrayHelper;
}
// -> define in range_base.cc
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp);
/******************
* MultiIndex *
******************/
@ -533,6 +538,12 @@ namespace MultiArrayTools
return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
}
template <class... Ranges>
SpaceType MultiRange<Ranges...>::spaceType() const
{
return SpaceType::ANY;
}
template <class... Ranges>
const typename MultiRange<Ranges...>::Space& MultiRange<Ranges...>::space() const
{

View file

@ -22,7 +22,7 @@ namespace MultiArrayTools
enum class SpaceType
{
NONE = 0, // meta data is that of a classic range, i.e. 0,1,2,...,N-1
ANY = 1, // meta data is arbitrary, i.e. explicitly stored
ANY = 1, // meta data is arbitrary, i.e. explicitly stored; range could be multiple
#define include_range_type(x,n) x = n,
#include "range_types/header.h"
#undef include_range_type
@ -80,6 +80,8 @@ namespace MultiArrayTools
virtual std::string stringMeta(size_t pos) const = 0;
virtual std::vector<char> data() const = 0; // usefull when writing to files, etc...
virtual SpaceType spaceType() const = 0;
//virtual bool regular() const = 0; // integer distance (e.g. 2,3,4,...)
//virtual bool linear() const = 0; // 1dim valuable (e.g. 2.45, 3.12, 3.56,...)
//virtual bool multi() const = 0; // mdim

View file

@ -38,6 +38,8 @@ namespace MultiArrayTools
virtual size_t size() const override;
virtual size_t dim() const override;
virtual SpaceType spaceType() const override;
virtual std::string stringMeta(size_t pos) const override;
virtual std::vector<char> data() const override;

View file

@ -48,6 +48,8 @@ namespace MultiArrayTools
virtual std::string stringMeta(size_t pos) const override;
virtual std::vector<char> data() const override;
virtual SpaceType spaceType() const override;
size_t get(size_t pos) const;
size_t getMeta(size_t metapos) const;

View file

@ -40,6 +40,8 @@ namespace MultiArrayTools
virtual std::string stringMeta(size_t pos) const override;
virtual std::vector<char> data() const override;
virtual SpaceType spaceType() const override;
int get(size_t pos) const;
size_t getMeta(int metaPos) const;
@ -75,10 +77,12 @@ namespace MultiArrayTools
struct PromoteMSpaceRange
{
template <class... SpaceRanges>
static auto mk(MultiRange<SpaceRanges...>) -> MultiRange<SpaceRange,SpaceRanges...>;
static auto mk(const MultiRange<SpaceRanges...>&)
-> MultiRange<SpaceRange,SpaceRanges...>;
template <class... SpaceRanges>
static auto mkf(MultiRangeFactory<SpaceRanges...>) -> MultiRangeFactory<SpaceRange,SpaceRanges...>;
static auto mkf(const MultiRangeFactory<SpaceRanges...>&)
-> MultiRangeFactory<SpaceRange,SpaceRanges...>;
};

View file

@ -41,6 +41,8 @@ namespace MultiArrayTools
virtual std::string stringMeta(size_t pos) const override;
virtual std::vector<char> data() const override;
virtual SpaceType spaceType() const override;
size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const;

View file

@ -107,6 +107,8 @@ namespace MultiArrayTools
virtual size_t size() const override;
virtual size_t dim() const override;
virtual SpaceType spaceType() const override;
virtual std::string stringMeta(size_t pos) const override;
virtual std::vector<char> data() const override;
@ -377,6 +379,12 @@ namespace MultiArrayTools
return 1;
}
template <typename U, SpaceType TYPE>
SpaceType SingleRange<U,TYPE>::spaceType() const
{
return TYPE;
}
template <typename U, SpaceType TYPE>
std::string SingleRange<U,TYPE>::stringMeta(size_t pos) const
{

View file

@ -77,6 +77,11 @@ namespace MultiArrayTools
return 1;
}
SpaceType AnonymousRange::spaceType() const
{
return SpaceType::ANON;
}
std::string AnonymousRange::stringMeta(size_t pos) const
{
std::string out = "[ ";

View file

@ -19,16 +19,42 @@ namespace MultiArrayTools
return id;
}
// !!!!!
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp)
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp, size_t metaSize)
{
return nullptr;
std::shared_ptr<RangeFactoryBase> out = nullptr;
std::vector<std::shared_ptr<RangeBase> > rvec(metaSize);
for(size_t i = 0; i != metaSize; ++i){
auto ff = createRangeFactory(dp);
rvec[i] = ff->create();
}
// !!!!!
std::shared_ptr<RangeFactoryBase> mkANONYMOUS(char** dp)
if(metaSize == 3){
if(rvec[0]->spaceType() == SpaceType::PSPACE and
rvec[1]->spaceType() == SpaceType::PSPACE and
rvec[2]->spaceType() == SpaceType::PSPACE) {
std::shared_ptr<PSpaceRange> r0 = std::dynamic_pointer_cast<PSpaceRange>( rvec[0] );
std::shared_ptr<PSpaceRange> r1 = std::dynamic_pointer_cast<PSpaceRange>( rvec[1] );
std::shared_ptr<PSpaceRange> r2 = std::dynamic_pointer_cast<PSpaceRange>( rvec[2] );
out = std::make_shared<MSpaceRF<PSpaceRange,3> >(r0,r1,r2);
}
}
else {
assert(0);
}
return out;
}
std::shared_ptr<RangeFactoryBase> mkANONYMOUS(char** dp, size_t metaSize)
{
return nullptr;
std::shared_ptr<RangeFactoryBase> out = nullptr;
auto arf = std::make_shared<AnonymousRangeFactory>();
for(size_t i = 0; i != metaSize; ++i){
auto ff = createRangeFactory(dp);
arf->append( ff->create() );
}
out = arf;
return out;
}
std::shared_ptr<RangeFactoryBase> createRangeFactory(char** dp)
@ -41,11 +67,11 @@ namespace MultiArrayTools
if(h.multiple != 0){
if(h.spaceType == static_cast<int>( SpaceType::ANY )) {
// multi range
out = mkMULTI(dp);
out = mkMULTI(dp, h.metaSize);
}
else if(h.spaceType == static_cast<int>( SpaceType::ANON ) ) {
// anonymous range
out = mkANONYMOUS(dp);
out = mkANONYMOUS(dp, h.metaSize);
}
else {
assert(0);

View file

@ -48,6 +48,11 @@ namespace MultiArrayTools
return 1;
}
SpaceType SingleRange<size_t,SpaceType::NONE>::spaceType() const
{
return SpaceType::NONE;
}
std::string SingleRange<size_t,SpaceType::NONE>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));

View file

@ -68,6 +68,11 @@ namespace MultiArrayTools
return 1;
}
SpaceType SingleRange<size_t,SpaceType::NUL>::spaceType() const
{
return SpaceType::NUL;
}
std::string SingleRange<size_t,SpaceType::NUL>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));

View file

@ -54,6 +54,11 @@ namespace MultiArrayTools
return 1;
}
SpaceType SingleRange<int,SpaceType::PSPACE>::spaceType() const
{
return SpaceType::PSPACE;
}
std::string SingleRange<int,SpaceType::PSPACE>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));

View file

@ -51,6 +51,11 @@ namespace MultiArrayTools
return 1;
}
SpaceType SingleRange<size_t,SpaceType::SPIN>::spaceType() const
{
return SpaceType::SPIN;
}
std::string SingleRange<size_t,SpaceType::SPIN>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));