Mercurial > octave-antonio
annotate src/ov-typeinfo.cc @ 9219:612918b993a0
remove redundant include
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 20 May 2009 11:48:30 +0200 |
parents | eb63fbe60fab |
children | 902a4597dce8 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008, 2009 John W. Eaton |
2376 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "ov-typeinfo.h" | |
29 | |
30 #include "defun.h" | |
31 #include "error.h" | |
32 | |
2479 | 33 const int |
34 octave_value_typeinfo::init_tab_sz (16); | |
35 | |
36 octave_value_typeinfo * | |
37 octave_value_typeinfo::instance (0); | |
2376 | 38 |
4515 | 39 #include <Array.h> |
40 #include <Array2.h> | |
41 #include <Array3.h> | |
42 | |
2376 | 43 #include <Array.cc> |
44 | |
7433 | 45 NO_INSTANTIATE_ARRAY_SORT (octave_value_typeinfo::unary_op_fcn); |
6708 | 46 INSTANTIATE_ARRAY (octave_value_typeinfo::unary_op_fcn, ); |
5759 | 47 template class Array2<octave_value_typeinfo::unary_op_fcn>; |
3203 | 48 |
7433 | 49 NO_INSTANTIATE_ARRAY_SORT (octave_value_typeinfo::non_const_unary_op_fcn); |
6708 | 50 INSTANTIATE_ARRAY (octave_value_typeinfo::non_const_unary_op_fcn, ); |
5759 | 51 template class Array2<octave_value_typeinfo::non_const_unary_op_fcn>; |
3203 | 52 |
7433 | 53 NO_INSTANTIATE_ARRAY_SORT (octave_value_typeinfo::binary_op_fcn); |
6708 | 54 INSTANTIATE_ARRAY (octave_value_typeinfo::binary_op_fcn, ); |
5759 | 55 template class Array2<octave_value_typeinfo::binary_op_fcn>; |
56 template class Array3<octave_value_typeinfo::binary_op_fcn>; | |
2376 | 57 |
7433 | 58 NO_INSTANTIATE_ARRAY_SORT (octave_value_typeinfo::cat_op_fcn); |
6708 | 59 INSTANTIATE_ARRAY (octave_value_typeinfo::cat_op_fcn, ); |
5759 | 60 template class Array2<octave_value_typeinfo::cat_op_fcn>; |
4915 | 61 |
7433 | 62 NO_INSTANTIATE_ARRAY_SORT (octave_value_typeinfo::assign_op_fcn); |
6708 | 63 INSTANTIATE_ARRAY (octave_value_typeinfo::assign_op_fcn, ); |
5759 | 64 template class Array2<octave_value_typeinfo::assign_op_fcn>; |
65 template class Array3<octave_value_typeinfo::assign_op_fcn>; | |
2376 | 66 |
7433 | 67 NO_INSTANTIATE_ARRAY_SORT (octave_value_typeinfo::assignany_op_fcn); |
6708 | 68 INSTANTIATE_ARRAY (octave_value_typeinfo::assignany_op_fcn, ); |
5891 | 69 template class Array2<octave_value_typeinfo::assignany_op_fcn>; |
70 | |
7433 | 71 NO_INSTANTIATE_ARRAY_SORT (octave_base_value::type_conv_fcn); |
6708 | 72 INSTANTIATE_ARRAY (octave_base_value::type_conv_fcn, ); |
5759 | 73 template class Array2<octave_base_value::type_conv_fcn>; |
2376 | 74 |
2926 | 75 bool |
76 octave_value_typeinfo::instance_ok (void) | |
77 { | |
78 bool retval = true; | |
79 if (! instance) | |
80 instance = new octave_value_typeinfo (); | |
81 | |
82 if (! instance) | |
83 { | |
84 ::error ("unable to create value type info object!"); | |
85 | |
86 retval = false; | |
87 } | |
88 | |
89 return retval; | |
90 } | |
91 | |
2376 | 92 int |
4612 | 93 octave_value_typeinfo::register_type (const std::string& t_name, |
4640 | 94 const std::string& c_name, |
95 const octave_value& val) | |
2376 | 96 { |
2926 | 97 return (instance_ok ()) |
4640 | 98 ? instance->do_register_type (t_name, c_name, val) : -1; |
2376 | 99 } |
100 | |
101 bool | |
7336 | 102 octave_value_typeinfo::register_unary_class_op (octave_value::unary_op op, |
103 octave_value_typeinfo::unary_class_op_fcn f) | |
104 { | |
105 return (instance_ok ()) | |
106 ? instance->do_register_unary_class_op (op, f) : false; | |
107 } | |
108 | |
109 bool | |
3203 | 110 octave_value_typeinfo::register_unary_op (octave_value::unary_op op, |
5759 | 111 int t, octave_value_typeinfo::unary_op_fcn f) |
3203 | 112 { |
113 return (instance_ok ()) | |
114 ? instance->do_register_unary_op (op, t, f) : false; | |
115 } | |
116 | |
117 bool | |
118 octave_value_typeinfo::register_non_const_unary_op (octave_value::unary_op op, | |
119 int t, | |
5759 | 120 octave_value_typeinfo::non_const_unary_op_fcn f) |
3203 | 121 { |
122 return (instance_ok ()) | |
123 ? instance->do_register_non_const_unary_op (op, t, f) : false; | |
124 } | |
125 | |
126 bool | |
7336 | 127 octave_value_typeinfo::register_binary_class_op (octave_value::binary_op op, |
128 octave_value_typeinfo::binary_class_op_fcn f) | |
129 { | |
130 return (instance_ok ()) | |
131 ? instance->do_register_binary_class_op (op, f) : false; | |
132 } | |
133 | |
134 bool | |
2376 | 135 octave_value_typeinfo::register_binary_op (octave_value::binary_op op, |
136 int t1, int t2, | |
5759 | 137 octave_value_typeinfo::binary_op_fcn f) |
2376 | 138 { |
2926 | 139 return (instance_ok ()) |
140 ? instance->do_register_binary_op (op, t1, t2, f) : false; | |
2376 | 141 } |
142 | |
143 bool | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
144 octave_value_typeinfo::register_binary_class_op (octave_value::compound_binary_op op, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
145 octave_value_typeinfo::binary_class_op_fcn f) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
146 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
147 return (instance_ok ()) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
148 ? instance->do_register_binary_class_op (op, f) : false; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
149 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
150 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
151 bool |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
152 octave_value_typeinfo::register_binary_op (octave_value::compound_binary_op op, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
153 int t1, int t2, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
154 octave_value_typeinfo::binary_op_fcn f) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
155 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
156 return (instance_ok ()) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
157 ? instance->do_register_binary_op (op, t1, t2, f) : false; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
158 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
159 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
160 bool |
5759 | 161 octave_value_typeinfo::register_cat_op (int t1, int t2, octave_value_typeinfo::cat_op_fcn f) |
4915 | 162 { |
163 return (instance_ok ()) | |
164 ? instance->do_register_cat_op (t1, t2, f) : false; | |
165 } | |
166 | |
167 bool | |
2882 | 168 octave_value_typeinfo::register_assign_op (octave_value::assign_op op, |
169 int t_lhs, int t_rhs, | |
5759 | 170 octave_value_typeinfo::assign_op_fcn f) |
2376 | 171 { |
2926 | 172 return (instance_ok ()) |
173 ? instance->do_register_assign_op (op, t_lhs, t_rhs, f) : -1; | |
2376 | 174 } |
175 | |
176 bool | |
3196 | 177 octave_value_typeinfo::register_assignany_op (octave_value::assign_op op, |
5759 | 178 int t_lhs, octave_value_typeinfo::assignany_op_fcn f) |
3196 | 179 { |
180 return (instance_ok ()) | |
181 ? instance->do_register_assignany_op (op, t_lhs, f) : -1; | |
182 } | |
183 | |
184 bool | |
2376 | 185 octave_value_typeinfo::register_pref_assign_conv (int t_lhs, int t_rhs, |
186 int t_result) | |
187 { | |
2926 | 188 return (instance_ok ()) |
189 ? instance->do_register_pref_assign_conv (t_lhs, t_rhs, t_result) : false; | |
2376 | 190 } |
191 | |
192 bool | |
4901 | 193 octave_value_typeinfo::register_type_conv_op (int t, int t_result, |
5759 | 194 octave_base_value::type_conv_fcn f) |
4901 | 195 { |
196 return (instance_ok ()) | |
197 ? instance->do_register_type_conv_op (t, t_result, f) : false; | |
198 } | |
199 | |
200 bool | |
2376 | 201 octave_value_typeinfo::register_widening_op (int t, int t_result, |
5759 | 202 octave_base_value::type_conv_fcn f) |
2376 | 203 { |
2926 | 204 return (instance_ok ()) |
205 ? instance->do_register_widening_op (t, t_result, f) : false; | |
2376 | 206 } |
207 | |
5775 | 208 // FIXME -- we should also store all class names and provide a |
4687 | 209 // way to list them (calling class with nargin == 0?). |
210 | |
2376 | 211 int |
4612 | 212 octave_value_typeinfo::do_register_type (const std::string& t_name, |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8474
diff
changeset
|
213 const std::string& /* c_name */, |
4640 | 214 const octave_value& val) |
2376 | 215 { |
216 int i = 0; | |
217 | |
218 for (i = 0; i < num_types; i++) | |
4612 | 219 if (t_name == types (i)) |
2376 | 220 return i; |
221 | |
222 int len = types.length (); | |
223 | |
224 if (i == len) | |
225 { | |
226 len *= 2; | |
227 | |
4625 | 228 types.resize (len, std::string ()); |
2376 | 229 |
4640 | 230 vals.resize (len, octave_value ()); |
231 | |
3203 | 232 unary_ops.resize (static_cast<int> (octave_value::num_unary_ops), |
5759 | 233 len, static_cast<octave_value_typeinfo::unary_op_fcn> (0)); |
3203 | 234 |
235 non_const_unary_ops.resize | |
236 (static_cast<int> (octave_value::num_unary_ops), | |
5759 | 237 len, static_cast<octave_value_typeinfo::non_const_unary_op_fcn> (0)); |
3203 | 238 |
2800 | 239 binary_ops.resize (static_cast<int> (octave_value::num_binary_ops), |
5759 | 240 len, len, static_cast<octave_value_typeinfo::binary_op_fcn> (0)); |
2376 | 241 |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
242 compound_binary_ops.resize (static_cast<int> (octave_value::num_compound_binary_ops), |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
243 len, len, static_cast<octave_value_typeinfo::binary_op_fcn> (0)); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
244 |
5759 | 245 cat_ops.resize (len, len, static_cast<octave_value_typeinfo::cat_op_fcn> (0)); |
4915 | 246 |
2882 | 247 assign_ops.resize (static_cast<int> (octave_value::num_assign_ops), |
5759 | 248 len, len, static_cast<octave_value_typeinfo::assign_op_fcn> (0)); |
2376 | 249 |
3196 | 250 assignany_ops.resize (static_cast<int> (octave_value::num_assign_ops), |
5759 | 251 len, static_cast<octave_value_typeinfo::assignany_op_fcn> (0)); |
3196 | 252 |
2376 | 253 pref_assign_conv.resize (len, len, -1); |
254 | |
5759 | 255 type_conv_ops.resize (len, len, static_cast<octave_base_value::type_conv_fcn> (0)); |
4901 | 256 |
5759 | 257 widening_ops.resize (len, len, static_cast<octave_base_value::type_conv_fcn> (0)); |
2376 | 258 } |
259 | |
4612 | 260 types (i) = t_name; |
2376 | 261 |
4640 | 262 vals (i) = val; |
263 | |
2376 | 264 num_types++; |
265 | |
266 return i; | |
267 } | |
268 | |
269 bool | |
7336 | 270 octave_value_typeinfo::do_register_unary_class_op (octave_value::unary_op op, |
271 octave_value_typeinfo::unary_class_op_fcn f) | |
272 { | |
273 if (lookup_unary_class_op (op)) | |
274 { | |
275 std::string op_name = octave_value::unary_op_as_string (op); | |
276 | |
277 warning ("duplicate unary operator `%s' for class dispatch", | |
278 op_name.c_str ()); | |
279 } | |
280 | |
281 unary_class_ops.checkelem (static_cast<int> (op)) = f; | |
282 | |
283 return false; | |
284 } | |
285 | |
286 bool | |
3203 | 287 octave_value_typeinfo::do_register_unary_op (octave_value::unary_op op, |
5759 | 288 int t, octave_value_typeinfo::unary_op_fcn f) |
3203 | 289 { |
4508 | 290 if (lookup_unary_op (op, t)) |
291 { | |
292 std::string op_name = octave_value::unary_op_as_string (op); | |
293 std::string type_name = types(t); | |
294 | |
295 warning ("duplicate unary operator `%s' for type `%s'", | |
296 op_name.c_str (), type_name.c_str ()); | |
297 } | |
298 | |
3203 | 299 unary_ops.checkelem (static_cast<int> (op), t) = f; |
300 | |
301 return false; | |
302 } | |
303 | |
304 bool | |
305 octave_value_typeinfo::do_register_non_const_unary_op | |
5759 | 306 (octave_value::unary_op op, int t, octave_value_typeinfo::non_const_unary_op_fcn f) |
3203 | 307 { |
4508 | 308 if (lookup_non_const_unary_op (op, t)) |
309 { | |
310 std::string op_name = octave_value::unary_op_as_string (op); | |
311 std::string type_name = types(t); | |
312 | |
313 warning ("duplicate unary operator `%s' for type `%s'", | |
314 op_name.c_str (), type_name.c_str ()); | |
315 } | |
316 | |
3203 | 317 non_const_unary_ops.checkelem (static_cast<int> (op), t) = f; |
318 | |
319 return false; | |
320 } | |
321 | |
322 bool | |
7336 | 323 octave_value_typeinfo::do_register_binary_class_op (octave_value::binary_op op, |
324 octave_value_typeinfo::binary_class_op_fcn f) | |
325 { | |
326 if (lookup_binary_class_op (op)) | |
327 { | |
328 std::string op_name = octave_value::binary_op_as_string (op); | |
329 | |
330 warning ("duplicate binary operator `%s' for class dispatch", | |
331 op_name.c_str ()); | |
332 } | |
333 | |
334 binary_class_ops.checkelem (static_cast<int> (op)) = f; | |
335 | |
336 return false; | |
337 } | |
338 | |
339 bool | |
2376 | 340 octave_value_typeinfo::do_register_binary_op (octave_value::binary_op op, |
341 int t1, int t2, | |
5759 | 342 octave_value_typeinfo::binary_op_fcn f) |
2376 | 343 { |
4508 | 344 if (lookup_binary_op (op, t1, t2)) |
345 { | |
346 std::string op_name = octave_value::binary_op_as_string (op); | |
347 std::string t1_name = types(t1); | |
348 std::string t2_name = types(t2); | |
349 | |
350 warning ("duplicate binary operator `%s' for types `%s' and `%s'", | |
351 op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); | |
352 } | |
353 | |
2800 | 354 binary_ops.checkelem (static_cast<int> (op), t1, t2) = f; |
2376 | 355 |
356 return false; | |
357 } | |
358 | |
359 bool | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
360 octave_value_typeinfo::do_register_binary_class_op (octave_value::compound_binary_op op, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
361 octave_value_typeinfo::binary_class_op_fcn f) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
362 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
363 if (lookup_binary_class_op (op)) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
364 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
365 std::string op_name = octave_value::binary_op_fcn_name (op); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
366 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
367 warning ("duplicate compound binary operator `%s' for class dispatch", |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
368 op_name.c_str ()); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
369 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
370 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
371 compound_binary_class_ops.checkelem (static_cast<int> (op)) = f; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
372 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
373 return false; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
374 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
375 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
376 bool |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
377 octave_value_typeinfo::do_register_binary_op (octave_value::compound_binary_op op, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
378 int t1, int t2, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
379 octave_value_typeinfo::binary_op_fcn f) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
380 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
381 if (lookup_binary_op (op, t1, t2)) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
382 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
383 std::string op_name = octave_value::binary_op_fcn_name (op); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
384 std::string t1_name = types(t1); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
385 std::string t2_name = types(t2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
386 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
387 warning ("duplicate compound binary operator `%s' for types `%s' and `%s'", |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
388 op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
389 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
390 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
391 compound_binary_ops.checkelem (static_cast<int> (op), t1, t2) = f; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
392 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
393 return false; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
394 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
395 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
396 bool |
5759 | 397 octave_value_typeinfo::do_register_cat_op (int t1, int t2, octave_value_typeinfo::cat_op_fcn f) |
4915 | 398 { |
399 if (lookup_cat_op (t1, t2)) | |
400 { | |
401 std::string t1_name = types(t1); | |
402 std::string t2_name = types(t2); | |
403 | |
404 warning ("duplicate concatenation operator for types `%s' and `%s'", | |
405 t1_name.c_str (), t1_name.c_str ()); | |
406 } | |
407 | |
408 cat_ops.checkelem (t1, t2) = f; | |
409 | |
410 return false; | |
411 } | |
412 | |
413 bool | |
2882 | 414 octave_value_typeinfo::do_register_assign_op (octave_value::assign_op op, |
415 int t_lhs, int t_rhs, | |
5759 | 416 octave_value_typeinfo::assign_op_fcn f) |
2376 | 417 { |
4508 | 418 if (lookup_assign_op (op, t_lhs, t_rhs)) |
419 { | |
420 std::string op_name = octave_value::assign_op_as_string (op); | |
421 std::string t_lhs_name = types(t_lhs); | |
422 std::string t_rhs_name = types(t_rhs); | |
423 | |
424 warning ("duplicate assignment operator `%s' for types `%s' and `%s'", | |
425 op_name.c_str (), t_lhs_name.c_str (), t_rhs_name.c_str ()); | |
426 } | |
427 | |
2882 | 428 assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs) = f; |
2376 | 429 |
430 return false; | |
431 } | |
432 | |
433 bool | |
3196 | 434 octave_value_typeinfo::do_register_assignany_op (octave_value::assign_op op, |
5759 | 435 int t_lhs, octave_value_typeinfo::assignany_op_fcn f) |
3196 | 436 { |
4508 | 437 if (lookup_assignany_op (op, t_lhs)) |
438 { | |
439 std::string op_name = octave_value::assign_op_as_string (op); | |
440 std::string t_lhs_name = types(t_lhs); | |
441 | |
442 warning ("duplicate assignment operator `%s' for types `%s'", | |
443 op_name.c_str (), t_lhs_name.c_str ()); | |
444 } | |
445 | |
3196 | 446 assignany_ops.checkelem (static_cast<int> (op), t_lhs) = f; |
447 | |
448 return false; | |
449 } | |
450 | |
451 bool | |
2376 | 452 octave_value_typeinfo::do_register_pref_assign_conv (int t_lhs, int t_rhs, |
453 int t_result) | |
454 { | |
4508 | 455 if (lookup_pref_assign_conv (t_lhs, t_rhs) >= 0) |
456 { | |
457 std::string t_lhs_name = types(t_lhs); | |
458 std::string t_rhs_name = types(t_rhs); | |
459 | |
460 warning ("overriding assignment conversion for types `%s' and `%s'", | |
461 t_lhs_name.c_str (), t_rhs_name.c_str ()); | |
462 } | |
463 | |
2376 | 464 pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result; |
465 | |
466 return false; | |
467 } | |
468 | |
469 bool | |
4901 | 470 octave_value_typeinfo::do_register_type_conv_op |
5759 | 471 (int t, int t_result, octave_base_value::type_conv_fcn f) |
4901 | 472 { |
473 if (lookup_type_conv_op (t, t_result)) | |
474 { | |
475 std::string t_name = types(t); | |
476 std::string t_result_name = types(t_result); | |
477 | |
478 warning ("overriding type conversion op for `%s' to `%s'", | |
479 t_name.c_str (), t_result_name.c_str ()); | |
480 } | |
481 | |
482 type_conv_ops.checkelem (t, t_result) = f; | |
483 | |
484 return false; | |
485 } | |
486 | |
487 bool | |
2376 | 488 octave_value_typeinfo::do_register_widening_op |
5759 | 489 (int t, int t_result, octave_base_value::type_conv_fcn f) |
2376 | 490 { |
4508 | 491 if (lookup_widening_op (t, t_result)) |
492 { | |
493 std::string t_name = types(t); | |
494 std::string t_result_name = types(t_result); | |
495 | |
496 warning ("overriding widening op for `%s' to `%s'", | |
497 t_name.c_str (), t_result_name.c_str ()); | |
498 } | |
499 | |
2376 | 500 widening_ops.checkelem (t, t_result) = f; |
501 | |
502 return false; | |
503 } | |
504 | |
4640 | 505 octave_value |
506 octave_value_typeinfo::do_lookup_type (const std::string& nm) | |
507 { | |
508 octave_value retval; | |
509 | |
510 for (int i = 0; i < num_types; i++) | |
511 { | |
512 if (nm == types(i)) | |
513 { | |
514 retval = vals(i); | |
4687 | 515 retval.make_unique (); |
4640 | 516 break; |
517 } | |
518 } | |
519 | |
520 return retval; | |
521 } | |
522 | |
7336 | 523 octave_value_typeinfo::unary_class_op_fcn |
524 octave_value_typeinfo::do_lookup_unary_class_op (octave_value::unary_op op) | |
525 { | |
526 return unary_class_ops.checkelem (static_cast<int> (op)); | |
527 } | |
528 | |
5759 | 529 octave_value_typeinfo::unary_op_fcn |
3203 | 530 octave_value_typeinfo::do_lookup_unary_op (octave_value::unary_op op, int t) |
531 { | |
532 return unary_ops.checkelem (static_cast<int> (op), t); | |
533 } | |
534 | |
5759 | 535 octave_value_typeinfo::non_const_unary_op_fcn |
3203 | 536 octave_value_typeinfo::do_lookup_non_const_unary_op |
537 (octave_value::unary_op op, int t) | |
538 { | |
539 return non_const_unary_ops.checkelem (static_cast<int> (op), t); | |
540 } | |
541 | |
7336 | 542 octave_value_typeinfo::binary_class_op_fcn |
543 octave_value_typeinfo::do_lookup_binary_class_op (octave_value::binary_op op) | |
544 { | |
545 return binary_class_ops.checkelem (static_cast<int> (op)); | |
546 } | |
547 | |
5759 | 548 octave_value_typeinfo::binary_op_fcn |
2376 | 549 octave_value_typeinfo::do_lookup_binary_op (octave_value::binary_op op, |
550 int t1, int t2) | |
551 { | |
2800 | 552 return binary_ops.checkelem (static_cast<int> (op), t1, t2); |
2376 | 553 } |
554 | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
555 octave_value_typeinfo::binary_class_op_fcn |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
556 octave_value_typeinfo::do_lookup_binary_class_op (octave_value::compound_binary_op op) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
557 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
558 return compound_binary_class_ops.checkelem (static_cast<int> (op)); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
559 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
560 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
561 octave_value_typeinfo::binary_op_fcn |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
562 octave_value_typeinfo::do_lookup_binary_op (octave_value::compound_binary_op op, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
563 int t1, int t2) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
564 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
565 return compound_binary_ops.checkelem (static_cast<int> (op), t1, t2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
566 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
567 |
5759 | 568 octave_value_typeinfo::cat_op_fcn |
4915 | 569 octave_value_typeinfo::do_lookup_cat_op (int t1, int t2) |
570 { | |
571 return cat_ops.checkelem (t1, t2); | |
572 } | |
573 | |
5759 | 574 octave_value_typeinfo::assign_op_fcn |
2882 | 575 octave_value_typeinfo::do_lookup_assign_op (octave_value::assign_op op, |
576 int t_lhs, int t_rhs) | |
2376 | 577 { |
2882 | 578 return assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs); |
2376 | 579 } |
580 | |
5759 | 581 octave_value_typeinfo::assignany_op_fcn |
3196 | 582 octave_value_typeinfo::do_lookup_assignany_op (octave_value::assign_op op, |
583 int t_lhs) | |
584 { | |
585 return assignany_ops.checkelem (static_cast<int> (op), t_lhs); | |
586 } | |
587 | |
2376 | 588 int |
589 octave_value_typeinfo::do_lookup_pref_assign_conv (int t_lhs, int t_rhs) | |
590 { | |
591 return pref_assign_conv.checkelem (t_lhs, t_rhs); | |
592 } | |
593 | |
5759 | 594 octave_base_value::type_conv_fcn |
4901 | 595 octave_value_typeinfo::do_lookup_type_conv_op (int t, int t_result) |
596 { | |
597 return type_conv_ops.checkelem (t, t_result); | |
598 } | |
599 | |
5759 | 600 octave_base_value::type_conv_fcn |
2376 | 601 octave_value_typeinfo::do_lookup_widening_op (int t, int t_result) |
602 { | |
603 return widening_ops.checkelem (t, t_result); | |
604 } | |
605 | |
606 string_vector | |
607 octave_value_typeinfo::do_installed_type_names (void) | |
608 { | |
609 string_vector retval (num_types); | |
610 | |
611 for (int i = 0;i < num_types; i++) | |
612 retval (i) = types (i); | |
613 | |
614 return retval; | |
615 } | |
616 | |
2457 | 617 DEFUN (typeinfo, args, , |
3445 | 618 "-*- texinfo -*-\n\ |
619 @deftypefn {Built-in Function} {} typeinfo (@var{expr})\n\ | |
2822 | 620 \n\ |
3445 | 621 Return the type of the expression @var{expr}, as a string. If\n\ |
8474 | 622 @var{expr} is omitted, return an array of strings containing all the\n\ |
3445 | 623 currently installed data types.\n\ |
624 @end deftypefn") | |
2376 | 625 { |
626 octave_value retval; | |
627 | |
628 int nargin = args.length (); | |
629 | |
630 if (nargin == 0) | |
631 retval = octave_value_typeinfo::installed_type_names (); | |
2822 | 632 else if (nargin == 1) |
633 retval = args(0).type_name (); | |
2376 | 634 else |
5823 | 635 print_usage (); |
2376 | 636 |
637 return retval; | |
638 } | |
639 | |
640 /* | |
641 ;;; Local Variables: *** | |
642 ;;; mode: C++ *** | |
643 ;;; End: *** | |
644 */ |