Mercurial > hg > octave-nkf
annotate src/ov-typeinfo.cc @ 13294:7dce7e110511
make concatenation of class objects work
* data.h: New file.
* src/Makefile.am (octinclude_HEADERS): Add it to the list.
* data.cc (attempt_type_conversion): New static function.
(do_class_concat): New function.
(do_cat): Use it if any elements of the list are objects.
Check whether any elements of the list are objects or cells.
Check whether all elements of the list are complex.
Check whether the first element of the list is a struct.
Maybe convert elements of the list to cells.
New tests for horzcat and vertcat.
* data.h (do_class_concat): Provide decl.
* ov-class.h (octave_class::octave_class): Allow optional parent
list.
* ov.h, ov.h (octave_value::octave_value (const Octave_map&,
const std::string&)): Likewise.
* pt-mat.cc (do_class_concat): New static function.
(tree_matrix::rvalue1): Use it to concatenate objects.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 07 Oct 2011 22:16:07 -0400 |
parents | 32fdd834c09a |
children | 7dd7cccf0757 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2376 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2376 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "ov-typeinfo.h" | |
28 | |
29 #include "defun.h" | |
30 #include "error.h" | |
31 | |
2479 | 32 const int |
33 octave_value_typeinfo::init_tab_sz (16); | |
34 | |
35 octave_value_typeinfo * | |
36 octave_value_typeinfo::instance (0); | |
2376 | 37 |
4515 | 38 #include <Array.h> |
39 | |
2926 | 40 bool |
41 octave_value_typeinfo::instance_ok (void) | |
42 { | |
43 bool retval = true; | |
44 if (! instance) | |
45 instance = new octave_value_typeinfo (); | |
46 | |
47 if (! instance) | |
48 { | |
49 ::error ("unable to create value type info object!"); | |
50 | |
51 retval = false; | |
52 } | |
53 | |
54 return retval; | |
55 } | |
56 | |
2376 | 57 int |
4612 | 58 octave_value_typeinfo::register_type (const std::string& t_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
59 const std::string& c_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 const octave_value& val) |
2376 | 61 { |
2926 | 62 return (instance_ok ()) |
4640 | 63 ? instance->do_register_type (t_name, c_name, val) : -1; |
2376 | 64 } |
65 | |
66 bool | |
7336 | 67 octave_value_typeinfo::register_unary_class_op (octave_value::unary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
68 octave_value_typeinfo::unary_class_op_fcn f) |
7336 | 69 { |
70 return (instance_ok ()) | |
71 ? instance->do_register_unary_class_op (op, f) : false; | |
72 } | |
73 | |
74 bool | |
3203 | 75 octave_value_typeinfo::register_unary_op (octave_value::unary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 int t, octave_value_typeinfo::unary_op_fcn f) |
3203 | 77 { |
78 return (instance_ok ()) | |
79 ? instance->do_register_unary_op (op, t, f) : false; | |
80 } | |
81 | |
82 bool | |
83 octave_value_typeinfo::register_non_const_unary_op (octave_value::unary_op op, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 int t, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 octave_value_typeinfo::non_const_unary_op_fcn f) |
3203 | 86 { |
87 return (instance_ok ()) | |
88 ? instance->do_register_non_const_unary_op (op, t, f) : false; | |
89 } | |
90 | |
91 bool | |
7336 | 92 octave_value_typeinfo::register_binary_class_op (octave_value::binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
93 octave_value_typeinfo::binary_class_op_fcn f) |
7336 | 94 { |
95 return (instance_ok ()) | |
96 ? instance->do_register_binary_class_op (op, f) : false; | |
97 } | |
98 | |
99 bool | |
2376 | 100 octave_value_typeinfo::register_binary_op (octave_value::binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 int t1, int t2, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 octave_value_typeinfo::binary_op_fcn f) |
2376 | 103 { |
2926 | 104 return (instance_ok ()) |
105 ? instance->do_register_binary_op (op, t1, t2, f) : false; | |
2376 | 106 } |
107 | |
108 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
|
109 octave_value_typeinfo::register_binary_class_op (octave_value::compound_binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 octave_value_typeinfo::binary_class_op_fcn f) |
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
|
111 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
112 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
|
113 ? 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
|
114 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
115 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
116 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
|
117 octave_value_typeinfo::register_binary_op (octave_value::compound_binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 int t1, int t2, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 octave_value_typeinfo::binary_op_fcn f) |
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
|
120 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
121 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
|
122 ? 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
|
123 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
124 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
125 bool |
5759 | 126 octave_value_typeinfo::register_cat_op (int t1, int t2, octave_value_typeinfo::cat_op_fcn f) |
4915 | 127 { |
128 return (instance_ok ()) | |
129 ? instance->do_register_cat_op (t1, t2, f) : false; | |
130 } | |
131 | |
132 bool | |
2882 | 133 octave_value_typeinfo::register_assign_op (octave_value::assign_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
134 int t_lhs, int t_rhs, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 octave_value_typeinfo::assign_op_fcn f) |
2376 | 136 { |
2926 | 137 return (instance_ok ()) |
138 ? instance->do_register_assign_op (op, t_lhs, t_rhs, f) : -1; | |
2376 | 139 } |
140 | |
141 bool | |
3196 | 142 octave_value_typeinfo::register_assignany_op (octave_value::assign_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 int t_lhs, octave_value_typeinfo::assignany_op_fcn f) |
3196 | 144 { |
145 return (instance_ok ()) | |
146 ? instance->do_register_assignany_op (op, t_lhs, f) : -1; | |
147 } | |
148 | |
149 bool | |
2376 | 150 octave_value_typeinfo::register_pref_assign_conv (int t_lhs, int t_rhs, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
151 int t_result) |
2376 | 152 { |
2926 | 153 return (instance_ok ()) |
154 ? instance->do_register_pref_assign_conv (t_lhs, t_rhs, t_result) : false; | |
2376 | 155 } |
156 | |
157 bool | |
4901 | 158 octave_value_typeinfo::register_type_conv_op (int t, int t_result, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
159 octave_base_value::type_conv_fcn f) |
4901 | 160 { |
161 return (instance_ok ()) | |
162 ? instance->do_register_type_conv_op (t, t_result, f) : false; | |
163 } | |
164 | |
165 bool | |
2376 | 166 octave_value_typeinfo::register_widening_op (int t, int t_result, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 octave_base_value::type_conv_fcn f) |
2376 | 168 { |
2926 | 169 return (instance_ok ()) |
170 ? instance->do_register_widening_op (t, t_result, f) : false; | |
2376 | 171 } |
172 | |
5775 | 173 // FIXME -- we should also store all class names and provide a |
4687 | 174 // way to list them (calling class with nargin == 0?). |
175 | |
2376 | 176 int |
4612 | 177 octave_value_typeinfo::do_register_type (const std::string& t_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 const std::string& /* c_name */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 const octave_value& val) |
2376 | 180 { |
181 int i = 0; | |
182 | |
183 for (i = 0; i < num_types; i++) | |
4612 | 184 if (t_name == types (i)) |
2376 | 185 return i; |
186 | |
187 int len = types.length (); | |
188 | |
189 if (i == len) | |
190 { | |
191 len *= 2; | |
192 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
193 types.resize (dim_vector (len, 1), std::string ()); |
2376 | 194 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
195 vals.resize (dim_vector (len, 1), octave_value ()); |
4640 | 196 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
197 unary_ops.resize (dim_vector (octave_value::num_unary_ops, len), 0); |
3203 | 198 |
199 non_const_unary_ops.resize | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
200 (dim_vector (octave_value::num_unary_ops, len), 0); |
3203 | 201 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
202 binary_ops.resize |
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
203 (dim_vector (octave_value::num_binary_ops, len, len), 0); |
2376 | 204 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
205 compound_binary_ops.resize |
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
206 (dim_vector (octave_value::num_compound_binary_ops, len, len), 0); |
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
|
207 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
208 cat_ops.resize (dim_vector (len, len), 0); |
4915 | 209 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
210 assign_ops.resize |
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
211 (dim_vector (octave_value::num_assign_ops, len, len), 0); |
2376 | 212 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
213 assignany_ops.resize |
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
214 (dim_vector (octave_value::num_assign_ops, len), 0); |
3196 | 215 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
216 pref_assign_conv.resize (dim_vector (len, len), -1); |
2376 | 217 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
218 type_conv_ops.resize (dim_vector (len, len), 0); |
4901 | 219 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
220 widening_ops.resize (dim_vector (len, len), 0); |
2376 | 221 } |
222 | |
4612 | 223 types (i) = t_name; |
2376 | 224 |
4640 | 225 vals (i) = val; |
226 | |
2376 | 227 num_types++; |
228 | |
229 return i; | |
230 } | |
231 | |
232 bool | |
7336 | 233 octave_value_typeinfo::do_register_unary_class_op (octave_value::unary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
234 octave_value_typeinfo::unary_class_op_fcn f) |
7336 | 235 { |
236 if (lookup_unary_class_op (op)) | |
237 { | |
238 std::string op_name = octave_value::unary_op_as_string (op); | |
239 | |
240 warning ("duplicate unary operator `%s' for class dispatch", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 op_name.c_str ()); |
7336 | 242 } |
243 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
244 unary_class_ops.checkelem (static_cast<int> (op)) = reinterpret_cast<void *> (f); |
7336 | 245 |
246 return false; | |
247 } | |
248 | |
249 bool | |
3203 | 250 octave_value_typeinfo::do_register_unary_op (octave_value::unary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 int t, octave_value_typeinfo::unary_op_fcn f) |
3203 | 252 { |
4508 | 253 if (lookup_unary_op (op, t)) |
254 { | |
255 std::string op_name = octave_value::unary_op_as_string (op); | |
256 std::string type_name = types(t); | |
257 | |
258 warning ("duplicate unary operator `%s' for type `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 op_name.c_str (), type_name.c_str ()); |
4508 | 260 } |
261 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
262 unary_ops.checkelem (static_cast<int> (op), t) = reinterpret_cast<void *> (f); |
3203 | 263 |
264 return false; | |
265 } | |
266 | |
267 bool | |
268 octave_value_typeinfo::do_register_non_const_unary_op | |
5759 | 269 (octave_value::unary_op op, int t, octave_value_typeinfo::non_const_unary_op_fcn f) |
3203 | 270 { |
4508 | 271 if (lookup_non_const_unary_op (op, t)) |
272 { | |
273 std::string op_name = octave_value::unary_op_as_string (op); | |
274 std::string type_name = types(t); | |
275 | |
276 warning ("duplicate unary operator `%s' for type `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 op_name.c_str (), type_name.c_str ()); |
4508 | 278 } |
279 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
280 non_const_unary_ops.checkelem (static_cast<int> (op), t) = reinterpret_cast<void *> (f); |
3203 | 281 |
282 return false; | |
283 } | |
284 | |
285 bool | |
7336 | 286 octave_value_typeinfo::do_register_binary_class_op (octave_value::binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 octave_value_typeinfo::binary_class_op_fcn f) |
7336 | 288 { |
289 if (lookup_binary_class_op (op)) | |
290 { | |
291 std::string op_name = octave_value::binary_op_as_string (op); | |
292 | |
293 warning ("duplicate binary operator `%s' for class dispatch", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 op_name.c_str ()); |
7336 | 295 } |
296 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
297 binary_class_ops.checkelem (static_cast<int> (op)) = reinterpret_cast<void *> (f); |
7336 | 298 |
299 return false; | |
300 } | |
301 | |
302 bool | |
2376 | 303 octave_value_typeinfo::do_register_binary_op (octave_value::binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
304 int t1, int t2, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 octave_value_typeinfo::binary_op_fcn f) |
2376 | 306 { |
4508 | 307 if (lookup_binary_op (op, t1, t2)) |
308 { | |
309 std::string op_name = octave_value::binary_op_as_string (op); | |
310 std::string t1_name = types(t1); | |
311 std::string t2_name = types(t2); | |
312 | |
313 warning ("duplicate binary operator `%s' for types `%s' and `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); |
4508 | 315 } |
316 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
317 binary_ops.checkelem (static_cast<int> (op), t1, t2) = reinterpret_cast<void *> (f); |
2376 | 318 |
319 return false; | |
320 } | |
321 | |
322 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
|
323 octave_value_typeinfo::do_register_binary_class_op (octave_value::compound_binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
324 octave_value_typeinfo::binary_class_op_fcn f) |
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
|
325 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
326 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
|
327 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
328 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
|
329 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
330 warning ("duplicate compound binary operator `%s' for class dispatch", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
331 op_name.c_str ()); |
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
|
332 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
333 |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
334 compound_binary_class_ops.checkelem (static_cast<int> (op)) = reinterpret_cast<void *> (f); |
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
|
335 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
336 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
|
337 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
338 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
339 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
|
340 octave_value_typeinfo::do_register_binary_op (octave_value::compound_binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
341 int t1, int t2, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
342 octave_value_typeinfo::binary_op_fcn f) |
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
|
343 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
344 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
|
345 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
350 warning ("duplicate compound binary operator `%s' for types `%s' and `%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
351 op_name.c_str (), t1_name.c_str (), t1_name.c_str ()); |
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
|
352 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
353 |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
354 compound_binary_ops.checkelem (static_cast<int> (op), t1, t2) = reinterpret_cast<void *> (f); |
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
|
355 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
356 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
|
357 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
358 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
359 bool |
5759 | 360 octave_value_typeinfo::do_register_cat_op (int t1, int t2, octave_value_typeinfo::cat_op_fcn f) |
4915 | 361 { |
362 if (lookup_cat_op (t1, t2)) | |
363 { | |
364 std::string t1_name = types(t1); | |
365 std::string t2_name = types(t2); | |
366 | |
367 warning ("duplicate concatenation operator for types `%s' and `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 t1_name.c_str (), t1_name.c_str ()); |
4915 | 369 } |
370 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
371 cat_ops.checkelem (t1, t2) = reinterpret_cast<void *> (f); |
4915 | 372 |
373 return false; | |
374 } | |
375 | |
376 bool | |
2882 | 377 octave_value_typeinfo::do_register_assign_op (octave_value::assign_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
378 int t_lhs, int t_rhs, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
379 octave_value_typeinfo::assign_op_fcn f) |
2376 | 380 { |
4508 | 381 if (lookup_assign_op (op, t_lhs, t_rhs)) |
382 { | |
383 std::string op_name = octave_value::assign_op_as_string (op); | |
384 std::string t_lhs_name = types(t_lhs); | |
385 std::string t_rhs_name = types(t_rhs); | |
386 | |
387 warning ("duplicate assignment operator `%s' for types `%s' and `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
388 op_name.c_str (), t_lhs_name.c_str (), t_rhs_name.c_str ()); |
4508 | 389 } |
390 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
391 assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs) = reinterpret_cast<void *> (f); |
2376 | 392 |
393 return false; | |
394 } | |
395 | |
396 bool | |
3196 | 397 octave_value_typeinfo::do_register_assignany_op (octave_value::assign_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
398 int t_lhs, octave_value_typeinfo::assignany_op_fcn f) |
3196 | 399 { |
4508 | 400 if (lookup_assignany_op (op, t_lhs)) |
401 { | |
402 std::string op_name = octave_value::assign_op_as_string (op); | |
403 std::string t_lhs_name = types(t_lhs); | |
404 | |
405 warning ("duplicate assignment operator `%s' for types `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 op_name.c_str (), t_lhs_name.c_str ()); |
4508 | 407 } |
408 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
409 assignany_ops.checkelem (static_cast<int> (op), t_lhs) = reinterpret_cast<void *> (f); |
3196 | 410 |
411 return false; | |
412 } | |
413 | |
414 bool | |
2376 | 415 octave_value_typeinfo::do_register_pref_assign_conv (int t_lhs, int t_rhs, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
416 int t_result) |
2376 | 417 { |
4508 | 418 if (lookup_pref_assign_conv (t_lhs, t_rhs) >= 0) |
419 { | |
420 std::string t_lhs_name = types(t_lhs); | |
421 std::string t_rhs_name = types(t_rhs); | |
422 | |
423 warning ("overriding assignment conversion for types `%s' and `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
424 t_lhs_name.c_str (), t_rhs_name.c_str ()); |
4508 | 425 } |
426 | |
2376 | 427 pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result; |
428 | |
429 return false; | |
430 } | |
431 | |
432 bool | |
4901 | 433 octave_value_typeinfo::do_register_type_conv_op |
5759 | 434 (int t, int t_result, octave_base_value::type_conv_fcn f) |
4901 | 435 { |
436 if (lookup_type_conv_op (t, t_result)) | |
437 { | |
438 std::string t_name = types(t); | |
439 std::string t_result_name = types(t_result); | |
440 | |
441 warning ("overriding type conversion op for `%s' to `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
442 t_name.c_str (), t_result_name.c_str ()); |
4901 | 443 } |
444 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
445 type_conv_ops.checkelem (t, t_result) = reinterpret_cast<void *> (f); |
4901 | 446 |
447 return false; | |
448 } | |
449 | |
450 bool | |
2376 | 451 octave_value_typeinfo::do_register_widening_op |
5759 | 452 (int t, int t_result, octave_base_value::type_conv_fcn f) |
2376 | 453 { |
4508 | 454 if (lookup_widening_op (t, t_result)) |
455 { | |
456 std::string t_name = types(t); | |
457 std::string t_result_name = types(t_result); | |
458 | |
459 warning ("overriding widening op for `%s' to `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
460 t_name.c_str (), t_result_name.c_str ()); |
4508 | 461 } |
462 | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
463 widening_ops.checkelem (t, t_result) = reinterpret_cast<void *> (f); |
2376 | 464 |
465 return false; | |
466 } | |
467 | |
4640 | 468 octave_value |
469 octave_value_typeinfo::do_lookup_type (const std::string& nm) | |
470 { | |
471 octave_value retval; | |
472 | |
473 for (int i = 0; i < num_types; i++) | |
474 { | |
475 if (nm == types(i)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
476 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
477 retval = vals(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
478 retval.make_unique (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
480 } |
4640 | 481 } |
482 | |
483 return retval; | |
484 } | |
485 | |
7336 | 486 octave_value_typeinfo::unary_class_op_fcn |
487 octave_value_typeinfo::do_lookup_unary_class_op (octave_value::unary_op op) | |
488 { | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
489 void *f = unary_class_ops.checkelem (static_cast<int> (op)); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
490 return reinterpret_cast<octave_value_typeinfo::unary_class_op_fcn> (f); |
7336 | 491 } |
492 | |
5759 | 493 octave_value_typeinfo::unary_op_fcn |
3203 | 494 octave_value_typeinfo::do_lookup_unary_op (octave_value::unary_op op, int t) |
495 { | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
496 void *f = unary_ops.checkelem (static_cast<int> (op), t); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
497 return reinterpret_cast<octave_value_typeinfo::unary_op_fcn> (f); |
3203 | 498 } |
499 | |
5759 | 500 octave_value_typeinfo::non_const_unary_op_fcn |
3203 | 501 octave_value_typeinfo::do_lookup_non_const_unary_op |
502 (octave_value::unary_op op, int t) | |
503 { | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
504 void *f = non_const_unary_ops.checkelem (static_cast<int> (op), t); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
505 return reinterpret_cast<octave_value_typeinfo::non_const_unary_op_fcn> (f); |
3203 | 506 } |
507 | |
7336 | 508 octave_value_typeinfo::binary_class_op_fcn |
509 octave_value_typeinfo::do_lookup_binary_class_op (octave_value::binary_op op) | |
510 { | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
511 void *f = binary_class_ops.checkelem (static_cast<int> (op)); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
512 return reinterpret_cast<octave_value_typeinfo::binary_class_op_fcn> (f); |
7336 | 513 } |
514 | |
5759 | 515 octave_value_typeinfo::binary_op_fcn |
2376 | 516 octave_value_typeinfo::do_lookup_binary_op (octave_value::binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
517 int t1, int t2) |
2376 | 518 { |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
519 void *f = binary_ops.checkelem (static_cast<int> (op), t1, t2); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
520 return reinterpret_cast<octave_value_typeinfo::binary_op_fcn> (f); |
2376 | 521 } |
522 | |
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
|
523 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
|
524 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
|
525 { |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
526 void *f = compound_binary_class_ops.checkelem (static_cast<int> (op)); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
527 return reinterpret_cast<octave_value_typeinfo::binary_class_op_fcn> (f); |
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
|
528 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
529 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
530 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
|
531 octave_value_typeinfo::do_lookup_binary_op (octave_value::compound_binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
532 int t1, int t2) |
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
|
533 { |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
534 void *f = compound_binary_ops.checkelem (static_cast<int> (op), t1, t2); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
535 return reinterpret_cast<octave_value_typeinfo::binary_op_fcn> (f); |
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
|
536 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7433
diff
changeset
|
537 |
5759 | 538 octave_value_typeinfo::cat_op_fcn |
4915 | 539 octave_value_typeinfo::do_lookup_cat_op (int t1, int t2) |
540 { | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
541 void *f = cat_ops.checkelem (t1, t2); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
542 return reinterpret_cast<octave_value_typeinfo::cat_op_fcn> (f); |
4915 | 543 } |
544 | |
5759 | 545 octave_value_typeinfo::assign_op_fcn |
2882 | 546 octave_value_typeinfo::do_lookup_assign_op (octave_value::assign_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
547 int t_lhs, int t_rhs) |
2376 | 548 { |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
549 void *f = assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
550 return reinterpret_cast<octave_value_typeinfo::assign_op_fcn> (f); |
2376 | 551 } |
552 | |
5759 | 553 octave_value_typeinfo::assignany_op_fcn |
3196 | 554 octave_value_typeinfo::do_lookup_assignany_op (octave_value::assign_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
555 int t_lhs) |
3196 | 556 { |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
557 void *f = assignany_ops.checkelem (static_cast<int> (op), t_lhs); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
558 return reinterpret_cast<octave_value_typeinfo::assignany_op_fcn> (f); |
3196 | 559 } |
560 | |
2376 | 561 int |
562 octave_value_typeinfo::do_lookup_pref_assign_conv (int t_lhs, int t_rhs) | |
563 { | |
564 return pref_assign_conv.checkelem (t_lhs, t_rhs); | |
565 } | |
566 | |
5759 | 567 octave_base_value::type_conv_fcn |
4901 | 568 octave_value_typeinfo::do_lookup_type_conv_op (int t, int t_result) |
569 { | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
570 void *f = type_conv_ops.checkelem (t, t_result); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
571 return reinterpret_cast<octave_base_value::type_conv_fcn> (f); |
4901 | 572 } |
573 | |
5759 | 574 octave_base_value::type_conv_fcn |
2376 | 575 octave_value_typeinfo::do_lookup_widening_op (int t, int t_result) |
576 { | |
9223
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
577 void *f = widening_ops.checkelem (t, t_result); |
902a4597dce8
use Array<void *> in ov-typeinfo.h
Jaroslav Hajek <highegg@gmail.com>
parents:
9219
diff
changeset
|
578 return reinterpret_cast<octave_base_value::type_conv_fcn> (f); |
2376 | 579 } |
580 | |
581 string_vector | |
582 octave_value_typeinfo::do_installed_type_names (void) | |
583 { | |
584 string_vector retval (num_types); | |
585 | |
11438
9e8497537319
typeinfo: return cellstr, not char array
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
586 for (int i = 0; i < num_types; i++) |
9e8497537319
typeinfo: return cellstr, not char array
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
587 retval(i) = types(i); |
2376 | 588 |
589 return retval; | |
590 } | |
591 | |
2457 | 592 DEFUN (typeinfo, args, , |
3445 | 593 "-*- texinfo -*-\n\ |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
594 @deftypefn {Built-in Function} {} typeinfo ()\n\ |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
595 @deftypefnx {Built-in Function} {} typeinfo (@var{expr})\n\ |
2822 | 596 \n\ |
3445 | 597 Return the type of the expression @var{expr}, as a string. If\n\ |
13095
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
598 @var{expr} is omitted, return an cell array of strings containing all the\n\ |
3445 | 599 currently installed data types.\n\ |
600 @end deftypefn") | |
2376 | 601 { |
602 octave_value retval; | |
603 | |
604 int nargin = args.length (); | |
605 | |
606 if (nargin == 0) | |
11438
9e8497537319
typeinfo: return cellstr, not char array
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
607 retval = Cell (octave_value_typeinfo::installed_type_names ()); |
2822 | 608 else if (nargin == 1) |
609 retval = args(0).type_name (); | |
2376 | 610 else |
5823 | 611 print_usage (); |
2376 | 612 |
613 return retval; | |
614 } | |
13095
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
615 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
616 /* |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
617 %!error typeinfo ("foo", 1); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
618 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
619 %!assert (iscellstr (typeinfo ())); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
620 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
621 %!assert (typeinfo (false), "bool"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
622 %!assert (typeinfo ([true, false]), "bool matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
623 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
624 %!assert (typeinfo (1:2), "range"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
625 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
626 %!assert (typeinfo ("string"), "string"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
627 %!assert (typeinfo ('string'), "sq_string"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
628 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
629 %!assert (typeinfo (diag ([1, 2])), "diagonal matrix") |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
630 %!assert (typeinfo (diag ([i, 2])), "complex diagonal matrix") |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
631 %!assert (typeinfo (single (diag ([1, 2]))), "float diagonal matrix") |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
632 %!assert (typeinfo (single (diag ([i, 2]))), "float complex diagonal matrix") |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
633 %!assert (typeinfo (diag (single ([1, 2]))), "float diagonal matrix") |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
634 %!assert (typeinfo (diag (single ([i, 2]))), "float complex diagonal matrix") |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
635 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
636 %!assert (typeinfo ([]), "null_matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
637 %!assert (typeinfo (""), "null_string"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
638 %!assert (typeinfo (''), "null_sq_string"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
639 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
640 %!assert (typeinfo (1), "scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
641 %!assert (typeinfo (double (1)), "scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
642 %!assert (typeinfo ([1, 2]), "matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
643 %!assert (typeinfo (double ([1, 2])), "matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
644 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
645 %!assert (typeinfo (i), "complex scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
646 %!assert (typeinfo ([i, 2]), "complex matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
647 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
648 %!assert (typeinfo (single (1)), "float scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
649 %!assert (typeinfo (single ([1, 2])), "float matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
650 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
651 %!assert (typeinfo (single (i)), "float complex scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
652 %!assert (typeinfo (single ([i, 2])), "float complex matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
653 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
654 %!assert (typeinfo (sparse (eye (10))), "sparse matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
655 %!assert (typeinfo (sparse (i * eye (10))), "sparse complex matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
656 %!assert (typeinfo (logical (sparse (i * eye (10)))), "sparse bool matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
657 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
658 %!assert (typeinfo (int8 (1)), "int8 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
659 %!assert (typeinfo (int16 (1)), "int16 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
660 %!assert (typeinfo (int32 (1)), "int32 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
661 %!assert (typeinfo (int64 (1)), "int64 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
662 %!assert (typeinfo (uint8 (1)), "uint8 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
663 %!assert (typeinfo (uint16 (1)), "uint16 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
664 %!assert (typeinfo (uint32 (1)), "uint32 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
665 %!assert (typeinfo (uint64 (1)), "uint64 scalar"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
666 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
667 %!test |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
668 %! s.a = 1; |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
669 %! assert (typeinfo (s), "scalar struct"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
670 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
671 %!test |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
672 %! s(2).a = 1; |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
673 %! assert (typeinfo (s), "struct"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
674 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
675 %!assert (typeinfo ({"cell"}), "cell"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
676 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
677 %!assert (typeinfo (@sin), "function handle"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
678 %!assert (typeinfo (@(x) x), "function handle"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
679 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
680 %!assert (typeinfo (inline ('x^2')), "inline function"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
681 |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
682 %!test |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
683 %! [l, u, p] = lu (rand (3)); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
684 %! assert (typeinfo (p), "permutation matrix"); |
32fdd834c09a
tests for typeinfo function
John W. Eaton <jwe@octave.org>
parents:
12546
diff
changeset
|
685 */ |