PLCnext API Documentation  21.0.0.35466
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);
53  void Save(void);
55  void LoadString(const String& xmlContent);
56 
57 protected: // virtual methods to override
58  virtual void ReadDocument(XmlReader& reader);
59 
60 private: // deleted methods
62  XmlConfigDocument(const XmlConfigDocument& arg) = delete;
64  XmlConfigDocument& operator=(const XmlConfigDocument& arg) = delete;
65 
66 protected: // fields
67  MultiXmlConfigDocument* pRootDoc;
68  IXmlSerializable& content;
69  String documentXmlElementName;
70  String path;
71  Version recentVersion;
72 };
73 
75 // inline methods of class XmlConfigDocument
76 
77 inline const String& XmlConfigDocument::GetPath(void)const
78 {
79  return this->path;
80 }
81 
83 {
84  return this->content;
85 }
86 
88 {
89  return this->pRootDoc;
90 }
91 
92 inline Version XmlConfigDocument::GetRecentVersion()const
93 {
94  return this->recentVersion;
95 }
96 
98 {
99  if (this->path.IsEmpty())
100  {
101  throw XmlException("Document filename was not set ");
102  }
103  this->Save(this->path);
104 }
105 
106 }}}} // end of namespace Arp::System::Commons::Xml
MultiXmlConfigDocument * GetRootDocument(void)
summary>Returns the recend implemented schema version, used by XmlSerializationContext
Definition: XmlConfigDocument.hpp:87
special version of XmlConfigDocument to include xml configuration data from other xml files inside a ...
Definition: MultiXmlConfigDocument.hpp:25
void Save(void)
summary>Loads the document from a string
Definition: XmlConfigDocument.hpp:97
const String & GetPath(void) const
Returns the path to the current file loaded by this document
Definition: XmlConfigDocument.hpp:77
virtual ~XmlConfigDocument(void)=default
Destructs this instance and frees all resouces.
bool IsEmpty() const
Determines if this string is empty.
Definition: BasicString.hxx:1099
This class represents the version of a special SDK or Arp build.
Definition: BasicVersion.hpp:34
Interface for all classes which should be serializable for xml
Definition: IXmlSerializable.hpp:17
Class handle xml configuration documents
Definition: XmlConfigDocument.hpp:20
bool TryLoad(const String &documentPath)
summary>saves the content xml encoded to documentPath
XmlConfigDocument(const String &documentXmlElementName, IXmlSerializable &content)
Constructs an XmlConfigDocument instance.
Root namespace for the PLCnext API
This exception is used for xml parsing errors.
Definition: XmlException.hpp:14
Class to read an XML File. Non buffered reader, can only read forward
Definition: XmlReader.hpp:22
IXmlSerializable & GetContent(void)
summary>Returns a pointer to the root document for MultiXmlConfigDocument
Definition: XmlConfigDocument.hpp:82
System components used by the System, Device, Plc or Io domains.
XML context used during XML reading and writing to hold the context information
Definition: XmlSerializationContext.hpp:25
void Load(const String &documentPath)
Loads the document from specified <paramref="documentPath"/>