]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/xml/xmltextags.h
initial
[xonotic/netradiant.git] / libs / xml / xmltextags.h
1 /*\r
2 Copyright (C) 2006, Stefan Greven.\r
3 All Rights Reserved.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 #if !defined(INCLUDED_XMLTEXTAGS_H)\r
23 #define INCLUDED_XMLTEXTAGS_H\r
24 \r
25 #include <set>\r
26 #include <string/string.h>\r
27 #include <vector>\r
28 \r
29 #include "iscriplib.h"\r
30 \r
31 #include <libxml/xpath.h>\r
32 #include <libxml/xmlwriter.h>\r
33 \r
34 enum NodeTagType\r
35 {\r
36   TAG,\r
37   EMPTY\r
38 };\r
39 \r
40 enum NodeShaderType\r
41 {\r
42   SHADER,\r
43   TEXTURE\r
44 };\r
45 \r
46 enum TextureType\r
47 {\r
48   STOCK,\r
49   CUSTOM\r
50 };\r
51 \r
52 class XmlTagBuilder\r
53 {\r
54 private:\r
55   CopiedString m_savefilename;\r
56   xmlDocPtr doc;\r
57   xmlXPathContextPtr context;\r
58   xmlNodeSetPtr nodePtr;\r
59 \r
60   xmlXPathObjectPtr XpathEval(const char* queryString)\r
61   {\r
62         xmlChar* expression = (xmlChar*)queryString;\r
63         xmlXPathObjectPtr result = xmlXPathEvalExpression(expression, context);\r
64         return result;\r
65   };\r
66 \r
67   char* GetTagsXpathExpression(char* buffer, const char* shader, NodeTagType nodeTagType)\r
68   {\r
69         strcpy(buffer, "/root/*/*[@path='");\r
70         strcat(buffer, shader);\r
71         \r
72         switch(nodeTagType)\r
73         {\r
74         case TAG:\r
75                 strcat(buffer, "']/tag");\r
76                 break;\r
77         case EMPTY:\r
78                 strcat(buffer, "']");\r
79         };\r
80 \r
81         return buffer;\r
82   }\r
83 \r
84 public:\r
85   XmlTagBuilder();\r
86   ~XmlTagBuilder();\r
87 \r
88   bool CreateXmlDocument();\r
89   bool OpenXmlDoc(const char* file, const char* savefile = 0);\r
90   bool SaveXmlDoc(const char* file);\r
91   bool SaveXmlDoc(void);\r
92   bool AddShaderNode(const char* shader, TextureType textureType, NodeShaderType nodeShaderType);\r
93   bool DeleteShaderNode(const char* shader);\r
94   bool CheckShaderTag(const char* shader);\r
95   bool CheckShaderTag(const char* shader, const char* content);\r
96   bool AddShaderTag(const char* shader, const char* content, NodeTagType nodeTagType);\r
97   bool DeleteTag(const char* tag);\r
98   int RenameShaderTag(const char* oldtag, CopiedString newtag);\r
99   bool DeleteShaderTag(const char* shader, const char* tag);\r
100   void GetShaderTags(const char* shader, std::vector<CopiedString>& tags);\r
101   void GetUntagged(std::set<CopiedString>& shaders);\r
102   void GetAllTags(std::set<CopiedString>& tags);\r
103   void TagSearch(const char* expression, std::set<CopiedString>& paths);\r
104 };\r
105 \r
106 #endif\r