PLCnext API Documentation  22.9.0.33
RscImplReadEnumerator.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Rsc/Services/IRscReadEnumerator.hxx"
9 
10 namespace Arp { namespace System { namespace Rsc { namespace Services
11 {
12 
17 template<class T>
19 {
20 public: // typedefs
21  typedef std::function<size_t()> BeginFunction;
22  typedef std::function<bool(T&)> NextFunction;
23  typedef std::function<bool(RscArrayReader&)> NextArrayFunction;
24  typedef std::function<void()> EndFunction;
25 
26 public: // construction/destruction
28  RscImplReadEnumerator(void) = default;
34  ~RscImplReadEnumerator(void) = default;
35 
36 public: // properties
40  BeginFunction Begin;
41 
45  NextFunction Next;
46 
50  NextArrayFunction NextArray;
51 
55  EndFunction End;
56 
57 public: // setter/getter operations
58 
59 public: // operations of IRscReadEnumerator
60  size_t BeginRead(void)override;
61  bool ReadNext(T&)override;
62  bool ReadNext(RscArrayReader& current)override;
63  void EndRead(void)override;
64 
65 private: // fields
66 };
67 
69 // inline methods of class RscImplReadEnumerator
70 template<class T>
72 {
73  if(!this->Begin)
74  {
75  throw InvalidOperationException("BeginWrite has to be intialized first.");
76  }
77  return this->Begin();
78 }
79 
80 template<class T>
81 inline bool RscImplReadEnumerator<T>::ReadNext(T& current)
82 {
83  if(!this->Next)
84  {
85  throw InvalidOperationException("Next has to be intialized first.");
86  }
87  return this->Next(current);
88 }
89 
90 template<class T>
92 {
93  if (!this->NextArray)
94  {
95  throw InvalidOperationException("NextArray has to be intialized first.");
96  }
97  return this->NextArray(current);
98 }
99 
100 template<class T>
102 {
103  if(this->End)
104  {
105  this->End();
106  }
107 }
108 
109 }}}} // 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:19
NextFunction Next
Write callback to ReadNext implementation of service method.
Definition: RscImplReadEnumerator.hxx:45
BeginFunction Begin
Read callback to BeginRead implementation of service method.
Definition: RscImplReadEnumerator.hxx:40
RscImplReadEnumerator(void)=default
Constructs an RscImplReadEnumerator instance.
EndFunction End
Write callback to EndRead implementation of service method.
Definition: RscImplReadEnumerator.hxx:55
RscImplReadEnumerator(const RscImplReadEnumerator &arg)=default
Copy constructor.
RscImplReadEnumerator & operator=(const RscImplReadEnumerator &arg)=default
Assignment operator.
bool ReadNext(T &) override
Reads the next enumerator element.
Definition: RscImplReadEnumerator.hxx:81
void EndRead(void) override
Ends the operation to read the enumerator. All enumerator elements had to be already been read.
Definition: RscImplReadEnumerator.hxx:101
NextArrayFunction NextArray
Write callback to ReadNext implementation for array elements of service method.
Definition: RscImplReadEnumerator.hxx:50
size_t BeginRead(void) override
Begins the operation to read the enumerator.
Definition: RscImplReadEnumerator.hxx:71
~RscImplReadEnumerator(void)=default
Destructs this instance and frees all resources.
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API