4#ifndef UTILS_PROXY_CONTAINER_H
5#define UTILS_PROXY_CONTAINER_H
36template <
bool isConst>
49template <
typename Container, AccessPolicy accessPolicy>
52 using ContainerPtr = std::conditional<accessPolicy==AccessPolicy::Const , const ContainerNonConst *, ContainerNonConst *>::type;
53 using ContainerType = std::conditional<accessPolicy==AccessPolicy::Const , const ContainerNonConst, ContainerNonConst>::type;
57template <
typename Container>
61template <
typename IndexType>
65template <
typename IndexType>
86template <
typename T_Proxy,
typename T_ContainerPtr,
typename T_Index>
89template <
typename T_Proxy>
92template <
typename T_DestProxy,
typename T_SrcProxy>
112 typename ElementIndexType>
114 static constexpr bool isConst = std::is_const_v<Container>;
117 using ContainerPtr = std::conditional<isConst , const ContainerNonConst *, ContainerNonConst *>::type;
134 template <
class OtherContainer>
136 requires(std::is_same_v<ContainerNonConst, typename OtherContainer::ContainerNonConst>
137 && (!OtherContainer::isConst ||
isConst) )
173 typename ElementIndexType>
175 static constexpr bool isConst = std::is_const_v<Container>;
178 using ContainerPtr = std::conditional<isConst , const ContainerNonConst *, ContainerNonConst *>::type;
180 template <
class OtherContainer>
182 requires(std::is_same_v<ContainerNonConst, typename OtherContainer::ContainerNonConst> || !OtherContainer::isConst)
236 template<
class OtherContainer>
242 return this->
m_index == other.m_index;
255 return ElementProxy::create(ptr,std::move(element_index));
267 return ElementProxy(ptr,std::move(element_index));
277 return ElementProxy::create(ptr, std::move(element_index));
280 return ElementProxy(ptr, std::move(element_index));
299 (void) BASE::operator++();
303 (void) BASE::operator+=(offset);
314 template<
class OtherContainer>
316 requires(std::is_same_v<typename BASE::ContainerNonConst, typename ProxyIteratorBase<OtherContainer, T_Derived, ElementProxy>::ContainerNonConst>)
322 using value_type =
decltype( std::declval<BASE>().operator *());
326 template <
typename T>
329 static std::int64_t
diff(
const T &
a,
const T &b)
330 requires(std::is_integral_v<T>)
334 static auto diff(
const T &
a,
const T &b)
339 static void diff([[maybe_unused]]
const T &
a, [[maybe_unused]]
const T &b)
345 std::declval<typename BASE::element_index_t>()) );
397 template <
typename T_RWProxy>
424 return element_proxy.index() - T_Derived::beginIndex(this->
cptr(),
m_index);
428 template <
typename T_ElementProxy>
433 return ElementProxy::getOriginalElementIndex(element_proxy.index()) - T_Derived::beginIndex(this->
cptr(),
m_index);
458 { assert( element_count <
size() );
464 { assert( element_count <
size() );
470 { assert( !
empty() );
475 { assert( !
empty() );
481 { assert(this->
size() > 0);
482 std::size_t element_count = this->
size()-1;
488 { assert(this->
size() > 0);
490 std::size_t element_count = this->
size()-1;
499 requires (std::is_same_v<index_t,RootNodeIndex> && std::is_convertible_v<std::size_t, element_index_t> &&
hasSize<ContainerNonConst> )
508 requires (std::is_same_v<index_t,RootNodeIndex> && std::is_convertible_v<std::size_t, element_index_t> &&
hasSize<Container>)
510 assert( !
container ||
container->size() < std::numeric_limits<element_index_t>::max());
518 return ++element_index;
528 {
return T_Derived::beginIndex(
container,this_index) + element_counter; }
storage of the time histories of all the cells
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
AccessPolicy
Indicate whether a container provides read only or read write access.
static constexpr AccessPolicy accessPolicy
static constexpr AccessPolicy accessPolicy
std::remove_cvref_t< Container > ContainerNonConst
std::conditional< accessPolicy==AccessPolicy::Const, const ContainerNonConst, ContainerNonConst >::type ContainerType
std::conditional< accessPolicy==AccessPolicy::Const, const ContainerNonConst *, ContainerNonConst * >::type ContainerPtr
ContainerNonConst * ptr()
std::remove_cvref_t< Container > ContainerNonConst
ContainerNonConst & container()
Return a non const pointer of the container which contains the elements this proxy refers to provided...
ContainerProxyBase(const ContainerProxyBase< OtherContainer, ElementIndexType > &a)
static constexpr bool isConst
ContainerProxyBase(ContainerNonConst *container)
ContainerProxyBase(const ContainerNonConst *container)
ElementIndexType element_index_t
const ContainerNonConst & container() const
std::conditional< isConst, const ContainerNonConst *, ContainerNonConst * >::type ContainerPtr
const ContainerNonConst * cptr() const
The proxy container object which provides the means to iterate over its elements and create element p...
const index_t & index() const
The index of this proxy container which identifies this proxy container within the parent container.
auto operator[](std::size_t element_count) const
Element access operator (read-only access)
BASE::ContainerNonConst ContainerNonConst
ProxyIterator< ContainerNonConst, RawDataContainerProxy< T_RawDataContainer, T_RawDataProxy >, T_RawDataProxy > iterator
std::size_t size() const
Default implementation to compute the number of elements this proxy container contains/refers to The ...
const_iterator begin() const
Get the begin iterator of this proxy container for read only element access.
auto operator[](std::size_t element_count)
Element access operator (read-write access)
iterator end()
Get the end iterator of this proxy container for read write element access provided the access policy...
auto front()
Get a proxy for the first child element (read-write).
static element_index_t elementIndexAt(const ContainerNonConst *container, const index_t &this_index, std::size_t element_counter)
Default implementation to get the full index of a certain element.
std::size_t empty() const
Default implementation to test whether the container does not contain elements.
ContainerProxy(const ContainerNonConst *container, const index_t &index)
Create a sub-container proxy with read-only access to its elements which is only possible if the cont...
auto back()
Get a proxy for the last child element (read-write).
ContainerProxy(const T_RWProxy &other)
Create a read only element proxy from a read write proxy.
element_index_t computeChildElementIndex(const T_ElementProxy &element_proxy) const
compute the "index" of the given element which can be used to recover this element via the access ope...
const_iterator end() const
Get the end iterator of this proxy container for read only element access.
ContainerProxy(const ContainerNonConst *container)
Create a root container proxy with read-only access to its elements which is only possible if the con...
ProxyIterator< const ContainerNonConst, RawDataContainerProxy< T_RawDataContainer, T_RawDataProxy >, T_RawDataProxy > const_iterator
element_index_t computeChildElementIndex(const ElementProxy &element_proxy) const
Compute the "index" of the given element which can be used to recover this element via the access ope...
iterator begin()
Get the begin iterator of this proxy container for read write element access provided the access poli...
ContainerProxy(ContainerNonConst *container, const index_t &index)
Create a sub-container proxy with read-write access to its elements where a sub-container proxy is a ...
ContainerProxyBase< T_RawDataContainer, typename T_RawDataProxy::index_t > BASE
static element_index_t nextElementIndex(const ContainerNonConst *container, element_index_t &&element_index)
ContainerProxy(ContainerNonConst *container)
Create a root container proxy with read-write access to its elements where a root container proxy ref...
static element_index_t beginIndex(const ContainerNonConst *container, const index_t &this_index)
Default implementation to get the index of the first element of this proxy container For a full range...
T_RawDataProxy value_type
static element_index_t endIndex(const ContainerNonConst *container, const index_t &this_index)
Default implementation to get the index after the last element of this proxy container For a full ran...
auto front() const
Get a proxy for the first child element (read-only) The operation is undefined if there are no child ...
typename T_RawDataProxy::index_t element_index_t
auto back() const
Get a proxy for the last child element (read-only).
static constexpr bool isConst
std::remove_cvref_t< T_RawDataContainer > ContainerNonConst
ElementProxyBase(ContainerNonConst *container, index_t &&index)
ElementProxyBase(const ElementProxyBase< OtherContainer, ElementIndexType > &other)
const ContainerNonConst & container() const
std::conditional< isConst, const ContainerNonConst *, ContainerNonConst * >::type ContainerPtr
const ContainerNonConst * cptr() const
ElementProxyBase(const ContainerNonConst *container, const index_t &index)
ContainerNonConst & container()
ElementProxyBase(const ContainerNonConst *container, index_t &&index)
ElementProxyBase(ContainerNonConst *container, const index_t &index)
Base class of iterators to iterate over the elements of this proxy container.
ProxyIteratorBase & operator+=(std::size_t offset)
typename ElementProxy::index_t element_index_t
ElementProxyBase< Container, element_index_t > BASE
static auto createElementProxy(const BASE::ContainerNonConst *ptr, element_index_t &&element_index)
Create a proxy for one element of the "container" this proxy represents (read-only access).
bool operator==(const ProxyIteratorBase< OtherContainer, T_Derived, ElementProxy > &other) const
static auto createElementProxy(const BASE::ContainerNonConst *ptr, element_index_t &&element_index)
Create a proxy for one element of the "container" this proxy represents (read-only access).
static auto createElementProxy(BASE::ContainerNonConst *ptr, element_index_t &&element_index)
Create a proxy for one element of the "container" this proxy represents (read-write access).
ProxyIteratorBase & operator++()
static auto diff(const T &a, const T &b)
static std::int64_t diff(const T &a, const T &b)
static void diff(const T &a, const T &b)
ProxyIterator operator++(int)
decltype(diff_type_helper< typename BASE::element_index_t >::diff(std::declval< typename BASE::element_index_t >(), std::declval< typename BASE::element_index_t >())) difference_type
ProxyIterator & operator++()
decltype(std::declval< BASE >().operator*()) value_type
bool operator!=(const ProxyIteratorBase< OtherContainer, T_Derived, ElementProxy > &other) const
ProxyIterator & operator+=(std::size_t offset)
ProxyIteratorBase< Container, T_Derived, ElementProxy > BASE
Helper struct to indicate the "index" of a top level container proxy.