PLCnext API Documentation 25.0.2.69
RscImplReadEnumerator.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Rsc/Commons/IRscReadEnumerator.hxx"
9#include "Arp/Base/Commons/Exceptions/InvalidOperationException.hpp"
10
11namespace Arp::Base::Rsc::Commons::Services
12{
13
22template<class T>
24{
25public: // usings
26 using BeginFunction = std::function<size_t()>;
27 using NextFunction = std::function<bool(T&)>;
28 using NextArrayFunction = std::function<bool(RscArrayReader&)>;
29 using EndFunction = std::function<void()>;
30
31public: // construction
33
34public: // properties
39
40public: // overridden operations from IRscReadEnumerator interface
41 size_t BeginRead(void)override;
42 bool ReadNext(T&)override;
43 bool ReadNext(RscArrayReader& current)override;
44 void EndRead(void)override;
45};
46
48// inline methods of class RscImplReadEnumerator
49
52template<class T>
54
58template<class T>
60{
61 if(!this->Begin)
62 {
63 throw InvalidOperationException("Begin callback is not set.");
64 }
65 return this->Begin();
66}
67
75template<class T>
77{
78 if(!this->Next)
79 {
80 throw InvalidOperationException("Next callback is not set.");
81 }
82 return this->Next(current);
83}
84
91template<class T>
93{
94 if (!this->NextArray)
95 {
96 throw InvalidOperationException("NextArray callback is not set.");
97 }
98 return this->NextArray(current);
99}
100
105template<class T>
107{
108 if(this->End)
109 {
110 this->End();
111 }
112}
113
114} // end of namespace Arp::Base::Rsc::Commons::Services
This exception is thrown when an operation cannot be executed because the related state is invalid.
Definition: InvalidOperationException.hpp:16
Interface for reading a arrays or enumerations.
Definition: IRscReadEnumerator.hxx:19
Utility class to read an array of primitive types from RscVariant. This class uses the array informat...
Definition: RscArrayReader.hpp:22
Implements IRscReadEnumerator to be used from within service implementations.
Definition: RscImplReadEnumerator.hxx:24
size_t BeginRead(void) override
This operation is called at the begin of reading the enumeration.
Definition: RscImplReadEnumerator.hxx:59
NextFunction Next
Delegate to ReadNext method of service implementation.
Definition: RscImplReadEnumerator.hxx:36
RscImplReadEnumerator(void)
Constructs an RscImplReadEnumerator instance.
bool ReadNext(T &) override
Reads the next element of the enumeration.
Definition: RscImplReadEnumerator.hxx:76
void EndRead(void) override
This operation is called at the end of reading the enumeration to perform any cleanup code or similar...
Definition: RscImplReadEnumerator.hxx:106
EndFunction End
Delegate to EndRead method of service implementation.
Definition: RscImplReadEnumerator.hxx:38
std::function< void()> EndFunction
The prototype of the End function.
Definition: RscImplReadEnumerator.hxx:29
std::function< bool(T &)> NextFunction
The prototype of the Next function.
Definition: RscImplReadEnumerator.hxx:27
std::function< bool(RscArrayReader &)> NextArrayFunction
The prototype of the NextArray function.
Definition: RscImplReadEnumerator.hxx:28
NextArrayFunction NextArray
Delegate to ReadNext method for array elements of service implementation.
Definition: RscImplReadEnumerator.hxx:37
std::function< size_t()> BeginFunction
The prototype of the Begin function.
Definition: RscImplReadEnumerator.hxx:26
BeginFunction Begin
Delegate to BeginRead method of service implementation.
Definition: RscImplReadEnumerator.hxx:35