PLCnext API Documentation 23.3.0.32
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
140 ARP_DEPRECATED("To be removed")
141 void InsertDimension(ArrayDimension& dimension);
142
143protected: // fields
144 DataTypeEnum dataType = DataType::None;
145 TypeIdentifier typeId;
146 size_t size = 0;
147 size_t alignment = 0;
148 ArrayDimensions dimensions; // To be moved to ChildTypeInfo
149 StandardAttributes standardAttributes;
150 CustomAttributes customAttributes;
151
152private: // fields
153};
154
156// inline methods of class TypeInfo
157
158inline size_t TypeInfo::GetFieldCount(void)
159{
160 return 7;
161}
162
163inline bool TypeInfo::IsEmpty()const
164{
165 return this->dataType.IsEmpty();
166}
167
168inline bool TypeInfo::IsHidden()const
169{
170 return this->standardAttributes.IsSet(StandardAttribute::Hidden);
171}
172
173inline size_t TypeInfo::GetTypeSize()const
174{
175 if (this->size != 0)
176 {
177 return this->size;
178 }
179 // else
180 return this->dataType.GetSize();
181}
182
184{
185 this->dataType = arg;
186}
188{
189 return this->dataType;
190}
191
193{
194 return this->customAttributes;
195}
196
198{
199 this->typeId = value;
200}
201
203{
204 return this->typeId;
205}
206
208{
209 return this->dimensions;
210}
211
212inline size_t TypeInfo::GetAlignment(void)const
213{
214 return this->alignment;
215}
216
218{
219 this->standardAttributes = value;
220}
221
223{
224 return this->standardAttributes;
225}
226
228{
229 this->standardAttributes = this->standardAttributes.GetValue() | value;
230}
231
232inline void TypeInfo::AddCustomAttribute(const String& name, const RscVariant<256>& value)
233{
234 customAttributes.push_back(CustomAttribute(name, value));
235}
236
237inline size_t TypeInfo::GetCacheSize(void)const
238{
239 size_t cacheSize = 0;
240 cacheSize += sizeof(this->dataType);
241 cacheSize += this->typeId.GetCacheSize();
242 cacheSize += sizeof(this->size);
243 cacheSize += sizeof(this->alignment);
244 cacheSize += this->dimensions.GetCacheSize();
245 cacheSize += this->standardAttributes.GetCacheSize();
246 cacheSize += std::accumulate(this->customAttributes.begin(), this->customAttributes.end(), static_cast<size_t>(0),
247 [](size_t result, const CustomAttribute & each)
248 {
249 return result + each.GetCacheSize();
250 });
251 return cacheSize;
252}
253
254}}}} // 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:163
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:192
size_t GetTypeSize() const
Get the size of the type.
Definition: TypeInfo.hpp:173
const StandardAttributes & GetStandardAttributes(void) const
Returns the StandardAttributes
Definition: TypeInfo.hpp:222
void AddStandardAttribute(StandardAttribute value)
Adds a StandardAttribute flags
Definition: TypeInfo.hpp:227
size_t GetCacheSize(void) const
Get the cache size
Definition: TypeInfo.hpp:237
bool IsHidden(void) const
Determines if this type is hidden.
Definition: TypeInfo.hpp:168
void AddCustomAttribute(const String &name, const RscVariant< 256 > &value)
Adds a CustomAttribute
Definition: TypeInfo.hpp:232
size_t GetAlignment(void) const
Get alignment.
Definition: TypeInfo.hpp:212
DataTypeEnum GetDataType() const
Get respective data type.
Definition: TypeInfo.hpp:187
void SetStandardAttributes(StandardAttribute value)
Sets the StandardAttributes
Definition: TypeInfo.hpp:217
void SetDataType(DataTypeEnum arg)
Set the data type.
Definition: TypeInfo.hpp:183
const ArrayDimensions & GetArrayDimensions(void) const
List of array dimensions and their informations.
Definition: TypeInfo.hpp:207
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:202
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:197
Marshalls structure or class data types. Serialize and Deserialize have to marshal fields in the same...
Definition: IRscSerializable.hpp:19
Reads data from Rsc
Definition: RscReader.hpp:26
Rsc container class for primitive data type, strings or information about arrays or structs....
Definition: RscVariant.hxx:68
Writes data to Rsc.
Definition: RscWriter.hpp:31
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
The class implements an adapter for enums to define the string literals of the enum entries.
Definition: EnumStrings.hxx:38