Mercurial > hg > octave-nkf
annotate src/genprops.awk @ 7895:f1a1f6dd7fac
avoid using gensub in genprops.awk
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 20 Jun 2008 23:38:44 +0200 |
parents | b74039822fd2 |
children | 75c99d3f97d7 |
rev | line source |
---|---|
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 ## | |
7427 | 111 ## r: Make the property read-only. A read-only property is not |
112 ## settable from the global set (caseless_str, octave_value) | |
113 ## method, but still has set_X accessor. | |
114 ## | |
115 ## u: The property has an updater method. This effectively add | |
116 ## the line | |
117 ## | |
118 ## update_NAME (); | |
119 ## | |
120 ## to the type-specific set function. This line is added before | |
121 ## any other update call (like those added by the 'l' or 'm' | |
122 ## modifiers. | |
123 ## | |
6874 | 124 ## The 'o' and 'O' qualifiers are only useful when the the property type |
125 ## is something other than octave_value. | |
126 | |
7363 | 127 ## simple accessor |
128 | |
129 function emit_get_accessor (i, rtype, faccess) | |
130 { | |
131 printf (" %s get_%s (void) const", rtype, name[i]); | |
132 | |
133 if (emit_get[i] == "definition") | |
134 printf (" { return %s.%s (); }\n", name[i], faccess); | |
135 else | |
136 printf (";\n"); | |
137 } | |
138 | |
139 ## bool_property | |
140 | |
141 function emit_get_bool (i) | |
142 { | |
143 printf (" bool is_%s (void) const", name[i]); | |
144 | |
145 if (emit_get[i] == "definition") | |
146 printf (" { return %s.is_on (); }\n", name[i]); | |
147 else | |
148 printf (";\n"); | |
149 | |
150 emit_get_accessor(i, "std::string", "current_value"); | |
151 } | |
152 | |
153 ## radio_property | |
154 | |
155 function emit_get_radio (i) | |
156 { | |
157 printf (" bool %s_is (const std::string& v) const", name[i]); | |
158 | |
159 if (emit_get[i] == "definition") | |
160 printf (" { return %s.is (v); }\n", name[i]); | |
161 else | |
162 printf (";\n"); | |
163 | |
164 emit_get_accessor(i, "std::string", "current_value"); | |
165 } | |
166 | |
167 ## color_property | |
168 | |
169 function emit_get_color (i) | |
170 { | |
171 printf (" bool %s_is_rgb (void) const { return %s.is_rgb (); }\n", name[i], name[i]); | |
172 | |
173 printf (" bool %s_is (const std::string& v) const", name[i]); | |
174 | |
175 if (emit_get[i] == "definition") | |
176 printf (" { return %s.is (v); }\n", name[i]); | |
177 else | |
178 printf (";\n"); | |
179 | |
180 printf (" Matrix get_%s_rgb (void) const", name[i]); | |
181 | |
182 if (emit_get[i] == "definition") | |
183 printf (" { return (%s.is_rgb () ? %s.rgb () : Matrix ()); }\n", name[i], name[i]); | |
184 else | |
185 printf (";\n"); | |
186 | |
187 emit_get_accessor(i, "octave_value", "get"); | |
188 } | |
189 | |
7844
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
190 ## double_radio_property |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
191 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
192 function emit_get_double_radio (i) |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
193 { |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
194 printf (" bool %s_is_double (void) const { return %s.is_double (); }\n", name[i], name[i]); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
195 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
196 printf (" bool %s_is (const std::string& v) const", name[i]); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
197 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
198 if (emit_get[i] == "definition") |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
199 printf (" { return %s.is (v); }\n", name[i]); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
200 else |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
201 printf (";\n"); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
202 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
203 printf (" double get_%s_double (void) const", name[i]); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
204 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
205 if (emit_get[i] == "definition") |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
206 printf (" { return (%s.is_double () ? %s.double_value () : 0); }\n", name[i], name[i]); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
207 else |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
208 printf (";\n"); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
209 |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
210 emit_get_accessor(i, "octave_value", "get"); |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
211 } |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
212 |
7363 | 213 ## callback_property |
214 | |
215 function emit_get_callback (i) | |
216 { | |
7367 | 217 printf (" void execute_%s (const octave_value& data = octave_value ()) const", name[i]); |
7363 | 218 |
219 if (emit_get[i] == "definition") | |
7367 | 220 printf (" { %s.execute (data); }\n", name[i]); |
7363 | 221 else |
222 printf (";\n"); | |
223 | |
224 emit_get_accessor(i, "octave_value", "get"); | |
225 } | |
226 | |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
227 ## array_property |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
228 |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
229 function emit_get_array (i) |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
230 { |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
231 emit_get_accessor(i, "octave_value", "get"); |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
232 } |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
233 |
7363 | 234 ## common section |
235 | |
236 function emit_common_declarations () | |
237 { | |
238 printf ("public:\n"); | |
239 printf (" properties (const graphics_handle& mh, const graphics_handle& p);\n\n"); | |
240 printf (" ~properties (void) { }\n\n"); | |
7406 | 241 printf (" void set (const caseless_str& pname, const octave_value& val);\n\n"); |
7379 | 242 printf (" octave_value get (bool all = false) const;\n\n"); |
7406 | 243 printf (" octave_value get (const caseless_str& pname) const;\n\n"); |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
244 printf (" property get_property (const caseless_str& pname);\n\n"); |
7363 | 245 printf (" std::string graphics_object_name (void) const { return go_name; }\n\n"); |
246 printf (" static property_list::pval_map_type factory_defaults (void);\n\n"); | |
247 printf ("private:\n static std::string go_name;\n\n"); | |
248 } | |
249 | |
7225 | 250 function emit_declarations () |
6874 | 251 { |
7363 | 252 if (class_name) |
253 emit_common_declarations(); | |
254 | |
6874 | 255 if (idx > 0) |
7363 | 256 print "private:\n"; |
6874 | 257 |
258 for (i = 1; i <= idx; i++) | |
7363 | 259 printf (" %s%s %s;\n", mutable[i] ? "mutable " : "", type[i], name[i]); |
6874 | 260 |
261 if (idx > 0) | |
7363 | 262 print "\npublic:\n"; |
6874 | 263 |
264 for (i = 1; i <= idx; i++) | |
265 { | |
7363 | 266 if (emit_get[i]) |
267 { | |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
268 if (type[i] == "any_property") |
7363 | 269 emit_get_accessor(i, "octave_value", "get"); |
270 else if (type[i] == "handle_property") | |
271 emit_get_accessor(i, "graphics_handle", "handle_value"); | |
272 else if (type[i] == "string_property") | |
273 emit_get_accessor(i, "std::string", "string_value"); | |
274 else if (type[i] == "double_property") | |
275 emit_get_accessor(i, "double", "double_value"); | |
7844
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
276 else if (type[i] == "double_radio_property") |
3d60445d3638
Add new double_radio_property class for alpha values.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7836
diff
changeset
|
277 emit_get_double_radio(i); |
7836
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
278 else if (type[i] == "array_property" \ |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
279 || type[i] == "row_vector_property") |
4fb2db9c87dd
Turn cdata properties into array_property. Add min/max computation to array_property.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7826
diff
changeset
|
280 emit_get_array(i); |
7363 | 281 else if (type[i] == "bool_property") |
282 emit_get_bool(i); | |
283 else if (type[i] == "radio_property") | |
284 emit_get_radio(i); | |
285 else if (type[i] == "color_property") | |
286 emit_get_color(i); | |
287 else if (type[i] == "callback_property") | |
288 emit_get_callback(i); | |
289 else | |
6874 | 290 { |
7363 | 291 printf (" %s get_%s (void) const", type[i], name[i]); |
6874 | 292 |
7363 | 293 if (emit_get[i] == "definition") |
294 printf (" { return %s; }\n", name[i]); | |
295 else | |
296 printf (";\n"); | |
6874 | 297 } |
7363 | 298 printf ("\n"); |
299 } | |
6874 | 300 } |
301 | |
302 if (idx > 0) | |
7363 | 303 printf ("\n"); |
6874 | 304 |
305 for (i = 1; i <= idx; i++) | |
306 { | |
7363 | 307 if (emit_set[i]) |
308 { | |
309 printf (" void set_%s (const octave_value& val)", name[i], type[i]); | |
6874 | 310 |
7363 | 311 if (emit_set[i] == "definition") |
312 { | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
313 if (updaters[i] || limits[i] || mode[i]) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
314 has_builtin_listeners = 1; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
315 else |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
316 has_builtin_listeners = 0; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
317 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
318 printf ("\n {\n if (! error_state)\n {\n %s.set (val, %s);\n", |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
319 name[i], (has_builtin_listeners ? "false" : "true")); |
7427 | 320 if (updater[i]) |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
321 printf (" update_%s ();\n", name[i]); |
7363 | 322 if (limits[i]) |
323 printf (" update_axis_limits (\"%s\");\n", name[i]); | |
324 if (mode[i]) | |
325 printf (" set_%smode (\"manual\");\n", name[i]); | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
326 if (has_builtin_listeners) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
327 printf (" %s.run_listeners (POSTSET);\n", name[i]); |
7363 | 328 printf (" mark_modified ();\n }\n }\n\n"); |
6874 | 329 } |
7363 | 330 else |
331 printf (";\n\n"); | |
332 } | |
6874 | 333 |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
334 if (updater[i] == "extern") |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
335 { |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
336 printf (" void update_%s (void);\n\n", name[i]); |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
337 } |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
338 |
7363 | 339 ## if (emit_ov_set[i]) |
340 ## { | |
341 ## printf (" void set_%s (const octave_value& val)", name[i]); | |
342 ## | |
343 ## if (emit_ov_set[i] == "definition") | |
344 ## printf (" { set_%s (%s (val)); }\n\n", name[i], type[i]); | |
345 ## else if (emit_ov_set[i] == "assignment") | |
346 ## { | |
347 ## printf ("\n {\n %s tmp (%s);\n tmp = val;\n set_%s (tmp);\n };\n\n", | |
348 ## type[i], name[i], name[i], name[i]); | |
349 ## } | |
350 ## else | |
351 ## printf (";\n"); | |
352 ## } | |
6874 | 353 } |
354 | |
7363 | 355 ## if (idx > 0) |
356 ## print "\nprivate:"; | |
357 } | |
358 | |
359 function emit_source () | |
360 { | |
361 if (class_name) | |
362 { | |
363 printf ("// ******** %s ********\n\n", class_name) >> filename; | |
364 | |
365 ## constructor | |
366 | |
367 printf ("%s::properties::properties (const graphics_handle& mh, const graphics_handle& p)\n", class_name) >> filename; | |
368 printf (" : base_properties (go_name, mh, p),\n") >> filename; | |
369 | |
370 for (i = 1; i <= idx; i++) | |
371 { | |
7397 | 372 printf (" %s (\"%s\", mh, %s)", name[i], name[i], defval[i]) >> filename; |
7363 | 373 if (i < idx) |
374 printf (",") >> filename; | |
375 printf ("\n") >> filename; | |
376 } | |
377 | |
7379 | 378 printf ("{\n") >> filename; |
7363 | 379 |
7379 | 380 for (i = 1; i <= idx; i++) |
381 { | |
382 ## printf (" insert_static_property (\"%s\", %s);\n", name[i], name[i]) >> filename; | |
383 if (hidden[i]) | |
384 printf (" %s.set_hidden (true);\n", name[i]) >> filename; | |
385 } | |
7363 | 386 |
7379 | 387 printf (" init ();\n}\n\n") >> filename; |
7363 | 388 |
389 ## set method | |
390 | |
7406 | 391 printf ("void\n%s::properties::set (const caseless_str& pname, const octave_value& val)\n{\n", |
7363 | 392 class_name) >> filename; |
393 | |
7865
b74039822fd2
Add support for hggroup
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7862
diff
changeset
|
394 first = 1; |
b74039822fd2
Add support for hggroup
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7862
diff
changeset
|
395 |
7363 | 396 for (i = 1; i <= idx; i++) |
397 { | |
7403 | 398 if (! readonly[i]) |
7865
b74039822fd2
Add support for hggroup
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7862
diff
changeset
|
399 { |
7406 | 400 printf (" %sif (pname.compare (\"%s\"))\n set_%s (val);\n", |
7865
b74039822fd2
Add support for hggroup
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7862
diff
changeset
|
401 (first == 0 ? "else " : ""), name[i], name[i]) >> filename; |
b74039822fd2
Add support for hggroup
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7862
diff
changeset
|
402 first = 0; |
b74039822fd2
Add support for hggroup
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7862
diff
changeset
|
403 } |
7363 | 404 } |
405 | |
7406 | 406 printf (" else\n base_properties::set (pname, val);\n}\n\n") >> filename; |
7363 | 407 |
408 ## get "all" method | |
409 | |
7379 | 410 printf ("octave_value\n%s::properties::get (bool all) const\n{\n", class_name) >> filename; |
411 printf (" Octave_map m = base_properties::get (all).map_value ();\n\n") >> filename; | |
7363 | 412 |
413 for (i = 1; i <= idx; i++) | |
414 { | |
7379 | 415 if (hidden[i]) |
416 printf (" if (all)\n m.assign (\"%s\", get_%s ()%s);\n", name[i], name[i], | |
417 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; | |
418 else | |
419 printf (" m.assign (\"%s\", get_%s ()%s);\n", name[i], name[i], | |
420 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; | |
7363 | 421 } |
422 | |
423 printf ("\n return m;\n}\n\n") >> filename; | |
424 | |
425 ## get "one" method | |
426 | |
7406 | 427 printf ("octave_value\n%s::properties::get (const caseless_str& pname) const\n{\n", |
7363 | 428 class_name) >> filename; |
429 printf (" octave_value retval;\n\n") >> filename; | |
430 | |
431 for (i = 1; i<= idx; i++) | |
432 { | |
7406 | 433 printf (" %sif (pname.compare (\"%s\"))\n", |
7363 | 434 (i > 1 ? "else " : ""), name[i]) >> filename; |
435 printf (" retval = get_%s ()%s;\n", name[i], | |
436 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; | |
437 } | |
438 | |
7406 | 439 printf (" else\n retval = base_properties::get (pname);\n\n") >> filename; |
7363 | 440 printf (" return retval;\n}\n\n") >> filename; |
441 | |
7849
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
442 ## get_property method |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
443 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
444 printf ("property\n%s::properties::get_property (const caseless_str& pname)\n{\n", |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
445 class_name) >> filename; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
446 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
447 for (i = 1; i<= idx; i++) |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
448 { |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
449 printf (" %sif (pname.compare (\"%s\"))\n", |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
450 (i > 1 ? "else " : ""), name[i]) >> filename; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
451 printf (" return property (&%s, true);\n", name[i]) >> filename; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
452 } |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
453 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
454 printf (" else\n return base_properties::get_property (pname);\n") >> filename; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
455 printf ("}\n\n") >> filename; |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
456 |
3249f64f69b2
Initial low-level support for property listeners.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7848
diff
changeset
|
457 |
7363 | 458 ## factory defaults method |
459 | |
460 printf ("property_list::pval_map_type\n%s::properties::factory_defaults (void)\n{\n", | |
461 class_name) >> filename; | |
462 printf (" property_list::pval_map_type m;\n\n") >> filename; | |
463 | |
464 for (i = 1; i <= idx; i++) | |
465 { | |
7397 | 466 dval = defval[i]; |
7363 | 467 if (type[i] == "radio_property" || type[i] == "color_property") |
7895
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
468 { |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
469 k = index (dval, "{"); |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
470 dval = substr (dval, k+1); |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
471 l = index (dval, "}"); |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
472 if (k > 0 && l > 0) |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
473 dval = "\"" + substr (dval, 1, l-1) + "\""; |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
474 else |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
475 dval = "octave_value ()"; |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
476 } |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
477 |
7853
263cdf57a1dd
Use all properties in factory default values (including the ones starting with __)
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
478 printf (" m[\"%s\"] = %s%s;\n", name[i], dval, |
263cdf57a1dd
Use all properties in factory default values (including the ones starting with __)
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7849
diff
changeset
|
479 (type[i] == "handle_property" ? ".as_octave_value ()" : "")) >> filename; |
7363 | 480 } |
481 | |
482 printf ("\n return m;\n}\n\n") >> filename; | |
483 | |
484 ## go_name static field | |
485 | |
486 printf ("std::string %s::properties::go_name (\"%s\");\n\n", | |
487 class_name, class_name) >> filename; | |
488 } | |
6874 | 489 } |
490 | |
491 BEGIN { | |
7363 | 492 filename = "graphics-props.cc"; |
493 printf ("// DO NOT EDIT! Generated automatically by genprops.awk.\n\n"); | |
494 printf ("// DO NOT EDIT! Generated automatically by genprops.awk.\n\n") > filename; | |
495 } | |
496 | |
497 /BEGIN_PROPERTIES\(.*\)/ { | |
498 gather = 1; | |
499 idx = 0; | |
7895
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
500 str = $0; |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
501 k = index (str, "BEGIN_PROPERTIES("); |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
502 str = substr (str, k + 17); |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
503 l = index (str, ")"); |
f1a1f6dd7fac
avoid using gensub in genprops.awk
Jaroslav Hajek <highegg@gmail.com>
parents:
7865
diff
changeset
|
504 class_name = substr (str, 1, l-1); |
7363 | 505 next; |
6874 | 506 } |
507 | |
508 /BEGIN_PROPERTIES/ { | |
7363 | 509 gather = 1; |
510 idx = 0; | |
511 class_name = ""; | |
512 next; | |
6874 | 513 } |
514 | |
515 /END_PROPERTIES/ { | |
7363 | 516 emit_declarations(); |
517 emit_source(); | |
518 gather = 0; | |
519 next; | |
6874 | 520 } |
521 | |
522 { | |
523 if (gather) | |
7363 | 524 { |
7403 | 525 if (NF < 2 || /^[ \t]*\/\//) |
7363 | 526 next; |
6874 | 527 |
7363 | 528 idx++; |
6874 | 529 |
7363 | 530 field = 1; |
6874 | 531 |
7363 | 532 if ($field == "mutable") |
533 { | |
534 mutable[idx] = 1; | |
535 field++; | |
536 } | |
537 else | |
538 mutable[idx] = 0; | |
6874 | 539 |
7363 | 540 type[idx] = $(field++); |
541 name[idx] = $(field++); | |
6874 | 542 |
7363 | 543 limits[idx] = 0; |
544 mode[idx] = 0; | |
7403 | 545 hidden[idx] = 0; |
546 readonly[idx] = 0; | |
7363 | 547 emit_get[idx] = "definition"; |
548 emit_set[idx] = "definition"; | |
7397 | 549 defval[idx] = ""; |
7427 | 550 updater[idx] = ""; |
7363 | 551 ## if (type[idx] == "octave_value") |
552 ## emit_ov_set[idx] = ""; | |
553 ## else | |
554 ## emit_ov_set[idx] = "definition"; | |
6874 | 555 |
7363 | 556 if (NF >= field) |
557 { | |
558 if ($field != ",") | |
559 { | |
560 quals = $(field++); | |
7214 | 561 |
7363 | 562 if (index (quals, "l")) |
563 limits[idx] = 1; | |
6874 | 564 |
7363 | 565 if (index (quals, "m")) |
566 mode[idx] = 1; | |
567 | |
568 ## There is a custom inline definition for the get function, | |
569 ## so we don't emit anything. | |
570 if (index (quals, "g")) | |
571 emit_get[idx] = ""; | |
6874 | 572 |
7363 | 573 ## There is a custom extern definition for the get function, |
574 ## but we still emit the declaration. | |
575 if (index (quals, "G")) | |
576 emit_get[idx] = "declaration"; | |
6874 | 577 |
7363 | 578 ## There is a custom inline definition for the set function, |
579 ## so we don't emit anything. | |
580 if (index (quals, "s")) | |
581 emit_set[idx] = ""; | |
6874 | 582 |
7363 | 583 ## There is a custom extern definition for the set function, |
584 ## but we still emit the declaration. | |
585 if (index (quals, "S")) | |
586 emit_set[idx] = "declaration"; | |
7379 | 587 |
7403 | 588 ## The property is hidden |
589 if (index (quals, "h")) | |
590 hidden[idx] = 1; | |
591 | |
592 ## The property is read-only | |
593 if (index (quals, "r")) | |
594 readonly[idx] = 1; | |
6904 | 595 |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
596 ## There is an inline updater method that should be called |
7427 | 597 ## from the set method |
598 if (index (quals, "u")) | |
7826
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
599 updater[idx] = "inline"; |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
600 |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
601 ## There is an extern updater method that should be called |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
602 ## from the set method |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
603 if (index (quals, "U")) |
68550ad9ee9c
Add support for extern updaters. Add set_figure_position interface to graphics_backend.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
7523
diff
changeset
|
604 updater[idx] = "extern"; |
7427 | 605 |
7363 | 606 ## ## emmit an asignment set function |
607 ## if (index (quals, "a")) | |
608 ## emit_ov_set[idx] = "assignment"; | |
609 ## | |
610 ## if (type[idx] != "octave_value") | |
611 ## { | |
612 ## ## The 'o' and 'O' qualifiers are only useful when the | |
613 ## ## the property type is something other than an | |
614 ## ## octave_value. | |
615 ## | |
616 ## ## There is a custom inline definition for the | |
617 ## ## octave_value version of the set function, so we | |
618 ## ## don't emit anything. | |
619 ## if (index (quals, "o")) | |
620 ## emit_ov_set[idx] = ""; | |
621 ## | |
622 ## ## There is a custom extern definition for the | |
623 ## ## octave_value version of the set function, but we | |
624 ## ## still emit the declaration. | |
625 ## if (index (quals, "O")) | |
626 ## emit_ov_set[idx] = "declaration"; | |
627 ## } | |
628 } | |
6874 | 629 |
7363 | 630 if (NF > field && $field == ",") |
631 { | |
632 field++; | |
6874 | 633 |
7363 | 634 for (i = field; i <= NF; i++) |
7397 | 635 defval[idx] = (defval[idx] (i > field ? " " : "") $i); |
7363 | 636 } |
6874 | 637 } |
7363 | 638 |
639 } | |
6874 | 640 else |
7363 | 641 print $0; |
6883 | 642 } |