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,6 +231,7 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const std::shared_ptr<RangeBase>& in,
|
||||
const vector<size_t>& num) const
|
||||
{
|
||||
if(num.size() != 0){
|
||||
size_t cnt = num[0];
|
||||
size_t rep_size = 1;
|
||||
// assert continuous ordering or replaced ranges:
|
||||
|
@ -247,6 +248,10 @@ namespace MultiArrayTools
|
|||
AnonymousRangeFactory arf(norig);
|
||||
return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
|
||||
}
|
||||
else {
|
||||
return std::dynamic_pointer_cast<AnonymousRange>( std::shared_ptr<RangeBase>(RB::mThis) );
|
||||
}
|
||||
}
|
||||
|
||||
const vector<std::shared_ptr<RangeBase> >& AnonymousRange::orig() const
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue