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