4#ifndef UTILS_PROXY_CONTAINER_H
5#define UTILS_PROXY_CONTAINER_H
36template <
typename Container>
40template <
typename IndexType>
44template <
typename IndexType>
65template <
typename T_Proxy,
typename T_ContainerPtr,
typename T_Index>
68template <
typename T_Proxy>
71template <
typename T_DestProxy,
typename T_SrcProxy>
96 typename ElementIndexType,
102 template <AccessPolicy ptrAccessPolicy=accessPolicy>
104 template <AccessPolicy IteratorAccessPolicy>
107 using ContainerPtr = std::conditional_t< ptrAccessPolicy == AccessPolicy::ReadOnly, const Container *, Container *>;
109 template <
class _Container,
116 template <AccessPolicy otherAccessPolicy>
145 template <AccessPolicy otherAccessPolicy>
156 template <AccessPolicy otherAccessPolicy>
174 template <AccessPolicy otherAccessPolicy>
189 template <AccessPolicy ptrAccessPolicy=accessPolicy>
217 template <
typename T_RWProxy>
297 template <
typename T_RWProxy>
310 return ElementProxy::create(ptr, std::move(element_index));
313 return ElementProxy(ptr, std::move(element_index));
323 return ElementProxy::create(ptr, std::move(element_index));
326 return ElementProxy(ptr, element_index);
331 template <AccessPolicy elementAccessPolicy>
335 template <AccessPolicy iteratorAccessPolicy>
341 this->
m_index = T_Derived::nextElementIndex(this->m_container.cptr(), std::move(this->m_index));
348 return createElementProxy(this->m_container.template accessPtr<iteratorAccessPolicy>(),
354 template<AccessPolicy otherIteratorAccessPolicy>
356 assert ( this->m_container == other.m_container);
357 return this->
m_index == other.m_index;
362 using iterator = iterator_base<AccessPolicy::ReadWrite>;
378 return element_proxy.index() - T_Derived::beginIndex(this->m_container.cptr(),
m_index);
382 template <
typename T_ElementProxy>
387 return ElementProxy::getOriginalElementIndex(element_proxy.index()) - T_Derived::beginIndex(this->m_container.cptr(),
m_index);
392 return iterator(this->m_container.ptr(), T_Derived::beginIndex(this->m_container.cptr(),
m_index) );
396 return iterator(this->m_container.ptr(), T_Derived::endIndex(this->m_container.cptr(),
m_index) );
401 return const_iterator(this->m_container.cptr(), T_Derived::beginIndex(this->m_container.cptr(),
m_index) );
405 return const_iterator(this->m_container.cptr(), T_Derived::endIndex(this->m_container.cptr(),
m_index) );
412 { assert( element_count <
size() );
413 return createElementProxy(this->m_container.cptr(), T_Derived::elementIndexAt(this->m_container.cptr(), this->m_index,element_count)); }
418 { assert( element_count <
size() );
419 return createElementProxy(this->m_container.ptr(), T_Derived::elementIndexAt(this->m_container.cptr(), this->m_index,element_count));}
424 { assert( !
empty() );
425 return createElementProxy(this->m_container.cptr(), T_Derived::beginIndex(this->m_container.cptr(), this->m_index));}
429 { assert( !
empty() );
430 return createElementProxy(this->m_container.ptr(), T_Derived::beginIndex(this->m_container.cptr(), this->m_index));}
435 { assert(this->
size() > 0);
436 std::size_t element_count = this->
size()-1;
437 return createElementProxy(this->m_container.cptr(), T_Derived::elementIndexAt(this->m_container.cptr(), this->m_index,element_count));
442 { assert(this->
size() > 0);
444 std::size_t element_count = this->
size()-1;
445 return createElementProxy(this->m_container.ptr(), T_Derived::elementIndexAt(this->m_container.ptr(), this->m_index,element_count));
453 requires (std::is_same_v<index_t,RootNodeIndex> && std::is_convertible_v<std::size_t, element_index_t> &&
hasSize<Container> )
462 requires (std::is_same_v<index_t,RootNodeIndex> && std::is_convertible_v<std::size_t, element_index_t> &&
hasSize<Container>)
464 assert( !
container ||
container->size() < std::numeric_limits<element_index_t>::max());
472 return ++element_index;
482 {
return T_Derived::beginIndex(
container,this_index) + element_counter; }
491 return (this->m_container.cptr()
492 ? T_Derived::endIndex(this->m_container.cptr(),
m_index)-T_Derived::beginIndex(this->m_container.cptr(),
m_index)
500 return (this->m_container.cptr()
501 ? T_Derived::endIndex(this->m_container.cptr(),
m_index)==T_Derived::beginIndex(this->m_container.cptr(),
m_index)
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
@breif Indicate whether a container provides read only or read write access
ContainerPtrBase(Container *container)
friend struct ContainerProxy
std::conditional_t< ptrAccessPolicy==AccessPolicy::ReadOnly, const Container *, Container * > ContainerPtr
friend class iterator_base
const Container & operator*() const
ContainerPtrBase(const Container *container)
const Container * cptr() const
const Container & container() const
ContainerPtrBase(ContainerPtrBase< otherAccessPolicy > container)
bool operator==(const ContainerPtrBase< otherAccessPolicy > &other) const
ElementProxyBase(const Container *container, index_t &&index)
const Container & container() const
ElementProxyBase(Container *container, const index_t &index)
ElementProxyBase(const ElementProxyBase< AccessPolicy::ReadWrite > &other)
ElementProxyBase(const ElementProxyBase< ptrAccessPolicy > &other)
ContainerPtrBase< ptrAccessPolicy > m_container
ElementProxyBase(Container *container, index_t &&index)
ElementProxyBase(const Container *container, const index_t &index)
ElementProxyBase(const T_RWProxy &other)
ElementIndexType element_index_t
ContainerPtrBase< AccessPolicy::ReadWrite > ContainerPtr
ContainerPtrBase< AccessPolicy::ReadOnly > ConstContainerPtr
const Container & container() const
ContainerProxyBase(Container *container)
Container & container()
Return a non const pointer of the container which contains the elements this proxy refers to provided...
ContainerPtrBase< accessPolicy > m_container
ContainerProxyBase(const Container *container)
Base class of iterators to iterate over the elements of this proxy container.
bool operator==(const iterator_base< otherIteratorAccessPolicy > &other) const
iterator_base & operator++()
The proxy container object which provides the means to iterate over its elements and create element p...
T_RawDataProxy value_type
iterator begin()
Get the begin iterator of this proxy container for read write element access provided the access poli...
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...
ContainerProxy(Container *container)
Create a root container proxy with read-write access to its elements where a root container proxy ref...
ContainerProxy(Container *container, const index_t &index)
Create a sub-container proxy with read-write access to its elements where a sub-container proxy is a ...
static auto createElementProxy(const Container *ptr, element_index_t &&element_index)
Create a proxy for one element of the "container" this proxy represents (read-only access).
iterator_base< AccessPolicy::ReadWrite > iterator
const_iterator end() const
Get the end iterator of this proxy container for read only element access.
auto front()
Get a proxy for the first child element (read-write).
auto operator[](std::size_t element_count) const
Element access operator (read-only access)
ContainerProxy(const Container *container)
Create a root container proxy with read-only access to its elements which is only possible if the acc...
static element_index_t beginIndex(const Container *container, const index_t &this_index)
Default implementation to get the index of the first element of this proxy container For a full range...
std::size_t size() const
Default implementation to compute the number of elements this proxy container contains/refers to The ...
static auto createElementProxy(Container *ptr, element_index_t &&element_index)
Create a proxy for one element of the "container" this proxy represents (read-write access).
const index_t & index() const
The index of this proxy container which identifies this proxy container within the parent container.
auto back() const
Get a proxy for the last child element (read-only).
auto back()
Get a proxy for the last child element (read-write).
typename T_RawDataProxy::index_t element_index_t
static element_index_t elementIndexAt(const Container *container, const index_t &this_index, std::size_t element_counter)
Default implementation to get the full index of a certain element.
const_iterator begin() const
Get the begin iterator of this proxy container for read only element access.
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...
static element_index_t endIndex(const Container *container, const index_t &this_index)
Default implementation to get the index after the last element of this proxy container For a full ran...
ContainerProxy(const T_RWProxy &other)
Create a read only element proxy from a read write proxy.
std::size_t empty() const
Default implementation to test whether the container does not contain elements.
auto operator[](std::size_t element_count)
Element access operator (read-write access)
static element_index_t nextElementIndex(const Container *container, element_index_t &&element_index)
iterator_base< AccessPolicy::ReadOnly > const_iterator
auto front() const
Get a proxy for the first child element (read-only) The operation is undefined if there are no child ...
iterator end()
Get the end iterator of this proxy container for read write element access provided the access policy...
ContainerProxy(const Container *container, const index_t &index)
Create a sub-container proxy with read-only access to its elements which is only possible if the acce...
ContainerProxyBase< T_RawDataContainer, typename T_RawDataProxy::index_t, accessPolicy > BASE
typename BASE::template ElementProxyBase< elementAccessPolicy > ElementProxyBase
Helper struct to indicate the "index" of a top level container proxy.