2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_value_typeinfo_h) |
|
25 #define octave_value_typeinfo_h 1 |
|
26 |
|
27 #include <string> |
|
28 |
|
29 #include "Array.h" |
|
30 #include "Array2.h" |
|
31 #include "Array3.h" |
|
32 |
|
33 #include "ov.h" |
|
34 |
|
35 class string_vector; |
|
36 |
|
37 class |
|
38 octave_value_typeinfo |
|
39 { |
|
40 public: |
|
41 |
5759
|
42 typedef octave_value (*unary_op_fcn) (const octave_base_value&); |
|
43 |
|
44 typedef void (*non_const_unary_op_fcn) (octave_base_value&); |
|
45 |
|
46 typedef octave_value (*binary_op_fcn) |
|
47 (const octave_base_value&, const octave_base_value&); |
|
48 |
|
49 typedef octave_value (*cat_op_fcn) |
|
50 (octave_base_value&, const octave_base_value&, const Array<int>& ra_idx); |
|
51 |
|
52 typedef octave_value (*assign_op_fcn) |
|
53 (octave_base_value&, const octave_value_list&, const octave_base_value&); |
|
54 |
|
55 typedef octave_value (*assignany_op_fcn) |
|
56 (octave_base_value&, const octave_value_list&, const octave_value&); |
|
57 |
2926
|
58 static bool instance_ok (void); |
|
59 |
4640
|
60 static int register_type (const std::string&, const std::string&, |
|
61 const octave_value&); |
2376
|
62 |
3203
|
63 static bool register_unary_op (octave_value::unary_op, int, unary_op_fcn); |
|
64 |
|
65 static bool register_non_const_unary_op (octave_value::unary_op, int, |
|
66 non_const_unary_op_fcn); |
|
67 |
2376
|
68 static bool register_binary_op (octave_value::binary_op, int, int, |
2427
|
69 binary_op_fcn); |
2376
|
70 |
4915
|
71 static bool register_cat_op (int, int, cat_op_fcn); |
|
72 |
2882
|
73 static bool register_assign_op (octave_value::assign_op, int, int, |
|
74 assign_op_fcn); |
2376
|
75 |
3196
|
76 static bool register_assignany_op (octave_value::assign_op, int, |
5759
|
77 assignany_op_fcn); |
3196
|
78 |
2376
|
79 static bool register_pref_assign_conv (int, int, int); |
|
80 |
5759
|
81 static bool |
|
82 register_type_conv_op (int, int, octave_base_value::type_conv_fcn); |
4901
|
83 |
5759
|
84 static bool |
|
85 register_widening_op (int, int, octave_base_value::type_conv_fcn); |
2376
|
86 |
4640
|
87 static octave_value |
|
88 lookup_type (const std::string& nm) |
|
89 { |
|
90 return instance->do_lookup_type (nm); |
|
91 } |
|
92 |
3203
|
93 static unary_op_fcn |
|
94 lookup_unary_op (octave_value::unary_op op, int t) |
|
95 { |
|
96 return instance->do_lookup_unary_op (op, t); |
|
97 } |
|
98 |
|
99 static non_const_unary_op_fcn |
|
100 lookup_non_const_unary_op (octave_value::unary_op op, int t) |
|
101 { |
|
102 return instance->do_lookup_non_const_unary_op (op, t); |
|
103 } |
|
104 |
2427
|
105 static binary_op_fcn |
2376
|
106 lookup_binary_op (octave_value::binary_op op, int t1, int t2) |
|
107 { |
|
108 return instance->do_lookup_binary_op (op, t1, t2); |
|
109 } |
|
110 |
4915
|
111 static cat_op_fcn |
|
112 lookup_cat_op (int t1, int t2) |
|
113 { |
|
114 return instance->do_lookup_cat_op (t1, t2); |
|
115 } |
|
116 |
2427
|
117 static assign_op_fcn |
2882
|
118 lookup_assign_op (octave_value::assign_op op, int t_lhs, int t_rhs) |
2376
|
119 { |
2882
|
120 return instance->do_lookup_assign_op (op, t_lhs, t_rhs); |
2376
|
121 } |
|
122 |
5759
|
123 static assignany_op_fcn |
3196
|
124 lookup_assignany_op (octave_value::assign_op op, int t_lhs) |
|
125 { |
|
126 return instance->do_lookup_assignany_op (op, t_lhs); |
|
127 } |
|
128 |
2376
|
129 static int |
|
130 lookup_pref_assign_conv (int t_lhs, int t_rhs) |
|
131 { |
|
132 return instance->do_lookup_pref_assign_conv (t_lhs, t_rhs); |
|
133 } |
|
134 |
5759
|
135 static octave_base_value::type_conv_fcn |
4901
|
136 lookup_type_conv_op (int t, int t_result) |
|
137 { |
|
138 return instance->do_lookup_type_conv_op (t, t_result); |
|
139 } |
|
140 |
5759
|
141 static octave_base_value::type_conv_fcn |
2376
|
142 lookup_widening_op (int t, int t_result) |
|
143 { |
|
144 return instance->do_lookup_widening_op (t, t_result); |
|
145 } |
|
146 |
|
147 static string_vector installed_type_names (void) |
|
148 { |
|
149 return instance->do_installed_type_names (); |
|
150 } |
|
151 |
|
152 protected: |
|
153 |
|
154 octave_value_typeinfo (void) |
3523
|
155 : num_types (0), types (init_tab_sz, std::string ()), |
4645
|
156 vals (init_tab_sz), |
3203
|
157 unary_ops (octave_value::num_unary_ops, init_tab_sz, |
|
158 (unary_op_fcn) 0), |
|
159 non_const_unary_ops (octave_value::num_unary_ops, init_tab_sz, |
|
160 (non_const_unary_op_fcn) 0), |
2479
|
161 binary_ops (octave_value::num_binary_ops, init_tab_sz, |
|
162 init_tab_sz, (binary_op_fcn) 0), |
4915
|
163 cat_ops (init_tab_sz, init_tab_sz, (cat_op_fcn) 0), |
2882
|
164 assign_ops (octave_value::num_assign_ops, init_tab_sz, |
|
165 init_tab_sz, (assign_op_fcn) 0), |
3196
|
166 assignany_ops (octave_value::num_assign_ops, init_tab_sz, |
5759
|
167 (assignany_op_fcn) 0), |
2479
|
168 pref_assign_conv (init_tab_sz, init_tab_sz, -1), |
5759
|
169 type_conv_ops (init_tab_sz, init_tab_sz, (octave_base_value::type_conv_fcn) 0), |
|
170 widening_ops (init_tab_sz, init_tab_sz, (octave_base_value::type_conv_fcn) 0) { } |
2376
|
171 |
|
172 private: |
|
173 |
2479
|
174 static const int init_tab_sz; |
|
175 |
2376
|
176 static octave_value_typeinfo *instance; |
|
177 |
|
178 int num_types; |
|
179 |
3523
|
180 Array<std::string> types; |
2376
|
181 |
4640
|
182 Array<octave_value> vals; |
|
183 |
3203
|
184 Array2<unary_op_fcn> unary_ops; |
|
185 |
|
186 Array2<non_const_unary_op_fcn> non_const_unary_ops; |
|
187 |
2427
|
188 Array3<binary_op_fcn> binary_ops; |
2376
|
189 |
4915
|
190 Array2<cat_op_fcn> cat_ops; |
|
191 |
2882
|
192 Array3<assign_op_fcn> assign_ops; |
2376
|
193 |
5759
|
194 Array2<assignany_op_fcn> assignany_ops; |
3196
|
195 |
2376
|
196 Array2<int> pref_assign_conv; |
|
197 |
5759
|
198 Array2<octave_base_value::type_conv_fcn> type_conv_ops; |
4901
|
199 |
5759
|
200 Array2<octave_base_value::type_conv_fcn> widening_ops; |
2376
|
201 |
4640
|
202 int do_register_type (const std::string&, const std::string&, |
|
203 const octave_value&); |
2376
|
204 |
3203
|
205 bool do_register_unary_op (octave_value::unary_op, int, unary_op_fcn); |
|
206 |
|
207 bool do_register_non_const_unary_op (octave_value::unary_op, int, |
|
208 non_const_unary_op_fcn); |
|
209 |
2376
|
210 bool do_register_binary_op (octave_value::binary_op, int, int, |
2427
|
211 binary_op_fcn); |
2376
|
212 |
4915
|
213 bool do_register_cat_op (int, int, cat_op_fcn); |
|
214 |
2882
|
215 bool do_register_assign_op (octave_value::assign_op, int, int, |
|
216 assign_op_fcn); |
2376
|
217 |
3196
|
218 bool do_register_assignany_op (octave_value::assign_op, int, |
5759
|
219 assignany_op_fcn); |
3196
|
220 |
2376
|
221 bool do_register_pref_assign_conv (int, int, int); |
|
222 |
5759
|
223 bool do_register_type_conv_op (int, int, octave_base_value::type_conv_fcn); |
4901
|
224 |
5759
|
225 bool do_register_widening_op (int, int, octave_base_value::type_conv_fcn); |
2376
|
226 |
4640
|
227 octave_value do_lookup_type (const std::string& nm); |
|
228 |
3203
|
229 unary_op_fcn do_lookup_unary_op (octave_value::unary_op, int); |
|
230 |
|
231 non_const_unary_op_fcn do_lookup_non_const_unary_op |
|
232 (octave_value::unary_op, int); |
2376
|
233 |
3203
|
234 binary_op_fcn do_lookup_binary_op (octave_value::binary_op, int, int); |
2376
|
235 |
4915
|
236 cat_op_fcn do_lookup_cat_op (int, int); |
|
237 |
3203
|
238 assign_op_fcn do_lookup_assign_op (octave_value::assign_op, int, int); |
|
239 |
5759
|
240 assignany_op_fcn do_lookup_assignany_op (octave_value::assign_op, int); |
3196
|
241 |
2376
|
242 int do_lookup_pref_assign_conv (int, int); |
|
243 |
5759
|
244 octave_base_value::type_conv_fcn do_lookup_type_conv_op (int, int); |
4901
|
245 |
5759
|
246 octave_base_value::type_conv_fcn do_lookup_widening_op (int, int); |
2376
|
247 |
|
248 string_vector do_installed_type_names (void); |
|
249 |
|
250 // No copying! |
|
251 |
|
252 octave_value_typeinfo (const octave_value_typeinfo&); |
|
253 |
|
254 octave_value_typeinfo& operator = (const octave_value_typeinfo&); |
|
255 }; |
|
256 |
|
257 #endif |
|
258 |
|
259 /* |
|
260 ;; Local Variables: *** |
|
261 ;; mode: C++ *** |
|
262 ;; End: *** |
|
263 */ |