7019
|
1 ## Copyright (C) 2007 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by the |
|
7 ## Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 ## |
6874
|
19 ## This script is used to generate the graphics.h file from graphics.h.in. |
|
20 ## |
|
21 ## Lines between the BEGIN_PROPERTIES and END_PROPERTIES markers have |
|
22 ## one of the following formats: |
|
23 ## |
|
24 ## TYPE NAME |
|
25 ## TYPE NAME QUALIFIERS |
|
26 ## mutable TYPE NAME |
|
27 ## mutable TYPE NAME QUALIFIERS |
|
28 ## |
|
29 ## For each property, we generate a declaration for the property. |
|
30 ## |
|
31 ## If QUALIFIERS is omitted, we generate the following functions directly |
|
32 ## in the class declaration: |
|
33 ## |
6875
|
34 ## TYPE |
|
35 ## get_NAME (void) const |
|
36 ## { |
|
37 ## return NAME; |
|
38 ## } |
|
39 ## |
|
40 ## void |
|
41 ## set_NAME (const TYPE& val) |
|
42 ## { |
|
43 ## if (! error_state) |
|
44 ## NAME = val; |
|
45 ## } |
|
46 ## |
|
47 ## void |
|
48 ## set_NAME (const octave_value& val) |
|
49 ## { |
|
50 ## set_NAME (TYPE (val)); |
|
51 ## } |
6874
|
52 ## |
|
53 ## If present, the QUALIFIERS string may include any of the characters |
|
54 ## g, G, m, s, S, o, O, which have the following meanings: |
|
55 ## |
|
56 ## g: There is a custom inline definition for the get function, |
|
57 ## so we don't emit one. |
|
58 ## |
|
59 ## G: There is a custom extern definition for the get function, |
|
60 ## so we emit only the declaration. |
|
61 ## |
|
62 ## s: There is a custom inline definition for the type-specific set |
|
63 ## function, so we don't emit one. |
|
64 ## |
|
65 ## S: There is a custom extern definition for the type-specific set |
|
66 ## function, so we emit only the declaration. |
|
67 ## |
|
68 ## o: There is a custom inline definition for the octave_value version |
|
69 ## of the set function, so we don't emit one. |
|
70 ## |
|
71 ## O: There is a custom extern definition for the octave_value version |
|
72 ## of the set function, so we emit only the declaration. |
|
73 ## |
6904
|
74 ## a: The octave_value version of the set function will use assignment: |
|
75 ## |
|
76 ## void |
|
77 ## set_NAME (const octave_value& val) |
|
78 ## { |
|
79 ## TYPE tmp (NAME); |
|
80 ## tmp = val; |
|
81 ## set_NAME (tmp); |
|
82 ## } |
|
83 ## |
|
84 ## This is useful for things like the radio_value classes which |
|
85 ## use an overloaded assignment operator of the form |
|
86 ## |
|
87 ## radio_property& operator = (const octave_value& val); |
|
88 ## |
|
89 ## that preserves the list of possible values, which is different |
|
90 ## from what would happen if we simply used the |
|
91 ## |
|
92 ## TYPE (const octave_value&) |
|
93 ## |
|
94 ## constructor, which creates a new radio_property and so cannot |
|
95 ## preserve the old list of possible values. |
|
96 ## |
7214
|
97 ## l: Add the line |
|
98 ## |
|
99 ## update_axis_limits ("NAME"); |
|
100 ## |
|
101 ## to the type-specific set function. |
|
102 ## |
6874
|
103 ## m: Add the line |
|
104 ## |
|
105 ## set_NAMEmode ("manual"); |
|
106 ## |
|
107 ## to the type-specific set function. |
|
108 ## |
|
109 ## The 'o' and 'O' qualifiers are only useful when the the property type |
|
110 ## is something other than octave_value. |
|
111 |
7225
|
112 function emit_declarations () |
6874
|
113 { |
|
114 if (idx > 0) |
|
115 print "private:\n"; |
|
116 |
|
117 for (i = 1; i <= idx; i++) |
|
118 printf (" %s%s %s;\n", mutable[i] ? "mutable " : "", type[i], name[i]); |
|
119 |
|
120 if (idx > 0) |
|
121 print "\npublic:\n"; |
|
122 |
|
123 for (i = 1; i <= idx; i++) |
|
124 { |
|
125 if (emit_get[i]) |
|
126 { |
|
127 printf (" %s get_%s (void) const", type[i], name[i]); |
|
128 |
7225
|
129 if (emit_get[i] == "definition") |
6874
|
130 printf (" { return %s; }\n", name[i]); |
|
131 else |
|
132 printf (";\n"); |
|
133 } |
|
134 } |
|
135 |
|
136 if (idx > 0) |
|
137 printf ("\n"); |
|
138 |
|
139 for (i = 1; i <= idx; i++) |
|
140 { |
|
141 if (emit_set[i]) |
|
142 { |
|
143 printf (" void set_%s (const %s& val)", name[i], type[i]); |
|
144 |
7225
|
145 if (emit_set[i] == "definition") |
6874
|
146 { |
|
147 printf ("\n {\n if (! error_state)\n {\n %s = val;\n", |
|
148 name[i]); |
7214
|
149 if (limits[i]) |
|
150 printf (" update_axis_limits (\"%s\");\n", name[i]); |
6874
|
151 if (mode[i]) |
|
152 printf (" set_%smode (\"manual\");\n", name[i]); |
|
153 printf (" mark_modified ();\n }\n }\n\n"); |
|
154 } |
|
155 else |
|
156 printf (";\n"); |
|
157 } |
|
158 |
|
159 if (emit_ov_set[i]) |
|
160 { |
|
161 printf (" void set_%s (const octave_value& val)", name[i]); |
|
162 |
7225
|
163 if (emit_ov_set[i] == "definition") |
6874
|
164 printf (" { set_%s (%s (val)); }\n\n", name[i], type[i]); |
7225
|
165 else if (emit_ov_set[i] == "assignment") |
6904
|
166 { |
|
167 printf ("\n {\n %s tmp (%s);\n tmp = val;\n set_%s (tmp);\n };\n\n", |
|
168 type[i], name[i], name[i], name[i]); |
|
169 } |
6874
|
170 else |
|
171 printf (";\n"); |
|
172 } |
|
173 } |
|
174 |
|
175 if (idx > 0) |
|
176 print "\nprivate:"; |
|
177 } |
|
178 |
|
179 BEGIN { |
|
180 printf ("// DO NOT EDIT! Generated automatically by genprops.awk.\n\n"); |
|
181 } |
|
182 |
|
183 /BEGIN_PROPERTIES/ { |
|
184 gather = 1; |
|
185 idx = 0; |
|
186 next; |
|
187 } |
|
188 |
|
189 /END_PROPERTIES/ { |
7225
|
190 emit_declarations(); |
6874
|
191 gather = 0; |
|
192 next; |
|
193 } |
|
194 |
|
195 { |
|
196 if (gather) |
|
197 { |
|
198 if (NF < 2 || NF > 4) |
|
199 next; |
|
200 |
|
201 idx++; |
|
202 |
|
203 field = 1; |
|
204 |
|
205 if ($field == "mutable") |
|
206 { |
|
207 mutable[idx] = 1; |
|
208 field++; |
|
209 } |
|
210 else |
|
211 mutable[idx] = 0; |
|
212 |
|
213 type[idx] = $(field++); |
|
214 name[idx] = $(field++); |
|
215 |
7214
|
216 limits[idx] = 0; |
6874
|
217 mode[idx] = 0; |
7225
|
218 emit_get[idx] = "definition"; |
|
219 emit_set[idx] = "definition"; |
6874
|
220 if (type[idx] == "octave_value") |
|
221 emit_ov_set[idx] = ""; |
|
222 else |
7225
|
223 emit_ov_set[idx] = "definition"; |
6874
|
224 |
|
225 if (NF == field) |
|
226 { |
|
227 quals = $field; |
|
228 |
7214
|
229 if (index (quals, "l")) |
|
230 limits[idx] = 1; |
|
231 |
6874
|
232 if (index (quals, "m")) |
|
233 mode[idx] = 1; |
|
234 |
|
235 ## There is a custom inline definition for the get function, |
|
236 ## so we don't emit anything. |
|
237 if (index (quals, "g")) |
|
238 emit_get[idx] = ""; |
|
239 |
|
240 ## There is a custom extern definition for the get function, |
|
241 ## but we still emit the declaration. |
|
242 if (index (quals, "G")) |
7225
|
243 emit_get[idx] = "declaration"; |
6874
|
244 |
|
245 ## There is a custom inline definition for the set function, |
|
246 ## so we don't emit anything. |
|
247 if (index (quals, "s")) |
|
248 emit_set[idx] = ""; |
|
249 |
|
250 ## There is a custom extern definition for the set function, |
|
251 ## but we still emit the declaration. |
|
252 if (index (quals, "S")) |
7225
|
253 emit_set[idx] = "declaration"; |
6874
|
254 |
6904
|
255 ## emmit an asignment set function |
|
256 if (index (quals, "a")) |
7225
|
257 emit_ov_set[idx] = "assignment"; |
6904
|
258 |
6874
|
259 if (type[idx] != "octave_value") |
|
260 { |
|
261 ## The 'o' and 'O' qualifiers are only useful when the |
|
262 ## the property type is something other than an |
|
263 ## octave_value. |
|
264 |
|
265 ## There is a custom inline definition for the |
|
266 ## octave_value version of the set function, so we |
|
267 ## don't emit anything. |
|
268 if (index (quals, "o")) |
|
269 emit_ov_set[idx] = ""; |
|
270 |
|
271 ## There is a custom extern definition for the |
|
272 ## octave_value version of the set function, but we |
|
273 ## still emit the declaration. |
|
274 if (index (quals, "O")) |
7225
|
275 emit_ov_set[idx] = "declaration"; |
6874
|
276 } |
|
277 } |
|
278 |
|
279 } |
|
280 else |
|
281 print $0; |
6883
|
282 } |