PLCnext API Documentation 23.6.0.37
RscImplWriteEnumerator.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/delegate.hxx"
9#include "Arp/System/Rsc/Services/IRscWriteEnumerator.hxx"
10#include "Arp/System/Rsc/Services/RscArrayWriter.hpp"
11#include <functional>
12
13
14namespace Arp { namespace System { namespace Rsc { namespace Services
15{
16
21template<class T>
23{
24public: // typedefs
25 typedef std::function<void(size_t)> BeginFunction;
26 typedef std::function<void(const T&)> NextFunction;
27 typedef std::function<RscArrayWriter(size_t, RscType)> NextArrayFunction;
28 typedef std::function<void()> EndFunction;
29
30public: // construction/destruction
32 RscImplWriteEnumerator(void) = default;
38 ~RscImplWriteEnumerator(void) = default;
39
40public: // properties
44 BeginFunction Begin;
45
49 NextFunction Next;
50
54 NextArrayFunction NextArray;
55
59 EndFunction End;
60
61public: // setter/getter operations
62
63public: // operations of IRscWriteEnumerator
64 void BeginWrite(size_t)override;
65 void WriteNext(const T&)override;
66 RscArrayWriter WriteNext(size_t arraySize, RscType elementType)override;
67 void EndWrite(void)override;
68
69private: // fields
70};
71
72template<class T>
74{
75 if(!this->Begin)
76 {
77 throw InvalidOperationException("BeginWrite has to be intialized first.");
78 }
79 this->Begin(count);
80}
81
82template<class T>
83inline void RscImplWriteEnumerator<T>::WriteNext(const T& current)
84{
85 if(!this->Next)
86 {
87 throw InvalidOperationException("WriteNext has to be intialized first.");
88 }
89 return this->Next(current);
90}
91
92template<class T>
93inline RscArrayWriter RscImplWriteEnumerator<T>::WriteNext(size_t arraySize, RscType elementType)
94{
95 if (!this->NextArray)
96 {
97 throw InvalidOperationException("WriteNext has to be intialized first.");
98 }
99 return this->NextArray(arraySize, elementType);
100}
101
102template<class T>
104{
105 if(this->End)
106 {
107 this->End();
108 }
109}
110
111}}}} // 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 writing an array or an enumerator. For regular enumerators UndefinedArrayLength is used...
Definition: IRscWriteEnumerator.hxx:23
Helper class to read an array of primtive types from an RscVariant. This class uses the array informa...
Definition: RscArrayWriter.hpp:22
Implements IRscWriteEnumerator for the service implementations. This should only be used in the imple...
Definition: RscImplWriteEnumerator.hxx:23
RscImplWriteEnumerator(const RscImplWriteEnumerator &arg)=default
Copy constructor.
RscImplWriteEnumerator(void)=default
Constructs an RscProxyArrayWriteEnumerator instance.
BeginFunction Begin
Write callback to BeginWrite implementation of service method.
Definition: RscImplWriteEnumerator.hxx:44
void WriteNext(const T &) override
Writes the next enumerator element.
Definition: RscImplWriteEnumerator.hxx:83
void EndWrite(void) override
Ends the enumerator. With an array enumerator all enumerator elements had to be written
Definition: RscImplWriteEnumerator.hxx:103
NextArrayFunction NextArray
Write callback to WriteNext implementation for array elements of service method.
Definition: RscImplWriteEnumerator.hxx:54
void BeginWrite(size_t) override
Begins the operation to write the enumerator.
Definition: RscImplWriteEnumerator.hxx:73
~RscImplWriteEnumerator(void)=default
Destructs this instance and frees all resources.
RscImplWriteEnumerator & operator=(const RscImplWriteEnumerator &arg)=default
Assignment operator.
EndFunction End
Write callback to EndWrite implementation of service method.
Definition: RscImplWriteEnumerator.hxx:59
NextFunction Next
Write callback to WriteNext implementation of service method.
Definition: RscImplWriteEnumerator.hxx:49
@ System
System components used by the System, Device, Plc or Io domains.
RscType
Data types supported by RSC.
Definition: RscType.hpp:36
Root namespace for the PLCnext API