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 ## |
|
56 ## m: Add the line |
|
57 ## |
|
58 ## set_NAMEmode ("manual"); |
|
59 ## |
|
60 ## to the type-specific set function. |
|
61 ## |
|
62 ## The 'o' and 'O' qualifiers are only useful when the the property type |
|
63 ## is something other than octave_value. |
|
64 |
|
65 function emit_decls () |
|
66 { |
|
67 if (idx > 0) |
|
68 print "private:\n"; |
|
69 |
|
70 for (i = 1; i <= idx; i++) |
|
71 printf (" %s%s %s;\n", mutable[i] ? "mutable " : "", type[i], name[i]); |
|
72 |
|
73 if (idx > 0) |
|
74 print "\npublic:\n"; |
|
75 |
|
76 for (i = 1; i <= idx; i++) |
|
77 { |
|
78 if (emit_get[i]) |
|
79 { |
|
80 printf (" %s get_%s (void) const", type[i], name[i]); |
|
81 |
|
82 if (emit_get[i] == "defn") |
|
83 printf (" { return %s; }\n", name[i]); |
|
84 else |
|
85 printf (";\n"); |
|
86 } |
|
87 } |
|
88 |
|
89 if (idx > 0) |
|
90 printf ("\n"); |
|
91 |
|
92 for (i = 1; i <= idx; i++) |
|
93 { |
|
94 if (emit_set[i]) |
|
95 { |
|
96 printf (" void set_%s (const %s& val)", name[i], type[i]); |
|
97 |
|
98 if (emit_set[i] == "defn") |
|
99 { |
|
100 printf ("\n {\n if (! error_state)\n {\n %s = val;\n", |
|
101 name[i]); |
|
102 if (mode[i]) |
|
103 printf (" set_%smode (\"manual\");\n", name[i]); |
|
104 printf (" mark_modified ();\n }\n }\n\n"); |
|
105 } |
|
106 else |
|
107 printf (";\n"); |
|
108 } |
|
109 |
|
110 if (emit_ov_set[i]) |
|
111 { |
|
112 printf (" void set_%s (const octave_value& val)", name[i]); |
|
113 |
|
114 if (emit_ov_set[i] == "defn") |
|
115 printf (" { set_%s (%s (val)); }\n\n", name[i], type[i]); |
|
116 else |
|
117 printf (";\n"); |
|
118 } |
|
119 } |
|
120 |
|
121 if (idx > 0) |
|
122 print "\nprivate:"; |
|
123 } |
|
124 |
|
125 BEGIN { |
|
126 printf ("// DO NOT EDIT! Generated automatically by genprops.awk.\n\n"); |
|
127 } |
|
128 |
|
129 /BEGIN_PROPERTIES/ { |
|
130 gather = 1; |
|
131 idx = 0; |
|
132 next; |
|
133 } |
|
134 |
|
135 /END_PROPERTIES/ { |
|
136 emit_decls(); |
|
137 gather = 0; |
|
138 next; |
|
139 } |
|
140 |
|
141 { |
|
142 if (gather) |
|
143 { |
|
144 if (NF < 2 || NF > 4) |
|
145 next; |
|
146 |
|
147 idx++; |
|
148 |
|
149 field = 1; |
|
150 |
|
151 if ($field == "mutable") |
|
152 { |
|
153 mutable[idx] = 1; |
|
154 field++; |
|
155 } |
|
156 else |
|
157 mutable[idx] = 0; |
|
158 |
|
159 type[idx] = $(field++); |
|
160 name[idx] = $(field++); |
|
161 |
|
162 mode[idx] = 0; |
|
163 emit_get[idx] = "defn"; |
|
164 emit_set[idx] = "defn"; |
|
165 if (type[idx] == "octave_value") |
|
166 emit_ov_set[idx] = ""; |
|
167 else |
|
168 emit_ov_set[idx] = "defn"; |
|
169 |
|
170 if (NF == field) |
|
171 { |
|
172 quals = $field; |
|
173 |
|
174 if (index (quals, "m")) |
|
175 mode[idx] = 1; |
|
176 |
|
177 ## There is a custom inline definition for the get function, |
|
178 ## so we don't emit anything. |
|
179 if (index (quals, "g")) |
|
180 emit_get[idx] = ""; |
|
181 |
|
182 ## There is a custom extern definition for the get function, |
|
183 ## but we still emit the declaration. |
|
184 if (index (quals, "G")) |
|
185 emit_get[idx] = "decl"; |
|
186 |
|
187 ## There is a custom inline definition for the set function, |
|
188 ## so we don't emit anything. |
|
189 if (index (quals, "s")) |
|
190 emit_set[idx] = ""; |
|
191 |
|
192 ## There is a custom extern definition for the set function, |
|
193 ## but we still emit the declaration. |
|
194 if (index (quals, "S")) |
|
195 emit_set[idx] = "decl"; |
|
196 |
|
197 if (type[idx] != "octave_value") |
|
198 { |
|
199 ## The 'o' and 'O' qualifiers are only useful when the |
|
200 ## the property type is something other than an |
|
201 ## octave_value. |
|
202 |
|
203 ## There is a custom inline definition for the |
|
204 ## octave_value version of the set function, so we |
|
205 ## don't emit anything. |
|
206 if (index (quals, "o")) |
|
207 emit_ov_set[idx] = ""; |
|
208 |
|
209 ## There is a custom extern definition for the |
|
210 ## octave_value version of the set function, but we |
|
211 ## still emit the declaration. |
|
212 if (index (quals, "O")) |
|
213 emit_ov_set[idx] = "decl"; |
|
214 } |
|
215 } |
|
216 |
|
217 } |
|
218 else |
|
219 print $0; |
6883
|
220 } |