ATLAS Offline Software
Loading...
Searching...
No Matches
Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy > Struct Template Reference

The proxy container object which provides the means to iterate over its elements and create element proxy objects @tparm Container The container type this proxy refers to e.g. More...

#include <ProxyContainer.h>

Inheritance diagram for Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >:
Collaboration diagram for Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >:

Classes

struct  iterator_base
 Base class of iterators to iterate over the elements of this proxy container. More...

Public Types

using value_type = ElementProxy
using index_t = IndexType
using element_index_t = typename ElementProxy::index_t
using BASE = ContainerProxyBase<Container, typename ElementProxy::index_t, accessPolicy>
template<AccessPolicy elementAccessPolicy>
using ElementProxyBase = typename BASE::template ElementProxyBase<elementAccessPolicy>
using iterator = iterator_base<AccessPolicy::ReadWrite>
using const_iterator = iterator_base<AccessPolicy::ReadOnly>
using ContainerPtr
using ConstContainerPtr

Public Member Functions

 ContainerProxy (Container *container)
 Create a root container proxy with read-write access to its elements where a root container proxy refers to the top node of a container hierarchy.
 ContainerProxy (const Container *container)
 Create a root container proxy with read-only access to its elements which is only possible if the accessPolicy of this proxy container class permits read-write access.
 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 container proxy which is an element of a parent container proxy.
 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 accessPolicy of this proxy container class permits read-write access.
template<typename T_RWProxy>
requires (accessPolicy == AccessPolicy::ReadOnly && isConvertableToReadOnlyProxy<ContainerProxy<Container, T_Derived, ElementProxy, IndexType, accessPolicy>, T_RWProxy> )
 ContainerProxy (const T_RWProxy &other)
 Create a read only element proxy from a read write proxy.
const index_tindex () const
 The index of this proxy container which identifies this proxy container within the parent container.
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 operator [].
template<typename T_ElementProxy>
requires ( hasCreateProxy<ElementProxy, const Container *, element_index_t> || hasCreateProxy<ElementProxy, Container *, element_index_t>)
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 operator [].
iterator begin ()
 Get the begin iterator of this proxy container for read write element access provided the access policy permits it.
iterator end ()
 Get the end iterator of this proxy container for read write element access provided the access policy permits it.
const_iterator begin () const
 Get the begin iterator of this proxy container for read only element access.
const_iterator end () const
 Get the end iterator of this proxy container for read only element access.
auto operator[] (std::size_t element_count) const
 Element access operator (read-only access)
auto operator[] (std::size_t element_count)
 Element access operator (read-write access)
auto front () const
 Get a proxy for the first child element (read-only) The operation is undefined if there are no child elements.
auto front ()
 Get a proxy for the first child element (read-write).
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).
std::size_t size () const
 Default implementation to compute the number of elements this proxy container contains/refers to The default implementation simply computes the differences between the end index and begin index, thus the IndexType has to implement the subtraction operator.
std::size_t empty () const
 Default implementation to test whether the container does not contain elements.
const Containercontainer () const
 return a const pointer of the container which contains the elements this proxy refers to.

Static Public Member Functions

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).
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).
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 container proxy e.g.
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 range container proxy e.g.
static element_index_t nextElementIndex (const Container *container, element_index_t &&element_index)
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.

Public Attributes

index_t m_index
ContainerPtrBase< accessPolicy > m_container

Detailed Description

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
struct Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >

The proxy container object which provides the means to iterate over its elements and create element proxy objects @tparm Container The container type this proxy refers to e.g.

CellData @tparm T_Derived The derived class of this proxy container class, which may have to define static methods to enable the iteration: element_index_t beginIndex(const container *, IndexType this_container_index); element_index_t endIndex(const container *, IndexType this_container_index); element_index_t nextIndex(const container *, element_index_t element_index);

Template Parameters
ElementProxyThe class to be used for element proxy objects, which can be a derived class of another ContainerProxy, or an ElementProxyBase
IndexTypeThe index type which is used to identify the element this container proxy refers to to if this container proxy is en element of a parent container proxy. The IndexType has to implement at least the equality operator. In most cases also a prefix increment operator is needed, which could also be implemented in the static method nextElementIndex of the parent container proxy.
accessPolicyTo choose read-only or read-write access (read-only is default)

Definition at line 267 of file ProxyContainer.h.

Member Typedef Documentation

◆ BASE

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
using Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::BASE = ContainerProxyBase<Container, typename ElementProxy::index_t, accessPolicy>

Definition at line 274 of file ProxyContainer.h.

◆ const_iterator

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
using Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::const_iterator = iterator_base<AccessPolicy::ReadOnly>

Definition at line 364 of file ProxyContainer.h.

◆ ConstContainerPtr

using Utils::ContainerProxyBase< Container, ElementProxy::index_t, accessPolicy >::ConstContainerPtr
inherited

Definition at line 181 of file ProxyContainer.h.

◆ ContainerPtr

using Utils::ContainerProxyBase< Container, ElementProxy::index_t, accessPolicy >::ContainerPtr
inherited

Definition at line 180 of file ProxyContainer.h.

◆ element_index_t

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
using Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::element_index_t = typename ElementProxy::index_t

Definition at line 270 of file ProxyContainer.h.

◆ ElementProxyBase

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
template<AccessPolicy elementAccessPolicy>
using Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::ElementProxyBase = typename BASE::template ElementProxyBase<elementAccessPolicy>

Definition at line 332 of file ProxyContainer.h.

◆ index_t

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
using Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::index_t = IndexType

Definition at line 269 of file ProxyContainer.h.

◆ iterator

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
using Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::iterator = iterator_base<AccessPolicy::ReadWrite>

Definition at line 362 of file ProxyContainer.h.

◆ value_type

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
using Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::value_type = ElementProxy

Definition at line 268 of file ProxyContainer.h.

Constructor & Destructor Documentation

◆ ContainerProxy() [1/5]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::ContainerProxy ( Container * container)
inline

Create a root container proxy with read-write access to its elements where a root container proxy refers to the top node of a container hierarchy.

Definition at line 278 of file ProxyContainer.h.

280 : BASE(container), m_index() {}
ContainerProxyBase< Container, typename ElementProxy::index_t, accessPolicy > BASE

◆ ContainerProxy() [2/5]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::ContainerProxy ( const Container * container)
inline

Create a root container proxy with read-only access to its elements which is only possible if the accessPolicy of this proxy container class permits read-write access.

Definition at line 284 of file ProxyContainer.h.

286 : BASE(container), m_index() {}

◆ ContainerProxy() [3/5]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::ContainerProxy ( Container * container,
const index_t & index )
inline

Create a sub-container proxy with read-write access to its elements where a sub-container proxy is a container proxy which is an element of a parent container proxy.

Definition at line 291 of file ProxyContainer.h.

const index_t & index() const
The index of this proxy container which identifies this proxy container within the parent container.

◆ ContainerProxy() [4/5]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::ContainerProxy ( const Container * container,
const index_t & index )
inline

Create a sub-container proxy with read-only access to its elements which is only possible if the accessPolicy of this proxy container class permits read-write access.

Definition at line 294 of file ProxyContainer.h.

◆ ContainerProxy() [5/5]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
template<typename T_RWProxy>
requires (accessPolicy == AccessPolicy::ReadOnly && isConvertableToReadOnlyProxy<ContainerProxy<Container, T_Derived, ElementProxy, IndexType, accessPolicy>, T_RWProxy> )
Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::ContainerProxy ( const T_RWProxy & other)
inline

Create a read only element proxy from a read write proxy.

Definition at line 298 of file ProxyContainer.h.

302 {}
The proxy container object which provides the means to iterate over its elements and create element p...

Member Function Documentation

◆ back() [1/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::back ( )
inline

Get a proxy for the last child element (read-write).

The operation is undefined if there are no child elements.

Definition at line 441 of file ProxyContainer.h.

442 { assert(this->size() > 0);
443 //coverity[INTEGER_OVERFLOW]
444 std::size_t element_count = this->size()-1;
446 }
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).
std::size_t size() const
Default implementation to compute the number of elements this proxy container contains/refers to The ...

◆ back() [2/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::back ( ) const
inline

Get a proxy for the last child element (read-only).

The operation is undefined if there are no child elements.

Definition at line 434 of file ProxyContainer.h.

435 { assert(this->size() > 0);
436 std::size_t element_count = this->size()-1;
438 }

◆ begin() [1/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
iterator Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::begin ( )
inline

Get the begin iterator of this proxy container for read write element access provided the access policy permits it.

Definition at line 391 of file ProxyContainer.h.

391 {
392 return iterator(this->m_container.ptr(), T_Derived::beginIndex(this->m_container.cptr(), m_index) );
393 }
iterator_base< AccessPolicy::ReadWrite > iterator

◆ begin() [2/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
const_iterator Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::begin ( ) const
inline

Get the begin iterator of this proxy container for read only element access.

Definition at line 400 of file ProxyContainer.h.

400 {
402 }
iterator_base< AccessPolicy::ReadOnly > const_iterator

◆ beginIndex()

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
element_index_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::beginIndex ( const Container * container,
const index_t & this_index )
inlinestatic

Default implementation to get the index of the first element of this proxy container For a full range container proxy e.g.

the root proxy container. this requires that the first element this proxy container refers to is identified by a simple integer index of 0u

Definition at line 452 of file ProxyContainer.h.

454 {
455 return static_cast<element_index_t>(0u);
456 }
typename ElementProxy::index_t element_index_t

◆ computeChildElementIndex() [1/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
element_index_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::computeChildElementIndex ( const ElementProxy & element_proxy) const
inline

Compute the "index" of the given element which can be used to recover this element via the access operator [].

Definition at line 374 of file ProxyContainer.h.

377 {
379 }

◆ computeChildElementIndex() [2/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
template<typename T_ElementProxy>
requires ( hasCreateProxy<ElementProxy, const Container *, element_index_t> || hasCreateProxy<ElementProxy, Container *, element_index_t>)
element_index_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::computeChildElementIndex ( const T_ElementProxy & element_proxy) const
inline

compute the "index" of the given element which can be used to recover this element via the access operator [].

Definition at line 383 of file ProxyContainer.h.

◆ container()

const Container & Utils::ContainerProxyBase< Container, ElementProxy::index_t, accessPolicy >::container ( ) const
inlineinherited

return a const pointer of the container which contains the elements this proxy refers to.

Definition at line 241 of file ProxyContainer.h.

241{ return m_container.container(); }
Base class of a container proxy.

◆ createElementProxy() [1/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::createElementProxy ( const Container * ptr,
element_index_t && element_index )
inlinestatic

Create a proxy for one element of the "container" this proxy represents (read-only access).

Parameters
ptrA pointer to the container which contains the element data
element_indexAn index which identifies the element in the given container.
Returns
A new proxy which represents the specified element.

Definition at line 308 of file ProxyContainer.h.

308 {
309 if constexpr(hasCreateProxy<ElementProxy, decltype(ptr), element_index_t> ) {
311 }
312 else {
314 }
315 }

◆ createElementProxy() [2/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::createElementProxy ( Container * ptr,
element_index_t && element_index )
inlinestatic

Create a proxy for one element of the "container" this proxy represents (read-write access).

Parameters
ptrA pointer to the container which contains the element data
element_indexAn index which identifies the element in the given container.
Returns
A new proxy which represents the specified element.

Definition at line 321 of file ProxyContainer.h.

321 {
322 if constexpr(hasCreateProxy<ElementProxy, decltype(ptr), element_index_t> ) {
324 }
325 else {
327 }
328 }

◆ elementIndexAt()

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
element_index_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::elementIndexAt ( const Container * container,
const index_t & this_index,
std::size_t element_counter )
inlinestatic

Default implementation to get the full index of a certain element.

Parameters
containerThe container which contains the element data,
this_indexThe index of this proxy.
element_counterthe number of iterations from the first element to reach this element.
Returns
the full index of the specified element which fully identifies this element in the given container.

Definition at line 480 of file ProxyContainer.h.

◆ empty()

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
std::size_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::empty ( ) const
inline

Default implementation to test whether the container does not contain elements.

The default implementation simply tests whether the begin and end index are identical.

Definition at line 498 of file ProxyContainer.h.

499 {
500 return (this->m_container.cptr()
502 : true);
503 }

◆ end() [1/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
iterator Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::end ( )
inline

Get the end iterator of this proxy container for read write element access provided the access policy permits it.

Definition at line 395 of file ProxyContainer.h.

395 {
396 return iterator(this->m_container.ptr(), T_Derived::endIndex(this->m_container.cptr(), m_index) );
397 }

◆ end() [2/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
const_iterator Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::end ( ) const
inline

Get the end iterator of this proxy container for read only element access.

Definition at line 404 of file ProxyContainer.h.

404 {
405 return const_iterator(this->m_container.cptr(), T_Derived::endIndex(this->m_container.cptr(), m_index) );
406 }

◆ endIndex()

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
element_index_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::endIndex ( const Container * container,
const index_t & this_index )
inlinestatic

Default implementation to get the index after the last element of this proxy container For a full range container proxy e.g.

the root proxy container. this requires that the last element this proxy container refers to is identified by a simple integer index which is provided by the size method of the container this proxy container refers to.

Definition at line 461 of file ProxyContainer.h.

463 {
465 return (container ? static_cast<element_index_t>(container->size()) : 0u);
466 }

◆ front() [1/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::front ( )
inline

Get a proxy for the first child element (read-write).

The operation is undefined if there are no child elements.

Definition at line 428 of file ProxyContainer.h.

429 { assert( !empty() );
std::size_t empty() const
Default implementation to test whether the container does not contain elements.

◆ front() [2/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::front ( ) const
inline

Get a proxy for the first child element (read-only) The operation is undefined if there are no child elements.

Definition at line 423 of file ProxyContainer.h.

424 { assert( !empty() );

◆ index()

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
const index_t & Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::index ( ) const
inline

The index of this proxy container which identifies this proxy container within the parent container.

For the top-level proxy container the index will be the empty RootNodeIndex struct. The index is not necessarily an index that can be used as argument for the element access operator of the parent proxy to recover this proxy i.e. parent_proxy[index] is not necessarily this proxy. For the latter use computeChildElementIndex.

Definition at line 371 of file ProxyContainer.h.

371{ return m_index; }

◆ nextElementIndex()

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
element_index_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::nextElementIndex ( const Container * container,
element_index_t && element_index )
inlinestatic

Definition at line 469 of file ProxyContainer.h.

470 {
471 assert( container );
472 return ++element_index;
473 }

◆ operator[]() [1/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::operator[] ( std::size_t element_count)
inline

Element access operator (read-write access)

Parameters
element_countis the "child_index", a consecutive number which is 0 for the first element and size()-1 for the last element
Returns
Proxy representing the specified element

Definition at line 417 of file ProxyContainer.h.

◆ operator[]() [2/2]

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
auto Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::operator[] ( std::size_t element_count) const
inline

Element access operator (read-only access)

Parameters
element_countis the "child_index", a consecutive number which is 0 for the first element and size()-1 for the last element
Returns
Proxy representing the specified element

Definition at line 411 of file ProxyContainer.h.

◆ size()

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
std::size_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::size ( ) const
inline

Default implementation to compute the number of elements this proxy container contains/refers to The default implementation simply computes the differences between the end index and begin index, thus the IndexType has to implement the subtraction operator.

Definition at line 488 of file ProxyContainer.h.

490 {
491 return (this->m_container.cptr()
493 : 0u);
494 }

Member Data Documentation

◆ m_container

ContainerPtrBase<accessPolicy> Utils::ContainerProxyBase< Container, ElementProxy::index_t, accessPolicy >::m_container
inherited

Definition at line 182 of file ProxyContainer.h.

◆ m_index

template<class Container, class T_Derived, class ElementProxy, typename IndexType, AccessPolicy accessPolicy>
index_t Utils::ContainerProxy< Container, T_Derived, ElementProxy, IndexType, accessPolicy >::m_index

Definition at line 271 of file ProxyContainer.h.


The documentation for this struct was generated from the following file: