PLCnext API Documentation 23.6.0.37
DataTypeDeductionBase.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/TypeDeduction.hxx"
9#include "Arp/Plc/Commons/DataType.hpp"
10#include "Arp/Plc/Commons/PlcTypes.h"
11#include "Arp/Plc/Commons/Esm/IProgram.hpp"
12namespace Arp { namespace Plc { namespace Commons { namespace Meta { namespace TypeSystem
13{
14
16
17// helper types to determine element type of arrays
18template<class T, bool IsArray = std::is_array<T>::value>
20{
21 using type = T; // primary template, none array
22};
23
24template<class T>
25struct array_element_type<T, true>
26{
27 using type = typename std::remove_reference<decltype(*std::begin(std::declval<T&>()))>;
28};
29
30// global function GetDataType<T>() to determine DataType value by type
31template<class T>
32inline DataType GetDataType(void)
33{
34 if (std::is_enum<T>::value)
35 {
36 return DataType::Enum | GetDataType<typename underlying_enum_type<T>::type>();
37 }
38 else if (std::is_class<T>::value)
39 {
40 return DataType::Struct;
41 }
42 else if (std::is_array<T>::value)
43 {
44 return DataType::Array | GetDataType<typename array_element_type<T>::type>();
45 }
46 else if (std::is_pointer<T>::value)
47 {
48 return DataType::Pointer | GetDataType<typename std::remove_pointer<T>::type>();
49 }
50 else
51 {
52 return DataType::None; // this should never be returned here
53 }
54}
55
56template<>
57inline DataType GetDataType<Bit>()
58{
59 return DataType::Bit;
60}
61
62template<>
63inline DataType GetDataType<boolean>()
64{
65 return DataType::Boolean;
66}
67
68template<>
69inline DataType GetDataType<char8>()
70{
71 return DataType::Char8;
72}
73
74//template<>
75//inline DataType GetDataType<Char16>(void) { return DataType::Char16; }
76//
77template<>
78inline DataType GetDataType<uint8>()
79{
80 return DataType::UInt8;
81}
82
83template<>
84inline DataType GetDataType<int8>(void)
85{
86 return DataType::Int8;
87}
88
89template<>
90inline DataType GetDataType<uint16>(void)
91{
92 return DataType::UInt16;
93}
94
95template<>
96inline DataType GetDataType<int16>(void)
97{
98 return DataType::Int16;
99}
100
101template<>
102inline DataType GetDataType<uint32>(void)
103{
104 return DataType::UInt32;
105}
106
107template<>
108inline DataType GetDataType<int32>(void)
109{
110 return DataType::Int32;
111}
112
113template<>
114inline DataType GetDataType<uint64>(void)
115{
116 return DataType::UInt64;
117}
118
119template<>
120inline DataType GetDataType<int64>(void)
121{
122 return DataType::Int64;
123}
124
125template<>
126inline DataType GetDataType<float32>(void)
127{
128 return DataType::Float32;
129}
130
131template<>
132inline DataType GetDataType<float64>(void)
133{
134 return DataType::Float64;
135}
136
137template<>
138inline DataType GetDataType<DateTime>(void)
139{
140 return DataType::DateTime;
141}
142
143template<>
144inline DataType GetDataType<String>(void)
145{
146 return DataType::String;
147}
148
149template<>
150inline DataType GetDataType<IProgram>(void)
151{
152 return DataType::Program;
153}
154
156{
157protected: // typedefs/usings
159
160protected: // construction
161 DataTypeDeductionBase(DataType value) : Value(value) {}
162 DataTypeDeductionBase(const DataTypeDeductionBase& arg) = default;
164 DataTypeDeductionBase& operator=(const DataTypeDeductionBase& arg) = default;
165 DataTypeDeductionBase& operator=(DataTypeDeductionBase&& arg) = default;
166 ~DataTypeDeductionBase(void) = default;
167
168public: // operators
169 operator DataType(void)const;
170
171public: // fields
172 DataType Value = DataType::None;
173};
174
176// inline methods of class DataTypeDeductionBase
177inline DataTypeDeductionBase::operator DataType()const
178{
179 return this->Value;
180}
181
182}}}}} // end of namespace Arp::Plc::Commons::Meta::TypeSystem
Interface to implement PLC program to be executed in realtime context.
Definition: IProgram.hpp:19
Definition: DataTypeDeductionBase.hpp:156
DataType
Definition: DataType.hpp:15
@ Float32
summary>Float64 - Arp C++ data type (8 Byte)
@ String
summary>Static Wide String type (UTF-16)
@ Boolean
summary>UInt8 - Arp C++ data type (1 Byte)
@ Int16
summary>UInt32 - Arp C++ data type (4 Byte)
@ None
summary>Unspecified.
@ Int8
summary>Char8 - Arp C++ data type (1 Byte)
@ UInt16
summary>Int16 - Arp C++ data type (2 Byte)
@ DateTime
summary>C++ DateTime type
@ Program
summary>Component
@ UInt64
summary>Int64 - Arp C++ data type (8 Byte)
@ UInt8
summary>Int8 - Arp C++ data type (1 Byte)
@ Int32
summary>UInt64 - Arp C++ data type (8 Byte)
@ Float64
summary>Limit of primitive types.
@ Char8
summary>Char16 - Arp C++ data type (2 Byte)
@ UInt32
summary>Int32 - Arp C++ data type (4 Byte)
@ Bit
summary>Boolean - Arp C++ data type (1 Byte)
@ Int64
summary>Float32 - Arp C++ data type (4 Byte)
Root namespace for the PLCnext API
Definition: DataTypeDeductionBase.hpp:20