PLCnext API Documentation  20.6.0.30321
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 
11 namespace Arp { namespace System { namespace Commons { namespace Xml
12 {
13 
14 // forwards
15 class MultiXmlConfigDocument;
16 
17 // TContent policy: implement IXmlSerializable and default contructable
20 {
21  friend class XmlSerializationContext;
22 
23 public: // construction/destruction
27  XmlConfigDocument(const String& documentXmlElementName, IXmlSerializable& content);
31  virtual ~XmlConfigDocument(void) = default;
32 
33 public: // setter/getter operations
35  const String& GetPath(void)const;
41  Version GetRecentVersion(void)const;
42 
43 public: // operations
45  void Load(const String& documentPath);
48  bool TryLoad(const String& documentPath);
50  void Save(const String& documentPath);
52  void Save(void);
53 
54 protected: // virtual methods to override
55  virtual void ReadDocument(XmlReader& reader);
56 
57 private: // deleted methods
59  XmlConfigDocument(const XmlConfigDocument& arg) = delete;
61  XmlConfigDocument& operator=(const XmlConfigDocument& arg) = delete;
62 
63 protected: // fields
64  MultiXmlConfigDocument* pRootDoc;
65  IXmlSerializable& content;
66  String documentXmlElementName;
67  String path;
68  Version recentVersion;
69 };
70 
72 // inline methods of class XmlConfigDocument
73 
74 inline const String& XmlConfigDocument::GetPath(void)const
75 {
76  return this->path;
77 }
78 
80 {
81  return this->content;
82 }
83 
85 {
86  return this->pRootDoc;
87 }
88 
89 inline Version XmlConfigDocument::GetRecentVersion()const
90 {
91  return this->recentVersion;
92 }
93 
94 inline void XmlConfigDocument::Save()
95 {
96  if (this->path.IsEmpty())
97  {
98  throw XmlException("Document filename was not set ");
99  }
100  this->Save(this->path);
101 }
102 
103 }}}} // end of namespace Arp::System::Commons::Xml
MultiXmlConfigDocument * GetRootDocument(void)
summary>Returns the recend implemented schema version, used by XmlSerializationContext
Definition: XmlConfigDocument.hpp:84
special version of XmlConfigDocument to include xml configuration data from other xml files inside a ...
Definition: MultiXmlConfigDocument.hpp:23
void Save(const String &documentPath)
summary>saves the content xml encoded to the file the document was loaded from
const String & GetPath(void) const
Returns the path to the current file loaded by this document
Definition: XmlConfigDocument.hpp:74
virtual ~XmlConfigDocument(void)=default
Destructs this instance and frees all resouces.
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:19
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:79
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:24
void Load(const String &documentPath)
loads and parses the xml document from documentPath