fix: consistent streaming of tuples
This commit is contained in:
parent
e2c33a2061
commit
388440764e
5 changed files with 77 additions and 26 deletions
|
@ -594,7 +594,10 @@ namespace MultiArrayTools
|
||||||
template <class Op, SpaceType XSTYPE, class... Ranges>
|
template <class Op, SpaceType XSTYPE, class... Ranges>
|
||||||
size_t GenMapRange<Op,XSTYPE,Ranges...>::cmeta(char* target, size_t pos) const
|
size_t GenMapRange<Op,XSTYPE,Ranges...>::cmeta(char* target, size_t pos) const
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getCMeta(target,pos,mSpace,cmetaSize());
|
//MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
||||||
|
assert(0);
|
||||||
|
return 0;
|
||||||
|
//return RPackNum<sizeof...(Ranges)-1>::getCMeta(xtarget,pos,mSpace,cmetaSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Op, SpaceType XSTYPE, class... Ranges>
|
template <class Op, SpaceType XSTYPE, class... Ranges>
|
||||||
|
|
|
@ -529,16 +529,16 @@ namespace MultiArrayTools
|
||||||
template <class EC>
|
template <class EC>
|
||||||
std::string DynamicRange<EC>::stringMeta(size_t pos) const
|
std::string DynamicRange<EC>::stringMeta(size_t pos) const
|
||||||
{
|
{
|
||||||
std::string out = "[ ";
|
std::string out = "";
|
||||||
//size_t xpos = pos;
|
//size_t xpos = pos;
|
||||||
for(size_t i = mOrig.size(); i != 0; --i) {
|
for(size_t i = mOrig.size(); i != 0; --i) {
|
||||||
auto& x = mOrig[i-1];
|
auto& x = mOrig[i-1];
|
||||||
const size_t redpos = pos % x->size();
|
const size_t redpos = pos % x->size();
|
||||||
out = ( (i == mOrig.size()) ? out : out + " , " ) + x->stringMeta(redpos);
|
out = x->stringMeta(redpos) + ( (i == mOrig.size()) ? out : ", " + out );
|
||||||
pos -= redpos;
|
pos -= redpos;
|
||||||
pos /= x->size();
|
pos /= x->size();
|
||||||
}
|
}
|
||||||
out += " ]";
|
out = "[" + out + "]";
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -596,7 +596,8 @@ namespace MultiArrayTools
|
||||||
size_t MultiRange<Ranges...>::cmeta(char* target, size_t pos) const
|
size_t MultiRange<Ranges...>::cmeta(char* target, size_t pos) const
|
||||||
{
|
{
|
||||||
const size_t off = cmetaSize();
|
const size_t off = cmetaSize();
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getCMeta(target,pos,mSpace,off);
|
MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
||||||
|
return RPackNum<sizeof...(Ranges)-1>::getCMeta(xtarget,pos,mSpace,off);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
|
|
@ -370,17 +370,17 @@ namespace MultiArrayHelper
|
||||||
RPackNum<N-1>::setSpace(rbvec, stp);
|
RPackNum<N-1>::setSpace(rbvec, stp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class MetaType, class... Ranges>
|
||||||
static inline size_t getCMeta(char* target, size_t pos, const std::tuple<std::shared_ptr<Ranges>...>& stp,
|
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
||||||
size_t off)
|
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
||||||
{
|
{
|
||||||
//constexpr size_t NN = sizeof...(Ranges);
|
//constexpr size_t NN = sizeof...(Ranges);
|
||||||
auto& r = *std::get<N>(stp);
|
auto& r = *std::get<N>(stp);
|
||||||
const size_t ownPos = pos % r.size();
|
const size_t ownPos = pos % r.size();
|
||||||
const size_t s = r.cmetaSize();
|
const size_t s = r.cmetaSize();
|
||||||
off -= s;
|
off -= s;
|
||||||
r.cmeta(target+off,ownPos);
|
r.cmeta(reinterpret_cast<char*>(&std::get<N>(*xtarget)), ownPos);
|
||||||
return s + RPackNum<N-1>::getCMeta(target, (pos - ownPos) / r.size(), stp, off);
|
return s + RPackNum<N-1>::getCMeta(xtarget, (pos - ownPos) / r.size(), stp, off);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
@ -668,9 +668,9 @@ namespace MultiArrayHelper
|
||||||
std::get<0>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[0] );
|
std::get<0>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class MetaType, class... Ranges>
|
||||||
static inline size_t getCMeta(char* target, size_t pos, const std::tuple<std::shared_ptr<Ranges>...>& stp,
|
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
||||||
size_t off)
|
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
||||||
{
|
{
|
||||||
//constexpr size_t NN = sizeof...(Ranges);
|
//constexpr size_t NN = sizeof...(Ranges);
|
||||||
auto& r = *std::get<0>(stp);
|
auto& r = *std::get<0>(stp);
|
||||||
|
@ -678,7 +678,7 @@ namespace MultiArrayHelper
|
||||||
const size_t s = r.cmetaSize();
|
const size_t s = r.cmetaSize();
|
||||||
off -= s;
|
off -= s;
|
||||||
assert(off == 0);
|
assert(off == 0);
|
||||||
r.cmeta(target,ownPos);
|
r.cmeta(reinterpret_cast<char*>(&std::get<0>(*xtarget)), ownPos);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -251,26 +251,73 @@ namespace {
|
||||||
EXPECT_EQ(ci2().pos(), ci2.max()-1);
|
EXPECT_EQ(ci2().pos(), ci2.max()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char& resolve0(const vector<char>& cv)
|
||||||
|
{
|
||||||
|
return cv[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::tuple<char,char,char>& resolve1(const vector<char>& cv)
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<const std::tuple<char,char,char>*>(cv.data()+1);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DynIndexTest, Iterate)
|
TEST_F(DynIndexTest, Iterate)
|
||||||
{
|
{
|
||||||
for(auto i = dr->begin(); i.pos() != i.max(); ++i){
|
for(auto i = dr->begin(); i.pos() != i.max(); ++i){
|
||||||
EXPECT_EQ(i.meta().size(), 4*sizeof(char));
|
EXPECT_EQ(i.meta().size(), 4*sizeof(char));
|
||||||
}
|
}
|
||||||
auto j = dr->begin();
|
auto j = dr->begin();
|
||||||
EXPECT_EQ(j.meta(), vector<char>({'e','a','1','0'}));
|
//std::cout << j.stringMeta() << std::endl;
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'e','a','1','7'}));
|
EXPECT_EQ(j.stringMeta(), "[e, [a,1,0]]");
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'e','b','1','0'}));
|
EXPECT_EQ(resolve0(j.meta()), 'e');
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'e','b','1','7'}));
|
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','0'));
|
||||||
|
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'b','a','1','0'}));
|
EXPECT_EQ((++j).stringMeta(), "[e, [a,1,7]]");
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'b','a','1','7'}));
|
EXPECT_EQ(resolve0(j.meta()), 'e');
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'b','b','1','0'}));
|
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','7'));
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'b','b','1','7'}));
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[e, [b,1,0]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'e');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','0'));
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[e, [b,1,7]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'e');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','7'));
|
||||||
|
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[b, [a,1,0]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'b');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','0'));
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[b, [a,1,7]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'b');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','7'));
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[b, [b,1,0]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'b');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','0'));
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[b, [b,1,7]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'b');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','7'));
|
||||||
|
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[n, [a,1,0]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'n');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','0'));
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[n, [a,1,7]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'n');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('a','1','7'));
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[n, [b,1,0]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'n');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','0'));
|
||||||
|
|
||||||
|
EXPECT_EQ((++j).stringMeta(), "[n, [b,1,7]]");
|
||||||
|
EXPECT_EQ(resolve0(j.meta()), 'n');
|
||||||
|
EXPECT_EQ(resolve1(j.meta()), mkt('b','1','7'));
|
||||||
|
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'n','a','1','0'}));
|
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'n','a','1','7'}));
|
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'n','b','1','0'}));
|
|
||||||
EXPECT_EQ((++j).meta(), vector<char>({'n','b','1','7'}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace
|
} // end namespace
|
||||||
|
|
Loading…
Reference in a new issue