2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "ov-typeinfo.h" |
|
32 |
|
33 #include "defun.h" |
|
34 #include "error.h" |
|
35 #include "oct-obj.h" |
|
36 |
2479
|
37 const int |
|
38 octave_value_typeinfo::init_tab_sz (16); |
|
39 |
|
40 octave_value_typeinfo * |
|
41 octave_value_typeinfo::instance (0); |
2376
|
42 |
|
43 #include <Array.cc> |
|
44 #include <Array2.cc> |
|
45 #include <Array3.cc> |
|
46 |
2427
|
47 template class Array<binary_op_fcn>; |
|
48 template class Array2<binary_op_fcn>; |
|
49 template class Array3<binary_op_fcn>; |
2376
|
50 |
2427
|
51 template class Array<assign_op_fcn>; |
|
52 template class Array2<assign_op_fcn>; |
2882
|
53 template class Array3<assign_op_fcn>; |
2376
|
54 |
2427
|
55 template class Array<type_conv_fcn>; |
|
56 template class Array2<type_conv_fcn>; |
2376
|
57 |
2926
|
58 bool |
|
59 octave_value_typeinfo::instance_ok (void) |
|
60 { |
|
61 bool retval = true; |
|
62 if (! instance) |
|
63 instance = new octave_value_typeinfo (); |
|
64 |
|
65 if (! instance) |
|
66 { |
|
67 ::error ("unable to create value type info object!"); |
|
68 |
|
69 retval = false; |
|
70 } |
|
71 |
|
72 return retval; |
|
73 } |
|
74 |
2376
|
75 int |
|
76 octave_value_typeinfo::register_type (const string& name) |
|
77 { |
2926
|
78 return (instance_ok ()) |
|
79 ? instance->do_register_type (name) : -1; |
2376
|
80 } |
|
81 |
|
82 bool |
|
83 octave_value_typeinfo::register_binary_op (octave_value::binary_op op, |
|
84 int t1, int t2, |
2427
|
85 binary_op_fcn f) |
2376
|
86 { |
2926
|
87 return (instance_ok ()) |
|
88 ? instance->do_register_binary_op (op, t1, t2, f) : false; |
2376
|
89 } |
|
90 |
|
91 bool |
2882
|
92 octave_value_typeinfo::register_assign_op (octave_value::assign_op op, |
|
93 int t_lhs, int t_rhs, |
2427
|
94 assign_op_fcn f) |
2376
|
95 { |
2926
|
96 return (instance_ok ()) |
|
97 ? instance->do_register_assign_op (op, t_lhs, t_rhs, f) : -1; |
2376
|
98 } |
|
99 |
|
100 bool |
3196
|
101 octave_value_typeinfo::register_assignany_op (octave_value::assign_op op, |
|
102 int t_lhs, assign_op_fcn f) |
|
103 { |
|
104 return (instance_ok ()) |
|
105 ? instance->do_register_assignany_op (op, t_lhs, f) : -1; |
|
106 } |
|
107 |
|
108 bool |
2376
|
109 octave_value_typeinfo::register_pref_assign_conv (int t_lhs, int t_rhs, |
|
110 int t_result) |
|
111 { |
2926
|
112 return (instance_ok ()) |
|
113 ? instance->do_register_pref_assign_conv (t_lhs, t_rhs, t_result) : false; |
2376
|
114 } |
|
115 |
|
116 bool |
|
117 octave_value_typeinfo::register_widening_op (int t, int t_result, |
2427
|
118 type_conv_fcn f) |
2376
|
119 { |
2926
|
120 return (instance_ok ()) |
|
121 ? instance->do_register_widening_op (t, t_result, f) : false; |
2376
|
122 } |
|
123 |
|
124 int |
|
125 octave_value_typeinfo::do_register_type (const string& name) |
|
126 { |
|
127 int i = 0; |
|
128 |
|
129 for (i = 0; i < num_types; i++) |
|
130 if (name == types (i)) |
|
131 return i; |
|
132 |
|
133 int len = types.length (); |
|
134 |
|
135 if (i == len) |
|
136 { |
|
137 len *= 2; |
|
138 |
|
139 types.resize (len, string ()); |
|
140 |
2800
|
141 binary_ops.resize (static_cast<int> (octave_value::num_binary_ops), |
|
142 len, len, static_cast<binary_op_fcn> (0)); |
2376
|
143 |
2882
|
144 assign_ops.resize (static_cast<int> (octave_value::num_assign_ops), |
|
145 len, len, static_cast<assign_op_fcn> (0)); |
2376
|
146 |
3196
|
147 assignany_ops.resize (static_cast<int> (octave_value::num_assign_ops), |
|
148 len, static_cast<assign_op_fcn> (0)); |
|
149 |
2376
|
150 pref_assign_conv.resize (len, len, -1); |
|
151 |
2800
|
152 widening_ops.resize (len, len, static_cast<type_conv_fcn> (0)); |
2376
|
153 } |
|
154 |
|
155 types (i) = name; |
|
156 |
|
157 num_types++; |
|
158 |
|
159 return i; |
|
160 } |
|
161 |
|
162 bool |
|
163 octave_value_typeinfo::do_register_binary_op (octave_value::binary_op op, |
|
164 int t1, int t2, |
2427
|
165 binary_op_fcn f) |
2376
|
166 { |
2800
|
167 binary_ops.checkelem (static_cast<int> (op), t1, t2) = f; |
2376
|
168 |
|
169 return false; |
|
170 } |
|
171 |
|
172 bool |
2882
|
173 octave_value_typeinfo::do_register_assign_op (octave_value::assign_op op, |
|
174 int t_lhs, int t_rhs, |
2427
|
175 assign_op_fcn f) |
2376
|
176 { |
2882
|
177 assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs) = f; |
2376
|
178 |
|
179 return false; |
|
180 } |
|
181 |
|
182 bool |
3196
|
183 octave_value_typeinfo::do_register_assignany_op (octave_value::assign_op op, |
|
184 int t_lhs, assign_op_fcn f) |
|
185 { |
|
186 assignany_ops.checkelem (static_cast<int> (op), t_lhs) = f; |
|
187 |
|
188 return false; |
|
189 } |
|
190 |
|
191 bool |
2376
|
192 octave_value_typeinfo::do_register_pref_assign_conv (int t_lhs, int t_rhs, |
|
193 int t_result) |
|
194 { |
|
195 pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result; |
|
196 |
|
197 return false; |
|
198 } |
|
199 |
|
200 bool |
|
201 octave_value_typeinfo::do_register_widening_op |
2427
|
202 (int t, int t_result, type_conv_fcn f) |
2376
|
203 { |
|
204 widening_ops.checkelem (t, t_result) = f; |
|
205 |
|
206 return false; |
|
207 } |
|
208 |
|
209 #include <iostream.h> |
|
210 |
2427
|
211 binary_op_fcn |
2376
|
212 octave_value_typeinfo::do_lookup_binary_op (octave_value::binary_op op, |
|
213 int t1, int t2) |
|
214 { |
2800
|
215 return binary_ops.checkelem (static_cast<int> (op), t1, t2); |
2376
|
216 } |
|
217 |
2427
|
218 assign_op_fcn |
2882
|
219 octave_value_typeinfo::do_lookup_assign_op (octave_value::assign_op op, |
|
220 int t_lhs, int t_rhs) |
2376
|
221 { |
2882
|
222 return assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs); |
2376
|
223 } |
|
224 |
3196
|
225 assign_op_fcn |
|
226 octave_value_typeinfo::do_lookup_assignany_op (octave_value::assign_op op, |
|
227 int t_lhs) |
|
228 { |
|
229 return assignany_ops.checkelem (static_cast<int> (op), t_lhs); |
|
230 } |
|
231 |
2376
|
232 int |
|
233 octave_value_typeinfo::do_lookup_pref_assign_conv (int t_lhs, int t_rhs) |
|
234 { |
|
235 return pref_assign_conv.checkelem (t_lhs, t_rhs); |
|
236 } |
|
237 |
2427
|
238 type_conv_fcn |
2376
|
239 octave_value_typeinfo::do_lookup_widening_op (int t, int t_result) |
|
240 { |
|
241 return widening_ops.checkelem (t, t_result); |
|
242 } |
|
243 |
|
244 string_vector |
|
245 octave_value_typeinfo::do_installed_type_names (void) |
|
246 { |
|
247 string_vector retval (num_types); |
|
248 |
|
249 for (int i = 0;i < num_types; i++) |
|
250 retval (i) = types (i); |
|
251 |
|
252 return retval; |
|
253 } |
|
254 |
2457
|
255 DEFUN (typeinfo, args, , |
2822
|
256 "usage: typeinfo (expr)\n\ |
|
257 \n\ |
|
258 Return the type of the expression EXPR, as a string. If EXPR is\n\ |
|
259 omitted, return an array of strings containing all the currently\n\ |
|
260 installed data types.") |
2376
|
261 { |
|
262 octave_value retval; |
|
263 |
|
264 int nargin = args.length (); |
|
265 |
|
266 if (nargin == 0) |
|
267 retval = octave_value_typeinfo::installed_type_names (); |
2822
|
268 else if (nargin == 1) |
|
269 retval = args(0).type_name (); |
2376
|
270 else |
|
271 print_usage ("typeinfo"); |
|
272 |
|
273 return retval; |
|
274 } |
|
275 |
|
276 /* |
|
277 ;;; Local Variables: *** |
|
278 ;;; mode: C++ *** |
|
279 ;;; End: *** |
|
280 */ |