PLCnext API Documentation 25.0.2.69
|
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom. More...
#include <IEnumerator.hxx>
Public Types | |
using | Ptr = std::shared_ptr< IEnumerator > |
The smart pointer type of this interface. | |
using | ValueType = T |
Type of the enumerated values | |
Public Member Functions | |
IEnumerator (void)=default | |
Constructs an IEnumerator instance. | |
IEnumerator (const IEnumerator &arg)=default | |
Deleted copy constructor. | |
IEnumerator (IEnumerator &&arg) noexcept=default | |
Move constructor. | |
IEnumerator & | operator= (const IEnumerator &arg)=default |
Deleted copy-assignment IEnumerator. | |
IEnumerator & | operator= (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... | |
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom.
T | The 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 the 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:
This interface might also be used with a reference type or even const reference type as template parameter, e.g.
|
pure virtual |
Gets the element at the current position.
Depending on the template parameter type of this interface, a reference or even const reference might be returned.
InvalidOperationException | When GetCurrent() is called before MoveNext() or after MoveNext() has returned false once. |
Implemented in Arp::Base::Core::Enumerator< T >::Composite< T >, Arp::Base::Core::Enumerator< T >::Empty< T >, Arp::Base::Core::Enumerator< T >::Filter< T >, Arp::Base::Core::Enumerator< T >, Arp::Base::Core::Enumerator< const DataInfo & >, Arp::Base::Core::Enumerator< ChildTypeInfo >, Arp::Base::Core::Enumerator< TypeInfo >, Arp::Base::Core::Enumerator< const String & >, Arp::Base::Core::Enumerator< T >::StackComposite< T >, Arp::Base::Core::Enumerator< T >::StlAdapter< T >, Arp::Base::Core::Enumerator< T >::Transform< T >, Arp::System::Commons::Io::Directory::Enumerator< Iterator >, Arp::System::Commons::Io::Directory::SearchEnumerator< Iterator >, and Arp::System::Commons::Io::Directory::EmptyEnumerator.
|
pure virtual |
Moves this enumerator to the next position.
false
if the end of the container/collections/enumeration has reached, otherwise true
.Implemented in Arp::Base::Core::Enumerator< T >::Composite< T >, Arp::Base::Core::Enumerator< T >::Empty< T >, Arp::Base::Core::Enumerator< T >::Filter< T >, Arp::Base::Core::Enumerator< T >::StackComposite< T >, Arp::Base::Core::Enumerator< T >::StlAdapter< T >, Arp::Base::Core::Enumerator< T >::Transform< T >, Arp::Plc::Commons::Meta::TypeSystem::TypeDefinition::ChildTypeInfoEnumerator, Arp::Plc::Commons::Meta::TypeSystem::TypeDomain::TypeInfoEnumerator, Arp::System::Commons::Configuration::PlaceholderExpression::Enumerator, Arp::System::Commons::Io::Directory::Enumerator< Iterator >, Arp::System::Commons::Io::Directory::SearchEnumerator< Iterator >, and Arp::System::Commons::Io::Directory::EmptyEnumerator.