PLCnext API Documentation  22.9.0.33
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;
71  ~DataInfoProvider(void) override = default;
72 
73 public: // getter properties
75  const String& GetLibraryNamespace() const;
76 
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
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
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:22
Declares the interface of the enumerator pattern, which is leaned on .NET enumerator idiom.
Definition: IEnumerator.hxx:48
Definition: ProgramProviderBase.hpp:16
Decorator for DataInfoProvider to set IsBackgroundDomain = true
Definition: ChangeDataInfoProvider.hpp:22
Provides information of component root variables
Definition: DataInfoProvider.hpp:36
void AddRoot(const char *name, const T &value)
Deduces the required information of a root variable and add it
Definition: DataInfoProvider.hpp:131
const String & GetLibraryNamespace() const
Returns the library namespace
DataInfoProvider(const char *libraryNamespace, ProgramProviderBase *pProgramProvider=nullptr)
Constructs an DataInfoProvider instance.
DataInfoProvider(DataInfoProvider &&arg)=default
Move constructor
DataInfoProvider(const DataInfoProvider &arg)=default
Copy constructor.
DataInfo GetRoot(const String &name) override
Returns the requested root variable of the component
void Reset(void)
Removes all variable information
void AddRootInfo(const DataInfo &rootInfo)
Adds information about a component root
Definition: DataInfoProvider.hpp:120
DataInfoProvider & operator=(const DataInfoProvider &arg)=default
Copy assignment operator.
IEnumerator< const DataInfo & >::Ptr GetRoots(void) override
Returns an IEnumerator to enumerate all root variables of the component
~DataInfoProvider(void) override=default
Destructs this instance and frees all resources.
void RemoveRootInfo(const String &name)
Removes the information about the specified variable
Definition: DataInfoProvider.hpp:125
DataInfoProvider & operator=(DataInfoProvider &&arg)=default
Move assignment operator
IDataInfoProvider & GetBackgroundProvider(void)
Returns an IDataInfoProvider for the background domain
Provides detailed informations for the respective data object.
Definition: DataInfo.hpp:32
Interface to provide information about component roots
Definition: IDataInfoProvider.hpp:18
Definition: DataInfoDeduction.hxx:14
Namespace for the type information of the Meta component
Definition: DataInfoDeduction.hxx:11
Root namespace for the PLCnext API