1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 module utils.GtkAlias;
21 
22 import std.string : splitLines, strip;
23 
24 import utils.GtkType;
25 import utils.GtkWrapper;
26 import utils.XML;
27 
28 final class GtkAlias
29 {
30 	string name;
31 	string cType;
32 	string doc;
33 
34 	GtkType baseType;
35 	GtkWrapper wrapper;
36 
37 	this(GtkWrapper wrapper)
38 	{
39 		this.wrapper = wrapper;
40 	}
41 
42 	void parse(T)(XMLReader!T reader)
43 	{
44 		name = reader.front.attributes["name"];
45 		cType = reader.front.attributes["c:type"];
46 
47 		reader.popFront();
48 
49 		while( !reader.empty && !reader.endTag("alias") )
50 		{
51 			switch(reader.front.value)
52 			{
53 				case "type":
54 					baseType = new GtkType(wrapper);
55 					baseType.parse(reader);
56 					break;
57 				case "doc":
58 					reader.popFront();
59 					doc ~= reader.front.value;
60 					reader.popFront();
61 					break;
62 				case "doc-deprecated":
63 					reader.popFront();
64 					doc ~= "\n\nDeprecated: "~ reader.front.value;
65 					reader.popFront();
66 					break;
67 				default:
68 					throw new XMLException(reader, "Unexpected tag: "~ reader.front.value ~" in GtkAlias: "~ name);
69 			}
70 			reader.popFront();
71 		}
72 	}
73 
74 	string[] getAliasDeclaration()
75 	{
76 		string[] buff;
77 		if ( doc !is null && wrapper.includeComments )
78 		{
79 			buff ~= "/**";
80 			foreach ( line; doc.splitLines() )
81 				buff ~= " * "~ line.strip();
82 			buff ~= " */";
83 		}
84 
85 		buff ~= "public alias "~ tokenToGtkD(baseType.cType, wrapper.aliasses) ~" "~ tokenToGtkD(cType, wrapper.aliasses) ~";";
86 
87 		return buff;
88 	}
89 }