diff --git a/src/include/base/base.h b/src/include/base/base.h index 24fe0fe..673041f 100644 --- a/src/include/base/base.h +++ b/src/include/base/base.h @@ -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__ diff --git a/src/include/ranges/crange.cc.h b/src/include/ranges/crange.cc.h new file mode 100644 index 0000000..e5308aa --- /dev/null +++ b/src/include/ranges/crange.cc.h @@ -0,0 +1,34 @@ + +#ifndef __cxz_crange_cc_h__ +#define __cxz_crange_cc_h__ + +#include "crange.h" + +namespace CNORXZ +{ + /* + template + auto CRange::ifor(SizeT step, Expr ex) const + -> For + { + return For(this, step, ex); + } + */ + /* + template + auto CRange::iforh(SizeT step, Expr ex) const + -> For + { + + } + + template + auto CRange::pifor(SizeT step, Expr ex) const + -> PFor + { + + } + */ +} + +#endif diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 7390030..c98b8c7 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -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,SizeT> + class CIndex : public IndexInterface { public: - typedef IndexInterface,SizeT> IB; + typedef IndexInterface 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 - auto ifor(SizeT step, Expr ex) const - -> For,Expr>; + //template + //auto ifor(SizeT step, Expr ex) const + // -> For; + /* template auto iforh(SizeT step, Expr ex) const -> For,Expr,ForType::HIDDEN>; @@ -51,7 +53,7 @@ namespace CNORXZ template auto pifor(SizeT step, Expr ex) const -> PFor,Expr>; - + */ private: Sptr 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 rangeCast(const RangePtr& r); + struct RangeCast + { + static Sptr func(const RangePtr& r); + }; } #endif diff --git a/src/include/ranges/index_base.cc.h b/src/include/ranges/index_base.cc.h index a3ccfbb..2a25edf 100644 --- a/src/include/ranges/index_base.cc.h +++ b/src/include/ranges/index_base.cc.h @@ -50,7 +50,7 @@ namespace CNORXZ IndexInterface::IndexInterface(SizeT pos) : mPos(pos) { - mPtrNum = reinterpret_cast(this); + mPtrId = reinterpret_cast(this); } template diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 6cb3852..58cb141 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -61,8 +61,7 @@ namespace CNORXZ { return THIS().template iforh(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& rel); - IndexPtr mRel = nullptr; SizeT mPos = 0; PtrId mPtrId = 0; }; diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index 0368422..ceff746 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -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" diff --git a/src/include/ranges/range_base.cc.h b/src/include/ranges/range_base.cc.h index 8e40a06..ef45d0a 100644 --- a/src/include/ranges/range_base.cc.h +++ b/src/include/ranges/range_base.cc.h @@ -18,6 +18,25 @@ namespace CNORXZ return Index(RangePtr(RB::mThis), this->size()); } + template + Sptr RangeCast::func(const RangePtr& r) + { + CXZ_ERROR("cast form '" << r->type().name() << "' to '" + << typeid(Range).name() << "' not available"); + return nullptr; + } + + template + Sptr rangeCast(const RangePtr r) + { + if(typeid(Range) == r->type()) { + return std::dynamic_pointer_cast(r); + } + else { + return RangeCast::func(r); + } + } + } #endif diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index bfaa7b4..c0b625d 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -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 + struct RangeCast + { + static Sptr func(const RangePtr& r); + }; + template Sptr rangeCast(const RangePtr r); diff --git a/src/include/ranges/ranges.cc.h b/src/include/ranges/ranges.cc.h index 51d721c..89228d1 100644 --- a/src/include/ranges/ranges.cc.h +++ b/src/include/ranges/ranges.cc.h @@ -1,2 +1,3 @@ #include "xindex.cc.h" +#include "crange.cc.h" diff --git a/src/include/ranges/ranges.h b/src/include/ranges/ranges.h index 4483373..dd34d31 100644 --- a/src/include/ranges/ranges.h +++ b/src/include/ranges/ranges.h @@ -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" diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index d255da2..701b1cb 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -13,24 +13,10 @@ namespace CNORXZ * UIndex * *****************/ - namespace - { - template - Sptr> rc(const RangePtr r) - { - if(typeid(URange) == r.type()){ - return std::dynamic_pointer_cast>(r) - } - else { - return rangeCast>(r); - } - } - } - template UIndex::UIndex(const RangePtr& range) : IndexInterface,MetaType>(0), - mRange(rc(range)), + mRange(rangeCast(range)), mMetaPtr(&get(0)) {} @@ -56,14 +42,14 @@ namespace CNORXZ } template - int UIndex::pp(std::intptr_t idxPtrNum) + Int UIndex::pp(PtrId idxPtrNum) { ++(*this); return 1; } template - int UIndex::mm(std::intptr_t idxPtrNum) + Int UIndex::mm(PtrId idxPtrNum) { --(*this); return 1; @@ -89,7 +75,7 @@ namespace CNORXZ } template - size_t UIndex::dim() // = 1 + size_t UIndex::dim() const // = 1 { return 1; } @@ -101,7 +87,7 @@ namespace CNORXZ } template - size_t UIndex::getStepSize(size_t n) + size_t UIndex::getStepSize(SizeT n) { return 1; } @@ -131,9 +117,9 @@ namespace CNORXZ } - /******************** - * SingleRange * - ********************/ + /********************** + * URangeFactory * + **********************/ template URangeFactory::URangeFactory(const Vector& space) : @@ -165,9 +151,9 @@ namespace CNORXZ } } - /******************** - * SingleRange * - ********************/ + /*************** + * URange * + ***************/ template URange::URange(const Vector& space) : @@ -191,7 +177,7 @@ namespace CNORXZ template - const MetaType& URange::get(size_t pos) const + const MetaType& URange::get(SizeT pos) const { return mSpace[pos]; } @@ -226,7 +212,7 @@ namespace CNORXZ typename URange::IndexType URange::begin() const { UIndex i( std::dynamic_pointer_cast > - ( std::shared_ptr( RB::mThis ) ) ); + ( RangePtr( RB::mThis ) ) ); i = 0; return i; } @@ -235,7 +221,7 @@ namespace CNORXZ typename URange::IndexType URange::end() const { UIndex i( std::dynamic_pointer_cast > - ( std::shared_ptr( RB::mThis ) ) ); + ( RangePtr( RB::mThis ) ) ); i = this->size(); return i; } @@ -245,11 +231,12 @@ namespace CNORXZ *******************/ template - Sptr> rangeCast>(const RangePtr& r) + Sptr> RangeCast>::func(const RangePtr& r) { CXZ_ERROR("to be implemented..."); return nullptr; } + } #endif diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index f62ca3b..073f519 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -109,7 +109,10 @@ namespace CNORXZ }; template - Sptr> rangeCast>(const RangePtr& r); + struct RangeCast> + { + static Sptr> func(const RangePtr& r); + }; } #endif diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 1a50051..59dcfe0 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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} ) diff --git a/src/lib/ranges/crange.cc b/src/lib/ranges/crange.cc new file mode 100644 index 0000000..6247cf1 --- /dev/null +++ b/src/lib/ranges/crange.cc @@ -0,0 +1,181 @@ + +#include "ranges/ranges.h" + +namespace CNORXZ +{ + /*************** + * CIndex * + ***************/ + + CIndex::CIndex(const RangePtr& range, SizeT pos) : + IndexInterface(pos), mRangePtr(rangeCast(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::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 + ( 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 RangeCast::func(const RangePtr& r) + { + return std::dynamic_pointer_cast( CRangeFactory(r->size(), r).create() ); + } +} + diff --git a/src/lib/ranges/range_types/null_range.cc b/src/lib/ranges/nrange.cc similarity index 100% rename from src/lib/ranges/range_types/null_range.cc rename to src/lib/ranges/nrange.cc diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index a346769..21a4436 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -12,8 +12,10 @@ namespace CNORXZ RangePtr RangeFactoryBase::create() { - this->make(); - mProd->mThis = mProd; + if(not mProd) { + this->make(); + mProd->mThis = mProd; + } return mProd; } diff --git a/src/lib/ranges/range_types/classic_range.cc b/src/lib/ranges/range_types/classic_range.cc deleted file mode 100644 index 73a0a22..0000000 --- a/src/lib/ranges/range_types/classic_range.cc +++ /dev/null @@ -1,116 +0,0 @@ - -#include "ranges/rheader.h" -#include "ranges/x_to_string.h" -#include "ranges/ranges_header.cc.h" - -namespace CNORXZ -{ - /******************** - * GenSingleRange * - ********************/ - - GenSingleRangeFactory::GenSingleRangeFactory(size_t size) - { - // Quasi Singleton - if(not mProd){ - mProd = std::shared_ptr( new GenSingleRange(size) ); - setSelf(); - } - } - - std::shared_ptr GenSingleRangeFactory::create() - { - return mProd; - } - - /******************** - * GenSingleRange * - ********************/ - - GenSingleRange::GenSingleRange(size_t size) : mSize(size) {} - - size_t GenSingleRange::get(size_t pos) const - { - return pos; - } - - size_t GenSingleRange::getMeta(size_t metaPos) const - { - return metaPos; - } - - size_t GenSingleRange::size() const - { - return mSize; - } - - size_t GenSingleRange::dim() const - { - return 1; - } - - SpaceType GenSingleRange::spaceType() const - { - return SpaceType::NONE; - } - - vector GenSingleRange::typeNum() const - { - return {NumTypeMap::num()}; - } - - size_t GenSingleRange::cmeta(char* target, size_t pos) const - { - *reinterpret_cast(target) = pos; - return sizeof(size_t); - } - - size_t GenSingleRange::cmetaSize() const - { - return sizeof(size_t); - } - - std::string GenSingleRange::stringMeta(size_t pos) const - { - return std::to_string(get(pos)); - } - - vector GenSingleRange::data() const - { - DataHeader h = dataHeader(); - vector out; - out.reserve(h.metaSize + sizeof(DataHeader)); - char* hcp = reinterpret_cast(&h); - out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); - const char* scp = reinterpret_cast(&mSize); - out.insert(out.end(), scp, scp + h.metaSize); - return out; - } - - DataHeader GenSingleRange::dataHeader() const - { - DataHeader h; - h.spaceType = static_cast( SpaceType::NONE ); - h.metaSize = sizeof(size_t); - h.multiple = 0; - return h; - } - - - typename GenSingleRange::IndexType GenSingleRange::begin() const - { - GenSingleIndex i( std::dynamic_pointer_cast > - ( std::shared_ptr( RB::mThis ) ) ); - i = 0; - return i; - } - - typename GenSingleRange::IndexType GenSingleRange::end() const - { - GenSingleIndex i( std::dynamic_pointer_cast > - ( std::shared_ptr( RB::mThis ) ) ); - i = size(); - return i; - } -} -