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