PLCnext API Documentation 23.0.2.9
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Protected Member Functions | List of all members
Arp::IEnumerator< T > Class Template Referenceabstract

Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom. More...

#include <IEnumerator.hxx>

Inheritance diagram for Arp::IEnumerator< T >:
Inheritance graph

Public Types

typedef std::shared_ptr< IEnumeratorPtr
 The smart pointer tpye of this interface.
 

Public Member Functions

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...
 

Protected Member Functions

 IEnumerator (void)=default
 Constructs an IEnumerator instance.
 
virtual ~IEnumerator (void)=default
 Destructs this instance and frees all resources.
 
 IEnumerator (const IEnumerator &arg)=default
 Copies an IEnumerator instance. More...
 
IEnumeratoroperator= (const IEnumerator &arg)=default
 Assigns an IEnumerator instance. More...
 

Detailed Description

template<class T>
class Arp::IEnumerator< T >

Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom.

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

The enumerator pattern is more easy to implement and to use, because the C++ iterator idiom always requires two arguments (begin, end) when defining algorithms or other operations working on containers or collections.

There is one big difference between iterators and enumerators: When a begin iterator is created it points to the first position of teh container/collection immediately. In contrast the enumerator has to be moved once after creation before accessing the first element of a container/collection. Thus, iterators are mostly used with for loops (or range based for loops), but enumerators should always be used with while loops as shown in the following example:

IEnumerator<Any> e = GetAnyEnumerator();
while(e.MoveNext())
{
// do anything with e.GetCurrent()
}
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom.
Definition: IEnumerator.hxx:48
virtual bool MoveNext(void)=0
Moves this enumerator to the next position.

This interface might also be used with a reference type or even const reference type as template parameter, e.g.

IEnumerator<Any&> e = GetAnyRefEnumerator();
while(e.MoveNext())
{
Any& item = e.GetCurrent(); // no copy of e.Current
}
IEnumerator<const Any&> e = GetAnyConstRefEnumerator();
while(e.MoveNext())
{
const Any& item = e.GetCurrent(); // no copy of e.Current, item is not mutable
}
virtual T GetCurrent(void)=0
Gets the element at the current position.

Constructor & Destructor Documentation

◆ IEnumerator()

template<class T >
Arp::IEnumerator< T >::IEnumerator ( const IEnumerator< T > &  arg)
protecteddefault

Copies an IEnumerator instance.

Parameters
argThe argument to copy.

Member Function Documentation

◆ GetCurrent()

template<class T >
virtual T Arp::IEnumerator< T >::GetCurrent ( void  )
pure virtual

◆ MoveNext()

template<class T >
virtual bool Arp::IEnumerator< T >::MoveNext ( void  )
pure virtual

◆ operator=()

template<class T >
IEnumerator & Arp::IEnumerator< T >::operator= ( const IEnumerator< T > &  arg)
protecteddefault

Assigns an IEnumerator instance.

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

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