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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_value_typeinfo_h) |
|
25 #define octave_value_typeinfo_h 1 |
|
26 |
|
27 #include <string> |
|
28 |
|
29 #include "Array.h" |
|
30 #include "Array2.h" |
|
31 #include "Array3.h" |
|
32 |
|
33 #include "ov.h" |
|
34 |
|
35 class string_vector; |
|
36 |
|
37 class |
6109
|
38 OCTINTERP_API |
2376
|
39 octave_value_typeinfo |
|
40 { |
|
41 public: |
|
42 |
5759
|
43 typedef octave_value (*unary_op_fcn) (const octave_base_value&); |
|
44 |
|
45 typedef void (*non_const_unary_op_fcn) (octave_base_value&); |
|
46 |
|
47 typedef octave_value (*binary_op_fcn) |
|
48 (const octave_base_value&, const octave_base_value&); |
|
49 |
|
50 typedef octave_value (*cat_op_fcn) |
|
51 (octave_base_value&, const octave_base_value&, const Array<int>& ra_idx); |
|
52 |
|
53 typedef octave_value (*assign_op_fcn) |
|
54 (octave_base_value&, const octave_value_list&, const octave_base_value&); |
|
55 |
|
56 typedef octave_value (*assignany_op_fcn) |
|
57 (octave_base_value&, const octave_value_list&, const octave_value&); |
|
58 |
2926
|
59 static bool instance_ok (void); |
|
60 |
4640
|
61 static int register_type (const std::string&, const std::string&, |
|
62 const octave_value&); |
2376
|
63 |
3203
|
64 static bool register_unary_op (octave_value::unary_op, int, unary_op_fcn); |
|
65 |
|
66 static bool register_non_const_unary_op (octave_value::unary_op, int, |
|
67 non_const_unary_op_fcn); |
|
68 |
2376
|
69 static bool register_binary_op (octave_value::binary_op, int, int, |
2427
|
70 binary_op_fcn); |
2376
|
71 |
4915
|
72 static bool register_cat_op (int, int, cat_op_fcn); |
|
73 |
2882
|
74 static bool register_assign_op (octave_value::assign_op, int, int, |
|
75 assign_op_fcn); |
2376
|
76 |
3196
|
77 static bool register_assignany_op (octave_value::assign_op, int, |
5759
|
78 assignany_op_fcn); |
3196
|
79 |
2376
|
80 static bool register_pref_assign_conv (int, int, int); |
|
81 |
5759
|
82 static bool |
|
83 register_type_conv_op (int, int, octave_base_value::type_conv_fcn); |
4901
|
84 |
5759
|
85 static bool |
|
86 register_widening_op (int, int, octave_base_value::type_conv_fcn); |
2376
|
87 |
4640
|
88 static octave_value |
|
89 lookup_type (const std::string& nm) |
|
90 { |
|
91 return instance->do_lookup_type (nm); |
|
92 } |
|
93 |
3203
|
94 static unary_op_fcn |
|
95 lookup_unary_op (octave_value::unary_op op, int t) |
|
96 { |
|
97 return instance->do_lookup_unary_op (op, t); |
|
98 } |
|
99 |
|
100 static non_const_unary_op_fcn |
|
101 lookup_non_const_unary_op (octave_value::unary_op op, int t) |
|
102 { |
|
103 return instance->do_lookup_non_const_unary_op (op, t); |
|
104 } |
|
105 |
2427
|
106 static binary_op_fcn |
2376
|
107 lookup_binary_op (octave_value::binary_op op, int t1, int t2) |
|
108 { |
|
109 return instance->do_lookup_binary_op (op, t1, t2); |
|
110 } |
|
111 |
4915
|
112 static cat_op_fcn |
|
113 lookup_cat_op (int t1, int t2) |
|
114 { |
|
115 return instance->do_lookup_cat_op (t1, t2); |
|
116 } |
|
117 |
2427
|
118 static assign_op_fcn |
2882
|
119 lookup_assign_op (octave_value::assign_op op, int t_lhs, int t_rhs) |
2376
|
120 { |
2882
|
121 return instance->do_lookup_assign_op (op, t_lhs, t_rhs); |
2376
|
122 } |
|
123 |
5759
|
124 static assignany_op_fcn |
3196
|
125 lookup_assignany_op (octave_value::assign_op op, int t_lhs) |
|
126 { |
|
127 return instance->do_lookup_assignany_op (op, t_lhs); |
|
128 } |
|
129 |
2376
|
130 static int |
|
131 lookup_pref_assign_conv (int t_lhs, int t_rhs) |
|
132 { |
|
133 return instance->do_lookup_pref_assign_conv (t_lhs, t_rhs); |
|
134 } |
|
135 |
5759
|
136 static octave_base_value::type_conv_fcn |
4901
|
137 lookup_type_conv_op (int t, int t_result) |
|
138 { |
|
139 return instance->do_lookup_type_conv_op (t, t_result); |
|
140 } |
|
141 |
5759
|
142 static octave_base_value::type_conv_fcn |
2376
|
143 lookup_widening_op (int t, int t_result) |
|
144 { |
|
145 return instance->do_lookup_widening_op (t, t_result); |
|
146 } |
|
147 |
|
148 static string_vector installed_type_names (void) |
|
149 { |
|
150 return instance->do_installed_type_names (); |
|
151 } |
|
152 |
|
153 protected: |
|
154 |
|
155 octave_value_typeinfo (void) |
3523
|
156 : num_types (0), types (init_tab_sz, std::string ()), |
4645
|
157 vals (init_tab_sz), |
5760
|
158 unary_ops (octave_value::num_unary_ops, init_tab_sz, 0), |
|
159 non_const_unary_ops (octave_value::num_unary_ops, init_tab_sz, 0), |
|
160 binary_ops (octave_value::num_binary_ops, init_tab_sz, init_tab_sz, 0), |
|
161 cat_ops (init_tab_sz, init_tab_sz, 0), |
|
162 assign_ops (octave_value::num_assign_ops, init_tab_sz, init_tab_sz, 0), |
|
163 assignany_ops (octave_value::num_assign_ops, init_tab_sz, 0), |
2479
|
164 pref_assign_conv (init_tab_sz, init_tab_sz, -1), |
5760
|
165 type_conv_ops (init_tab_sz, init_tab_sz, 0), |
|
166 widening_ops (init_tab_sz, init_tab_sz, 0) { } |
2376
|
167 |
|
168 private: |
|
169 |
2479
|
170 static const int init_tab_sz; |
|
171 |
2376
|
172 static octave_value_typeinfo *instance; |
|
173 |
|
174 int num_types; |
|
175 |
3523
|
176 Array<std::string> types; |
2376
|
177 |
4640
|
178 Array<octave_value> vals; |
|
179 |
3203
|
180 Array2<unary_op_fcn> unary_ops; |
|
181 |
|
182 Array2<non_const_unary_op_fcn> non_const_unary_ops; |
|
183 |
2427
|
184 Array3<binary_op_fcn> binary_ops; |
2376
|
185 |
4915
|
186 Array2<cat_op_fcn> cat_ops; |
|
187 |
2882
|
188 Array3<assign_op_fcn> assign_ops; |
2376
|
189 |
5759
|
190 Array2<assignany_op_fcn> assignany_ops; |
3196
|
191 |
2376
|
192 Array2<int> pref_assign_conv; |
|
193 |
5759
|
194 Array2<octave_base_value::type_conv_fcn> type_conv_ops; |
4901
|
195 |
5759
|
196 Array2<octave_base_value::type_conv_fcn> widening_ops; |
2376
|
197 |
4640
|
198 int do_register_type (const std::string&, const std::string&, |
|
199 const octave_value&); |
2376
|
200 |
3203
|
201 bool do_register_unary_op (octave_value::unary_op, int, unary_op_fcn); |
|
202 |
|
203 bool do_register_non_const_unary_op (octave_value::unary_op, int, |
|
204 non_const_unary_op_fcn); |
|
205 |
2376
|
206 bool do_register_binary_op (octave_value::binary_op, int, int, |
2427
|
207 binary_op_fcn); |
2376
|
208 |
4915
|
209 bool do_register_cat_op (int, int, cat_op_fcn); |
|
210 |
2882
|
211 bool do_register_assign_op (octave_value::assign_op, int, int, |
|
212 assign_op_fcn); |
2376
|
213 |
3196
|
214 bool do_register_assignany_op (octave_value::assign_op, int, |
5759
|
215 assignany_op_fcn); |
3196
|
216 |
2376
|
217 bool do_register_pref_assign_conv (int, int, int); |
|
218 |
5759
|
219 bool do_register_type_conv_op (int, int, octave_base_value::type_conv_fcn); |
4901
|
220 |
5759
|
221 bool do_register_widening_op (int, int, octave_base_value::type_conv_fcn); |
2376
|
222 |
4640
|
223 octave_value do_lookup_type (const std::string& nm); |
|
224 |
3203
|
225 unary_op_fcn do_lookup_unary_op (octave_value::unary_op, int); |
|
226 |
|
227 non_const_unary_op_fcn do_lookup_non_const_unary_op |
|
228 (octave_value::unary_op, int); |
2376
|
229 |
3203
|
230 binary_op_fcn do_lookup_binary_op (octave_value::binary_op, int, int); |
2376
|
231 |
4915
|
232 cat_op_fcn do_lookup_cat_op (int, int); |
|
233 |
3203
|
234 assign_op_fcn do_lookup_assign_op (octave_value::assign_op, int, int); |
|
235 |
5759
|
236 assignany_op_fcn do_lookup_assignany_op (octave_value::assign_op, int); |
3196
|
237 |
2376
|
238 int do_lookup_pref_assign_conv (int, int); |
|
239 |
5759
|
240 octave_base_value::type_conv_fcn do_lookup_type_conv_op (int, int); |
4901
|
241 |
5759
|
242 octave_base_value::type_conv_fcn do_lookup_widening_op (int, int); |
2376
|
243 |
|
244 string_vector do_installed_type_names (void); |
|
245 |
|
246 // No copying! |
|
247 |
|
248 octave_value_typeinfo (const octave_value_typeinfo&); |
|
249 |
|
250 octave_value_typeinfo& operator = (const octave_value_typeinfo&); |
|
251 }; |
|
252 |
|
253 #endif |
|
254 |
|
255 /* |
6705
|
256 ;;; Local Variables: *** |
|
257 ;;; mode: C++ *** |
|
258 ;;; End: *** |
2376
|
259 */ |