PLCnext API Documentation 26.0.1.58
TicConfigDocument.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Commons/Configuration/TicReader.hpp"
9#include "Arp/System/Commons/Configuration/TicSerializationContext.hpp"
10#include <type_traits>
11namespace Arp { namespace System { namespace Commons { namespace Configuration
12{
13
14// TContent policy: implements ITicSerializable and default contructable
15template<class TContent>
17{
18public: // typedefs
19 typedef TContent Content;
20 typedef typename TContent::Ptr ContentPtr;
21 typedef std::shared_ptr<TicConfigDocument<TContent>> Ptr;
22
23public: // construction/destruction
25 TicConfigDocument(ContentPtr contentPtr = nullptr);
28
29public: // setter/getter operations
30 const String& GetDocumentFilename(void)const;
31 ContentPtr GetContent(void);
32
33public: // operations
34 void Load(const String& filename);
35
36private: // deleted methods
38 TicConfigDocument(const TicConfigDocument& arg) = delete;
40 TicConfigDocument(TicConfigDocument&& other) noexcept = delete;
42 TicConfigDocument& operator=(const TicConfigDocument& arg) = delete;
44 TicConfigDocument& operator=(TicConfigDocument&& other) noexcept = delete;
45
46private: // fields
47 ContentPtr contentPtr;
48 String documentFilename;
49};
50
52// inline methods of class TicConfigDocument
53template<class T>
54inline TicConfigDocument<T>::TicConfigDocument(ContentPtr contentPtrArg)
55 : contentPtr(contentPtrArg)
56 , documentFilename()
57{
58 if (this->contentPtr == nullptr)
59 {
60 this->contentPtr = ContentPtr(new Content());
61 }
62}
63
64template<class T>
66{
67 if constexpr (std::is_pointer_v<ContentPtr>)
68 {
69 if (this->contentPtr != nullptr)
70 {
71 delete this->contentPtr;
72 this->contentPtr = nullptr;
73 }
74 }
75}
76
77template<class T>
78inline typename TicConfigDocument<T>::ContentPtr TicConfigDocument<T>::GetContent(void)
79{
80 return this->contentPtr;
81}
82
83template<class T>
85{
86 return this->documentFilename;
87}
88
89template<class T>
90inline void TicConfigDocument<T>::Load(const String& filename)
91{
92 TicReader reader = TicReader::Create(filename);
93 TicSerializationContext context(reader);
94
95 this->documentFilename = filename;
96 context.SetFilePath(filename);
97
98 // start reading
99 reader.GetXmlReader().ReadStartElement("TIC");
100 // read context
101 context.ReadDocumentContext(reader);
102 // read content
103 this->contentPtr->ReadTic(reader, context);
104 // end reading
105 reader.GetXmlReader().ReadEndElement();
106}
107
108}}}} // end of namespace Arp::System::Commons::Configuration
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Definition: TicConfigDocument.hxx:17
TicConfigDocument(ContentPtr contentPtr=nullptr)
Constructs an TicConfigDocument instance.
Definition: TicConfigDocument.hxx:54
~TicConfigDocument(void)
Destructs this instance and frees all resouces.
Definition: TicConfigDocument.hxx:65
Definition: TicSerializationContext.hpp:19
void ReadStartElement(const char *elementName=nullptr)
reads to the next element and test if this is a start element with the given name
Definition: XmlReader.cpp:593
void ReadEndElement(void)
reads until the next end element is reached skips over an empty element
Definition: XmlReader.cpp:714
Root namespace for the PLCnext API