PLCnext API Documentation  22.9.0.33
XmlConfigDocument.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Xml/IXmlSerializable.hpp"
9 #include "Arp/System/Commons/Xml/XmlSerializationContext.hpp"
10 #include "Arp/System/Commons/Configuration/ConfigSettings.hpp"
11 
12 namespace Arp { namespace System { namespace Commons { namespace Xml
13 {
14 
15 // forwards
16 class MultiXmlConfigDocument;
17 
18 // TContent policy: implement IXmlSerializable and default contructable
21 {
22  friend class XmlSerializationContext;
23 
24 public: // construction/destruction
28  XmlConfigDocument(const String& documentXmlElementName, IXmlSerializable& content);
32  virtual ~XmlConfigDocument(void) = default;
33 
34 public: // setter/getter operations
36  const String& GetPath(void)const;
42  Version GetRecentVersion(void)const;
43 
44 public: // operations
46  void Load(const String& documentPath);
49  bool TryLoad(const String& documentPath);
51  void Save(const String& documentPath);
54  void Save(const String& documentPath, bool syncFilesystem);
56  void Save(void);
59  void Save(bool syncFilesystem);
61  void LoadString(const String& xmlContent);
62 
63 protected: // virtual methods to override
64  virtual void ReadDocument(XmlReader& reader);
65 
66 private: // deleted methods
68  XmlConfigDocument(const XmlConfigDocument& arg) = delete;
70  XmlConfigDocument& operator=(const XmlConfigDocument& arg) = delete;
71 
72 protected: // fields
73  MultiXmlConfigDocument* pRootDoc;
74  IXmlSerializable& content;
75  String documentXmlElementName;
76  String path;
77  Version recentVersion;
78 };
79 
81 // inline methods of class XmlConfigDocument
82 
83 inline const String& XmlConfigDocument::GetPath(void)const
84 {
85  return this->path;
86 }
87 
89 {
90  return this->content;
91 }
92 
94 {
95  return this->pRootDoc;
96 }
97 
98 inline Version XmlConfigDocument::GetRecentVersion()const
99 {
100  return this->recentVersion;
101 }
102 
104 {
105  this->Save(true);
106 }
107 
108 }}}} // end of namespace Arp::System::Commons::Xml
This class represents the version of a special SDK or Arp build.
Definition: BasicVersion.hpp:35
Interface for all classes which should be serializable for xml
Definition: IXmlSerializable.hpp:18
special version of XmlConfigDocument to include xml configuration data from other xml files inside a ...
Definition: MultiXmlConfigDocument.hpp:26
Class handle xml configuration documents
Definition: XmlConfigDocument.hpp:21
virtual ~XmlConfigDocument(void)=default
Destructs this instance and frees all resouces.
XmlConfigDocument(const String &documentXmlElementName, IXmlSerializable &content)
Constructs an XmlConfigDocument instance.
MultiXmlConfigDocument * GetRootDocument(void)
summary>Returns the recend implemented schema version, used by XmlSerializationContext
Definition: XmlConfigDocument.hpp:93
const String & GetPath(void) const
Returns the path to the current file loaded by this document
Definition: XmlConfigDocument.hpp:83
void Load(const String &documentPath)
Loads the document from specified <paramref="documentPath"/>
bool TryLoad(const String &documentPath)
summary>saves the content xml encoded to documentPath with filesystem sync
void Save(const String &documentPath, bool syncFilesystem)
summary>saves the content xml encoded to the file the document was loaded from with filesystem sync
XmlConfigDocument(MultiXmlConfigDocument &rootDocument, IXmlSerializable &content)
Constructs an XmlConfigDocument instance.
void Save(void)
Definition: XmlConfigDocument.hpp:103
void Save(const String &documentPath)
void Save(bool syncFilesystem)
summary>Loads the document from a string
IXmlSerializable & GetContent(void)
summary>Returns a pointer to the root document for MultiXmlConfigDocument
Definition: XmlConfigDocument.hpp:88
Class to read an XML File. Non buffered reader, can only read forward
Definition: XmlReader.hpp:25
XML context used during XML reading and writing to hold the context information
Definition: XmlSerializationContext.hpp:26
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API