PLCnext API Documentation 25.0.2.69
DataTagDeduction.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Plc/Commons/Meta/DataTag.hpp"
9#include "Arp/Plc/Commons/Meta/TypeSystem/DataTypeDeduction.hxx"
10#include "Arp/Plc/Commons/Meta/TypeSystem/TypeIdentifierDeduction.hxx"
11
12namespace Arp { namespace Plc { namespace Commons { namespace Meta { namespace TypeSystem
13{
14
16{
17public: // construction/destruction
19 DataTagDeduction(const char* libraryNamespace = nullptr);
21 DataTagDeduction(const DataTagDeduction& arg) = default;
29 ~DataTagDeduction(void) = default;
30
31public: // static operations
32 template<class T>
33 DataTag operator()(const char* name, T& value)const;
34
35private: // fields
36 const char* libraryNamespace;
37
38private: // nested class GetAdressBase
39 struct GetAdressBase
40 {
41 protected: // typedefs/usings
42 using Base = GetAdressBase;
43 using ValueType = byte*;
44
45 protected: // construction
46 GetAdressBase(ValueType value) : Value(value) {}
47 GetAdressBase(const GetAdressBase& arg) = default;
48 GetAdressBase(GetAdressBase&& arg) = default;
49 GetAdressBase& operator=(const GetAdressBase& arg) = default;
50 GetAdressBase& operator=(GetAdressBase&& arg) = default;
51 ~GetAdressBase(void) = default;
52
53 public: // operators
54 operator ValueType(void)const
55 {
56 return this->Value;
57 }
58
59 public: // fields
60 ValueType Value = nullptr;
61 };
62
63private: // nested template class GetAdress
64 template<class T>
65 struct GetAdress : public GetAdressBase
66 {
67 GetAdress(T& value): Base(const_cast<ValueType>(reinterpret_cast<const byte*>(&value))) {}
68 };
69
70 template<class T>
71 struct GetAdress<std::shared_ptr<T>> : public GetAdressBase
72 {
73 GetAdress(std::shared_ptr<T>& value) : Base(const_cast<ValueType>(reinterpret_cast<const byte*>(value.get()))) {}
74 };
75
76 template<class T>
77 struct GetAdress<const std::shared_ptr<T>> : public GetAdressBase
78 {
79 GetAdress(const std::shared_ptr<T>& value) : Base(const_cast<ValueType>(reinterpret_cast<const byte*>(value.get()))) {}
80 };
81};
82
84// inline methods of class DataInfoDeduction
85
86template<class T>
87inline DataTag DataTagDeduction::operator()(const char* name, T& value)const
88{
89 DataType dataType = DataTypeDeduction<T>();
90 TypeIdentifierDeduction getTypeId(this->libraryNamespace);
91 TypeIdentifier typeId = getTypeId(value);
92
93 return DataTag(name, GetAdress<T>(value), dataType, typeId);
94}
95
96}}}}} // end of namespace Arp::Plc::Commons::Meta::TypeSystem
Includes kind as well as instance browse name.
Definition: DataTag.hpp:24
DataTagDeduction(const char *libraryNamespace=nullptr)
Constructs an DataInfoDeduction instance.
Definition: DataTagDeduction.cpp:12
~DataTagDeduction(void)=default
Destructs this instance and frees all resources.
DataTagDeduction & operator=(DataTagDeduction &&arg)=default
Move assignment operator.
DataTagDeduction & operator=(const DataTagDeduction &arg)=default
Copy assignment operator.
DataTagDeduction(DataTagDeduction &&arg)=default
Move constructor.
DataTagDeduction(const DataTagDeduction &arg)=default
Copy constructor.
std::byte byte
The Arp byte type.
Definition: Byte.hpp:24
DataType
This enum represents the data type of a variable.
Definition: DataType.hpp:15
Root namespace for the PLCnext API
Namespace of the C++ standard library