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 |
|
101 octave_value_typeinfo::register_pref_assign_conv (int t_lhs, int t_rhs, |
|
102 int t_result) |
|
103 { |
2926
|
104 return (instance_ok ()) |
|
105 ? instance->do_register_pref_assign_conv (t_lhs, t_rhs, t_result) : false; |
2376
|
106 } |
|
107 |
|
108 bool |
|
109 octave_value_typeinfo::register_widening_op (int t, int t_result, |
2427
|
110 type_conv_fcn f) |
2376
|
111 { |
2926
|
112 return (instance_ok ()) |
|
113 ? instance->do_register_widening_op (t, t_result, f) : false; |
2376
|
114 } |
|
115 |
|
116 int |
|
117 octave_value_typeinfo::do_register_type (const string& name) |
|
118 { |
|
119 int i = 0; |
|
120 |
|
121 for (i = 0; i < num_types; i++) |
|
122 if (name == types (i)) |
|
123 return i; |
|
124 |
|
125 int len = types.length (); |
|
126 |
|
127 if (i == len) |
|
128 { |
|
129 len *= 2; |
|
130 |
|
131 types.resize (len, string ()); |
|
132 |
2800
|
133 binary_ops.resize (static_cast<int> (octave_value::num_binary_ops), |
|
134 len, len, static_cast<binary_op_fcn> (0)); |
2376
|
135 |
2882
|
136 assign_ops.resize (static_cast<int> (octave_value::num_assign_ops), |
|
137 len, len, static_cast<assign_op_fcn> (0)); |
2376
|
138 |
|
139 pref_assign_conv.resize (len, len, -1); |
|
140 |
2800
|
141 widening_ops.resize (len, len, static_cast<type_conv_fcn> (0)); |
2376
|
142 } |
|
143 |
|
144 types (i) = name; |
|
145 |
|
146 num_types++; |
|
147 |
|
148 return i; |
|
149 } |
|
150 |
|
151 bool |
|
152 octave_value_typeinfo::do_register_binary_op (octave_value::binary_op op, |
|
153 int t1, int t2, |
2427
|
154 binary_op_fcn f) |
2376
|
155 { |
2800
|
156 binary_ops.checkelem (static_cast<int> (op), t1, t2) = f; |
2376
|
157 |
|
158 return false; |
|
159 } |
|
160 |
|
161 bool |
2882
|
162 octave_value_typeinfo::do_register_assign_op (octave_value::assign_op op, |
|
163 int t_lhs, int t_rhs, |
2427
|
164 assign_op_fcn f) |
2376
|
165 { |
2882
|
166 assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs) = f; |
2376
|
167 |
|
168 return false; |
|
169 } |
|
170 |
|
171 bool |
|
172 octave_value_typeinfo::do_register_pref_assign_conv (int t_lhs, int t_rhs, |
|
173 int t_result) |
|
174 { |
|
175 pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result; |
|
176 |
|
177 return false; |
|
178 } |
|
179 |
|
180 bool |
|
181 octave_value_typeinfo::do_register_widening_op |
2427
|
182 (int t, int t_result, type_conv_fcn f) |
2376
|
183 { |
|
184 widening_ops.checkelem (t, t_result) = f; |
|
185 |
|
186 return false; |
|
187 } |
|
188 |
|
189 #include <iostream.h> |
|
190 |
2427
|
191 binary_op_fcn |
2376
|
192 octave_value_typeinfo::do_lookup_binary_op (octave_value::binary_op op, |
|
193 int t1, int t2) |
|
194 { |
2800
|
195 return binary_ops.checkelem (static_cast<int> (op), t1, t2); |
2376
|
196 } |
|
197 |
2427
|
198 assign_op_fcn |
2882
|
199 octave_value_typeinfo::do_lookup_assign_op (octave_value::assign_op op, |
|
200 int t_lhs, int t_rhs) |
2376
|
201 { |
2882
|
202 return assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs); |
2376
|
203 } |
|
204 |
|
205 int |
|
206 octave_value_typeinfo::do_lookup_pref_assign_conv (int t_lhs, int t_rhs) |
|
207 { |
|
208 return pref_assign_conv.checkelem (t_lhs, t_rhs); |
|
209 } |
|
210 |
2427
|
211 type_conv_fcn |
2376
|
212 octave_value_typeinfo::do_lookup_widening_op (int t, int t_result) |
|
213 { |
|
214 return widening_ops.checkelem (t, t_result); |
|
215 } |
|
216 |
|
217 string_vector |
|
218 octave_value_typeinfo::do_installed_type_names (void) |
|
219 { |
|
220 string_vector retval (num_types); |
|
221 |
|
222 for (int i = 0;i < num_types; i++) |
|
223 retval (i) = types (i); |
|
224 |
|
225 return retval; |
|
226 } |
|
227 |
2457
|
228 DEFUN (typeinfo, args, , |
2822
|
229 "usage: typeinfo (expr)\n\ |
|
230 \n\ |
|
231 Return the type of the expression EXPR, as a string. If EXPR is\n\ |
|
232 omitted, return an array of strings containing all the currently\n\ |
|
233 installed data types.") |
2376
|
234 { |
|
235 octave_value retval; |
|
236 |
|
237 int nargin = args.length (); |
|
238 |
|
239 if (nargin == 0) |
|
240 retval = octave_value_typeinfo::installed_type_names (); |
2822
|
241 else if (nargin == 1) |
|
242 retval = args(0).type_name (); |
2376
|
243 else |
|
244 print_usage ("typeinfo"); |
|
245 |
|
246 return retval; |
|
247 } |
|
248 |
|
249 /* |
|
250 ;;; Local Variables: *** |
|
251 ;;; mode: C++ *** |
|
252 ;;; End: *** |
|
253 */ |