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