alternative to assert
[gtkD.git] / gtkD / wrap / utils / convparms.d
blob118a1ccebcf0e5f85cd418ac57166c5f2df452af
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 as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module utils.convparms;
21 //debug = omitCode;
23 public struct ConvParms
26 private import utils.GtkDClass;
27 private import std.stdio;
29 public char[] inFile;
30 public char[] outPack;
31 public char[] bindDir;
32 public char[] outFile;
33 public char[] strct;
34 public char[] realStrct;
35 public char[] ctorStrct; /// the ToolItem derivates all retrun GtkToolItem
36 public char[] clss;
37 public char[] interf;
38 public char[][] templ;
39 public char[] extend;
40 public char[][] impl;
41 public char[][] prefixes;
42 public bool strictPrefix; /// include only function that match the prefix
43 public char[][] imprts;
44 public char[][char[]] structWrap;
45 public char[][] noStructs;
46 public char[][] noPrefixes;
47 public char[][] noCode; /// insert the external declaration but not the wrapping code
48 public char[][char[]] aliases;
49 public char[][char[]] mAliases;
50 public char[] classCode; /// any valid D code to be copied to the final GtkD class
51 public char[] interfaceCode; /// any valid D code to be copied to the final GtkD interface
52 public char[][] text; /// text to be added to the text read from the file
54 public void clearAll()
56 char[][char[]] clear(){char[][char[]] cc;return cc;};
58 inFile.length = 0;
59 //outPack.length = 0;
60 outFile.length = 0;
61 bindDir.length = 0;
62 strct.length = 0;
63 realStrct.length = 0;
64 ctorStrct.length = 0;
65 clss.length = 0;
66 interf.length = 0;
67 extend.length = 0;
68 prefixes.length = 0;
69 templ.length = 0;
70 impl.length = 0;
71 strictPrefix = false;
72 imprts.length = 0;
73 structWrap = clear();
74 noPrefixes.length = 0;
75 noCode.length = 0;
76 noStructs.length = 0;
77 aliases = clear();
78 mAliases = clear();
79 classCode.length = 0;
80 interfaceCode.length = 0;
81 text.length = 0;
85 public char[] toString()
87 char[] text;
88 text ~= "/*";
89 text ~= "\n * Conversion parameters:";
90 text ~= "\n * inFile = "~inFile;
91 text ~= "\n * outPack = "~outPack;
92 text ~= "\n * outFile = "~outFile;
93 text ~= "\n * strct = "~strct;
94 text ~= "\n * realStrct="~realStrct;
95 text ~= "\n * ctorStrct="~ctorStrct;
96 text ~= "\n * clss = "~clss;
97 text ~= "\n * interf = "~interf;
98 text ~= "\n * class Code: " ~ (classCode.length>0 ? "Yes" : "No");
99 text ~= "\n * interface Code: " ~ (interfaceCode.length>0 ? "Yes" : "No");
100 text ~= "\n * template for:";
101 foreach ( char[] tp ; templ )
103 text ~= "\n * \t- "~tp;
106 text ~= "\n * extend = "~extend;
108 text ~= "\n * implements:";
109 foreach ( char[] ip ; impl )
111 text ~= "\n * \t- "~ip;
114 text ~= "\n * prefixes:";
115 foreach ( char[] prefix ; prefixes )
117 text ~= "\n * \t- "~prefix;
120 text ~= "\n * omit structs:";
121 foreach ( char[] noStruct ; noStructs )
123 text ~= "\n * \t- "~noStruct;
126 text ~= "\n * omit prefixes:";
127 foreach ( char[] noPrefix ; noPrefixes )
129 text ~= "\n * \t- "~noPrefix;
132 text ~= "\n * omit code:";
133 foreach ( char[] ncode ; noCode )
135 text ~= "\n * \t- "~ncode;
138 text ~= "\n * imports:";
139 foreach ( char[] imp ; imprts )
141 text ~= "\n * \t- "~imp;
144 text ~= "\n * structWrap:";
145 foreach ( char[] key ; structWrap.keys.sort )
147 text ~= "\n * \t- "~key~" -> "~structWrap[key];
150 text ~= "\n * module aliases:";
151 foreach ( char[] key ; mAliases.keys.sort )
153 text ~= "\n * \t- "~key~" -> "~mAliases[key];
155 text ~= "\n * local aliases:";
156 foreach ( char[] key ; aliases.keys.sort )
158 text ~= "\n * \t- "~key~" -> "~aliases[key];
160 text ~= "\n */\n\n";
161 return text;
166 public void appendAsComment(inout char[] text)
168 text ~= toString();
171 public bool containsPrefix(char[] prefix)
173 bool contains = false;
174 int i = 0;
175 while ( !contains && i<prefixes.length )
177 contains = GtkDClass.startsWith(prefix, prefixes[i]);
178 ++i;
180 return contains;
183 public char[] getPrefix(char[] prefix)
185 char[] fundPrefix;
186 bool contains = false;
187 int i = 0;
188 while ( !contains && i<prefixes.length )
190 if ( GtkDClass.startsWith(prefix, prefixes[i]) )
192 contains = true;
193 fundPrefix = prefixes[i];
195 ++i;
197 return fundPrefix;
200 public bool omitCode(char[] codeName)
202 bool omit = false;
203 int i=0;
204 while ( !omit && i<noCode.length )
206 omit = codeName == noCode[i];
207 debug(omitCode)writefln("\t (%s) %s ?= %s", omit, codeName, noCode[i]);
208 ++i;
210 debug(omitCode)writefln("\t (%s) %s %s", i, (omit?"omited >>>>>>>":"included <<<<<"), codeName);
211 return omit;