char meta function in ranges

This commit is contained in:
Christian Zimmermann 2019-03-14 14:20:38 +01:00
parent 7003d68097
commit d8ecf51698
20 changed files with 214 additions and 34 deletions

View file

@ -496,12 +496,24 @@ namespace MultiArrayTools
return mSpace;
}
template <class MapF, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<MapF,XSTYPE,Ranges...>::typeNum() const
{
return 0;
}
template <class MapF, SpaceType XSTYPE, class... Ranges>
size_t GenMapRange<MapF,XSTYPE,Ranges...>::cmeta(char* target, size_t pos) const
{
return RPackNum<sizeof...(Ranges)-1>::getCMeta(target,pos,mSpace);
}
template <class MapF, SpaceType XSTYPE, class... Ranges>
std::string GenMapRange<MapF,XSTYPE,Ranges...>::stringMeta(size_t pos) const
{
auto i = begin();
i = pos;
return "[ " + RPackNum<sizeof...(Ranges)-1>::metaTupleToString(i.meta()) + " ]";
return "[ " + RPackNum<sizeof...(Ranges)-1>::getStringMeta(i) + " ]";
}
template <class MapF, SpaceType XSTYPE, class... Ranges>

View file

@ -257,6 +257,8 @@ namespace MultiArrayTools
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;

View file

@ -80,6 +80,8 @@ namespace MultiArrayTools
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;

View file

@ -439,14 +439,9 @@ namespace MultiArrayTools
template <class EC>
typename DynamicRange<EC>::MetaType DynamicRange<EC>::get(size_t pos) const
{
for(size_t i = mOrig.size(); i != 0; --i) {
auto& x = mOrig[i-1];
const size_t redpos = pos % x->size();
out = out + x->stringMeta(redpos);
pos -= redpos;
pos /= x->size();
}
return MetaType(); // !!!
std::vector<char> out(cmeta(nullptr,0));
cmeta(out.data(),pos);
return out;
}
template <class EC>
@ -479,6 +474,27 @@ namespace MultiArrayTools
return mEmpty;
}
template <class EC>
size_t DynamicRange<EC>::typeNum() const
{
return 0;
}
template <class EC>
size_t DynamicRange<EC>::cmeta(char* target, size_t pos) const
{
size_t out = 0;
for(size_t i = mOrig.size(); i != 0; --i) {
auto& x = mOrig[i-1];
const size_t redpos = pos % x->size();
const size_t offset = x->cmeta(target+out,redpos);
out += offset;
pos -= redpos;
pos /= x->size();
}
return out;
}
template <class EC>
std::string DynamicRange<EC>::stringMeta(size_t pos) const
{

View file

@ -169,7 +169,7 @@ namespace MultiArrayTools
//typedef SingleRange<size_t,SpaceType::DYN> DynamicRange;
template <class EC>
class DynamicIndex : public IndexInterface<DynamicIndex<EC>,DynamicMetaT>
class DynamicIndex : public IndexInterface<DynamicIndex<EC>,std::vector<char>>
{
private:
typedef vector<std::pair<std::shared_ptr<IndexW<EC>>,size_t>> IVecT;
@ -177,7 +177,7 @@ namespace MultiArrayTools
IVecT mIVec;
public:
typedef IndexInterface<DynamicIndex<EC>,DynamicMetaT> IB;
typedef IndexInterface<DynamicIndex<EC>,std::vector<char>> IB;
typedef std::vector<char> MetaType;
typedef DynamicRange<EC> RangeType;
typedef DynamicIndex IType;
@ -319,6 +319,8 @@ namespace MultiArrayTools
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;

View file

@ -200,6 +200,8 @@ namespace MultiArrayTools
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;
@ -581,12 +583,24 @@ namespace MultiArrayTools
return mSpace;
}
template <class... Ranges>
size_t MultiRange<Ranges...>::typeNum() const
{
return 0;
}
template <class... Ranges>
size_t MultiRange<Ranges...>::cmeta(char* target, size_t pos) const
{
return RPackNum<sizeof...(Ranges)-1>::getCMeta(target,pos,mSpace);
}
template <class... Ranges>
std::string MultiRange<Ranges...>::stringMeta(size_t pos) const
{
auto i = begin();
i = pos;
return "[ " + RPackNum<sizeof...(Ranges)-1>::metaTupleToString(i.meta()) + " ]";
return "[ " + RPackNum<sizeof...(Ranges)-1>::getStringMeta(i) + " ]";
}
template <class... Ranges>

View file

@ -81,8 +81,8 @@ namespace MultiArrayTools
std::intptr_t id() const;
virtual size_t typeNum() const = 0;
virtual std::string stringMeta(size_t pos) const = 0;
virtual const char* cmeta(size_t pos) const = 0;
virtual size_t cmeta(char* target, size_t pos) const = 0;
virtual std::string stringMeta(size_t pos) const = 0;
virtual vector<char> data() const = 0; // usefull when writing to files, etc...
virtual SpaceType spaceType() const = 0;

View file

@ -42,6 +42,8 @@ namespace MultiArrayTools
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;

View file

@ -46,6 +46,8 @@ namespace MultiArrayTools
virtual size_t size() const final;
virtual size_t dim() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;

View file

@ -38,6 +38,8 @@ namespace MultiArrayTools
virtual size_t size() const final;
virtual size_t dim() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;

View file

@ -39,6 +39,8 @@ namespace MultiArrayTools
virtual size_t size() const final;
virtual size_t dim() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;

View file

@ -340,10 +340,10 @@ namespace MultiArrayHelper
RPackNum<N-1>::checkIfCreated(p,a);
}
template <class MetaTuple>
static inline std::string metaTupleToString(const MetaTuple& mtp)
template <class MIndex>
static inline std::string getStringMeta(const MIndex& mi)
{
return RPackNum<N-1>::metaTupleToString(mtp) + " , " + xToString(std::get<N>(mtp));
return RPackNum<N-1>::getStringMeta(mi) + " , " + mi.template getPtr<N>()->stringMeta();
}
template <class... Ranges>
@ -369,6 +369,16 @@ namespace MultiArrayHelper
std::get<N>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[N] );
RPackNum<N-1>::setSpace(rbvec, stp);
}
template <class... Ranges>
static inline size_t getCMeta(char* target, size_t pos, const std::tuple<std::shared_ptr<Ranges>...>& stp)
{
constexpr size_t NN = sizeof...(Ranges);
auto& r = *std::get<NN-N-1>(stp);
const size_t ownPos = pos % r.size();
const size_t offset = r.cmeta(target,ownPos);
return offset + RPackNum<N-1>::getCMeta(target + offset , (pos - ownPos) / r.size(), stp);
}
};
@ -610,10 +620,10 @@ namespace MultiArrayHelper
return reinterpret_cast<std::intptr_t>( std::get<0>(p).get() ) == a[0];
}
template <class MetaTuple>
static inline std::string metaTupleToString(const MetaTuple& mtp)
template <class MIndex>
static inline std::string getStringMeta(const MIndex& mi)
{
return xToString(std::get<0>(mtp));
return mi.template getPtr<0>()->stringMeta();
}
template <class... Ranges>
@ -638,6 +648,15 @@ namespace MultiArrayHelper
std::get<0>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[0] );
}
template <class... Ranges>
static inline size_t getCMeta(char* target, size_t pos, const std::tuple<std::shared_ptr<Ranges>...>& stp)
{
constexpr size_t NN = sizeof...(Ranges);
auto& r = *std::get<NN-1>(stp);
const size_t ownPos = pos % r.size();
return r.cmeta(target,ownPos);
}
};
template <IndexType IT>

View file

@ -232,9 +232,9 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;
virtual const char* cmeta() const final;
bool isMeta(const U& metaPos) const;
@ -371,12 +371,6 @@ namespace MultiArrayTools
return 1;
}
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleIndex<U,TYPE,S>::typeNum() const
{
return NumTypeMap<U>::num;
}
template <typename U, SpaceType TYPE, size_t S>
std::string GenSingleIndex<U,TYPE,S>::stringMeta() const
{
@ -390,12 +384,6 @@ namespace MultiArrayTools
( mMetaPtr, IB::mPos, mExplicitRangePtr );
}
template <typename U, SpaceType TYPE, size_t S>
const char* GenSingleIndex<U,TYPE,S>::cmeta() const
{
return reinterpret_cast<const char*>(mSpace.data());
}
template <typename U, SpaceType TYPE, size_t S>
const U* GenSingleIndex<U,TYPE,S>::metaPtr() const
{
@ -579,6 +567,21 @@ namespace MultiArrayTools
return TYPE;
}
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleRange<U,TYPE,S>::typeNum() const
{
return NumTypeMap<U>::num;
}
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleRange<U,TYPE,S>::cmeta(char* target, size_t pos) const
{
if(target){
*reinterpret_cast<U*>(target) = mSpace[pos];
}
return sizeof(U);
}
template <typename U, SpaceType TYPE, size_t S>
std::string GenSingleRange<U,TYPE,S>::stringMeta(size_t pos) const
{

View file

@ -120,6 +120,8 @@ namespace MultiArrayTools
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const final;
virtual size_t cmeta(char* target, size_t pos) const final;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;
@ -401,6 +403,18 @@ namespace MultiArrayTools
return h;
}
template <class Range>
size_t SubRange<Range>::typeNum() const
{
return mFullRange->typeNum();
}
template <class Range>
size_t SubRange<Range>::cmeta(char* target, size_t pos) const
{
return mFullRange->cmeta(target, mSubSet[pos]);
}
template <class Range>
std::string SubRange<Range>::stringMeta(size_t pos) const
{

View file

@ -111,6 +111,8 @@ namespace MultiArrayTools
virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final;
virtual size_t typeNum() const = 0;
virtual size_t cmeta(char* target, size_t pos) const = 0;
virtual std::string stringMeta(size_t pos) const final;
virtual vector<char> data() const final;
@ -348,6 +350,21 @@ namespace MultiArrayTools
return SpaceType::NONE;
}
template <typename U>
size_t ValueRange<U>::typeNum() const
{
return NumTypeMap<U>::num;
}
template <typename U>
size_t ValueRange<U>::cmeta(char* target, size_t pos) const
{
if(target){
*reinterpret_cast<U*>(target) = *mMeta;
}
return sizeof(U);
}
template <typename U>
std::string ValueRange<U>::stringMeta(size_t pos) const
{

View file

@ -93,6 +93,25 @@ namespace MultiArrayTools
return mEmpty;
}
size_t AnonymousRange::typeNum() const
{
return 0;
}
size_t AnonymousRange::cmeta(char* target, size_t pos) const
{
size_t out = 0;
for(size_t i = mOrig.size(); i != 0; --i) {
auto& x = mOrig[i-1];
const size_t redpos = pos % x->size();
const size_t offset = x->cmeta(target+out, redpos);
out += offset;
pos -= redpos;
pos /= x->size();
}
return out;
}
std::string AnonymousRange::stringMeta(size_t pos) const
{
std::string out = "[ ";

View file

@ -53,6 +53,19 @@ namespace MultiArrayTools
return SpaceType::NONE;
}
size_t GenSingleRange<size_t,SpaceType::NONE,-1>::typeNum() const
{
return NumTypeMap<size_t>::num;
}
size_t GenSingleRange<size_t,SpaceType::NONE,-1>::cmeta(char* target, size_t pos) const
{
if(target){
*reinterpret_cast<size_t*>(target) = pos;
}
return sizeof(size_t);
}
std::string GenSingleRange<size_t,SpaceType::NONE,-1>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));

View file

@ -76,6 +76,19 @@ namespace MultiArrayTools
return SpaceType::NUL;
}
size_t GenSingleRange<size_t,SpaceType::NUL,0>::typeNum() const
{
return NumTypeMap<size_t>::num;
}
size_t GenSingleRange<size_t,SpaceType::NUL,0>::cmeta(char* target, size_t pos) const
{
if(target){
*reinterpret_cast<size_t*>(target) = 0;
}
return sizeof(size_t);
}
std::string GenSingleRange<size_t,SpaceType::NUL,0>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));

View file

@ -59,6 +59,19 @@ namespace MultiArrayTools
return SpaceType::PSPACE;
}
size_t GenSingleRange<int,SpaceType::PSPACE,-1>::typeNum() const
{
return NumTypeMap<int>::num;
}
size_t GenSingleRange<int,SpaceType::PSPACE,-1>::cmeta(char* target, size_t pos) const
{
if(target){
*reinterpret_cast<int*>(target) = get(pos);
}
return sizeof(int);
}
std::string GenSingleRange<int,SpaceType::PSPACE,-1>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));

View file

@ -56,6 +56,19 @@ namespace MultiArrayTools
return SpaceType::SPIN;
}
size_t GenSingleRange<size_t,SpaceType::SPIN,4>::typeNum() const
{
return NumTypeMap<size_t>::num;
}
size_t GenSingleRange<size_t,SpaceType::SPIN,4>::cmeta(char* target, size_t pos) const
{
if(target){
*reinterpret_cast<size_t*>(target) = pos;
}
return sizeof(size_t);
}
std::string GenSingleRange<size_t,SpaceType::SPIN,4>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));