PLCnext API Documentation 23.6.0.37
DataTag.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/Plc/Commons/DataTypeEnum.hpp"
9#include "Arp/Plc/Commons/Meta/TypeIdentifier.hpp"
10#include "Arp/System/Rsc/Services/IRscSerializable.hpp"
11
12
13
14namespace Arp { namespace Plc { namespace Commons { namespace Meta
15{
16
17using namespace Arp::System::Rsc::Services;
18
19//forwards
20class DataInfo;
21class IChangeNavigator;
22
25{
26 friend class DataInfo;
27
28public: // construction/destruction
30 DataTag(void) = default;
32 DataTag(const String& name, const void* valueAddress, DataType dataType, const TypeIdentifier& typeId, bool isBackgroundDomain = false);
34 DataTag(const DataTag& arg) = default;
36 DataTag(DataTag&& arg) = default;
38 DataTag& operator=(const DataTag& arg) = default;
40 DataTag& operator=(DataTag&& arg) = default;
42 ~DataTag(void) override = default;
43
44public: // setter/getter operations
47 bool IsEmpty(void)const;
48
51 const String& GetName(void)const;
52
54 void SetDataType(DataType value);
55
59
62 const DataTypeEnum& GetDataType(void)const;
63
67
71
73 void SetValueAddress(const byte* value);
74
77 const byte* GetDataAddress(void)const;
78
81 const byte* GetVariableAddress(void)const;
82
85 const byte* GetChangeCounterpartAddress(void)const;
86
89 bool IsBackgroundDomain(void)const;
90
93 bool& IsBackgroundDomain(void);
94
97 bool IsNullPointer(void)const;
98
101 bool IsChangeCounterpartNullPointer(void)const;
102
105 bool IsEmptyOrNullPointer(void)const;
106
107public: // operations
110
112 void ShiftValueAddress(size_t offset);
113
116 void SetChangeCounterpart(const byte* value, const byte* typeTag);
117
120 void SetChangeCounterpart(const DataTag& changeCounterpart);
121
124 void GetChangeInfo(const byte*& valueAddressOut, const byte*& changeCounterpartAddressOut, bool& isBackgroundDomainOut)const;
125
128 void Change(IChangeNavigator* pChangeNavigator);
129
130public: // IRscSerializable operations
131 void Serialize(RscWriter& writer)const override;
132 void Deserialize(RscReader& reader)override;
133 static size_t GetFieldCount(void);
134
135private: // methods
136 void SetName(const String& value);
137 void SwapDomain(void);
138
139private: // static methods
140 static const byte* ResolveIndirectAddress(const byte* address);
141
142private: // fields
143 String name;
144 DataTypeEnum dataType = DataType::None;
145 TypeIdentifier typeId;
146 const byte* variableAddress = nullptr;
147 const byte* changeCounterpartAddress = nullptr;
148 bool isBackgroundDomain = false;
149};
150
152// inline methods of class DataTag
153inline bool DataTag::IsEmpty()const
154{
155 return this->dataType == DataType::None;
156}
157
158inline void DataTag::SetName(const String& value)
159{
160 this->name = value;
161}
162
163inline const String& DataTag::GetName()const
164{
165 return this->name;
166}
167
169{
170 this->dataType = value;
171}
172
174{
175 return this->dataType;
176}
177
178inline const DataTypeEnum& DataTag::GetDataType()const
179{
180 return this->dataType;
181}
182
184{
185 return this->typeId;
186}
187
189{
190 return this->typeId;
191}
192
193inline void DataTag::SetValueAddress(const byte* value)
194{
195 this->variableAddress = value;
196}
197
198inline void DataTag::ShiftValueAddress(size_t offset)
199{
200 this->variableAddress += offset;
201}
202
203inline const byte* DataTag::GetDataAddress()const
204{
205 if (this->dataType.IsIndirect())
206 {
207 if (this->variableAddress == nullptr)
208 {
210 "Attempt to dereference variableAddress == nullptr for DataTag: name={}, dataType={}",
211 this->name, this->dataType);
212 }
213 return ResolveIndirectAddress(this->variableAddress);
214 }
215 // else
216 return this->variableAddress;
217}
218
219inline const byte* DataTag::GetVariableAddress()const
220{
221 return this->variableAddress;
222}
223
224inline void DataTag::SetChangeCounterpart(const byte* value, const byte* /*typeTag*/)
225{
226 this->changeCounterpartAddress = value;
227}
228
230{
231 if (this->dataType.IsIndirect())
232 {
233 if (this->changeCounterpartAddress == nullptr)
234 {
236 "Attempt to dereference changeCounterpartAddress == nullptr for DataTag: name={}, dataType={}",
237 this->name, this->dataType);
238 }
239 return ResolveIndirectAddress(this->changeCounterpartAddress);
240 }
241 // else
242 return this->changeCounterpartAddress;
243}
244
246{
247 return this->isBackgroundDomain;
248}
249
250inline bool& DataTag::IsBackgroundDomain()
251{
252 return this->isBackgroundDomain;
253}
254
255inline bool DataTag::IsNullPointer()const
256{
257 return (this->variableAddress == nullptr) || (this->GetDataAddress() == nullptr);
258}
259
261{
262 return (this->changeCounterpartAddress == nullptr) || (this->GetChangeCounterpartAddress() == nullptr);
263}
264
265inline bool DataTag::IsEmptyOrNullPointer(void) const
266{
267 return this->IsEmpty() || this->IsNullPointer();
268}
269
270inline size_t DataTag::GetFieldCount()
271{
272 return 6;
273}
274
275
276inline const byte* DataTag::ResolveIndirectAddress(const byte* address)
277{
278 return *reinterpret_cast<byte*const*>(address);
279}
280
281}}}} // end of namespace Arp::Plc::Meta
Definition: DataTypeEnum.hpp:16
bool IsIndirect(void) const
Checks if this data type is an indirect data type, that is a pointer or reference type.
Definition: DataTypeEnum.hpp:168
Provides detailed informations for the respective data object.
Definition: DataInfo.hpp:32
Includes kind as well as instance browse name.
Definition: DataTag.hpp:25
DataTag(const DataTag &arg)=default
Constructs an DataTag instance.
void SetChangeCounterpart(const DataTag &changeCounterpart)
For internal use only.
bool IsChangeCounterpartNullPointer(void) const
Only for internal using.
Definition: DataTag.hpp:260
bool IsEmpty(void) const
Determines if this instance is empty.
Definition: DataTag.hpp:153
DataTag(DataTag &&arg)=default
Move constructor.
DataTag(void)=default
Constructs an DataTag instance.
void ResolveIndirection(void)
Resolves the value address if this is an indirect data type like reference or pointer.
const byte * GetVariableAddress(void) const
For internal use only.
Definition: DataTag.hpp:219
bool IsNullPointer(void) const
Only for internal using.
Definition: DataTag.hpp:255
~DataTag(void) override=default
Destructs this instance and frees all resources.
DataTag & operator=(DataTag &&arg)=default
Move assignment operator
bool IsBackgroundDomain(void) const
Only for internal using.
Definition: DataTag.hpp:245
void ShiftValueAddress(size_t offset)
Shifts the value address for the given offset .
Definition: DataTag.hpp:198
void SetChangeCounterpart(const byte *value, const byte *typeTag)
For internal use only.
Definition: DataTag.hpp:224
DataTag(const String &name, const void *valueAddress, DataType dataType, const TypeIdentifier &typeId, bool isBackgroundDomain=false)
Constructs an DataTag instance.
void Deserialize(RscReader &reader) override
Deserializes the datatype. All fields of the datatype have to be deserialized in use of RscReader.
void GetChangeInfo(const byte *&valueAddressOut, const byte *&changeCounterpartAddressOut, bool &isBackgroundDomainOut) const
For internal use only.
TypeIdentifier & GetTypeIdentifier(void)
Returns the type identifier of this instance.
Definition: DataTag.hpp:183
void SetDataType(DataType value)
Sets the data type.
Definition: DataTag.hpp:168
DataTypeEnum & GetDataType(void)
The data type of this instance.
Definition: DataTag.hpp:173
const byte * GetChangeCounterpartAddress(void) const
For internal use only.
Definition: DataTag.hpp:229
void Change(IChangeNavigator *pChangeNavigator)
For internal use only.
void Serialize(RscWriter &writer) const override
Serializes the datatype. All fields of the datatype have to be serialized in use of RscWriter.
bool & IsBackgroundDomain(void)
Only for internal using.
const TypeIdentifier & GetTypeIdentifier(void) const
Returns the type identifier of this instance.
void SetValueAddress(const byte *value)
Sets the value address of this instance.
Definition: DataTag.hpp:193
const String & GetName(void) const
Provides data browsing instance naming for this object.
Definition: DataTag.hpp:163
bool IsEmptyOrNullPointer(void) const
Only for internal using.
Definition: DataTag.hpp:265
DataTag & operator=(const DataTag &arg)=default
Copy assignment operator.
const DataTypeEnum & GetDataType(void) const
The data type of this instance.
const byte * GetDataAddress(void) const
For internal use only.
Definition: DataTag.hpp:203
Enables switching of counterparts during download change
Definition: IChangeNavigator.hpp:17
Identifies a type descriptions
Definition: TypeIdentifier.hpp:24
This exception is used when a method call is invalid for object's current state.
Definition: InvalidOperationException.hpp:15
Marshalls structure or class data types. Serialize and Deserialize have to marshal fields in the same...
Definition: IRscSerializable.hpp:20
Reads data from Rsc
Definition: RscReader.hpp:27
Writes data to Rsc.
Definition: RscWriter.hpp:32
DataType
Definition: DataType.hpp:15
@ None
summary>Unspecified.
Namespace for classes and interfaces for the Remote Service Call implementation
Root namespace for the PLCnext API