PLCnext API Documentation  21.0.0.35466
DataInfoProvider.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/Enumerator.hxx"
9 #include "Arp/Plc/Commons/Meta/IDataInfoProvider.hpp"
10 #include "Arp/Plc/Commons/Meta/TypeSystem/DataInfoDeduction.hxx"
11 #include "Arp/Plc/Commons/Esm/ProgramProviderBase.hpp"
12 #include "Arp/Plc/Commons/Meta/ChangeDataInfoProvider.hpp"
13 #include <map>
14 
15 // forwards
16 namespace Arp { namespace Plc { namespace Commons { namespace Esm
17 {
18 class ProgramComponentBase;
19 }}}} // end of namespace Arp::Plc::Commons::Esm
20 
21 namespace Arp { namespace Plc { namespace Commons { namespace Meta
22 {
23 
24 // forwards
25 class ChangeDataInfoProvider;
26 
29 
30 
36 {
38 
39 public: // typedefs/usings
40  using Roots = std::map<String, DataInfo>;
41 
42 private: // nested types
43  class RootsEnumerator : public Enumerator<const DataInfo&>
44  {
45  public: // construcion
46  RootsEnumerator(const Roots& roots);
47 
48  public: // Enumerator<DataInfo> operations
49  bool MoveNext(void)override;
50 
51  private:
52  const Roots& roots;
53  Roots::const_iterator currentIterator;
54  Roots::const_iterator endIterator;
55  bool isFirstMove = true;
56  };
57 
58 public: // construction/destruction
61  DataInfoProvider(const char* libraryNamespace, ProgramProviderBase* pProgramProvider = nullptr);
63  DataInfoProvider(const DataInfoProvider& arg) = default;
65  DataInfoProvider(DataInfoProvider&& arg) = default;
67  DataInfoProvider& operator=(const DataInfoProvider& arg) = default;
69  DataInfoProvider& operator=(DataInfoProvider&& arg) = default;
71  ~DataInfoProvider(void) = default;
72 
73 public: // getter properties
75  const String& GetLibraryNamespace() const;
76 
80  IDataInfoProvider& GetBackgroundProvider(void);
81 
82 public: // operations
84  void Reset(void);
85 
88  void AddRootInfo(const DataInfo& rootInfo);
89 
92  void RemoveRootInfo(const String& name);
93 
99  template<class T>
100  void AddRoot(const char* name, const T& value);
101 
102 public: // IDataInfoProvider operations
103  IEnumerator<const DataInfo&>::Ptr GetRoots(void)override;
104  DataInfo GetRoot(const String& name)override;
105 
106 private: // methods
107  void AddDataInfo(const DataInfo& dataInfo);
108  void RemoveDataInfo(const String& localVariableName);
109 
110 private: // fields
111  String libraryNamespace;
112  ProgramProviderBase* pProgramProvider = nullptr; // Deprecated (binary compatibility). Keeping track of programs is handled in ProgamProviderBase.
113  Roots roots;
114  ChangeDataInfoProvider backgroundProvider;
115 };
116 
118 // inline methods of class DataInfoProvider
119 
120 inline void DataInfoProvider::AddRootInfo(const DataInfo& rootInfo)
121 {
122  this->AddDataInfo(rootInfo);
123 }
124 
125 inline void DataInfoProvider::RemoveRootInfo(const String& name)
126 {
127  this->roots.erase(name);
128 }
129 
130 template<class T>
131 inline void DataInfoProvider::AddRoot(const char* name, const T& value)
132 {
133  DataInfoDeduction getDataInfo(this->libraryNamespace);
134  this->AddDataInfo(getDataInfo(name, value));
135 }
136 
137 }}}} // end of namespace Arp::Plc::Commons::Meta
Definition: DataInfoDeduction.hxx:13
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom...
Definition: IEnumerator.hxx:47
void AddRoot(const char *name, const T &value)
Deduces the required information of a root variable and add it
Definition: DataInfoProvider.hpp:131
Provides information of component root variables
Definition: DataInfoProvider.hpp:35
Decorator for DataInfoProvider to set IsBackgroundDomain = true
Definition: ChangeDataInfoProvider.hpp:21
void AddRootInfo(const DataInfo &rootInfo)
Adds information about a component root
Definition: DataInfoProvider.hpp:120
Root namespace for the PLCnext API
Provides detailed informations for the respective data object.
Definition: DataInfo.hpp:31
Namespace for the type information of the Meta component
Definition: DataInfoDeduction.hxx:10
Interface to provide information about component roots
Definition: IDataInfoProvider.hpp:17
void RemoveRootInfo(const String &name)
Removes the information about the specified variable
Definition: DataInfoProvider.hpp:125
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:21
Definition: ProgramProviderBase.hpp:15