add UR_Test + remove operator-> for index classes where it conflicts with c++ syntax

This commit is contained in:
Christian Zimmermann 2022-11-13 02:23:33 +01:00
parent 4e2244db79
commit 62a9df39d3
15 changed files with 58 additions and 135 deletions

View file

@ -30,11 +30,7 @@ namespace CNORXZ
IndexId<0> id() const;
SizeT operator*() const;
SizeT operator->() const;
Int pp(PtrId idxPtrNum);
Int mm(PtrId idxPtrNum);
SizeT dim() const; // = 1
Sptr<RangeType> range() const;
UPos stepSize(const IndexId<0>& id) const;

View file

@ -36,10 +36,6 @@ namespace CNORXZ
IndexId<0> id() const;
DType operator*() const;
DType operator->() const;
Int pp(PtrId idxPtrNum);
Int mm(PtrId idxPtrNum);
SizeT dim() const;
RangePtr range() const;

View file

@ -41,11 +41,7 @@ namespace CNORXZ
bool operator<=(const IndexInterface& in) const;
bool operator>=(const IndexInterface& in) const;
decltype(auto) operator*() const { return THIS().operator*(); }
decltype(auto) operator->() const { return THIS().operator->(); }
Int pp(PtrId idxPtrNum) { return THIS().pp(idxPtrNum); }
Int mm(PtrId idxPtrNum) { return THIS().mm(idxPtrNum); }
SizeT dim() const { return THIS().dim(); }
decltype(auto) range() const { return THIS().range(); }

View file

@ -198,12 +198,6 @@ namespace CNORXZ
return meta();
}
template <class... Indices>
MetaType MIndex<Indices...>::operator->() const
{
return meta();
}
template <class... Indices>
SizeT MIndex<Indices...>::dim() const
{

View file

@ -46,7 +46,6 @@ namespace CNORXZ
IndexId<0> id() const;
MetaType operator*() const;
MetaType operator->() const;
SizeT dim() const
Sptr<RangeType> range() const;

View file

@ -48,9 +48,6 @@ namespace CNORXZ
SubIndex& operator()(const std::shared_ptr<Index>& ind); // set full index
int pp(std::intptr_t idxPtrNum);
int mm(std::intptr_t idxPtrNum);
std::string stringMeta() const;
MetaType meta() const;
const MetaType* metaPtr() const;

View file

@ -17,7 +17,7 @@ namespace CNORXZ
template <typename MetaType>
UIndex<MetaType>::UIndex(const RangePtr& range, SizeT pos) :
IndexInterface<UIndex<MetaType>,MetaType>(pos),
mRangePtr(rangeCast<MetaType>(range)),
mRangePtr(rangeCast<RangeType>(range)),
mMetaPtr(&mRangePtr->get(0))
{}
@ -86,12 +86,6 @@ namespace CNORXZ
return mMetaPtr[IB::mPos];
}
template <typename MetaType>
const MetaType* UIndex<MetaType>::operator->() const
{
return mMetaPtr + IB::mPos;
}
template <typename MetaType>
String UIndex<MetaType>::stringMeta() const
{
@ -134,7 +128,7 @@ namespace CNORXZ
template <class Xpr, class F>
decltype(auto) UIndex<MetaType>::ifor(const Xpr& xpr, F&& f) const
{
return For<0,Xpr>(this->max(), this->id(), xpr, std::forward<F>(f));
return For<0,Xpr,F>(this->max(), this->id(), xpr, std::forward<F>(f));
}
/**********************
@ -160,9 +154,9 @@ namespace CNORXZ
template <typename MetaType>
void URangeFactory<MetaType>::make()
{
auto info = typeid(URange<MetaType>);
const auto& info = typeid(URange<MetaType>);
if(mRef != nullptr) {
mProd = this->fromCreated[info.hash_code()][mRef->id()];
mProd = this->fromCreated(info, {mRef->id()});
}
if(mProd == nullptr){
RangePtr key = mProd = std::shared_ptr<URange<MetaType>>
@ -188,7 +182,7 @@ namespace CNORXZ
template <typename MetaType>
URange<MetaType>::URange(Vector<MetaType>&& space) :
RangeInterface<URange<MetaType>,MetaType>(),
RangeInterface<UIndex<MetaType>,MetaType>(),
mSpace(space)
{
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
@ -230,21 +224,15 @@ namespace CNORXZ
}
template <typename MetaType>
typename URange<MetaType>::IndexType URange<MetaType>::begin() const
const TypeInfo& URange<MetaType>::type() const
{
UIndex<MetaType> i( std::dynamic_pointer_cast<URange<MetaType> >
( RangePtr( RB::mThis ) ) );
i = 0;
return i;
return typeid(URange<MetaType>);
}
template <typename MetaType>
typename URange<MetaType>::IndexType URange<MetaType>::end() const
const TypeInfo& URange<MetaType>::metaType() const
{
UIndex<MetaType> i( std::dynamic_pointer_cast<URange<MetaType> >
( RangePtr( RB::mThis ) ) );
i = this->size();
return i;
return typeid(MetaType);
}
/*******************

View file

@ -33,7 +33,6 @@ namespace CNORXZ
IndexId<0> id() const;
const MetaType& operator*() const;
const MetaType* operator->() const;
SizeT dim() const; // = 1
Sptr<RangeType> range() const;
@ -82,8 +81,8 @@ namespace CNORXZ
virtual SizeT size() const override final;
virtual SizeT dim() const override final;
virtual String stringMeta(SizeT pos) const override final;
virtual IndexType begin() const override final;
virtual IndexType end() const override final;
virtual const TypeInfo& type() const override final;
virtual const TypeInfo& metaType() const override final;
const MetaType& get(SizeT pos) const;
SizeT getMeta(const MetaType& metaPos) const;

View file

@ -95,26 +95,6 @@ namespace CNORXZ
{
return DType(*(*mI));
}
template <class Index, typename Meta>
DType XIndex<Index,Meta>::operator->() const
{
return DType(*(*mI));
}
template <class Index, typename Meta>
Int XIndex<Index,Meta>::pp(PtrId idxPtrNum)
{
Int out = mI->pp(idxPtrNum);
return out;
}
template <class Index, typename Meta>
Int XIndex<Index,Meta>::mm(PtrId idxPtrNum)
{
Int out = mI->mm(idxPtrNum);
return out;
}
template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::dim() const

View file

@ -29,10 +29,6 @@ namespace CNORXZ
virtual IndexId<0> id() const = 0;
virtual DType operator*() const = 0;
virtual DType operator->() const = 0;
virtual Int pp(PtrId idxPtrNum) = 0;
virtual Int mm(PtrId idxPtrNum) = 0;
virtual SizeT dim() const = 0;
virtual RangePtr range() const = 0;
@ -79,10 +75,6 @@ namespace CNORXZ
virtual IndexId<0> id() const override final;
virtual DType operator*() const override final;
virtual DType operator->() const override final;
virtual Int pp(PtrId idxPtrNum) override final;
virtual Int mm(PtrId idxPtrNum) override final;
virtual SizeT dim() const override final;
virtual RangePtr range() const override final;

View file

@ -38,10 +38,6 @@ namespace CNORXZ
IndexId<0> id() const;
DType operator*() const;
DType operator->() const;
Int pp(PtrId idxPtrNum);
Int mm(PtrId idxPtrNum);
SizeT dim() const;
Sptr<YRange> range() const;

View file

@ -66,23 +66,6 @@ namespace CNORXZ
return IB::mPos;
}
SizeT CIndex::operator->() const
{
return IB::mPos; // check if this makes sense!!!
}
Int CIndex::pp(PtrId idxPtrNum)
{
++(*this);
return 1;
}
Int CIndex::mm(PtrId idxPtrNum)
{
--(*this);
return 1;
}
SizeT CIndex::dim() const // = 1
{
return 1;

View file

@ -87,25 +87,6 @@ namespace CNORXZ
return *(*mI);
}
DType DIndex::operator->() const
{
return *(*mI);
}
Int DIndex::pp(PtrId idxPtrNum)
{
const Int out = mI->pp(idxPtrNum);
IB::mPos = mI->pos();
return out;
}
Int DIndex::mm(PtrId idxPtrNum)
{
const Int out = mI->mm(idxPtrNum);
IB::mPos = mI->pos();
return out;
}
SizeT DIndex::dim() const
{
return mI->dim();

View file

@ -106,26 +106,6 @@ namespace CNORXZ
return DType();
}
DType YIndex::operator->() const
{
assert(0);
return DType();
}
Int YIndex::pp(PtrId idxPtrNum)
{
assert(0);
// sub inds !!!
return 0;
}
Int YIndex::mm(PtrId idxPtrNum)
{
assert(0);
// sub inds !!!
return 0;
}
SizeT YIndex::dim() const
{
return mRangePtr->dim();

View file

@ -25,6 +25,19 @@ namespace
SizeT mSize;
};
class UR_Test : public ::testing::Test
{
protected:
UR_Test()
{
mMeta = { "These", "are", "test", "strings", "foo", "bar", "baz" };
std::sort(mMeta.begin(), mMeta.end(), std::less<String>());
}
Vector<String> mMeta;
};
TEST_F(CR_Test, Basics)
{
auto cr = CRangeFactory(mSize).create();
@ -47,7 +60,8 @@ namespace
auto endxi = cr->end();
for(auto xi = cr->begin(); xi != endxi; ++xi){
EXPECT_EQ(xi.pos(), cnt);
EXPECT_EQ(*xi, cnt);
EXPECT_TRUE(*xi == DType(cnt));
EXPECT_EQ((*xi).str(), std::to_string(cnt));
++cnt;
}
@ -58,6 +72,38 @@ namespace
}
TEST_F(UR_Test, Basics)
{
auto ur = URangeFactory<String>(mMeta).create();
auto urx = std::dynamic_pointer_cast<URange<String>>(ur);
EXPECT_EQ(ur->size(), mMeta.size());
EXPECT_EQ(urx->size(), mMeta.size());
EXPECT_TRUE(urx->begin() != urx->end());
EXPECT_FALSE(urx->begin() == urx->end());
EXPECT_EQ(urx->begin().pos(), 0u);
EXPECT_EQ(urx->end().pos(), mMeta.size());
EXPECT_TRUE(ur->begin() != ur->end());
EXPECT_FALSE(ur->begin() == ur->end());
EXPECT_EQ(ur->begin().pos(), 0u);
EXPECT_EQ(ur->end().pos(), mMeta.size());
SizeT cnt = 0;
auto endxi = ur->end();
for(auto xi = ur->begin(); xi != endxi; ++xi){
EXPECT_EQ(xi.pos(), cnt);
EXPECT_TRUE(*xi == DType(mMeta[cnt]));
EXPECT_EQ((*xi).str(), mMeta[cnt]);
++cnt;
}
SizeT cnt2 = 0;
for(auto x: *urx){
EXPECT_EQ(x, mMeta[cnt2++]);
}
}
// UR_Test
// RCast_Test
}