alternative to assert
[gtkD.git] / wrap / utils / convparms.d
blobbaa08b136cae55a8d7900308e1669e488c6e93cc
1 /*
2 * This file is part of duit.
3 *
4 * duit 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 * duit 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 duit; 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.DuitClass;
27 private import std.stdio;
29 public char[] inFile;
30 public char[] outPack;
31 public char[] outFile;
32 public char[] strct;
33 public char[] realStrct;
34 public char[] ctorStrct; /// the ToolItem derivates all retrun GtkToolItem
35 public char[] clss;
36 public char[] interf;
37 public char[][] templ;
38 public char[] extend;
39 public char[][] impl;
40 public char[][] prefixes;
41 public bit strictPrefix; /// include only function that match the prefix
42 public char[][] imprts;
43 public char[][char[]] structWrap;
44 public char[][] noStructs;
45 public char[][] noPrefixes;
46 public char[][] noCode; /// insert the external declaration but not the wrapping code
47 public char[][char[]] aliases;
48 public char[] classCode; /// any valid D code to be copied to the final Duit class
49 public char[] interfaceCode; /// any valid D code to be copied to the final Duit interface
50 public char[][] text; /// text to be added to the text read from the file
52 public void clearAll()
54 char[][char[]] clear(){char[][char[]] cc;return cc;};
56 inFile.length = 0;
57 //outPack.length = 0;
58 outFile.length = 0;
59 strct.length = 0;
60 realStrct.length = 0;
61 ctorStrct.length = 0;
62 clss.length = 0;
63 interf.length = 0;
64 extend.length = 0;
65 prefixes.length = 0;
66 templ.length = 0;
67 impl.length = 0;
68 strictPrefix = false;
69 imprts.length = 0;
70 structWrap = clear();
71 noPrefixes.length = 0;
72 noCode.length = 0;
73 noStructs.length = 0;
74 aliases = clear();
75 classCode.length = 0;
76 interfaceCode.length = 0;
77 text.length = 0;
81 public char[] toString()
83 char[] text;
84 text ~= "/*";
85 text ~= "\n * Conversion parameters:";
86 text ~= "\n * inFile = "~inFile;
87 text ~= "\n * outPack = "~outPack;
88 text ~= "\n * outFile = "~outFile;
89 text ~= "\n * strct = "~strct;
90 text ~= "\n * realStrct="~realStrct;
91 text ~= "\n * ctorStrct="~ctorStrct;
92 text ~= "\n * clss = "~clss;
93 text ~= "\n * interf = "~interf;
94 text ~= "\n * class Code: " ~ (classCode.length>0 ? "Yes" : "No");
95 text ~= "\n * interface Code: " ~ (interfaceCode.length>0 ? "Yes" : "No");
96 text ~= "\n * template for:";
97 foreach ( char[] tp ; templ )
99 text ~= "\n * \t- "~tp;
102 text ~= "\n * extend = "~extend;
104 text ~= "\n * implements:";
105 foreach ( char[] ip ; impl )
107 text ~= "\n * \t- "~ip;
110 text ~= "\n * prefixes:";
111 foreach ( char[] prefix ; prefixes )
113 text ~= "\n * \t- "~prefix;
116 text ~= "\n * omit structs:";
117 foreach ( char[] noStruct ; noStructs )
119 text ~= "\n * \t- "~noStruct;
122 text ~= "\n * omit prefixes:";
123 foreach ( char[] noPrefix ; noPrefixes )
125 text ~= "\n * \t- "~noPrefix;
128 text ~= "\n * omit code:";
129 foreach ( char[] ncode ; noCode )
131 text ~= "\n * \t- "~ncode;
134 text ~= "\n * imports:";
135 foreach ( char[] imp ; imprts )
137 text ~= "\n * \t- "~imp;
140 text ~= "\n * structWrap:";
141 foreach ( char[] key ; structWrap.keys.sort )
143 text ~= "\n * \t- "~key~" -> "~structWrap[key];
146 text ~= "\n * local aliases:";
147 foreach ( char[] key ; aliases.keys.sort )
149 text ~= "\n * \t- "~key~" -> "~aliases[key];
151 text ~= "\n */\n\n";
152 return text;
157 public void appendAsComment(inout char[] text)
159 text ~= toString();
162 public bit containsPrefix(char[] prefix)
164 bit contains = false;
165 int i = 0;
166 while ( !contains && i<prefixes.length )
168 contains = DuitClass.startsWith(prefix, prefixes[i]);
169 ++i;
171 return contains;
174 public char[] getPrefix(char[] prefix)
176 char[] fundPrefix;
177 bit contains = false;
178 int i = 0;
179 while ( !contains && i<prefixes.length )
181 if ( DuitClass.startsWith(prefix, prefixes[i]) )
183 contains = true;
184 fundPrefix = prefixes[i];
186 ++i;
188 return fundPrefix;
191 public bit omitCode(char[] codeName)
193 bit omit = false;
194 int i=0;
195 while ( !omit && i<noCode.length )
197 omit = codeName == noCode[i];
198 debug(omitCode)writefln("\t (%s) %s ?= %s", omit, codeName, noCode[i]);
199 ++i;
201 debug(omitCode)writefln("\t (%s) %s %s", i, (omit?"omited >>>>>>>":"included <<<<<"), codeName);
202 return omit;