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