PLCnext API Documentation 23.6.0.37
DataTypeEnum.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/Plc/Commons/DataType.hpp"
9#include "Arp/System/Rsc/Services/RscType.hpp"
10
11namespace Arp { namespace Plc { namespace Commons
12{
14
16{
17public: // construction/destruction
19 DataTypeEnum(DataType dataType);
21 DataTypeEnum(const DataTypeEnum& arg) = default;
23 DataTypeEnum(DataTypeEnum&& arg) = default;
25 DataTypeEnum& operator=(const DataTypeEnum& arg) = default;
27 ~DataTypeEnum(void) = default;
28
29public: // operators
30 operator DataType(void)const;
31 bool operator==(DataType rhs)const;
32
33public: // setter operations
34 void SetFlags(DataType flags);
35 void ResetFlags(DataType flags);
36 void ResetIndirection();
37
38public: // getter operations
40 DataType GetValue(void)const;
42 bool IsSet(DataType flag)const;
44 bool IsAnySet(DataType flags)const;
46 bool IsPrimitive(void)const;
48 bool IsElementary(bool useBaseType = true)const;
50 bool IsComplex(bool useBaseType = true)const;
52 bool IsPointer(void)const;
54 bool IsReference(void)const;
56 bool IsIndirect(void)const;
58 bool IsArray(void)const;
60 bool IsEnum(void)const;
62 bool IsString(void)const;
64 bool Is8BitString()const;
66 bool IsWideString()const;
68 bool IsIecObject(void)const;
70 bool HasChilds(void)const;
74 size_t GetSize(void)const;
76 size_t GetBaseSize(void)const;
78 size_t GetDataAlignment(void)const;
80 bool IsEmpty(void)const;
82 RscType GetRscType()const;
83
84private: // fields
86};
87
89// inline methods of class DataTypeEnum
90
92 : value(dataType)
93{
94}
95
96inline DataTypeEnum::operator DataType()const
97{
98 return this->value;
99}
100
101inline bool DataTypeEnum::operator==(DataType rhs)const
102{
103 return this->value == rhs;
104}
105
107{
108 return this->value;
109}
110
111inline bool DataTypeEnum::IsSet(DataType flag)const
112{
113 return (this->value & flag) == flag;
114}
115
116inline bool DataTypeEnum::IsAnySet(DataType flags)const
117{
118 return (this->value & flags) != DataType::None;
119}
120
122{
123 DataType baseDataType = this->GetBaseDataType();
124 if ((baseDataType != DataType::None) && (baseDataType <= DataType::Primitive))
125 {
126 return true;
127 }
128 // else
129 return false;
130}
131
132inline bool DataTypeEnum::IsElementary(bool useBaseType)const
133{
134 if (!useBaseType)
135 {
136 if (this->IsAnySet(DataType::Pointer | DataType::Enum | DataType::Array | DataType::Reference))
137 {
138 return true;
139 }
140 }
141 DataType baseType = this->GetBaseDataType();
142 return (baseType > DataType::Primitive) && (baseType <= DataType::Elementary);
143}
144
145inline bool DataTypeEnum::IsComplex(bool useBaseType)const
146{
147 if (!useBaseType)
148 {
149 if (this->IsAnySet(DataType::Pointer | DataType::Enum | DataType::Array | DataType::Reference))
150 {
151 return false;
152 }
153 }
154 DataType baseType = this->GetBaseDataType();
155 return (baseType > DataType::Elementary) && (baseType <= DataType::Complex);
156}
157
158inline bool DataTypeEnum::IsPointer()const
159{
160 return this->IsSet(DataType::Pointer);
161}
162
164{
165 return this->IsSet(DataType::Reference);
166}
167
168inline bool DataTypeEnum::IsIndirect()const
169{
170 return this->IsPointer() || this->IsReference();
171}
172
173inline bool DataTypeEnum::IsArray()const
174{
175 return this->IsSet(DataType::Array);
176}
177
178inline bool DataTypeEnum::IsEnum()const
179{
180 return this->IsSet(DataType::Enum);
181}
182
183inline bool DataTypeEnum::IsString()const
184{
185 return this->Is8BitString() || this->IsWideString();
186}
187
189{
190 DataType baseType = this->GetBaseDataType();
191 return (baseType == DataType::String) ||
192 (baseType == DataType::IecString) ||
193 (baseType == DataType::StaticString);
194}
195
197{
198 DataType baseType = this->GetBaseDataType();
199 return (baseType == DataType::IecWString) ||
200 (baseType == DataType::StaticWString);
201}
202
204{
205 DataType baseType = this->GetBaseDataType();
206 const bool isIecObjectType =
207 (baseType == DataType::FunctionBlock) ||
208 (baseType == DataType::Program) ||
209 (baseType == DataType::Class) ||
210 (baseType == DataType::Component);
211 return this->IsArray() || isIecObjectType;
212}
213
214inline bool DataTypeEnum::HasChilds()const
215{
216 if (this->IsAnySet(DataType::Enum))
217 {
218 return false;
219 }
220 // else
221 DataType baseType = this->GetBaseDataType();
222 return (baseType > DataType::Elementary) && (baseType <= DataType::Complex);
223}
224
226{
227 return DataType::BaseTypeMask & this->value;
228}
229
230inline bool DataTypeEnum::IsEmpty()const
231{
232 return this->value == DataType::None;
233}
234
235inline void DataTypeEnum::SetFlags(DataType flags)
236{
237 this->value = (this->value | flags);
238}
239
240inline void DataTypeEnum::ResetFlags(DataType flags)
241{
242 this->value = (this->value & ~flags);
243}
244
245}}} // end of namespace Arp::Plc::Commons
Definition: DataTypeEnum.hpp:16
bool IsReference(void) const
Checks if this data type is a reference type.
Definition: DataTypeEnum.hpp:163
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
bool IsString(void) const
Checks if this data type is a string type.
Definition: DataTypeEnum.hpp:183
size_t GetBaseSize(void) const
Returns the size of the base data type if it could be deduced, otherwise 0
DataTypeEnum(const DataTypeEnum &arg)=default
Copy constructor.
bool IsArray(void) const
Checks if this data type is an array.
Definition: DataTypeEnum.hpp:173
bool IsAnySet(DataType flags) const
Checks if any of the given flags is set.
Definition: DataTypeEnum.hpp:116
bool IsIecObject(void) const
Checks if this data type is a managed object inside the IEC context.
Definition: DataTypeEnum.hpp:203
DataTypeEnum(DataType dataType)
Constructs an DataTypeEnum instance.
Definition: DataTypeEnum.hpp:91
bool IsEnum(void) const
Checks if this data type is an enum.
Definition: DataTypeEnum.hpp:178
bool IsEmpty(void) const
True if not set
Definition: DataTypeEnum.hpp:230
DataTypeEnum GetBaseDataType(void) const
Returns the element type for an array, the underlying type for an enum, and the referenced type for a...
Definition: DataTypeEnum.hpp:225
DataTypeEnum & operator=(const DataTypeEnum &arg)=default
Assignment operator.
bool IsComplex(bool useBaseType=true) const
Checks if this data type is complex.
Definition: DataTypeEnum.hpp:145
bool IsSet(DataType flag) const
Checks if the given flag is set.
Definition: DataTypeEnum.hpp:111
bool HasChilds(void) const
Checks if this data type might have any childs. Pointer of structs are treated as structs,...
Definition: DataTypeEnum.hpp:214
size_t GetSize(void) const
Returns the size of the this data type if it could be deduced, otherwise 0
RscType GetRscType() const
Returns the associated rsc type.
DataType GetValue(void) const
Returns the unwraped original enum value of type DataType.
Definition: DataTypeEnum.hpp:106
~DataTypeEnum(void)=default
Destructs this instance and frees all resources.
bool Is8BitString() const
Checks if this data type is a 8 byte string type.
Definition: DataTypeEnum.hpp:188
bool IsPointer(void) const
Checks if this data type is a pointer type.
Definition: DataTypeEnum.hpp:158
bool IsElementary(bool useBaseType=true) const
Checks if this data type is elementary (but not primitive).
Definition: DataTypeEnum.hpp:132
size_t GetDataAlignment(void) const
Returns the alignment of this data type if it could be deduced, otherwise 0
DataTypeEnum(DataTypeEnum &&arg)=default
Move constructor.
bool IsPrimitive(void) const
Checks if this data type is primitive.
Definition: DataTypeEnum.hpp:121
bool IsWideString() const
Checks if this data type is a wide string type.
Definition: DataTypeEnum.hpp:196
DataType
Definition: DataType.hpp:15
@ BaseTypeMask
summary>For removing all flags
@ String
summary>Static Wide String type (UTF-16)
@ Component
summary>Library
@ IecString
summary>.NET/C# String type, only for internal use (not supported yet)
@ StaticWString
summary>Iec Wide String type (UTF-16), only for internal use
@ IecWString
summary>Limit of elementary types.
@ StaticString
summary>Iec String type, only for internal use
@ None
summary>Unspecified.
@ FunctionBlock
summary>Subsystem
@ Program
summary>Component
@ Class
summary>Function Block
RscType
Data types supported by RSC.
Definition: RscType.hpp:36
Root namespace for the PLCnext API