1 #pragma once
2 
3 #include "XmlNode.h"
4 #include "XmlNodeSet.h"
5 #include <libxml/parser.h>
6 #include "no_warning_map"
7 #include "no_warning_string"
8 
9 namespace opencollada
10 {
11 	class XmlNode;
12 
13 	using XPathCacheKey = std::tuple<xmlNodePtr, std::string>;
14 	using XPathCache = std::map<XPathCacheKey, XmlNodeSet>;
15 
16 	class XmlDoc
17 	{
18 		friend class XmlSchema;
19 		friend class XmlNode;
20 
21 	public:
22 		XmlDoc() = default;
23 		XmlDoc(XmlDoc && other);
24 		virtual ~XmlDoc();
25 
26 		const XmlDoc & operator = (XmlDoc && other);
27 
28 		virtual void readFile(const std::string & path);
29 
30 		operator bool() const;
31 		void reset();
32 		XmlNode root() const;
33 		std::string getRootNamespace() const;
34 
35 		class TempRootMod
36 		{
37 		public:
38 			TempRootMod(const XmlNode & old_root);
39 			TempRootMod(TempRootMod && other);
40 			~TempRootMod();
41 
42 		private:
43 			TempRootMod(const TempRootMod&) = delete;
44 			const TempRootMod & operator = (const TempRootMod&) = delete;
45 
46 		private:
47 			XmlNode mOldDocChildren;
48 			XmlNode mOldDocLast;
49 		};
50 
51 		// Temporarily changes document's root node.
52 		// Original root is restored when TempRootMod object is destroyed.
53 		TempRootMod setTempRoot(const XmlNode & node) const;
54 
55 	private:
56 		XmlDoc(const XmlDoc&) = delete;
57 		const XmlDoc& operator = (const XmlDoc & other) = delete;
58 
59 		static XmlDoc & GetXmlDoc(xmlDocPtr doc);
60 
61 	private:
62 		xmlDocPtr mDoc = nullptr;
63 
64 		XPathCache mXPathCache;
65 	};
66 }