generalize cmeta routine for vector meta data + catch 'no range' case in anonymousRange::sreplace(vec)
This commit is contained in:
parent
ba8655896b
commit
ea974ce50b
2 changed files with 46 additions and 17 deletions
|
@ -224,6 +224,29 @@ namespace MultiArrayTools
|
|||
static constexpr size_t HASMETACONT = false;
|
||||
};
|
||||
|
||||
template <typename U>
|
||||
struct ToCMeta
|
||||
{
|
||||
static inline size_t apply(char* target, const U& elem)
|
||||
{
|
||||
*reinterpret_cast<U*>(target) = elem;
|
||||
return sizeof(U);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename V>
|
||||
struct ToCMeta<vector<V>>
|
||||
{
|
||||
static inline size_t apply(char* target, const vector<V>& elem)
|
||||
{
|
||||
size_t o = 0;
|
||||
for(auto& e: elem){
|
||||
o += ToCMeta<V>::apply(target, e);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename U, SpaceType TYPE, size_t S>
|
||||
class GenSingleRange : public RangeInterface<GenSingleIndex<U,TYPE,S> >
|
||||
{
|
||||
|
@ -600,8 +623,9 @@ namespace MultiArrayTools
|
|||
template <typename U, SpaceType TYPE, size_t S>
|
||||
size_t GenSingleRange<U,TYPE,S>::cmeta(char* target, size_t pos) const
|
||||
{
|
||||
*reinterpret_cast<U*>(target) = mSpace[pos];
|
||||
return sizeof(U);
|
||||
//*reinterpret_cast<U*>(target) = mSpace[pos];
|
||||
//return sizeof(U);
|
||||
return ToCMeta<U>::apply(target, mSpace[pos]);
|
||||
}
|
||||
|
||||
template <typename U, SpaceType TYPE, size_t S>
|
||||
|
|
|
@ -231,21 +231,26 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const std::shared_ptr<RangeBase>& in,
|
||||
const vector<size_t>& num) const
|
||||
{
|
||||
size_t cnt = num[0];
|
||||
size_t rep_size = 1;
|
||||
// assert continuous ordering or replaced ranges:
|
||||
for(auto& x: num){
|
||||
assert(cnt++ == x);
|
||||
rep_size *= mOrig[x]->size();
|
||||
if(num.size() != 0){
|
||||
size_t cnt = num[0];
|
||||
size_t rep_size = 1;
|
||||
// assert continuous ordering or replaced ranges:
|
||||
for(auto& x: num){
|
||||
assert(cnt++ == x);
|
||||
rep_size *= mOrig[x]->size();
|
||||
}
|
||||
assert(rep_size == in->size());
|
||||
vector<std::shared_ptr<RangeBase>> norig;
|
||||
norig.reserve(mOrig.size()-num.size()+1);
|
||||
norig.insert(norig.end(),mOrig.begin(),mOrig.begin()+num[0]);
|
||||
norig.push_back(in);
|
||||
norig.insert(norig.end(),mOrig.begin()+num.back()+1,mOrig.end());
|
||||
AnonymousRangeFactory arf(norig);
|
||||
return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
|
||||
}
|
||||
else {
|
||||
return std::dynamic_pointer_cast<AnonymousRange>( std::shared_ptr<RangeBase>(RB::mThis) );
|
||||
}
|
||||
assert(rep_size == in->size());
|
||||
vector<std::shared_ptr<RangeBase>> norig;
|
||||
norig.reserve(mOrig.size()-num.size()+1);
|
||||
norig.insert(norig.end(),mOrig.begin(),mOrig.begin()+num[0]);
|
||||
norig.push_back(in);
|
||||
norig.insert(norig.end(),mOrig.begin()+num.back()+1,mOrig.end());
|
||||
AnonymousRangeFactory arf(norig);
|
||||
return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
|
||||
}
|
||||
|
||||
const vector<std::shared_ptr<RangeBase> >& AnonymousRange::orig() const
|
||||
|
|
Loading…
Reference in a new issue