PLCnext API Documentation  22.9.0.33
TicConfigDocument.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Configuration/TicReader.hpp"
9 #include "Arp/System/Commons/Configuration/TicSerializationContext.hpp"
10 namespace Arp { namespace System { namespace Commons { namespace Configuration
11 {
12 
13 // TContent policy: implements ITicSerializable and default contructable
14 template<class TContent>
16 {
17 public: // typedefs
18  typedef TContent Content;
19  typedef typename TContent::Ptr ContentPtr;
20  typedef std::shared_ptr<TicConfigDocument<TContent>> Ptr;
21 
22 public: // construction/destruction
24  TicConfigDocument(ContentPtr contentPtr = nullptr);
26  ~TicConfigDocument(void) = default;
27 
28 public: // setter/getter operations
29  const String& GetDocumentFilename(void)const;
30  ContentPtr GetContent(void);
31 
32 public: // operations
33  void Load(const String& filename);
34 
35 private: // deleted methods
37  TicConfigDocument(const TicConfigDocument& arg) = delete;
39  TicConfigDocument& operator=(const TicConfigDocument& arg) = delete;
40 
41 private: // fields
42  ContentPtr contentPtr;
43  String documentFilename;
44 };
45 
47 // inline methods of class TicConfigDocument
48 template<class T>
49 inline TicConfigDocument<T>::TicConfigDocument(ContentPtr contentPtrArg)
50  : contentPtr(contentPtrArg)
51  , documentFilename()
52 {
53  if (this->contentPtr == nullptr)
54  {
55  this->contentPtr = ContentPtr(new Content());
56  }
57 }
58 
59 template<class T>
60 inline typename TicConfigDocument<T>::ContentPtr TicConfigDocument<T>::GetContent(void)
61 {
62  return this->contentPtr;
63 }
64 
65 template<class T>
66 inline const String& TicConfigDocument<T>::GetDocumentFilename(void)const
67 {
68  return this->documentFilename;
69 }
70 
71 template<class T>
72 inline void TicConfigDocument<T>::Load(const String& filename)
73 {
74  TicReader reader = TicReader::Create(filename);
75  TicSerializationContext context(reader);
76 
77  this->documentFilename = filename;
78  context.SetFilePath(filename);
79 
80  // start reading
81  reader.GetXmlReader().ReadStartElement("TIC");
82  // read context
83  context.ReadDocumentContext(reader);
84  // read content
85  this->contentPtr->ReadTic(reader, context);
86  // end reading
87  reader.GetXmlReader().ReadEndElement();
88 }
89 
90 }}}} // end of namespace Arp::System::Commons::Configuration
Definition: TicConfigDocument.hxx:16
TicConfigDocument(ContentPtr contentPtr=nullptr)
Constructs an TicConfigDocument instance.
Definition: TicConfigDocument.hxx:49
~TicConfigDocument(void)=default
Destructs this instance and frees all resouces.
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API