PLCnext API Documentation 25.0.2.69
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Arp::Base::Core::Enumerator< T > Class Template Reference

This class defines a base class for all enumerator implementations and some predefined enumerators as nested classes. More...

#include <Enumerator.hxx>

Inheritance diagram for Arp::Base::Core::Enumerator< T >:
Inheritance graph

Classes

class  Composite
 Use this class to build a single enumerator by two given enumerator, e.g. to enumerate multiple container/collections or trees. More...
 
class  Empty
 Implements an empty enumerator, that is, every call to Enumerator<T>::Empty::MoveNext() will return false. More...
 
class  Filter
 This class implements a filtering enumerator. It enumerates all nodes of the source enumerator matching a given predicate. More...
 
class  IteratorAdapters
 This class implements several adapter of STL iterators to extract specific properties. More...
 
class  StackComposite
 Use this class to build a single enumerator by multiple other enumerators using a stack More...
 
class  StlAdapter
 This class implements an enumerator adapter for STL container based on iterators. More...
 
class  Transform
 This class implements a transforming enumerator. A transform operation is applied to each element. More...
 

Public Member Functions

 Enumerator (void)
 Constructs a default Enumerator instance.
 
 Enumerator (const Enumerator &arg)=delete
 
 Enumerator (Enumerator &&arg) noexcept
 Move constructor. More...
 
Enumeratoroperator= (const Enumerator &arg)=delete
 
Enumeratoroperator= (Enumerator &&arg) noexcept
 Move assignment operator. More...
 
 ~Enumerator (void) override
 Destructs this instance and frees all resources.
 
GetCurrent (void) override
 Gets the element at the current position. More...
 
template<class S , class O >
IEnumerator< T >::Ptr CreateTransform (std::shared_ptr< S > sourcePtr, O transformOperation)
 Creates a transforming adapter enumerating applying a transform operation to each element. More...
 
- Public Member Functions inherited from Arp::Base::Core::IEnumerator< T >
 IEnumerator (void)=default
 Constructs an IEnumerator instance.
 
 IEnumerator (const IEnumerator &arg)=default
 Deleted copy constructor.
 
 IEnumerator (IEnumerator &&arg) noexcept=default
 Move constructor.
 
IEnumeratoroperator= (const IEnumerator &arg)=default
 Deleted copy-assignment IEnumerator.
 
IEnumeratoroperator= (IEnumerator &&arg) noexcept=default
 Move-assignment operator.
 
virtual ~IEnumerator (void)=default
 Destructs this instance and frees all resources.
 
virtual bool MoveNext (void)=0
 Moves this enumerator to the next position. More...
 
virtual T GetCurrent (void)=0
 Gets the element at the current position. More...
 

Static Public Member Functions

static IEnumerator< T >::Ptr CreateEmpty (void)
 Creates an empty enumerator. More...
 
static IEnumerator< T >::Ptr CreateComposite (typename IEnumerator< T >::Ptr first, typename IEnumerator< T >::Ptr second)
 Creates a composite enumerator from the two given enumerators, e.g. to enumerate trees easily. More...
 
template<class TIterator >
static IEnumerator< T >::Ptr CreateStlAdapter (TIterator begin, TIterator end)
 Creates an enumerator adapter from the given STL iterators. More...
 
template<class TContainer >
static IEnumerator< T >::Ptr CreateStlAdapter (TContainer &c)
 Creates an enumerator adapter from the given STL container. More...
 
template<class TContainer >
static IEnumerator< T >::Ptr CreateStlAdapter (const TContainer &c)
 Creates an enumerator adapter from the given STL container. More...
 
template<class TContainer >
static IEnumerator< T >::Ptr CreateKeysAdapter (TContainer &c)
 Creates an enumerator adapter from the given STL map enumerating the keys. More...
 
template<class TContainer >
static IEnumerator< T >::Ptr CreateKeysAdapter (const TContainer &c)
 Creates an enumerator adapter from the given const STL map enumerating the keys. More...
 
template<class TContainer >
static IEnumerator< T >::Ptr CreateMappedAdapter (TContainer &c)
 Creates an enumerator adapter from the given STL map enumerating the mapped items. More...
 
template<class TContainer >
static IEnumerator< T >::Ptr CreateMappedAdapter (const TContainer &c)
 Creates an enumerator adapter from the given const STL map enumerating the mapped items. More...
 
template<class Predicate >
static IEnumerator< T >::Ptr CreateFilter (typename IEnumerator< T >::Ptr source, Predicate predicate)
 Creates a filtering adapter enumerating only the nodes matching a given predicate. More...
 
template<class SourceEnumerator , class TransformOperation >
static IEnumerator< T >::Ptr CreateTransform (std::shared_ptr< SourceEnumerator > source, TransformOperation transformOp)
 

Protected Attributes

TCurrent current {}
 The current field of this enumerator.
 

Additional Inherited Members

- Public Types inherited from Arp::Base::Core::IEnumerator< T >
using Ptr = std::shared_ptr< IEnumerator >
 The smart pointer type of this interface.
 
using ValueType = T
 Type of the enumerated values
 

Detailed Description

template<class T>
class Arp::Base::Core::Enumerator< T >

This class defines a base class for all enumerator implementations and some predefined enumerators as nested classes.

Template Parameters
TThe element type of the container or collection, respectively.

Derive a specialized enumerator implementation from this class to inherit the current field an its getter operation Enumerator<T>::GetCurrent(). Override the Enumerator<T>::MoveNext() operations to implement specific enumeration logic.

Template Parameters
TThe enumerated type.

Constructor & Destructor Documentation

◆ Enumerator()

template<class T >
Arp::Base::Core::Enumerator< T >::Enumerator ( Enumerator< T > &&  arg)
inlinedefaultnoexcept

Move constructor.

Parameters
argThe argument to move.

Member Function Documentation

◆ CreateComposite()

template<class T >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateComposite ( typename IEnumerator< T >::Ptr  first,
typename IEnumerator< T >::Ptr  second 
)
inlinestatic

Creates a composite enumerator from the two given enumerators, e.g. to enumerate trees easily.

Parameters
firstThe first enumerator to create a composite from.
secondThe second enumerator to create a composite from.
Returns
A composite enumerator built from the as arguments passed enumerators.

When enumerating trees using this operations, it is possible to traverse them in DFS (depth-first-search) manner or in BFS (breadth-first-search) manner, depending on the order of passed arguments: If the first enumerator is the one of the current node and the second is the new enumerator of the node children, the tree is enumerated in DFS manner. If the arguments are passed vice-versa, the tree is enumerated in BFS manner.

◆ CreateEmpty()

template<class T >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateEmpty ( void  )
inlinestatic

Creates an empty enumerator.

Returns
An instance of Enumerator<T>::Empty.

◆ CreateFilter()

template<class T >
template<class Predicate >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateFilter ( typename IEnumerator< T >::Ptr  source,
Predicate  filter 
)
inlinestatic

Creates a filtering adapter enumerating only the nodes matching a given predicate.

Parameters
sourceThe source enumerator.
filterThe filter to apply to each element of the source.
Returns
A filtering enumerator of the as argument passed source which is filtered by the given filter .
Template Parameters
PredicateThe type of the filter to apply to each element.

◆ CreateKeysAdapter() [1/2]

template<class T >
template<class TContainer >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateKeysAdapter ( const TContainer &  c)
inlinestatic

Creates an enumerator adapter from the given const STL map enumerating the keys.

Parameters
cThe const STL map to enumerate.
Returns
An enumerator adapter of the as argument passed map enumerating the keys.
Template Parameters
TContainerThe type of the map.

◆ CreateKeysAdapter() [2/2]

template<class T >
template<class TContainer >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateKeysAdapter ( TContainer &  c)
inlinestatic

Creates an enumerator adapter from the given STL map enumerating the keys.

Parameters
cThe STL map to enumerate.
Returns
An enumerator adapter of the as argument passed map enumerating the keys.
Template Parameters
TContainerThe type of the map.

◆ CreateMappedAdapter() [1/2]

template<class T >
template<class TContainer >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateMappedAdapter ( const TContainer &  c)
inlinestatic

Creates an enumerator adapter from the given const STL map enumerating the mapped items.

Parameters
cThe const STL map to enumerate.
Returns
An enumerator adapter of the as argument passed map enumerating the mapped items.
Template Parameters
TContainerThe type of the map.

◆ CreateMappedAdapter() [2/2]

template<class T >
template<class TContainer >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateMappedAdapter ( TContainer &  c)
inlinestatic

Creates an enumerator adapter from the given STL map enumerating the mapped items.

Parameters
cThe STL map to enumerate.
Returns
An enumerator adapter of the as argument passed map enumerating the mapped items.
Template Parameters
TContainerThe type of the map.

◆ CreateStlAdapter() [1/3]

template<class T >
template<class TContainer >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateStlAdapter ( const TContainer &  c)
inlinestatic

Creates an enumerator adapter from the given STL container.

Parameters
cThe const container to enumerate.
Returns
An enumerator adapter of the as argument passed container.
Template Parameters
TContainerThe type of the container.

◆ CreateStlAdapter() [2/3]

template<class T >
template<class TContainer >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateStlAdapter ( TContainer &  c)
inlinestatic

Creates an enumerator adapter from the given STL container.

Parameters
cThe container to enumerate.
Returns
An enumerator adapter of the as argument passed container.
Template Parameters
TContainerThe type of the container.

◆ CreateStlAdapter() [3/3]

template<class T >
template<class TIterator >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateStlAdapter ( TIterator  begin,
TIterator  end 
)
inlinestatic

Creates an enumerator adapter from the given STL iterators.

Parameters
beginThe begin iterator of the container to enumerate.
endThe end iterator of the container to enumerate.
Returns
An enumerator adapter of the as arguments passed iterators.
Template Parameters
TIteratorThe iterator type of the container.

◆ CreateTransform()

template<class T >
template<class S , class O >
IEnumerator< T >::Ptr Arp::Base::Core::Enumerator< T >::CreateTransform ( std::shared_ptr< S >  sourcePtr,
transformOperation 
)
inline

Creates a transforming adapter enumerating applying a transform operation to each element.

Parameters
sourcePtrThe source enumerator.
transformOperationThe transform operation to apply to each element of the source.
Returns
An enumerator where the transform operation is applied to each element in source.
Template Parameters
SThe type of the source enumerator. This may differ from the result enumerator.
OThe type of the transform operation. This may be a function, function object or lambda.

◆ GetCurrent()

template<class T >
T Arp::Base::Core::Enumerator< T >::GetCurrent ( void  )
inlineoverridevirtual

Gets the element at the current position.

Returns
The element at the current position.

Depending on the template parameter type of this interface, a reference or even const reference might be returned.

Exceptions
InvalidOperationExceptionWhen GetCurrent() is called before MoveNext() or after MoveNext() has returned false once.

Implements Arp::Base::Core::IEnumerator< T >.

◆ operator=()

template<class T >
Enumerator< T >::Enumerator & Arp::Base::Core::Enumerator< T >::operator= ( Enumerator< T > &&  arg)
inlinedefaultnoexcept

Move assignment operator.

Parameters
argThe argument to assign to this instance.
Returns
This instance as reference.

The documentation for this class was generated from the following files: