version 0.1.0
[fms.git] / include / ifmsxmldocument.h
1 #ifndef _ifmsxmldocument_\r
2 #define _ifmsxmldocument_\r
3 \r
4 #include "stringfunctions.h"\r
5 \r
6 #include <string>\r
7 #include <tinyxml.h>\r
8 \r
9 /**\r
10         \brief Interface for objects that represent an XML document\r
11 */\r
12 class IFMSXMLDocument\r
13 {\r
14 public:\r
15         \r
16         /**\r
17                 \brief Returns xml document represented by this object\r
18                 \r
19                 \return xml document\r
20         */\r
21         virtual std::string GetXML()=0;\r
22         \r
23         /**\r
24                 \brief Parses an xml document into this object\r
25                 \r
26                 \return true if the document was parsed successfully, false if it was not\r
27         */\r
28         virtual const bool ParseXML(const std::string &xml)=0;\r
29 \r
30 protected:\r
31         /**\r
32                 \brief Creates and returns an element with a boolean value\r
33         */\r
34         virtual TiXmlElement *XMLCreateBooleanElement(const std::string &name, const bool value)\r
35         {\r
36                 TiXmlText *txt=new TiXmlText(value ? "true" : "false");\r
37                 TiXmlElement *el=new TiXmlElement(name);\r
38                 el->LinkEndChild(txt);\r
39                 return el;\r
40         }\r
41 \r
42         /**\r
43                 \brief Creates and returns an element with a CDATA value\r
44         */\r
45         virtual TiXmlElement *XMLCreateCDATAElement(const std::string &name, const std::string &data)\r
46         {\r
47                 TiXmlText *txt=new TiXmlText(data);\r
48                 txt->SetCDATA(true);\r
49                 TiXmlElement *el=new TiXmlElement(name);\r
50                 el->LinkEndChild(txt);\r
51                 return el;\r
52         }\r
53 \r
54         /**\r
55                 \brief Creates and returns a text element\r
56         */\r
57         virtual TiXmlElement *XMLCreateTextElement(const std::string &name, const std::string &data)\r
58         {\r
59                 TiXmlText *txt=new TiXmlText(data);\r
60                 TiXmlElement *el=new TiXmlElement(name);\r
61                 el->LinkEndChild(txt);\r
62                 return el;\r
63         }\r
64 \r
65         virtual TiXmlElement *XMLCreateTextElement(const std::string &name, const long data)\r
66         {\r
67                 std::string datastr;\r
68                 StringFunctions::Convert(data,datastr);\r
69                 return XMLCreateTextElement(name,datastr);\r
70         }\r
71 \r
72         virtual const bool XMLGetBooleanElement(TiXmlElement *parent, const std::string &name)\r
73         {\r
74                 TiXmlHandle hnd(parent);\r
75                 TiXmlText *txt=hnd.FirstChild(name).FirstChild().ToText();\r
76                 if(txt)\r
77                 {\r
78                         if(txt->ValueStr()=="true")\r
79                         {\r
80                                 return true;\r
81                         }\r
82                         else\r
83                         {\r
84                                 return false;\r
85                         }\r
86                 }\r
87                 return false;\r
88         }\r
89         \r
90 };\r
91 \r
92 #endif  // _ifmsxmldocument_\r