PLCnext API Documentation 25.0.2.69
Enumerator.Transform.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/Detail/Enumerator.hxx"
10
11namespace Arp { namespace Base { namespace Core
12{
13
18template<class T>
19template<typename U, typename O>
20class Enumerator<T>::Transform : public IEnumerator<T>
21{
22private: // usings
23 using SourcePtr = typename IEnumerator<U>::Ptr;
24 using TransformOperation = O;
25
26public: // construction/destruction
27 Transform(SourcePtr sourcePtr, O transformOp);
28 Transform(const Transform& arg) = delete;
29 Transform(Transform&& arg)noexcept;
30 Transform& operator=(const Transform& arg) = delete;
31 Transform& operator=(Transform&& arg)noexcept;
32 ~Transform(void)override;
33
34public: // overridden operations
35 bool MoveNext(void)override;
36 T GetCurrent(void)override;
37
38private: // fields
39 SourcePtr sourcePtr;
40 TransformOperation transformOp;
41};
42
44// inline methods of class Enumerator<T>::TransformEnumerator
45
48template<class T>
49template<class U, class O>
50inline Enumerator<T>::Transform<U, O>::Transform(Transform&& arg)noexcept = default;
51
55template<class T>
56template<class U, class O>
57inline typename Enumerator<T>::Transform<U, O>& Enumerator<T>::Transform<U, O>::operator=(Transform&& arg)noexcept = default;
58
60template<class T>
61template<class U, class O>
63
67template<class T>
68template<class U, class O>
69Enumerator<T>::Transform<U, O>::Transform(SourcePtr sourcePtr, O transformOp)
70 : sourcePtr(std::move(sourcePtr)), transformOp(std::move(transformOp))
71{
72}
73
74// inherited doc
75template<class T>
76template<class U, class O>
78{
79 return this->sourcePtr->MoveNext();
80}
81
82// inherited doc
83template<class T>
84template<class U, class O>
86{
87 return this->transformOp(this->sourcePtr->GetCurrent());
88}
89
90// Implementation of factory operation of class Enumerator<T>
91
98template<class T>
99template<class S, class O>
100inline typename IEnumerator<T>::Ptr Enumerator<T>::CreateTransform(std::shared_ptr<S> sourcePtr, O transformOperation)
101{
102 using U = typename S::ValueType;
103 return std::make_shared<Enumerator<T>::Transform<U, O>>(std::move(sourcePtr), std::move(transformOperation));
104}
105
106}}} // end of namespace Arp::Base::Core
This class implements a transforming enumerator. A transform operation is applied to each element.
Definition: Enumerator.Transform.hxx:21
Transform & operator=(Transform &&arg) noexcept
Move assignment operator.
Transform(Transform &&arg) noexcept
Move constructor.
~Transform(void) override
Destructs this instance and frees all resources.
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:24
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
virtual bool MoveNext(void)=0
Moves this enumerator to the next position.
std::shared_ptr< IEnumerator > Ptr
The smart pointer type of this interface.
Definition: IEnumerator.hxx:52
Root namespace for the PLCnext API
Namespace of the C++ standard library