PLCnext API Documentation 23.6.0.37
DataTagDeduction.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
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 = const void*;
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(&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(&(*value)) {}
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(&(*value)) {}
80 };
81};
82
84// inline methods of class DataInfoDeduction
85inline DataTagDeduction::DataTagDeduction(const char* libraryNamespace)
86 : libraryNamespace(libraryNamespace)
87{
88}
89
90template<class T>
91inline DataTag DataTagDeduction::operator()(const char* name, T& value)const
92{
93 DataType dataType = DataTypeDeduction<T>();
94 TypeIdentifierDeduction getTypeId(this->libraryNamespace);
95 TypeIdentifier typeId = getTypeId(value);
96
97 return DataTag(name, GetAdress<T>(value), dataType, typeId);
98}
99
100}}}}} // end of namespace Arp::Plc::Commons::Meta::TypeSystem
Includes kind as well as instance browse name.
Definition: DataTag.hpp:25
Identifies a type descriptions
Definition: TypeIdentifier.hpp:24
DataTagDeduction(const char *libraryNamespace=nullptr)
Constructs an DataInfoDeduction instance.
Definition: DataTagDeduction.hxx:85
~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.
Definition: DataTypeDeduction.hxx:16
Definition: TypeIdentifierDeduction.hxx:20
DataType
Definition: DataType.hpp:15
Root namespace for the PLCnext API
Namespace of the C++ standard library