PLCnext API Documentation 23.6.0.37
TypeInfo.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/Plc/Commons/Meta/ArrayDimension.hpp"
11#include "Arp/Plc/Commons/Meta/ArrayDimensions.hpp"
12#include "Arp/Plc/Commons/Meta/StandardAttributes.hpp"
13#include "Arp/Plc/Commons/Meta/CustomAttribute.hpp"
14#include "Arp/Plc/Commons/Meta/CustomAttributes.hpp"
15#include "Arp/System/Rsc/Services/IRscSerializable.hpp"
16#include <vector>
17#include <numeric>
18
19namespace Arp { namespace Plc { namespace Commons { namespace Meta
20{
21
22
23using namespace Arp::System::Rsc::Services;
24
25
28{
29public: // construction/destruction
31 TypeInfo(void) = default;
33 TypeInfo(DataType dataType, const TypeIdentifier& typeId, size_t size, size_t alignment);
36 ARP_DEPRECATED("Use ChildTypeInfo to define arrays")
37 TypeInfo(DataType elementType, const TypeIdentifier& elementTypeId, size_t elementSize, size_t alignment, const ArrayDimension& arrayDimension);
41 TypeInfo(DataType elementType, const TypeIdentifier& elementTypeId, size_t elementSize, size_t alignment, const ArrayDimensions& arrayDimensions);
43 TypeInfo(DataType dataType, const TypeIdentifier& typeId, size_t size, size_t alignment, StandardAttributes standardAttributes,
44 const CustomAttributes& customAttributes);
46 TypeInfo(DataType dataType, const TypeIdentifier& typeId);
48 TypeInfo(const TypeInfo& arg) = default;
50 TypeInfo(TypeInfo&& arg) = default;
52 TypeInfo& operator=(const TypeInfo& arg) = default;
54 TypeInfo& operator=(TypeInfo&& arg) = default;
56 ~TypeInfo(void) override = default;
57
58protected:
61 TypeInfo(DataType dataType, const TypeIdentifier& typeId, size_t size, size_t alignment, const ArrayDimensions& arrayDimensions,
62 StandardAttributes standardAttributes, const CustomAttributes& customAttributes);
63
64
65public: // static fields
66 static const TypeInfo Empty;
67
68public: // IRscSerializable operatios
69 void Serialize(RscWriter& writer)const override;
70 void Deserialize(RscReader& reader)override;
71
72public: // static operations
73 static size_t GetFieldCount(void);
74
75public: // setter/getter operations
78 bool IsEmpty(void)const;
79
82 bool IsHidden(void)const;
83
86 size_t GetTypeSize()const;
87
89 void SetDataType(DataTypeEnum arg);
90
94
97 const CustomAttributes& GetAttributes(void)const;
98
100 void SetTypeIdentifier(const TypeIdentifier& value);
101
104 const TypeIdentifier& GetTypeIdentifier(void)const;
105
108 size_t GetAlignment(void)const;
109
114 const ArrayDimensions& GetArrayDimensions(void)const;
115
119
123
126 size_t GetCacheSize(void)const;
127
128public: // operations
132
136 void AddCustomAttribute(const String& name, const RscVariant<256>& value);
137
138private: // methods
141 ARP_DEPRECATED("To be removed")
142 void InsertDimension(ArrayDimension& dimension);
143
144protected: // fields
145 DataTypeEnum dataType = DataType::None;
146 TypeIdentifier typeId;
147 size_t size = 0;
148 size_t alignment = 0;
149 ArrayDimensions dimensions; // To be moved to ChildTypeInfo
150 StandardAttributes standardAttributes;
151 CustomAttributes customAttributes;
152
153private: // fields
154};
155
157// inline methods of class TypeInfo
158
159inline size_t TypeInfo::GetFieldCount(void)
160{
161 return 7;
162}
163
164inline bool TypeInfo::IsEmpty()const
165{
166 return this->dataType.IsEmpty();
167}
168
169inline bool TypeInfo::IsHidden()const
170{
171 return this->standardAttributes.IsSet(StandardAttribute::Hidden);
172}
173
174inline size_t TypeInfo::GetTypeSize()const
175{
176 if (this->size != 0)
177 {
178 return this->size;
179 }
180 // else
181 return this->dataType.GetSize();
182}
183
185{
186 this->dataType = arg;
187}
189{
190 return this->dataType;
191}
192
194{
195 return this->customAttributes;
196}
197
199{
200 this->typeId = value;
201}
202
204{
205 return this->typeId;
206}
207
209{
210 return this->dimensions;
211}
212
213inline size_t TypeInfo::GetAlignment(void)const
214{
215 return this->alignment;
216}
217
219{
220 this->standardAttributes = value;
221}
222
224{
225 return this->standardAttributes;
226}
227
229{
230 this->standardAttributes = this->standardAttributes.GetValue() | value;
231}
232
233inline void TypeInfo::AddCustomAttribute(const String& name, const RscVariant<256>& value)
234{
235 customAttributes.push_back(CustomAttribute(name, value));
236}
237
238inline size_t TypeInfo::GetCacheSize(void)const
239{
240 size_t cacheSize = 0;
241 cacheSize += sizeof(this->dataType);
242 cacheSize += this->typeId.GetCacheSize();
243 cacheSize += sizeof(this->size);
244 cacheSize += sizeof(this->alignment);
245 cacheSize += this->dimensions.GetCacheSize();
246 cacheSize += this->standardAttributes.GetCacheSize();
247 cacheSize += std::accumulate(this->customAttributes.begin(), this->customAttributes.end(), static_cast<size_t>(0),
248 [](size_t result, const CustomAttribute & each)
249 {
250 return result + each.GetCacheSize();
251 });
252 return cacheSize;
253}
254
255}}}} // end of namespace Arp::Plc::Commons::Meta
Definition: DataTypeEnum.hpp:16
bool IsEmpty(void) const
True if not set
Definition: DataTypeEnum.hpp:230
size_t GetSize(void) const
Returns the size of the this data type if it could be deduced, otherwise 0
Provide array information.
Definition: ArrayDimension.hpp:21
Provide array information.
Definition: ArrayDimensions.hpp:18
size_t GetCacheSize(void) const
Get the cache size
Definition: ArrayDimensions.hpp:136
Provides detailed type information of a child within TypeBrowser interface.
Definition: ChildTypeInfo.hpp:27
Container for individual attributes within the interface DataBrowser
Definition: CustomAttribute.hpp:21
Collection of StandardAttribute flags
Definition: StandardAttributes.hpp:16
bool IsSet(StandardAttribute flag) const
Check if a flag is set
Definition: StandardAttributes.hpp:80
StandardAttribute GetValue(void) const
Gets the underlying value
Definition: StandardAttributes.hpp:99
size_t GetCacheSize(void) const
Get the cache size
Definition: StandardAttributes.hpp:104
Identifies a type descriptions
Definition: TypeIdentifier.hpp:24
size_t GetCacheSize() const
Get the cache size
Provides detailed type information within TypeBrowser interface.
Definition: TypeInfo.hpp:28
bool IsEmpty(void) const
Determines if this instance is empty.
Definition: TypeInfo.hpp:164
void Serialize(RscWriter &writer) const override
Serializes the datatype. All fields of the datatype have to be serialized in use of RscWriter.
TypeInfo(DataType dataType, const TypeIdentifier &typeId, size_t size, size_t alignment)
Complex data type, example struct
const CustomAttributes & GetAttributes(void) const
List of data attributes.
Definition: TypeInfo.hpp:193
size_t GetTypeSize() const
Get the size of the type.
Definition: TypeInfo.hpp:174
const StandardAttributes & GetStandardAttributes(void) const
Returns the StandardAttributes
Definition: TypeInfo.hpp:223
void AddStandardAttribute(StandardAttribute value)
Adds a StandardAttribute flags
Definition: TypeInfo.hpp:228
size_t GetCacheSize(void) const
Get the cache size
Definition: TypeInfo.hpp:238
bool IsHidden(void) const
Determines if this type is hidden.
Definition: TypeInfo.hpp:169
void AddCustomAttribute(const String &name, const RscVariant< 256 > &value)
Adds a CustomAttribute
Definition: TypeInfo.hpp:233
size_t GetAlignment(void) const
Get alignment.
Definition: TypeInfo.hpp:213
DataTypeEnum GetDataType() const
Get respective data type.
Definition: TypeInfo.hpp:188
void SetStandardAttributes(StandardAttribute value)
Sets the StandardAttributes
Definition: TypeInfo.hpp:218
void SetDataType(DataTypeEnum arg)
Set the data type.
Definition: TypeInfo.hpp:184
const ArrayDimensions & GetArrayDimensions(void) const
Deprecated! List of array dimensions and their informations.
Definition: TypeInfo.hpp:208
TypeInfo(void)=default
Constructs an TypeInfo instance for simple elementary data type.
const TypeIdentifier & GetTypeIdentifier(void) const
The TypeIdentifier of a struct, program or any other complex type.
Definition: TypeInfo.hpp:203
void Deserialize(RscReader &reader) override
Deserializes the datatype. All fields of the datatype have to be deserialized in use of RscReader.
void SetTypeIdentifier(const TypeIdentifier &value)
The TypeIdentifier of a struct, program or any other complex type.
Definition: TypeInfo.hpp:198
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
Rsc container class for primitive data type, strings or information about arrays or structs....
Definition: RscVariant.hxx:69
Writes data to Rsc.
Definition: RscWriter.hpp:32
std::vector< CustomAttribute > CustomAttributes
List of type attributes TypeAttribute.
Definition: CustomAttributes.hpp:15
StandardAttribute
Standard attributes to types
Definition: StandardAttribute.hpp:18
@ Hidden
The node is hidden, that is, it has just a technical purpose but no logical meaning and does not occu...
DataType
Definition: DataType.hpp:15
Namespace for classes and interfaces for the Remote Service Call implementation
Root namespace for the PLCnext API
class ARP_DEPRECATED("Use Arp::Enum<T> instead.") EnumStrings
Deprecated! The class implements an adapter for enums to define the string literals of the enum entri...
Definition: EnumStrings.hxx:38