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 |
7379
|
54 ## g, G, m, s, S, o, O, h, which have the following meanings: |
6874
|
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 ## |
7379
|
109 ## h: Make the property hidden |
|
110 ## |
6874
|
111 ## The 'o' and 'O' qualifiers are only useful when the the property type |
|
112 ## is something other than octave_value. |
|
113 |
7363
|
114 ## simple accessor |
|
115 |
|
116 function emit_get_accessor (i, rtype, faccess) |
|
117 { |
|
118 printf (" %s get_%s (void) const", rtype, name[i]); |
|
119 |
|
120 if (emit_get[i] == "definition") |
|
121 printf (" { return %s.%s (); }\n", name[i], faccess); |
|
122 else |
|
123 printf (";\n"); |
|
124 } |
|
125 |
|
126 ## bool_property |
|
127 |
|
128 function emit_get_bool (i) |
|
129 { |
|
130 printf (" bool is_%s (void) const", name[i]); |
|
131 |
|
132 if (emit_get[i] == "definition") |
|
133 printf (" { return %s.is_on (); }\n", name[i]); |
|
134 else |
|
135 printf (";\n"); |
|
136 |
|
137 emit_get_accessor(i, "std::string", "current_value"); |
|
138 } |
|
139 |
|
140 ## radio_property |
|
141 |
|
142 function emit_get_radio (i) |
|
143 { |
|
144 printf (" bool %s_is (const std::string& v) const", name[i]); |
|
145 |
|
146 if (emit_get[i] == "definition") |
|
147 printf (" { return %s.is (v); }\n", name[i]); |
|
148 else |
|
149 printf (";\n"); |
|
150 |
|
151 emit_get_accessor(i, "std::string", "current_value"); |
|
152 } |
|
153 |
|
154 ## color_property |
|
155 |
|
156 function emit_get_color (i) |
|
157 { |
|
158 printf (" bool %s_is_rgb (void) const { return %s.is_rgb (); }\n", name[i], name[i]); |
|
159 |
|
160 printf (" bool %s_is (const std::string& v) const", name[i]); |
|
161 |
|
162 if (emit_get[i] == "definition") |
|
163 printf (" { return %s.is (v); }\n", name[i]); |
|
164 else |
|
165 printf (";\n"); |
|
166 |
|
167 printf (" Matrix get_%s_rgb (void) const", name[i]); |
|
168 |
|
169 if (emit_get[i] == "definition") |
|
170 printf (" { return (%s.is_rgb () ? %s.rgb () : Matrix ()); }\n", name[i], name[i]); |
|
171 else |
|
172 printf (";\n"); |
|
173 |
|
174 emit_get_accessor(i, "octave_value", "get"); |
|
175 } |
|
176 |
|
177 ## callback_property |
|
178 |
|
179 function emit_get_callback (i) |
|
180 { |
7367
|
181 printf (" void execute_%s (const octave_value& data = octave_value ()) const", name[i]); |
7363
|
182 |
|
183 if (emit_get[i] == "definition") |
7367
|
184 printf (" { %s.execute (data); }\n", name[i]); |
7363
|
185 else |
|
186 printf (";\n"); |
|
187 |
|
188 emit_get_accessor(i, "octave_value", "get"); |
|
189 } |
|
190 |
|
191 ## data_property |
|
192 |
|
193 function emit_get_data (i) |
|
194 { |
|
195 emit_get_accessor(i, "NDArray", "array_value"); |
|
196 |
|
197 printf (" data_property get_%s_property (void) const { return %s; }\n", |
|
198 name[i], name[i]); |
|
199 } |
|
200 |
|
201 ## common section |
|
202 |
|
203 function emit_common_declarations () |
|
204 { |
|
205 printf ("public:\n"); |
|
206 printf (" properties (const graphics_handle& mh, const graphics_handle& p);\n\n"); |
|
207 printf (" ~properties (void) { }\n\n"); |
7406
|
208 printf (" void set (const caseless_str& pname, const octave_value& val);\n\n"); |
7379
|
209 printf (" octave_value get (bool all = false) const;\n\n"); |
7406
|
210 printf (" octave_value get (const caseless_str& pname) const;\n\n"); |
7363
|
211 printf (" std::string graphics_object_name (void) const { return go_name; }\n\n"); |
|
212 printf (" static property_list::pval_map_type factory_defaults (void);\n\n"); |
|
213 printf ("private:\n static std::string go_name;\n\n"); |
|
214 } |
|
215 |
7225
|
216 function emit_declarations () |
6874
|
217 { |
7363
|
218 if (class_name) |
|
219 emit_common_declarations(); |
|
220 |
6874
|
221 if (idx > 0) |
7363
|
222 print "private:\n"; |
6874
|
223 |
|
224 for (i = 1; i <= idx; i++) |
7363
|
225 printf (" %s%s %s;\n", mutable[i] ? "mutable " : "", type[i], name[i]); |
6874
|
226 |
|
227 if (idx > 0) |
7363
|
228 print "\npublic:\n"; |
6874
|
229 |
|
230 for (i = 1; i <= idx; i++) |
|
231 { |
7363
|
232 if (emit_get[i]) |
|
233 { |
|
234 if (type[i] == "array_property" || type[i] == "any_property") |
|
235 emit_get_accessor(i, "octave_value", "get"); |
|
236 else if (type[i] == "handle_property") |
|
237 emit_get_accessor(i, "graphics_handle", "handle_value"); |
|
238 else if (type[i] == "string_property") |
|
239 emit_get_accessor(i, "std::string", "string_value"); |
|
240 else if (type[i] == "double_property") |
|
241 emit_get_accessor(i, "double", "double_value"); |
|
242 else if (type[i] == "data_property") |
|
243 emit_get_data(i); |
|
244 else if (type[i] == "bool_property") |
|
245 emit_get_bool(i); |
|
246 else if (type[i] == "radio_property") |
|
247 emit_get_radio(i); |
|
248 else if (type[i] == "color_property") |
|
249 emit_get_color(i); |
|
250 else if (type[i] == "callback_property") |
|
251 emit_get_callback(i); |
|
252 else |
6874
|
253 { |
7363
|
254 printf (" %s get_%s (void) const", type[i], name[i]); |
6874
|
255 |
7363
|
256 if (emit_get[i] == "definition") |
|
257 printf (" { return %s; }\n", name[i]); |
|
258 else |
|
259 printf (";\n"); |
6874
|
260 } |
7363
|
261 printf ("\n"); |
|
262 } |
6874
|
263 } |
|
264 |
|
265 if (idx > 0) |
7363
|
266 printf ("\n"); |
6874
|
267 |
|
268 for (i = 1; i <= idx; i++) |
|
269 { |
7363
|
270 if (emit_set[i]) |
|
271 { |
|
272 printf (" void set_%s (const octave_value& val)", name[i], type[i]); |
6874
|
273 |
7363
|
274 if (emit_set[i] == "definition") |
|
275 { |
|
276 printf ("\n {\n if (! error_state)\n {\n %s = val;\n", |
|
277 name[i]); |
|
278 if (limits[i]) |
|
279 printf (" update_axis_limits (\"%s\");\n", name[i]); |
|
280 if (mode[i]) |
|
281 printf (" set_%smode (\"manual\");\n", name[i]); |
|
282 printf (" mark_modified ();\n }\n }\n\n"); |
6874
|
283 } |
7363
|
284 else |
|
285 printf (";\n\n"); |
|
286 } |
6874
|
287 |
7363
|
288 ## if (emit_ov_set[i]) |
|
289 ## { |
|
290 ## printf (" void set_%s (const octave_value& val)", name[i]); |
|
291 ## |
|
292 ## if (emit_ov_set[i] == "definition") |
|
293 ## printf (" { set_%s (%s (val)); }\n\n", name[i], type[i]); |
|
294 ## else if (emit_ov_set[i] == "assignment") |
|
295 ## { |
|
296 ## printf ("\n {\n %s tmp (%s);\n tmp = val;\n set_%s (tmp);\n };\n\n", |
|
297 ## type[i], name[i], name[i], name[i]); |
|
298 ## } |
|
299 ## else |
|
300 ## printf (";\n"); |
|
301 ## } |
6874
|
302 } |
|
303 |
7363
|
304 ## if (idx > 0) |
|
305 ## print "\nprivate:"; |
|
306 } |
|
307 |
|
308 function emit_source () |
|
309 { |
|
310 if (class_name) |
|
311 { |
|
312 printf ("// ******** %s ********\n\n", class_name) >> filename; |
|
313 |
|
314 ## constructor |
|
315 |
|
316 printf ("%s::properties::properties (const graphics_handle& mh, const graphics_handle& p)\n", class_name) >> filename; |
|
317 printf (" : base_properties (go_name, mh, p),\n") >> filename; |
|
318 |
|
319 for (i = 1; i <= idx; i++) |
|
320 { |
7397
|
321 printf (" %s (\"%s\", mh, %s)", name[i], name[i], defval[i]) >> filename; |
7363
|
322 if (i < idx) |
|
323 printf (",") >> filename; |
|
324 printf ("\n") >> filename; |
|
325 } |
|
326 |
7379
|
327 printf ("{\n") >> filename; |
7363
|
328 |
7379
|
329 for (i = 1; i <= idx; i++) |
|
330 { |
|
331 ## printf (" insert_static_property (\"%s\", %s);\n", name[i], name[i]) >> filename; |
|
332 if (hidden[i]) |
|
333 printf (" %s.set_hidden (true);\n", name[i]) >> filename; |
|
334 } |
7363
|
335 |
7379
|
336 printf (" init ();\n}\n\n") >> filename; |
7363
|
337 |
|
338 ## set method |
|
339 |
7406
|
340 printf ("void\n%s::properties::set (const caseless_str& pname, const octave_value& val)\n{\n", |
7363
|
341 class_name) >> filename; |
|
342 |
|
343 for (i = 1; i <= idx; i++) |
|
344 { |
7403
|
345 if (! readonly[i]) |
7406
|
346 printf (" %sif (pname.compare (\"%s\"))\n set_%s (val);\n", |
7403
|
347 (i > 1 ? "else " : ""), name[i], name[i]) >> filename; |
7363
|
348 } |
|
349 |
7406
|
350 printf (" else\n base_properties::set (pname, val);\n}\n\n") >> filename; |
7363
|
351 |
|
352 ## get "all" method |
|
353 |
7379
|
354 printf ("octave_value\n%s::properties::get (bool all) const\n{\n", class_name) >> filename; |
|
355 printf (" Octave_map m = base_properties::get (all).map_value ();\n\n") >> filename; |
7363
|
356 |
|
357 for (i = 1; i <= idx; i++) |
|
358 { |
7379
|
359 if (hidden[i]) |
|
360 printf (" if (all)\n m.assign (\"%s\", get_%s ()%s);\n", name[i], name[i], |
|
361 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; |
|
362 else |
|
363 printf (" m.assign (\"%s\", get_%s ()%s);\n", name[i], name[i], |
|
364 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; |
7363
|
365 } |
|
366 |
|
367 printf ("\n return m;\n}\n\n") >> filename; |
|
368 |
|
369 ## get "one" method |
|
370 |
7406
|
371 printf ("octave_value\n%s::properties::get (const caseless_str& pname) const\n{\n", |
7363
|
372 class_name) >> filename; |
|
373 printf (" octave_value retval;\n\n") >> filename; |
|
374 |
|
375 for (i = 1; i<= idx; i++) |
|
376 { |
7406
|
377 printf (" %sif (pname.compare (\"%s\"))\n", |
7363
|
378 (i > 1 ? "else " : ""), name[i]) >> filename; |
|
379 printf (" retval = get_%s ()%s;\n", name[i], |
|
380 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; |
|
381 } |
|
382 |
7406
|
383 printf (" else\n retval = base_properties::get (pname);\n\n") >> filename; |
7363
|
384 printf (" return retval;\n}\n\n") >> filename; |
|
385 |
|
386 ## factory defaults method |
|
387 |
|
388 printf ("property_list::pval_map_type\n%s::properties::factory_defaults (void)\n{\n", |
|
389 class_name) >> filename; |
|
390 printf (" property_list::pval_map_type m;\n\n") >> filename; |
|
391 |
|
392 for (i = 1; i <= idx; i++) |
|
393 { |
7397
|
394 dval = defval[i]; |
7363
|
395 if (type[i] == "radio_property" || type[i] == "color_property") |
7397
|
396 dval = gensub (/^.*\{(.*)\}.*$/, "\"\\1\"", "g", dval); |
|
397 if (! dval) |
|
398 dval = "octave_value ()"; |
7363
|
399 if (name[i] !~ /__.*/) |
7397
|
400 printf (" m[\"%s\"] = %s%s;\n", name[i], dval, |
7363
|
401 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; |
|
402 } |
|
403 |
|
404 printf ("\n return m;\n}\n\n") >> filename; |
|
405 |
|
406 ## go_name static field |
|
407 |
|
408 printf ("std::string %s::properties::go_name (\"%s\");\n\n", |
|
409 class_name, class_name) >> filename; |
|
410 } |
6874
|
411 } |
|
412 |
|
413 BEGIN { |
7363
|
414 filename = "graphics-props.cc"; |
|
415 printf ("// DO NOT EDIT! Generated automatically by genprops.awk.\n\n"); |
|
416 printf ("// DO NOT EDIT! Generated automatically by genprops.awk.\n\n") > filename; |
|
417 } |
|
418 |
|
419 /BEGIN_PROPERTIES\(.*\)/ { |
|
420 gather = 1; |
|
421 idx = 0; |
|
422 class_name = gensub (/^.*BEGIN_PROPERTIES\((.*)\)/, "\\1", "g"); |
|
423 next; |
6874
|
424 } |
|
425 |
|
426 /BEGIN_PROPERTIES/ { |
7363
|
427 gather = 1; |
|
428 idx = 0; |
|
429 class_name = ""; |
|
430 next; |
6874
|
431 } |
|
432 |
|
433 /END_PROPERTIES/ { |
7363
|
434 emit_declarations(); |
|
435 emit_source(); |
|
436 gather = 0; |
|
437 next; |
6874
|
438 } |
|
439 |
|
440 { |
|
441 if (gather) |
7363
|
442 { |
7403
|
443 if (NF < 2 || /^[ \t]*\/\//) |
7363
|
444 next; |
6874
|
445 |
7363
|
446 idx++; |
6874
|
447 |
7363
|
448 field = 1; |
6874
|
449 |
7363
|
450 if ($field == "mutable") |
|
451 { |
|
452 mutable[idx] = 1; |
|
453 field++; |
|
454 } |
|
455 else |
|
456 mutable[idx] = 0; |
6874
|
457 |
7363
|
458 type[idx] = $(field++); |
|
459 name[idx] = $(field++); |
6874
|
460 |
7363
|
461 limits[idx] = 0; |
|
462 mode[idx] = 0; |
7403
|
463 hidden[idx] = 0; |
|
464 readonly[idx] = 0; |
7363
|
465 emit_get[idx] = "definition"; |
|
466 emit_set[idx] = "definition"; |
7397
|
467 defval[idx] = ""; |
7363
|
468 ## if (type[idx] == "octave_value") |
|
469 ## emit_ov_set[idx] = ""; |
|
470 ## else |
|
471 ## emit_ov_set[idx] = "definition"; |
6874
|
472 |
7363
|
473 if (NF >= field) |
|
474 { |
|
475 if ($field != ",") |
|
476 { |
|
477 quals = $(field++); |
7214
|
478 |
7363
|
479 if (index (quals, "l")) |
|
480 limits[idx] = 1; |
6874
|
481 |
7363
|
482 if (index (quals, "m")) |
|
483 mode[idx] = 1; |
|
484 |
|
485 ## There is a custom inline definition for the get function, |
|
486 ## so we don't emit anything. |
|
487 if (index (quals, "g")) |
|
488 emit_get[idx] = ""; |
6874
|
489 |
7363
|
490 ## There is a custom extern definition for the get function, |
|
491 ## but we still emit the declaration. |
|
492 if (index (quals, "G")) |
|
493 emit_get[idx] = "declaration"; |
6874
|
494 |
7363
|
495 ## There is a custom inline definition for the set function, |
|
496 ## so we don't emit anything. |
|
497 if (index (quals, "s")) |
|
498 emit_set[idx] = ""; |
6874
|
499 |
7363
|
500 ## There is a custom extern definition for the set function, |
|
501 ## but we still emit the declaration. |
|
502 if (index (quals, "S")) |
|
503 emit_set[idx] = "declaration"; |
7379
|
504 |
7403
|
505 ## The property is hidden |
|
506 if (index (quals, "h")) |
|
507 hidden[idx] = 1; |
|
508 |
|
509 ## The property is read-only |
|
510 if (index (quals, "r")) |
|
511 readonly[idx] = 1; |
6904
|
512 |
7363
|
513 ## ## emmit an asignment set function |
|
514 ## if (index (quals, "a")) |
|
515 ## emit_ov_set[idx] = "assignment"; |
|
516 ## |
|
517 ## if (type[idx] != "octave_value") |
|
518 ## { |
|
519 ## ## The 'o' and 'O' qualifiers are only useful when the |
|
520 ## ## the property type is something other than an |
|
521 ## ## octave_value. |
|
522 ## |
|
523 ## ## There is a custom inline definition for the |
|
524 ## ## octave_value version of the set function, so we |
|
525 ## ## don't emit anything. |
|
526 ## if (index (quals, "o")) |
|
527 ## emit_ov_set[idx] = ""; |
|
528 ## |
|
529 ## ## There is a custom extern definition for the |
|
530 ## ## octave_value version of the set function, but we |
|
531 ## ## still emit the declaration. |
|
532 ## if (index (quals, "O")) |
|
533 ## emit_ov_set[idx] = "declaration"; |
|
534 ## } |
|
535 } |
6874
|
536 |
7363
|
537 if (NF > field && $field == ",") |
|
538 { |
|
539 field++; |
6874
|
540 |
7363
|
541 for (i = field; i <= NF; i++) |
7397
|
542 defval[idx] = (defval[idx] (i > field ? " " : "") $i); |
7363
|
543 } |
6874
|
544 } |
7363
|
545 |
|
546 } |
6874
|
547 else |
7363
|
548 print $0; |
6883
|
549 } |