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 "help.h" |
|
36 #include "oct-obj.h" |
|
37 |
2479
|
38 const int |
|
39 octave_value_typeinfo::init_tab_sz (16); |
|
40 |
|
41 octave_value_typeinfo * |
|
42 octave_value_typeinfo::instance (0); |
2376
|
43 |
|
44 #include <Array.cc> |
|
45 #include <Array2.cc> |
|
46 #include <Array3.cc> |
|
47 |
2427
|
48 template class Array<binary_op_fcn>; |
|
49 template class Array2<binary_op_fcn>; |
|
50 template class Array3<binary_op_fcn>; |
2376
|
51 |
2427
|
52 template class Array<assign_op_fcn>; |
|
53 template class Array2<assign_op_fcn>; |
2882
|
54 template class Array3<assign_op_fcn>; |
2376
|
55 |
2427
|
56 template class Array<type_conv_fcn>; |
|
57 template class Array2<type_conv_fcn>; |
2376
|
58 |
|
59 int |
|
60 octave_value_typeinfo::register_type (const string& name) |
|
61 { |
|
62 if (! instance) |
|
63 instance = new octave_value_typeinfo (); |
|
64 |
|
65 return instance->do_register_type (name); |
|
66 } |
|
67 |
|
68 bool |
|
69 octave_value_typeinfo::register_binary_op (octave_value::binary_op op, |
|
70 int t1, int t2, |
2427
|
71 binary_op_fcn f) |
2376
|
72 { |
|
73 if (! instance) |
|
74 instance = new octave_value_typeinfo (); |
|
75 |
|
76 return instance->do_register_binary_op (op, t1, t2, f); |
|
77 } |
|
78 |
|
79 bool |
2882
|
80 octave_value_typeinfo::register_assign_op (octave_value::assign_op op, |
|
81 int t_lhs, int t_rhs, |
2427
|
82 assign_op_fcn f) |
2376
|
83 { |
|
84 if (! instance) |
|
85 instance = new octave_value_typeinfo (); |
|
86 |
2882
|
87 return instance->do_register_assign_op (op, t_lhs, t_rhs, f); |
2376
|
88 } |
|
89 |
|
90 bool |
|
91 octave_value_typeinfo::register_pref_assign_conv (int t_lhs, int t_rhs, |
|
92 int t_result) |
|
93 { |
|
94 if (! instance) |
|
95 instance = new octave_value_typeinfo (); |
|
96 |
|
97 return instance->do_register_pref_assign_conv (t_lhs, t_rhs, t_result); |
|
98 } |
|
99 |
|
100 bool |
|
101 octave_value_typeinfo::register_widening_op (int t, int t_result, |
2427
|
102 type_conv_fcn f) |
2376
|
103 { |
|
104 if (! instance) |
|
105 instance = new octave_value_typeinfo (); |
|
106 |
|
107 return instance->do_register_widening_op (t, t_result, f); |
|
108 } |
|
109 |
|
110 int |
|
111 octave_value_typeinfo::do_register_type (const string& name) |
|
112 { |
|
113 int i = 0; |
|
114 |
|
115 for (i = 0; i < num_types; i++) |
|
116 if (name == types (i)) |
|
117 return i; |
|
118 |
|
119 int len = types.length (); |
|
120 |
|
121 if (i == len) |
|
122 { |
|
123 len *= 2; |
|
124 |
|
125 types.resize (len, string ()); |
|
126 |
2800
|
127 binary_ops.resize (static_cast<int> (octave_value::num_binary_ops), |
|
128 len, len, static_cast<binary_op_fcn> (0)); |
2376
|
129 |
2882
|
130 assign_ops.resize (static_cast<int> (octave_value::num_assign_ops), |
|
131 len, len, static_cast<assign_op_fcn> (0)); |
2376
|
132 |
|
133 pref_assign_conv.resize (len, len, -1); |
|
134 |
2800
|
135 widening_ops.resize (len, len, static_cast<type_conv_fcn> (0)); |
2376
|
136 } |
|
137 |
|
138 types (i) = name; |
|
139 |
|
140 num_types++; |
|
141 |
|
142 return i; |
|
143 } |
|
144 |
|
145 bool |
|
146 octave_value_typeinfo::do_register_binary_op (octave_value::binary_op op, |
|
147 int t1, int t2, |
2427
|
148 binary_op_fcn f) |
2376
|
149 { |
2800
|
150 binary_ops.checkelem (static_cast<int> (op), t1, t2) = f; |
2376
|
151 |
|
152 return false; |
|
153 } |
|
154 |
|
155 bool |
2882
|
156 octave_value_typeinfo::do_register_assign_op (octave_value::assign_op op, |
|
157 int t_lhs, int t_rhs, |
2427
|
158 assign_op_fcn f) |
2376
|
159 { |
2882
|
160 assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs) = f; |
2376
|
161 |
|
162 return false; |
|
163 } |
|
164 |
|
165 bool |
|
166 octave_value_typeinfo::do_register_pref_assign_conv (int t_lhs, int t_rhs, |
|
167 int t_result) |
|
168 { |
|
169 pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result; |
|
170 |
|
171 return false; |
|
172 } |
|
173 |
|
174 bool |
|
175 octave_value_typeinfo::do_register_widening_op |
2427
|
176 (int t, int t_result, type_conv_fcn f) |
2376
|
177 { |
|
178 widening_ops.checkelem (t, t_result) = f; |
|
179 |
|
180 return false; |
|
181 } |
|
182 |
|
183 #include <iostream.h> |
|
184 |
2427
|
185 binary_op_fcn |
2376
|
186 octave_value_typeinfo::do_lookup_binary_op (octave_value::binary_op op, |
|
187 int t1, int t2) |
|
188 { |
2800
|
189 return binary_ops.checkelem (static_cast<int> (op), t1, t2); |
2376
|
190 } |
|
191 |
2427
|
192 assign_op_fcn |
2882
|
193 octave_value_typeinfo::do_lookup_assign_op (octave_value::assign_op op, |
|
194 int t_lhs, int t_rhs) |
2376
|
195 { |
2882
|
196 return assign_ops.checkelem (static_cast<int> (op), t_lhs, t_rhs); |
2376
|
197 } |
|
198 |
|
199 int |
|
200 octave_value_typeinfo::do_lookup_pref_assign_conv (int t_lhs, int t_rhs) |
|
201 { |
|
202 return pref_assign_conv.checkelem (t_lhs, t_rhs); |
|
203 } |
|
204 |
2427
|
205 type_conv_fcn |
2376
|
206 octave_value_typeinfo::do_lookup_widening_op (int t, int t_result) |
|
207 { |
|
208 return widening_ops.checkelem (t, t_result); |
|
209 } |
|
210 |
|
211 string_vector |
|
212 octave_value_typeinfo::do_installed_type_names (void) |
|
213 { |
|
214 string_vector retval (num_types); |
|
215 |
|
216 for (int i = 0;i < num_types; i++) |
|
217 retval (i) = types (i); |
|
218 |
|
219 return retval; |
|
220 } |
|
221 |
2457
|
222 DEFUN (typeinfo, args, , |
2822
|
223 "usage: typeinfo (expr)\n\ |
|
224 \n\ |
|
225 Return the type of the expression EXPR, as a string. If EXPR is\n\ |
|
226 omitted, return an array of strings containing all the currently\n\ |
|
227 installed data types.") |
2376
|
228 { |
|
229 octave_value retval; |
|
230 |
|
231 int nargin = args.length (); |
|
232 |
|
233 if (nargin == 0) |
|
234 retval = octave_value_typeinfo::installed_type_names (); |
2822
|
235 else if (nargin == 1) |
|
236 retval = args(0).type_name (); |
2376
|
237 else |
|
238 print_usage ("typeinfo"); |
|
239 |
|
240 return retval; |
|
241 } |
|
242 |
|
243 /* |
|
244 ;;; Local Variables: *** |
|
245 ;;; mode: C++ *** |
|
246 ;;; End: *** |
|
247 */ |