PLCnext API Documentation 25.0.2.69
RscImplWriteEnumerator.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/delegate.hxx"
9#include "Arp/Base/Rsc/Commons/IRscWriteEnumerator.hxx"
10#include "Arp/Base/Rsc/Commons/RscArrayWriter.hpp"
11#include <functional>
12
13namespace Arp::Base::Rsc::Commons::Services
14{
15
23template<class T>
25{
26public: // usings
27 using BeginFunction = std::function<void(size_t)>;
28 using NextFunction = std::function<void(const T&)>;
29 using NextArrayFunction = std::function<RscArrayWriter(size_t, RscType)>;
30 using EndFunction = std::function<void()>;
31
32public: // construction
34
35public: // properties
40
41public: // operations of IRscWriteEnumerator
42 void BeginWrite(size_t)override;
43 void WriteNext(const T&)override;
44 RscArrayWriter WriteNext(size_t arraySize, RscType elementType)override;
45 void EndWrite(void)override;
46};
47
49// inline methods of class RscImplWriteEnumerator
50
53template<class T>
55
59template<class T>
61{
62 if(!this->Begin)
63 {
64 throw InvalidOperationException("Begin has to be initialized first.");
65 }
66 this->Begin(count);
67}
68
72template<class T>
73inline void RscImplWriteEnumerator<T>::WriteNext(const T& current)
74{
75 if(!this->Next)
76 {
77 throw InvalidOperationException("Next has to be initialized first.");
78 }
79 return this->Next(current);
80}
81
89template<class T>
90inline RscArrayWriter RscImplWriteEnumerator<T>::WriteNext(size_t arraySize, RscType elementType)
91{
92 if (!this->NextArray)
93 {
94 throw InvalidOperationException("NextArray has to be initialized first.");
95 }
96 return this->NextArray(arraySize, elementType);
97}
98
103template<class T>
105{
106 if(this->End)
107 {
108 this->End();
109 }
110}
111
112} // 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 writing an array enumeration or enumeration of unspefied length.
Definition: IRscWriteEnumerator.hxx:20
Helper class to write a dynamic array of primtive types from RscVariant. This class uses the array in...
Definition: RscArrayWriter.hpp:23
Implements IRscWriteEnumerator to be used from within service implementations.
Definition: RscImplWriteEnumerator.hxx:25
void BeginWrite(size_t) override
This operation is called at the begin of writing the enumeration.
Definition: RscImplWriteEnumerator.hxx:60
EndFunction End
Write delegate to EndWrite implementation of service method.
Definition: RscImplWriteEnumerator.hxx:39
BeginFunction Begin
Write delegate to BeginWrite implementation of service method.
Definition: RscImplWriteEnumerator.hxx:36
NextFunction Next
Write delegate to WriteNext implementation of service method.
Definition: RscImplWriteEnumerator.hxx:37
void EndWrite(void) override
This operation is called at the end of writing the enumeration to perform any flushing code or simila...
Definition: RscImplWriteEnumerator.hxx:104
std::function< void()> EndFunction
The prototype of the End function.
Definition: RscImplWriteEnumerator.hxx:30
void WriteNext(const T &) override
Writes the next element of the enumeration.
Definition: RscImplWriteEnumerator.hxx:73
RscImplWriteEnumerator(void)
Constructs an RscImplWriteEnumerator instance.
std::function< RscArrayWriter(size_t, RscType)> NextArrayFunction
The prototype of the NextArray function.
Definition: RscImplWriteEnumerator.hxx:29
std::function< void(size_t)> BeginFunction
The prototype of the Begin function.
Definition: RscImplWriteEnumerator.hxx:27
std::function< void(const T &)> NextFunction
The prototype of the Next function.
Definition: RscImplWriteEnumerator.hxx:28
NextArrayFunction NextArray
Write delegate to WriteNext implementation for array elements of service method.
Definition: RscImplWriteEnumerator.hxx:38