PLCnext API Documentation 25.0.2.69
Enumerator.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/Exception.hpp"
9#include "Arp/Base/Core/IEnumerator.hxx"
10
11namespace Arp { namespace Base { namespace Core
12{
13
22template<class T>
23class Enumerator : public IEnumerator<T>
24{
25public: // forwards of nested classes
26 class Empty;
27 class Composite;
28 class StackComposite;
29
30 template<class Predicate>
31 class Filter;
32 template<class Iterator, class IteratorAdapter>
33 class StlAdapter;
34 template<typename SourceEnumerator, typename TransformOperation>
35 class Transform;
36 template<class Iterator>
37 class IteratorAdapters;
38
39public: // construction/destruction
41 Enumerator(const Enumerator& arg) = delete;
42 Enumerator(Enumerator&& arg)noexcept;
43 Enumerator& operator=(const Enumerator& arg) = delete;
45 ~Enumerator(void)override;
46
47public: // static factory operations
48 static typename IEnumerator<T>::Ptr CreateEmpty(void);
49 static typename IEnumerator<T>::Ptr CreateComposite(typename IEnumerator<T>::Ptr first, typename IEnumerator<T>::Ptr second);
50
51 template<class TIterator>
52 static typename IEnumerator<T>::Ptr CreateStlAdapter(TIterator begin, TIterator end);
53
54 template<class TContainer>
55 static typename IEnumerator<T>::Ptr CreateStlAdapter(TContainer& c);
56
57 template<class TContainer>
58 static typename IEnumerator<T>::Ptr CreateStlAdapter(const TContainer& c);
59
60 template<class TContainer>
61 static typename IEnumerator<T>::Ptr CreateKeysAdapter(TContainer& c);
62
63 template<class TContainer>
64 static typename IEnumerator<T>::Ptr CreateKeysAdapter(const TContainer& c);
65
66 template<class TContainer>
67 static typename IEnumerator<T>::Ptr CreateMappedAdapter(TContainer& c);
68
69 template<class TContainer>
70 static typename IEnumerator<T>::Ptr CreateMappedAdapter(const TContainer& c);
71
72 template<class Predicate>
73 static typename IEnumerator<T>::Ptr CreateFilter(typename IEnumerator<T>::Ptr source, Predicate predicate);
74
75 template<class SourceEnumerator, class TransformOperation>
76 static typename IEnumerator<T>::Ptr CreateTransform(std::shared_ptr<SourceEnumerator> source, TransformOperation transformOp);
77
78public: // overridden operations inherited from IEnumerator
79 T GetCurrent(void)override;
80
81private: // usings
82 // remove const and & qualifier
83 using TCurrent = typename std::remove_const<typename std::remove_reference<T>::type>::type;
84
85protected:
86 TCurrent current{};
87};
88
90// inline methods of class Enumerator<T>
91
93template<class T>
94inline Enumerator<T>::Enumerator() = default;
95
98template<class T>
99inline Enumerator<T>::Enumerator(Enumerator&& arg)noexcept = default;
100
104template<class T>
105inline typename Enumerator<T>::Enumerator& Enumerator<T>::operator=(Enumerator&& arg)noexcept = default;
106
108template<class T>
109inline Enumerator<T>::~Enumerator() = default;
110
111// inherited doc
112template<class T>
114{
115 return this->current;
116}
117
118}}} // end of namespace Arp::Base::Core
119
120namespace Arp {
123}
Use this class to build a single enumerator by two given enumerator, e.g. to enumerate multiple conta...
Definition: Enumerator.Composite.hxx:20
Implements an empty enumerator, that is, every call to Enumerator<T>::Empty::MoveNext() will return f...
Definition: Enumerator.Empty.hxx:22
This class implements a filtering enumerator. It enumerates all nodes of the source enumerator matchi...
Definition: Enumerator.Filter.hxx:19
This class implements several adapter of STL iterators to extract specific properties.
Definition: Enumerator.IteratorAdapters.hxx:18
Use this class to build a single enumerator by multiple other enumerators using a stack
Definition: Enumerator.StackComposite.hxx:23
This class implements an enumerator adapter for STL container based on iterators.
Definition: Enumerator.StlAdapter.hxx:23
This class implements a transforming enumerator. A transform operation is applied to each element.
Definition: Enumerator.Transform.hxx:21
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:24
static IEnumerator< T >::Ptr CreateMappedAdapter(TContainer &c)
Creates an enumerator adapter from the given STL map enumerating the mapped items.
Definition: Enumerator.StlAdapter.hxx:171
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.
Definition: Enumerator.Composite.hxx:122
Enumerator & operator=(Enumerator &&arg) noexcept
Move assignment operator.
static IEnumerator< T >::Ptr CreateKeysAdapter(TContainer &c)
Creates an enumerator adapter from the given STL map enumerating the keys.
Definition: Enumerator.StlAdapter.hxx:149
static IEnumerator< T >::Ptr CreateStlAdapter(TIterator begin, TIterator end)
Creates an enumerator adapter from the given STL iterators.
Definition: Enumerator.StlAdapter.hxx:116
TCurrent current
The current field of this enumerator.
Definition: Enumerator.hxx:86
Enumerator(Enumerator &&arg) noexcept
Move constructor.
static IEnumerator< T >::Ptr CreateEmpty(void)
Creates an empty enumerator.
Definition: Enumerator.Empty.hxx:77
static IEnumerator< T >::Ptr CreateFilter(typename IEnumerator< T >::Ptr source, Predicate predicate)
Creates a filtering adapter enumerating only the nodes matching a given predicate.
Definition: Enumerator.Filter.hxx:104
Enumerator(void)
Constructs a default Enumerator instance.
~Enumerator(void) override
Destructs this instance and frees all resources.
T GetCurrent(void) override
Gets the element at the current position.
Definition: Enumerator.hxx:113
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom.
Definition: IEnumerator.hxx:49
std::shared_ptr< IEnumerator > Ptr
The smart pointer type of this interface.
Definition: IEnumerator.hxx:52
Root namespace for the PLCnext API