8#include "Arp/System/Rsc/Services/Rsc.h"
9#include "Arp/System/Commons/Logging.h"
10#include "Arp/System/Commons/Exceptions/Exceptions.h"
11#include "Arp/System/Rsc/Services/RscException.hpp"
12#include "Arp/System/Rsc/Services/IRscWriteEnumerator.hxx"
13#include "Arp/System/Rsc/Services/RscWriter.hpp"
14#include "Arp/System/Rsc/Services/RscArrayWriter.hpp"
17namespace Arp {
namespace System {
namespace Rsc {
namespace Services
37 void BeginWrite(
size_t arrayLengthArg = (
size_t) -1)
override;
46 RemotingWriter& remotingWriter;
47 bool isArrayEnumerator;
49 size_t arrayLength = 0;
50 bool endWritten =
false;
51 size_t fieldCount = 0;
58 : isArrayEnumerator(isArrayEnumeratorArg)
59 , remotingWriter(rscWriter.GetRemotingWriter())
60 , rscType(GetRscTypeFrom(T()))
61 , fieldCount(StructInfo<T>().FieldCount)
70 Log::Error(
"Rsc Enumerating was not ended properly, call EndWrite() method when writing was finished.");
77 this->arrayLength = arrayLengthArg;
79 if(this->isArrayEnumerator)
81 if(this->arrayLength == (
size_t) -1)
89 this->remotingWriter.WriteBeginStruct(this->fieldCount);
93 this->remotingWriter.WriteTag(this->rscType);
95 this->remotingWriter.WriteArrayLength(this->arrayLength);
99 if(this->arrayLength != (
size_t) -1)
101 throw ArgumentException(
"Array length could not be defined for standard enumerators.");
110 if(this->isArrayEnumerator)
112 if(this->arrayLength == 0)
121 this->remotingWriter.WriteEnumeratorTag(this->rscType);
124 this->remotingWriter.WriteFieldCount(this->fieldCount);
127 RscValueAdapter<T> valueAdapter(current);
128 valueAdapter.Write(this->remotingWriter,
false);
135 this->remotingWriter.WriteTag(arrayElementType);
136 this->remotingWriter.WriteArrayLength(arraySize);
137 return RscArrayWriter(arraySize, arrayElementType, this->remotingWriter);
143 if(this->isArrayEnumerator)
145 if(this->arrayLength != 0)
155 this->endWritten =
true;
This exception is used when an invalid argument occurs.
Definition: ArgumentException.hpp:15
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
Implementation of IRscWriteEnumerator used on client side.
Definition: RscWriteEnumerator.hxx:25
void BeginWrite(size_t arrayLengthArg=(size_t) -1) override
Begins the operation to write the enumerator.
Definition: RscWriteEnumerator.hxx:75
void EndWrite(void) override
Ends the enumerator. With an array enumerator all enumerator elements had to be written
Definition: RscWriteEnumerator.hxx:141
void WriteNext(const T ¤t) override
Writes the next enumerator element.
Definition: RscWriteEnumerator.hxx:108
RscWriteEnumerator(RscWriter &rscWriter, bool isArrayEnumerator)
Constructs an RscEnumeratorBase instance.
Definition: RscWriteEnumerator.hxx:57
~RscWriteEnumerator(void)
Destructs this instance and frees all resources.
Definition: RscWriteEnumerator.hxx:66
RscWriteEnumerator(const RscWriteEnumerator &arg)=default
Copy constructor.
Writes data to Rsc.
Definition: RscWriter.hpp:32
@ System
System components used by the System, Device, Plc or Io domains.
RscType
Data types supported by RSC.
Definition: RscType.hpp:36
@ Enumerator
Enumerator type implemented as IRscReadEnumerator or IRscWriteEnumerator
@ Array
std::vector<T> or RSC enumerators
@ Struct
struct derived by IRscSerializable
Root namespace for the PLCnext API