libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
XML_Stuff.hpp
Go to the documentation of this file.
1 // TITLE:
2 //
3 // AUTHOR:
4 // Created by J.M.McGuiness, E-mail: coder@hussar.me.uk
5 //
6 // DESCRIPTION:
7 // Note: You need to put the line "#import <msxml4.dll> implementation_only" in the "stdafx.cpp" or you'll get link errors with the MSXML stuff....
8 // (I need to do this as the more simple route of omitting the "no_implementation" in this file leads to those link errors anyway, if the "#import <msxml4.dll>" is put in "stdafx.h".
9 //
10 // LEGALITIES:
11 // Copyright © 2004 by J.M.McGuiness, all rights reserved.
12 //
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
17 //
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 //
27 /////////////////////////////////////////////////////////////////////////////
28 
29 #import<msxml6.dll> no_implementation
30 
31 #include"exception.hpp"
32 
33 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace NTUtils { namespace XML {
34 
36 
37  typedef enum {
41  text
42  } node_types;
43 
44  inline MSXML2::IXMLDOMNodePtr __fastcall CreateNode(const node_types type,const tchar *node_name,const MSXML2::IXMLDOMDocumentPtr &doc,const tchar *xml_ns);
45  inline MSXML2::IXMLDOMNodePtr __fastcall CreateNode(const node_types type,const tchar *node_name,const MSXML2::IXMLDOMDocumentPtr &doc,const tchar *xml_ns,const MSXML2::IXMLDOMNodePtr &node);
47  inline tstring __fastcall GetParseError(const MSXML2::IXMLDOMDocumentPtr &doc);
48 
49  inline void __fastcall ToXML(const MSXML2::IXMLDOMDocumentPtr &doc,const MSXML2::IXMLDOMNodePtr &n,const POINT &pt,const tchar *xml_ns);
50  inline void __fastcall FromXML(const MSXML2::IXMLDOMNodePtr &n,POINT &pt);
51  inline void __fastcall ToXML(const MSXML2::IXMLDOMDocumentPtr &doc,const MSXML2::IXMLDOMNodePtr &n,const RECT &rect,const tchar *xml_ns);
52  inline void __fastcall FromXML(const MSXML2::IXMLDOMNodePtr &n,RECT &rect);
53  template<typename Value> inline void __fastcall ToXML(const MSXML2::IXMLDOMDocumentPtr &doc,const MSXML2::IXMLDOMNodePtr &n,const tchar *colln_name,const std::vector<Value> &colln,const tchar *xml_ns);
54  template<> inline void __fastcall ToXML(const MSXML2::IXMLDOMDocumentPtr &doc,const MSXML2::IXMLDOMNodePtr &n,const tchar *colln_name,const std::vector<double> &colln,const tchar *xml_ns);
55  template<> inline void __fastcall ToXML(const MSXML2::IXMLDOMDocumentPtr &doc,const MSXML2::IXMLDOMNodePtr &n,const tchar *colln_name,const std::vector<CPoint> &colln,const tchar *xml_ns);
56  template<typename Value> inline void __fastcall FromXML(const MSXML2::IXMLDOMNodePtr &n,const tstring &colln_name,std::vector<Value> &colln);
57  template<> inline void __fastcall FromXML(const MSXML2::IXMLDOMNodePtr &n,const tstring &colln_name,std::vector<double> &colln);
58  template<> inline void __fastcall FromXML(const MSXML2::IXMLDOMNodePtr &n,const tstring &colln_name,std::vector<CPoint> &colln);
59 
60  class DocWrapper {
61  public:
62  inline __stdcall DocWrapper(void);
63  inline __stdcall DocWrapper(const DocWrapper &);
64  virtual inline __stdcall ~DocWrapper(void);
65 
66  inline const MSXML2::IXMLDOMDocumentPtr & __fastcall Doc(void) const noexcept(true);
67 
68  inline void __fastcall LoadXML(const tchar *xml);
69  inline void __fastcall Load(const tchar *filename);
70  inline void __fastcall Load(const IStreamPtr &file);
71  inline void __fastcall Save(const tchar *filename);
72 
73  private:
74  const MSXML2::IXMLDOMDocumentPtr doc;
75 
76  static inline MSXML2::IXMLDOMDocumentPtr __fastcall MakeDoc(void);
77 
78  // I don't allow assignment.
79  inline DocWrapper & __fastcall operator=(const DocWrapper &);
80  };
81 
82  class DocNS : public DocWrapper {
83  public:
84  inline __stdcall DocNS(const tstring &ns=_T(""))
86  }
87  inline __stdcall DocNS(const DocNS &d)
89  }
90  virtual inline __stdcall ~DocNS(void) {
91  }
92 
93  inline const tstring & __fastcall
94  Namespace(void) const noexcept(true) {
95  return n_space;
96  }
97 
98  inline MSXML2::IXMLDOMNodePtr __fastcall
100  return XML::CreateNode(type,node_name,Doc(),n_space.c_str(),node);
101  }
102 
103  inline MSXML2::IXMLDOMNodePtr __fastcall
105  return XML::CreateComment(node_name,comment,Doc(),n_space.c_str(),node);
106  }
107 
108  inline void __fastcall
109  ToXML(const MSXML2::IXMLDOMNodePtr &n,const POINT &pt) {
110  XML::ToXML(Doc(),n,pt,n_space.c_str());
111  }
112  inline void __fastcall
113  ToXML(const MSXML2::IXMLDOMNodePtr &n,const RECT &rect) {
114  XML::ToXML(Doc(),n,rect,n_space.c_str());
115  }
116  template<typename Value> inline void __fastcall
117  ToXML(const MSXML2::IXMLDOMNodePtr &n,const tchar *colln_name,const std::vector<Value> &colln) {
118  XML::ToXML(Doc(),n,colln_name,colln,n_space.c_str());
119  }
120 
121  private:
122  const tstring n_space;
123 
124  // I don't allow assignment.
125  inline DocNS & __fastcall operator=(const DocNS &);
126  };
127 
128 } } } }