PLCnext API Documentation  22.9.0.33
RscImplWriteEnumerator.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
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 
14 namespace Arp { namespace System { namespace Rsc { namespace Services
15 {
16 
21 template<class T>
23 {
24 public: // 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 
30 public: // construction/destruction
32  RscImplWriteEnumerator(void) = default;
38  ~RscImplWriteEnumerator(void) = default;
39 
40 public: // properties
44  BeginFunction Begin;
45 
49  NextFunction Next;
50 
54  NextArrayFunction NextArray;
55 
59  EndFunction End;
60 
61 public: // setter/getter operations
62 
63 public: // 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 
69 private: // fields
70 };
71 
72 template<class T>
73 inline void RscImplWriteEnumerator<T>::BeginWrite(size_t count)
74 {
75  if(!this->Begin)
76  {
77  throw InvalidOperationException("BeginWrite has to be intialized first.");
78  }
79  this->Begin(count);
80 }
81 
82 template<class T>
83 inline 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 
92 template<class T>
93 inline 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 
102 template<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.
EndFunction End
Write callback to EndWrite implementation of service method.
Definition: RscImplWriteEnumerator.hxx:59
RscImplWriteEnumerator & operator=(const RscImplWriteEnumerator &arg)=default
Assignment operator.
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
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType....
Definition: RscType.hpp:37
Root namespace for the PLCnext API