From 53aa87c3624feff4e0fdb0fd5e515ae1299c55d9 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sat, 31 Dec 2022 19:43:06 +0100 Subject: [PATCH] index format --- src/include/ranges/index_format.cc.h | 128 +++++++++++++++++++++++++++ src/include/ranges/index_format.h | 89 +++++++++++++++++++ src/include/ranges/ranges.cc.h | 1 + src/include/ranges/ranges.h | 1 + src/lib/CMakeLists.txt | 1 + src/lib/ranges/index_format.cc | 30 +++++++ 6 files changed, 250 insertions(+) create mode 100644 src/include/ranges/index_format.cc.h create mode 100644 src/include/ranges/index_format.h create mode 100644 src/lib/ranges/index_format.cc diff --git a/src/include/ranges/index_format.cc.h b/src/include/ranges/index_format.cc.h new file mode 100644 index 0000000..21eee1b --- /dev/null +++ b/src/include/ranges/index_format.cc.h @@ -0,0 +1,128 @@ + +#ifndef __cxz_index_format_cc_h__ +#define __cxz_index_format_cc_h__ + +#include "index_format.h" + +namespace CNORXZ +{ + /*************** + * MFormat * + ***************/ + + template + constexpr MFormat::MFormat(const Arr& b) : + mB(b) + {} + + template + template + constexpr MFormat::MFormat(const FormatT& f) + { + static_assert(f.size() == N, "try to assign format of wrong dimension"); + iter<0,N>( [&](auto i) { mB[i] = f[i]; }, NoF{} ); + } + + template + const Arr& MFormat::all() const + { + return mB; + } + + template + constexpr decltype(auto) MFormat::size() const + { + return std::integral_constant{}; + } + + template + template + constexpr decltype(auto) MFormat::get(std::integral_constant i) const + { + return std::get(mB); + } + + template + template + constexpr decltype(auto) MFormat::operator[](std::integral_constant i) const + { + return get(i); + } + + + /**************** + * GMFormat * + ****************/ + + template + constexpr GMFormat::GMFormat(const Tuple& b) : + mB(b) + {} + + template + template + constexpr GMFormat::GMFormat(const FormatT& f) + { + static_assert(f.size() == size(), "try to assign format of wrong dimension"); + iter<0,sizeof...(PosT)>( [&](auto i) { mB[i] = f[i]; }, NoF{} ); + } + + template + const Tuple& GMFormat::all() const + { + return mB; + } + + template + constexpr decltype(auto) GMFormat::size() const + { + return std::integral_constant{}; + } + + template + template + constexpr decltype(auto) GMFormat::get(std::integral_constant i) const + { + return std::get(mB); + } + + template + template + constexpr decltype(auto) GMFormat::operator[](std::integral_constant i) const + { + return get(i); + } + + /*************** + * YFormat * + ***************/ + + template + YFormat::YFormat(const FormatT& f) : mB(f.size()) + { + // replace by check if integral constant + if constexpr(is_static_format::value){ + iter<0,f.size()>( [&](auto i) { mB[i] = f[i]; }, NoF{} ); + } + else { + for(SizeT i = 0; i != mB.size(); ++i){ + mB[i] = f[i]; + } + } + } + + template + const UPos& YFormat::get(std::integral_constant i) const + { + return mB[i]; + } + + template + const UPos& YFormat::operator[](std::integral_constant i) const + { + return mB[i]; + } + +} + +#endif diff --git a/src/include/ranges/index_format.h b/src/include/ranges/index_format.h new file mode 100644 index 0000000..07485df --- /dev/null +++ b/src/include/ranges/index_format.h @@ -0,0 +1,89 @@ + +#ifndef __cxz_index_format_h__ +#define __cxz_index_format_h__ + +#include "base/base.h" +#include "xpr/xpr.h" + +namespace CNORXZ +{ + template struct is_static_format { CXZ_CVAL_FALSE; }; + + template + class MFormat + { + public: + SP_DEFAULT_MEMBERS(constexpr,MFormat); + explicit constexpr MFormat(const Arr& b); + + template + constexpr MFormat(const FormatT& f); + + const Arr& all() const; + constexpr decltype(auto) size() const; + + template + constexpr decltype(auto) get(std::integral_constant i) const; + + template + constexpr decltype(auto) operator[](std::integral_constant i) const; + + private: + Arr mB; + + }; + + template struct is_static_format> { CXZ_CVAL_TRUE; }; + + template + class GMFormat + { + public: + SP_DEFAULT_MEMBERS(constexpr,GMFormat); + explicit constexpr GMFormat(const Tuple& b); + + template + constexpr GMFormat(const FormatT& f); + + const Tuple& all() const; + constexpr decltype(auto) size() const; + + template + constexpr decltype(auto) get(std::integral_constant i) const; + + template + constexpr decltype(auto) operator[](std::integral_constant i) const; + + private: + Tuple mB; + }; + + template struct is_static_format> { CXZ_CVAL_TRUE; }; + + class YFormat + { + public: + DEFAULT_MEMBERS(YFormat); + explicit YFormat(const Vector& b); + + template + YFormat(const FormatT& f); + + const Vector& all() const; + SizeT size() const; + + template + const UPos& get(std::integral_constant i) const; + + template + const UPos& operator[](std::integral_constant i) const; + + const UPos& get(SizeT i) const; + const UPos& operator[](SizeT i) const; + + private: + Vector mB; + }; +} + +#endif diff --git a/src/include/ranges/ranges.cc.h b/src/include/ranges/ranges.cc.h index 59de5f9..7537d90 100644 --- a/src/include/ranges/ranges.cc.h +++ b/src/include/ranges/ranges.cc.h @@ -9,3 +9,4 @@ #include "lindex.cc.h" #include "index_mul.cc.h" #include "index_pack.cc.h" +#include "index_format.cc.h" diff --git a/src/include/ranges/ranges.h b/src/include/ranges/ranges.h index 801ad48..380ece0 100644 --- a/src/include/ranges/ranges.h +++ b/src/include/ranges/ranges.h @@ -11,5 +11,6 @@ #include "lindex.h" #include "index_mul.h" #include "index_pack.h" +#include "index_format.h" #include "ranges.cc.h" diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 0d469b1..f405cfc 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -7,6 +7,7 @@ set(libcnorxz_a_SOURCES ${CMAKE_SOURCE_DIR}/src/lib/ranges/crange.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/dindex.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/index_pack.cc + ${CMAKE_SOURCE_DIR}/src/lib/ranges/index_format.cc ) add_library(cnorxz_obj OBJECT diff --git a/src/lib/ranges/index_format.cc b/src/lib/ranges/index_format.cc new file mode 100644 index 0000000..33177f2 --- /dev/null +++ b/src/lib/ranges/index_format.cc @@ -0,0 +1,30 @@ + +#include "ranges/index_format.h" + +namespace CNORXZ +{ + YFormat::YFormat(const Vector& b) : + mB(b) + {} + + const Vector& YFormat::all() const + { + return mB; + } + + SizeT YFormat::size() const + { + return mB.size(); + } + + const UPos& YFormat::get(SizeT i) const + { + return mB[i]; + } + + const UPos& YFormat::operator[](SizeT i) const + { + return mB[i]; + } + +}