PLCnext API Documentation 23.6.0.37
RscImplReadEnumerator.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Rsc/Services/IRscReadEnumerator.hxx"
9#include "Arp/System/Commons/Exceptions/Exceptions.h"
10
11namespace Arp { namespace System { namespace Rsc { namespace Services
12{
13
18template<class T>
20{
21public: // typedefs
22 typedef std::function<size_t()> BeginFunction;
23 typedef std::function<bool(T&)> NextFunction;
24 typedef std::function<bool(RscArrayReader&)> NextArrayFunction;
25 typedef std::function<void()> EndFunction;
26
27public: // construction/destruction
29 RscImplReadEnumerator(void) = default;
35 ~RscImplReadEnumerator(void) = default;
36
37public: // properties
41 BeginFunction Begin;
42
46 NextFunction Next;
47
51 NextArrayFunction NextArray;
52
56 EndFunction End;
57
58public: // setter/getter operations
59
60public: // operations of IRscReadEnumerator
61 size_t BeginRead(void)override;
62 bool ReadNext(T&)override;
63 bool ReadNext(RscArrayReader& current)override;
64 void EndRead(void)override;
65
66private: // fields
67};
68
70// inline methods of class RscImplReadEnumerator
71template<class T>
73{
74 if(!this->Begin)
75 {
76 throw InvalidOperationException("BeginWrite has to be intialized first.");
77 }
78 return this->Begin();
79}
80
81template<class T>
83{
84 if(!this->Next)
85 {
86 throw InvalidOperationException("Next has to be intialized first.");
87 }
88 return this->Next(current);
89}
90
91template<class T>
93{
94 if (!this->NextArray)
95 {
96 throw InvalidOperationException("NextArray has to be intialized first.");
97 }
98 return this->NextArray(current);
99}
100
101template<class T>
103{
104 if(this->End)
105 {
106 this->End();
107 }
108}
109
110}}}} // end of namespace Arp::System::Rsc::Services
This exception is used when a method call is invalid for object's current state.
Definition: InvalidOperationException.hpp:15
Interface for reading an array or an enumerator. For regular enumerators UndefinedArrayLength is used...
Definition: IRscReadEnumerator.hxx:21
Helper class to read an array of primtive types from an RscVariant. This class uses the array informa...
Definition: RscArrayReader.hpp:23
Implements IRscReadEnumeratorfor the service implementations. This should only be used in the impleme...
Definition: RscImplReadEnumerator.hxx:20
NextFunction Next
Write callback to ReadNext implementation of service method.
Definition: RscImplReadEnumerator.hxx:46
BeginFunction Begin
Read callback to BeginRead implementation of service method.
Definition: RscImplReadEnumerator.hxx:41
RscImplReadEnumerator(void)=default
Constructs an RscImplReadEnumerator instance.
EndFunction End
Write callback to EndRead implementation of service method.
Definition: RscImplReadEnumerator.hxx:56
RscImplReadEnumerator(const RscImplReadEnumerator &arg)=default
Copy constructor.
bool ReadNext(T &) override
Reads the next enumerator element.
Definition: RscImplReadEnumerator.hxx:82
void EndRead(void) override
Ends the operation to read the enumerator. All enumerator elements had to be already been read.
Definition: RscImplReadEnumerator.hxx:102
NextArrayFunction NextArray
Write callback to ReadNext implementation for array elements of service method.
Definition: RscImplReadEnumerator.hxx:51
size_t BeginRead(void) override
Begins the operation to read the enumerator.
Definition: RscImplReadEnumerator.hxx:72
~RscImplReadEnumerator(void)=default
Destructs this instance and frees all resources.
RscImplReadEnumerator & operator=(const RscImplReadEnumerator &arg)=default
Assignment operator.
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API