further renaming + fixes

This commit is contained in:
Christian Zimmermann 2022-09-14 18:58:06 +02:00
parent 0ec807c8fa
commit 0dcf7d3b5a
17 changed files with 309 additions and 181 deletions

View file

@ -1,3 +1,14 @@
/**
File: include/base/base.h
Include basic headers containing defintions and macros
used throughout this library
Copyright (c) 2022 Christian Zimmermann. All rights reserved.
Mail: chizeta@f3l.de
**/
#ifndef __cxz_base_h__
#define __cxz_base_h__

View file

@ -0,0 +1,34 @@
#ifndef __cxz_crange_cc_h__
#define __cxz_crange_cc_h__
#include "crange.h"
namespace CNORXZ
{
/*
template <class Expr>
auto CRange::ifor(SizeT step, Expr ex) const
-> For<CIndex,Expr>
{
return For<CIndex,Expr>(this, step, ex);
}
*/
/*
template <class Expr>
auto CRange::iforh(SizeT step, Expr ex) const
-> For<CIndex,Expr,ForType::HIDDEN>
{
}
template <class Expr>
auto CRange::pifor(SizeT step, Expr ex) const
-> PFor<CIndex,Expr>
{
}
*/
}
#endif

View file

@ -1,22 +1,23 @@
#ifndef __cxz_range_type_classic_def__
#define __cxz_range_type_classic_def__
#ifndef __cxz_crange_h__
#define __cxz_crange_h__
#include "base/base.h"
#include "ranges/index_base.h"
#include "ranges/range_base.h"
#include "xfor/for_type.h"
//#include "xfor/for_type.h"
#include "xfor/xfor.h"
namespace CNORXZ
{
class CIndex : public IndexInterface<CIndex<MetaType>,SizeT>
class CIndex : public IndexInterface<CIndex,SizeT>
{
public:
typedef IndexInterface<CIndex<SizeT>,SizeT> IB;
typedef IndexInterface<CIndex,SizeT> IB;
typedef CRange RangeType;
CIndex(const RangePtr& range);
CIndex(const RangePtr& range, SizeT pos = 0);
CIndex& operator=(SizeT pos);
CIndex& operator++();
@ -40,10 +41,11 @@ namespace CNORXZ
SizeT meta() const;
CIndex& at(const SizeT& metaPos);
template <class Expr>
auto ifor(SizeT step, Expr ex) const
-> For<CIndex<SizeT>,Expr>;
//template <class Expr>
//auto ifor(SizeT step, Expr ex) const
// -> For<CIndex,Expr>;
/*
template <class Expr>
auto iforh(SizeT step, Expr ex) const
-> For<CIndex<SizeT>,Expr,ForType::HIDDEN>;
@ -51,7 +53,7 @@ namespace CNORXZ
template <class Expr>
auto pifor(SizeT step, Expr ex) const
-> PFor<CIndex<SizeT>,Expr>;
*/
private:
Sptr<RangeType> mRangePtr;
};
@ -69,6 +71,7 @@ namespace CNORXZ
virtual void make() override;
private:
SizeT mSize;
RangePtr mRef;
};
@ -81,11 +84,11 @@ namespace CNORXZ
friend CRangeFactory;
virtual SizeT size() const final;
virtual SizeT dim() const final;
virtual String stringMeta(SizeT pos) const final;
virtual IndexType begin() const final;
virtual IndexType end() const final;
virtual SizeT size() const override final;
virtual SizeT dim() const override final;
virtual String stringMeta(SizeT pos) const override final;
virtual const TypeInfo& type() const override final;
virtual const TypeInfo& metaType() const override final;
SizeT get(SizeT pos) const;
SizeT getMeta(SizeT metaPos) const;
@ -100,7 +103,10 @@ namespace CNORXZ
};
template <>
Sptr<CRange> rangeCast<CRange>(const RangePtr& r);
struct RangeCast<CRange>
{
static Sptr<CRange> func(const RangePtr& r);
};
}
#endif

View file

@ -50,7 +50,7 @@ namespace CNORXZ
IndexInterface<I,MetaType>::IndexInterface(SizeT pos) :
mPos(pos)
{
mPtrNum = reinterpret_cast<PtrId>(this);
mPtrId = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>

View file

@ -61,8 +61,7 @@ namespace CNORXZ
{ return THIS().template iforh<Expr>(step,ex); }
private:
friend I;
friend I; // why not protected???!!!
// NO DEFAULT CONSTRUCTORS/ASSIGNMENTS!
IndexInterface();
@ -71,8 +70,8 @@ namespace CNORXZ
IndexInterface(IndexInterface&& in);
IndexInterface& operator=(IndexInterface&& in);
IndexInterface(SizeT pos);
IndexInterface(SizeT pos, const IndexPtr<I,MetaType>& rel);
IndexPtr<I,MetaType> mRel = nullptr;
SizeT mPos = 0;
PtrId mPtrId = 0;
};

View file

@ -10,7 +10,7 @@
#include "index_base.h"
#include "range_helper.h"
#include "multi_range_factory_product_map.h"
//#include "multi_range_factory_product_map.h"
#include "statics/static_for.h"

View file

@ -18,6 +18,25 @@ namespace CNORXZ
return Index(RangePtr(RB::mThis), this->size());
}
template <class Range>
Sptr<Range> RangeCast<Range>::func(const RangePtr& r)
{
CXZ_ERROR("cast form '" << r->type().name() << "' to '"
<< typeid(Range).name() << "' not available");
return nullptr;
}
template <class Range>
Sptr<Range> rangeCast(const RangePtr r)
{
if(typeid(Range) == r->type()) {
return std::dynamic_pointer_cast<Range>(r);
}
else {
return RangeCast<Range>::func(r);
}
}
}
#endif

View file

@ -51,8 +51,8 @@ namespace CNORXZ
bool operator==(const RangeBase& in) const;
bool operator!=(const RangeBase& in) const;
virtual TypeInfo type() const = 0;
virtual TypeInfo metaType() const = 0;
virtual const TypeInfo& type() const = 0;
virtual const TypeInfo& metaType() const = 0;
virtual String stringMeta(SizeT pos) const = 0;
PtrId id() const;
@ -82,6 +82,12 @@ namespace CNORXZ
RangeInterface() = default;
};
template <class Range>
struct RangeCast
{
static Sptr<Range> func(const RangePtr& r);
};
template <class Range>
Sptr<Range> rangeCast(const RangePtr r);

View file

@ -1,2 +1,3 @@
#include "xindex.cc.h"
#include "crange.cc.h"

View file

@ -1,9 +1,9 @@
#include "index_base.h"
#include "multi_range.h"
#include "range_base.h"
#include "range_helper.h"
#include "single_range.h"
#include "index_base.h"
//#include "mrange.h"
//#include "range_helper.h"
#include "crange.h"
//#include "subrange.h"
//#include "value_range.h"
#include "xindex.h"

View file

@ -13,24 +13,10 @@ namespace CNORXZ
* UIndex *
*****************/
namespace
{
template <typename MetaType>
Sptr<URange<MetaType>> rc(const RangePtr r)
{
if(typeid(URange<MetaType>) == r.type()){
return std::dynamic_pointer_cast<URange<MetaType>>(r)
}
else {
return rangeCast<URange<MetaType>>(r);
}
}
}
template <typename MetaType>
UIndex<MetaType>::UIndex(const RangePtr& range) :
IndexInterface<UIndex<MetaType>,MetaType>(0),
mRange(rc<MetaType>(range)),
mRange(rangeCast<MetaType>(range)),
mMetaPtr(&get(0))
{}
@ -56,14 +42,14 @@ namespace CNORXZ
}
template <typename MetaType>
int UIndex<MetaType>::pp(std::intptr_t idxPtrNum)
Int UIndex<MetaType>::pp(PtrId idxPtrNum)
{
++(*this);
return 1;
}
template <typename MetaType>
int UIndex<MetaType>::mm(std::intptr_t idxPtrNum)
Int UIndex<MetaType>::mm(PtrId idxPtrNum)
{
--(*this);
return 1;
@ -89,7 +75,7 @@ namespace CNORXZ
}
template <typename MetaType>
size_t UIndex<MetaType>::dim() // = 1
size_t UIndex<MetaType>::dim() const // = 1
{
return 1;
}
@ -101,7 +87,7 @@ namespace CNORXZ
}
template <typename MetaType>
size_t UIndex<MetaType>::getStepSize(size_t n)
size_t UIndex<MetaType>::getStepSize(SizeT n)
{
return 1;
}
@ -131,9 +117,9 @@ namespace CNORXZ
}
/********************
* SingleRange *
********************/
/**********************
* URangeFactory *
**********************/
template <typename MetaType>
URangeFactory<MetaType>::URangeFactory(const Vector<MetaType>& space) :
@ -165,9 +151,9 @@ namespace CNORXZ
}
}
/********************
* SingleRange *
********************/
/***************
* URange *
***************/
template <typename MetaType>
URange<MetaType>::URange(const Vector<MetaType>& space) :
@ -191,7 +177,7 @@ namespace CNORXZ
template <typename MetaType>
const MetaType& URange<MetaType>::get(size_t pos) const
const MetaType& URange<MetaType>::get(SizeT pos) const
{
return mSpace[pos];
}
@ -226,7 +212,7 @@ namespace CNORXZ
typename URange<MetaType>::IndexType URange<MetaType>::begin() const
{
UIndex<MetaType> i( std::dynamic_pointer_cast<URange<MetaType> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
( RangePtr( RB::mThis ) ) );
i = 0;
return i;
}
@ -235,7 +221,7 @@ namespace CNORXZ
typename URange<MetaType>::IndexType URange<MetaType>::end() const
{
UIndex<MetaType> i( std::dynamic_pointer_cast<URange<MetaType> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
( RangePtr( RB::mThis ) ) );
i = this->size();
return i;
}
@ -245,11 +231,12 @@ namespace CNORXZ
*******************/
template <typename MetaType>
Sptr<URange<MetaType>> rangeCast<URange<MetaType>>(const RangePtr& r)
Sptr<URange<MetaType>> RangeCast<URange<MetaType>>::func(const RangePtr& r)
{
CXZ_ERROR("to be implemented...");
return nullptr;
}
}
#endif

View file

@ -109,7 +109,10 @@ namespace CNORXZ
};
template <typename MetaType>
Sptr<URange<MetaType>> rangeCast<URange<MetaType>>(const RangePtr& r);
struct RangeCast<URange<MetaType>>
{
static Sptr<URange<MetaType>> func(const RangePtr& r);
};
}
#endif

View file

@ -2,14 +2,9 @@
set(libcnorxz_a_SOURCES
${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc
${CMAKE_SOURCE_DIR}/src/lib/ranges/yindex.cc
${CMAKE_SOURCE_DIR}/src/lib/ranges/crange.cc
)
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc")
foreach(ccfile ${cc_files})
set(libcnorxz_a_SOURCES ${libcnorxz_a_SOURCES}
${ccfile})
endforeach(ccfile)
add_library(cnorxz_obj OBJECT
${libcnorxz_a_SOURCES}
)

181
src/lib/ranges/crange.cc Normal file
View file

@ -0,0 +1,181 @@
#include "ranges/ranges.h"
namespace CNORXZ
{
/***************
* CIndex *
***************/
CIndex::CIndex(const RangePtr& range, SizeT pos) :
IndexInterface<CIndex,SizeT>(pos), mRangePtr(rangeCast<RangeType>(range))
{}
CIndex& CIndex::operator=(SizeT pos)
{
IB::mPos = pos;
return *this;
}
CIndex& CIndex::operator++()
{
++IB::mPos;
return *this;
}
CIndex& CIndex::operator--()
{
--IB::mPos;
return *this;
}
CIndex CIndex::operator+(Int n) const
{
return CIndex(mRangePtr, IB::mPos + n);
}
CIndex CIndex::operator-(Int n) const
{
return CIndex(mRangePtr, IB::mPos - n);
}
CIndex& CIndex::operator+=(Int n)
{
IB::mPos += n;
return *this;
}
CIndex& CIndex::operator-=(Int n)
{
IB::mPos -= n;
return *this;
}
SizeT CIndex::operator*() const
{
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;
}
Sptr<CIndex::RangeType> CIndex::range() const
{
return mRangePtr;
}
SizeT CIndex::getStepSize(SizeT n) const
{
return 1;
}
String CIndex::stringMeta() const
{
return toString(IB::mPos);
}
SizeT CIndex::meta() const
{
return IB::mPos;
}
CIndex& CIndex::at(const SizeT& metaPos)
{
IB::mPos = metaPos;
return *this;
}
/***************
* CRange *
***************/
CRangeFactory::CRangeFactory(SizeT size) :
mSize(size) {}
CRangeFactory::CRangeFactory(SizeT size, RangePtr ref) :
mSize(size), mRef(ref) {}
void CRangeFactory::make()
{
if(mRef != nullptr) {
mProd = this->fromCreated(typeid(oType), {mRef->id()});
}
if(mProd == nullptr){
RangePtr key = mProd = std::shared_ptr<oType>
( new CRange( mSize ) );
if(mRef != nullptr) { key = mRef; }
this->addToCreated(typeid(oType), { key->id() }, mProd);
}
}
/***************
* CRange *
***************/
CRange::CRange(SizeT size) : mSize(size) {}
SizeT CRange::get(SizeT pos) const
{
return pos;
}
SizeT CRange::getMeta(SizeT metaPos) const
{
return metaPos;
}
SizeT CRange::size() const
{
return mSize;
}
SizeT CRange::dim() const
{
return 1;
}
std::string CRange::stringMeta(SizeT pos) const
{
return toString(pos);
}
const TypeInfo& CRange::type() const
{
return typeid(CRange);
}
const TypeInfo& CRange::metaType() const
{
return typeid(SizeT);
}
/*******************
* Range Casts *
*******************/
Sptr<CRange> RangeCast<CRange>::func(const RangePtr& r)
{
return std::dynamic_pointer_cast<CRange>( CRangeFactory(r->size(), r).create() );
}
}

View file

@ -12,8 +12,10 @@ namespace CNORXZ
RangePtr RangeFactoryBase::create()
{
this->make();
mProd->mThis = mProd;
if(not mProd) {
this->make();
mProd->mThis = mProd;
}
return mProd;
}

View file

@ -1,116 +0,0 @@
#include "ranges/rheader.h"
#include "ranges/x_to_string.h"
#include "ranges/ranges_header.cc.h"
namespace CNORXZ
{
/********************
* GenSingleRange *
********************/
GenSingleRangeFactory<size_t,SpaceType::NONE,MUI>::GenSingleRangeFactory(size_t size)
{
// Quasi Singleton
if(not mProd){
mProd = std::shared_ptr<oType>( new GenSingleRange<size_t,SpaceType::NONE,MUI>(size) );
setSelf();
}
}
std::shared_ptr<RangeBase> GenSingleRangeFactory<size_t,SpaceType::NONE,MUI>::create()
{
return mProd;
}
/********************
* GenSingleRange *
********************/
GenSingleRange<size_t,SpaceType::NONE,MUI>::GenSingleRange(size_t size) : mSize(size) {}
size_t GenSingleRange<size_t,SpaceType::NONE,MUI>::get(size_t pos) const
{
return pos;
}
size_t GenSingleRange<size_t,SpaceType::NONE,MUI>::getMeta(size_t metaPos) const
{
return metaPos;
}
size_t GenSingleRange<size_t,SpaceType::NONE,MUI>::size() const
{
return mSize;
}
size_t GenSingleRange<size_t,SpaceType::NONE,MUI>::dim() const
{
return 1;
}
SpaceType GenSingleRange<size_t,SpaceType::NONE,MUI>::spaceType() const
{
return SpaceType::NONE;
}
vector<size_t> GenSingleRange<size_t,SpaceType::NONE,MUI>::typeNum() const
{
return {NumTypeMap<size_t>::num()};
}
size_t GenSingleRange<size_t,SpaceType::NONE,MUI>::cmeta(char* target, size_t pos) const
{
*reinterpret_cast<size_t*>(target) = pos;
return sizeof(size_t);
}
size_t GenSingleRange<size_t,SpaceType::NONE,MUI>::cmetaSize() const
{
return sizeof(size_t);
}
std::string GenSingleRange<size_t,SpaceType::NONE,MUI>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));
}
vector<char> GenSingleRange<size_t,SpaceType::NONE,MUI>::data() const
{
DataHeader h = dataHeader();
vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
const char* scp = reinterpret_cast<const char*>(&mSize);
out.insert(out.end(), scp, scp + h.metaSize);
return out;
}
DataHeader GenSingleRange<size_t,SpaceType::NONE,MUI>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::NONE );
h.metaSize = sizeof(size_t);
h.multiple = 0;
return h;
}
typename GenSingleRange<size_t,SpaceType::NONE,MUI>::IndexType GenSingleRange<size_t,SpaceType::NONE,MUI>::begin() const
{
GenSingleIndex<size_t,SpaceType::NONE,MUI> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::NONE,MUI> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename GenSingleRange<size_t,SpaceType::NONE,MUI>::IndexType GenSingleRange<size_t,SpaceType::NONE,MUI>::end() const
{
GenSingleIndex<size_t,SpaceType::NONE,MUI> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::NONE,MUI> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;
}
}