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