2022-09-12 01:09:51 +02:00
|
|
|
|
|
|
|
#ifndef __cxz_urange_cc_h__
|
|
|
|
#define __cxz_urange_cc_h__
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "urange.h"
|
2022-10-16 23:05:48 +02:00
|
|
|
#include "xpr/for.h"
|
2022-09-12 01:09:51 +02:00
|
|
|
|
|
|
|
namespace CNORXZ
|
|
|
|
{
|
|
|
|
/*****************
|
|
|
|
* UIndex *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-09-18 22:50:07 +02:00
|
|
|
UIndex<MetaType>::UIndex(const RangePtr& range, SizeT pos) :
|
|
|
|
IndexInterface<UIndex<MetaType>,MetaType>(pos),
|
2022-09-15 16:45:45 +02:00
|
|
|
mRangePtr(rangeCast<MetaType>(range)),
|
|
|
|
mMetaPtr(&mRangePtr->get(0))
|
2022-09-12 01:09:51 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType>& UIndex<MetaType>::operator=(size_t pos)
|
|
|
|
{
|
|
|
|
IB::mPos = pos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType>& UIndex<MetaType>::operator++()
|
|
|
|
{
|
|
|
|
++IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType>& UIndex<MetaType>::operator--()
|
|
|
|
{
|
|
|
|
--IB::mPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-09-18 22:50:07 +02:00
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType> UIndex<MetaType>::operator+(Int n) const
|
|
|
|
{
|
|
|
|
return UIndex(mRangePtr, IB::mPos + n);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType> UIndex<MetaType>::operator-(Int n) const
|
|
|
|
{
|
|
|
|
return UIndex(mRangePtr, IB::mPos - n);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType>& UIndex<MetaType>::operator+=(Int n)
|
|
|
|
{
|
|
|
|
IB::mPos += n;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType>& UIndex<MetaType>::operator-=(Int n)
|
|
|
|
{
|
|
|
|
IB::mPos -= n;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-10-16 23:05:48 +02:00
|
|
|
template <typename MetaType>
|
|
|
|
SizeT UIndex<MetaType>::max() const
|
|
|
|
{
|
|
|
|
return mRangePtr->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
IndexId<0> UIndex<MetaType>::id() const
|
|
|
|
{
|
|
|
|
return IndexId<0>(this->ptrId());
|
|
|
|
}
|
|
|
|
|
2022-09-18 22:50:07 +02:00
|
|
|
template <typename MetaType>
|
|
|
|
const MetaType& UIndex<MetaType>::operator*() const
|
|
|
|
{
|
|
|
|
return mMetaPtr[IB::mPos];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
const MetaType* UIndex<MetaType>::operator->() const
|
|
|
|
{
|
|
|
|
return mMetaPtr + IB::mPos;
|
|
|
|
}
|
|
|
|
|
2022-09-12 01:09:51 +02:00
|
|
|
template <typename MetaType>
|
2022-09-14 18:58:06 +02:00
|
|
|
Int UIndex<MetaType>::pp(PtrId idxPtrNum)
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
|
|
|
++(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-09-14 18:58:06 +02:00
|
|
|
Int UIndex<MetaType>::mm(PtrId idxPtrNum)
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
|
|
|
--(*this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
String UIndex<MetaType>::stringMeta() const
|
|
|
|
{
|
|
|
|
return toString(this->meta());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-09-15 16:45:45 +02:00
|
|
|
const MetaType& UIndex<MetaType>::meta() const
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
2022-09-15 16:45:45 +02:00
|
|
|
return mMetaPtr[IB::mPos];
|
2022-09-12 01:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
UIndex<MetaType>& UIndex<MetaType>::at(const MetaType& metaPos)
|
|
|
|
{
|
|
|
|
(*this) = mRangePtr->getMeta(metaPos);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-09-14 18:58:06 +02:00
|
|
|
size_t UIndex<MetaType>::dim() const // = 1
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-09-15 16:45:45 +02:00
|
|
|
Sptr<URange<MetaType>> UIndex<MetaType>::range() const
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
|
|
|
return mRangePtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-10-16 23:05:48 +02:00
|
|
|
template <SizeT I>
|
|
|
|
UPos UIndex<MetaType>::stepSize(const IndexId<I>& id) const
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
2022-10-16 23:05:48 +02:00
|
|
|
return UPos(id == this->id() ? 1 : 0);
|
2022-09-18 22:50:07 +02:00
|
|
|
}
|
|
|
|
|
2022-09-12 01:09:51 +02:00
|
|
|
template <typename MetaType>
|
2022-10-16 23:05:48 +02:00
|
|
|
template <class PosT, class Xpr>
|
|
|
|
decltype(auto) UIndex<MetaType>::ifor(const PosT step, Xpr xpr) const
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
2022-10-16 23:05:48 +02:00
|
|
|
return For<0,PosT,Xpr>(this->max(), this->id(), step, xpr);
|
2022-09-12 01:09:51 +02:00
|
|
|
}
|
|
|
|
|
2022-09-14 18:58:06 +02:00
|
|
|
/**********************
|
|
|
|
* URangeFactory *
|
|
|
|
**********************/
|
2022-09-12 01:09:51 +02:00
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
URangeFactory<MetaType>::URangeFactory(const Vector<MetaType>& space) :
|
|
|
|
mSpace(space) {}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
URangeFactory<MetaType>::URangeFactory(Vector<MetaType>&& space) :
|
|
|
|
mSpace(space) {}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
URangeFactory<MetaType>::URangeFactory(const Vector<MetaType>& space, const RangePtr& ref) :
|
|
|
|
mSpace(space), mRef(ref) {}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
URangeFactory<MetaType>::URangeFactory(Vector<MetaType>&& space, const RangePtr& ref) :
|
|
|
|
mSpace(space), mRef(ref) {}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
void URangeFactory<MetaType>::make()
|
|
|
|
{
|
2022-09-15 16:45:45 +02:00
|
|
|
auto info = typeid(URange<MetaType>);
|
2022-09-12 01:09:51 +02:00
|
|
|
if(mRef != nullptr) {
|
2022-09-15 16:45:45 +02:00
|
|
|
mProd = this->fromCreated[info.hash_code()][mRef->id()];
|
2022-09-12 01:09:51 +02:00
|
|
|
}
|
|
|
|
if(mProd == nullptr){
|
2022-09-15 16:45:45 +02:00
|
|
|
RangePtr key = mProd = std::shared_ptr<URange<MetaType>>
|
2022-09-12 01:09:51 +02:00
|
|
|
( new URange<MetaType>( std::move(mSpace) ) );
|
2022-09-15 16:45:45 +02:00
|
|
|
if(mRef != nullptr) { key = mRef; }
|
|
|
|
this->addToCreated(info, { key->id() }, mProd);
|
2022-09-12 01:09:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 18:58:06 +02:00
|
|
|
/***************
|
|
|
|
* URange *
|
|
|
|
***************/
|
2022-09-12 01:09:51 +02:00
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
URange<MetaType>::URange(const Vector<MetaType>& space) :
|
2022-09-15 16:45:45 +02:00
|
|
|
RangeInterface<URange<MetaType>,MetaType>(),
|
2022-09-12 01:09:51 +02:00
|
|
|
mSpace(space)
|
|
|
|
{
|
|
|
|
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
|
|
|
|
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
|
|
|
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
URange<MetaType>::URange(Vector<MetaType>&& space) :
|
2022-09-15 16:45:45 +02:00
|
|
|
RangeInterface<URange<MetaType>,MetaType>(),
|
2022-09-12 01:09:51 +02:00
|
|
|
mSpace(space)
|
|
|
|
{
|
|
|
|
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
|
|
|
|
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
|
|
|
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-09-14 18:58:06 +02:00
|
|
|
const MetaType& URange<MetaType>::get(SizeT pos) const
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
|
|
|
return mSpace[pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
SizeT URange<MetaType>::getMeta(const MetaType& meta) const
|
|
|
|
{
|
|
|
|
auto b = mSpace.begin();
|
|
|
|
auto e = mSpace.end();
|
|
|
|
return std::lower_bound(b, e, meta, std::less<MetaType>()) - b;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
SizeT URange<MetaType>::size() const
|
|
|
|
{
|
|
|
|
return mSpace.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
SizeT URange<MetaType>::dim() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
String URange<MetaType>::stringMeta(SizeT pos) const
|
|
|
|
{
|
|
|
|
return toString(this->get(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
typename URange<MetaType>::IndexType URange<MetaType>::begin() const
|
|
|
|
{
|
|
|
|
UIndex<MetaType> i( std::dynamic_pointer_cast<URange<MetaType> >
|
2022-09-14 18:58:06 +02:00
|
|
|
( RangePtr( RB::mThis ) ) );
|
2022-09-12 01:09:51 +02:00
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MetaType>
|
|
|
|
typename URange<MetaType>::IndexType URange<MetaType>::end() const
|
|
|
|
{
|
|
|
|
UIndex<MetaType> i( std::dynamic_pointer_cast<URange<MetaType> >
|
2022-09-14 18:58:06 +02:00
|
|
|
( RangePtr( RB::mThis ) ) );
|
2022-09-12 01:09:51 +02:00
|
|
|
i = this->size();
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************
|
|
|
|
* Range Casts *
|
|
|
|
*******************/
|
|
|
|
|
|
|
|
template <typename MetaType>
|
2022-09-14 18:58:06 +02:00
|
|
|
Sptr<URange<MetaType>> RangeCast<URange<MetaType>>::func(const RangePtr& r)
|
2022-09-12 01:09:51 +02:00
|
|
|
{
|
|
|
|
CXZ_ERROR("to be implemented...");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-09-14 18:58:06 +02:00
|
|
|
|
2022-09-12 01:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|