PLCnext API Documentation 23.6.0.37
TicConfigDocument.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Commons/Configuration/TicReader.hpp"
9#include "Arp/System/Commons/Configuration/TicSerializationContext.hpp"
10namespace Arp { namespace System { namespace Commons { namespace Configuration
11{
12
13// TContent policy: implements ITicSerializable and default contructable
14template<class TContent>
16{
17public: // typedefs
18 typedef TContent Content;
19 typedef typename TContent::Ptr ContentPtr;
20 typedef std::shared_ptr<TicConfigDocument<TContent>> Ptr;
21
22public: // construction/destruction
24 TicConfigDocument(ContentPtr contentPtr = nullptr);
26 ~TicConfigDocument(void) = default;
27
28public: // setter/getter operations
29 const String& GetDocumentFilename(void)const;
30 ContentPtr GetContent(void);
31
32public: // operations
33 void Load(const String& filename);
34
35private: // deleted methods
37 TicConfigDocument(const TicConfigDocument& arg) = delete;
39 TicConfigDocument& operator=(const TicConfigDocument& arg) = delete;
40
41private: // fields
42 ContentPtr contentPtr;
43 String documentFilename;
44};
45
47// inline methods of class TicConfigDocument
48template<class T>
49inline 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
59template<class T>
60inline typename TicConfigDocument<T>::ContentPtr TicConfigDocument<T>::GetContent(void)
61{
62 return this->contentPtr;
63}
64
65template<class T>
66inline const String& TicConfigDocument<T>::GetDocumentFilename(void)const
67{
68 return this->documentFilename;
69}
70
71template<class T>
72inline 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