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 |
2901
|
31 #include <iostream.h> |
|
32 |
2376
|
33 #include "lo-ieee.h" |
|
34 |
|
35 #include "gripes.h" |
|
36 #include "oct-map.h" |
2974
|
37 #include "oct-obj.h" |
2979
|
38 #include "oct-lvalue.h" |
2376
|
39 #include "ops.h" |
|
40 #include "ov-base.h" |
|
41 #include "ov-scalar.h" |
|
42 #include "ov-re-mat.h" |
|
43 #include "ov-complex.h" |
|
44 #include "ov-cx-mat.h" |
|
45 #include "ov-ch-mat.h" |
|
46 #include "ov-str-mat.h" |
|
47 #include "ov-range.h" |
2882
|
48 #include "ov-list.h" |
2948
|
49 #include "variables.h" |
2376
|
50 |
|
51 int octave_base_value::t_id = -1; |
|
52 |
|
53 const string octave_base_value::t_name ("<unknown type>"); |
|
54 |
|
55 octave_value |
2974
|
56 octave_base_value::do_index_op (const octave_value_list&) |
|
57 { |
|
58 string nm = type_name (); |
|
59 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
60 return octave_value (); |
|
61 } |
|
62 |
|
63 octave_value_list |
|
64 octave_base_value::do_index_op (int, const octave_value_list&) |
2376
|
65 { |
|
66 string nm = type_name (); |
|
67 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
68 return octave_value (); |
|
69 } |
|
70 |
|
71 idx_vector |
|
72 octave_base_value::index_vector (void) const |
|
73 { |
|
74 string nm = type_name (); |
|
75 error ("%s type invalid as index value", nm.c_str ()); |
|
76 return idx_vector (); |
|
77 } |
|
78 |
|
79 octave_value |
2962
|
80 octave_base_value::do_struct_elt_index_op (const string&, |
|
81 const octave_value_list&, |
|
82 bool) |
|
83 { |
|
84 string nm = type_name (); |
|
85 error ("can't perform indexed structure reference operations for %s type", |
|
86 nm.c_str ()); |
|
87 return octave_value (); |
|
88 } |
|
89 |
|
90 octave_value |
|
91 octave_base_value::do_struct_elt_index_op (const string&, bool) |
2376
|
92 { |
|
93 string nm = type_name (); |
|
94 error ("can't perform structure reference operations for %s type", |
|
95 nm.c_str ()); |
|
96 return octave_value (); |
|
97 } |
|
98 |
2979
|
99 octave_lvalue |
2948
|
100 octave_base_value::struct_elt_ref (octave_value *, const string&) |
2376
|
101 { |
|
102 string nm = type_name (); |
|
103 error ("can't perform structure reference operations for %s type", |
|
104 nm.c_str ()); |
2979
|
105 return octave_lvalue (); |
2376
|
106 } |
|
107 |
|
108 octave_value |
|
109 octave_base_value::convert_to_str (void) const |
|
110 { |
|
111 gripe_wrong_type_arg ("octave_base_value::convert_to_str ()", |
|
112 type_name ()); |
|
113 return octave_value (); |
|
114 } |
|
115 |
|
116 void |
|
117 octave_base_value::convert_to_row_or_column_vector (void) |
|
118 { |
|
119 gripe_wrong_type_arg |
|
120 ("octave_base_value::convert_to_row_or_column_vector ()", |
|
121 type_name ()); |
|
122 } |
|
123 |
|
124 void |
2901
|
125 octave_base_value::print (ostream&, bool) const |
2376
|
126 { |
3195
|
127 gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); |
2376
|
128 } |
|
129 |
2901
|
130 void |
|
131 octave_base_value::print_raw (ostream&, bool) const |
|
132 { |
3195
|
133 gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ()); |
2901
|
134 } |
|
135 |
|
136 bool |
|
137 octave_base_value::print_name_tag (ostream& os, const string& name) const |
|
138 { |
|
139 indent (os); |
|
140 os << name << " ="; |
|
141 newline (os); |
|
142 newline (os); |
|
143 return true; |
|
144 } |
|
145 |
3195
|
146 int |
3202
|
147 octave_base_value::int_value (bool require_int, bool frc_str_conv) const |
|
148 { |
|
149 int retval = 0; |
|
150 |
|
151 double d = double_value (frc_str_conv); |
|
152 |
|
153 if (! error_state) |
|
154 { |
|
155 if (require_int && D_NINT (d) != d) |
|
156 { |
|
157 error ("conversion to integer value failed"); |
|
158 return retval; |
|
159 } |
|
160 |
|
161 retval = static_cast<int> (d); |
|
162 } |
|
163 else |
|
164 gripe_wrong_type_arg ("octave_base_value::int_value ()", type_name ()); |
|
165 |
|
166 return retval; |
|
167 } |
|
168 |
|
169 int |
|
170 octave_base_value::nint_value (bool frc_str_conv) const |
|
171 { |
|
172 int retval = 0; |
|
173 |
|
174 double d = double_value (frc_str_conv); |
|
175 |
|
176 if (! error_state) |
|
177 { |
|
178 if (xisnan (d)) |
|
179 { |
|
180 error ("conversion of NaN to integer value failed"); |
|
181 return retval; |
|
182 } |
|
183 |
|
184 retval = NINT (d); |
|
185 } |
|
186 else |
|
187 gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ()); |
|
188 |
|
189 return retval; |
|
190 } |
|
191 |
2376
|
192 double |
|
193 octave_base_value::double_value (bool) const |
|
194 { |
|
195 double retval = octave_NaN; |
|
196 gripe_wrong_type_arg ("octave_base_value::double_value ()", type_name ()); |
|
197 return retval; |
|
198 } |
|
199 |
|
200 Matrix |
|
201 octave_base_value::matrix_value (bool) const |
|
202 { |
|
203 Matrix retval; |
|
204 gripe_wrong_type_arg ("octave_base_value::matrix_value()", type_name ()); |
|
205 return retval; |
|
206 } |
|
207 |
|
208 Complex |
|
209 octave_base_value::complex_value (bool) const |
|
210 { |
|
211 Complex retval (octave_NaN, octave_NaN); |
|
212 gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
|
213 return retval; |
|
214 } |
|
215 |
|
216 ComplexMatrix |
|
217 octave_base_value::complex_matrix_value (bool) const |
|
218 { |
|
219 ComplexMatrix retval; |
|
220 gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
|
221 type_name ()); |
|
222 return retval; |
|
223 } |
|
224 |
|
225 charMatrix |
|
226 octave_base_value::char_matrix_value (bool) const |
|
227 { |
|
228 charMatrix retval; |
|
229 gripe_wrong_type_arg ("octave_base_value::char_matrix_value()", |
|
230 type_name ()); |
|
231 return retval; |
|
232 } |
|
233 |
2493
|
234 string_vector |
2376
|
235 octave_base_value::all_strings (void) const |
|
236 { |
2493
|
237 string_vector retval; |
2376
|
238 gripe_wrong_type_arg ("octave_base_value::all_strings()", type_name ()); |
|
239 return retval; |
|
240 } |
|
241 |
|
242 string |
|
243 octave_base_value::string_value (void) const |
|
244 { |
|
245 string retval; |
|
246 gripe_wrong_type_arg ("octave_base_value::string_value()", type_name ()); |
|
247 return retval; |
|
248 } |
|
249 |
|
250 Range |
|
251 octave_base_value::range_value (void) const |
|
252 { |
|
253 Range retval; |
|
254 gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
|
255 return retval; |
|
256 } |
|
257 |
|
258 Octave_map |
|
259 octave_base_value::map_value (void) const |
|
260 { |
|
261 Octave_map retval; |
|
262 gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
|
263 return retval; |
|
264 } |
|
265 |
2901
|
266 octave_stream * |
|
267 octave_base_value::stream_value (void) const |
|
268 { |
|
269 octave_stream *retval = 0; |
|
270 gripe_wrong_type_arg ("octave_base_value::stream_value()", type_name ()); |
|
271 return retval; |
|
272 } |
|
273 |
|
274 int |
|
275 octave_base_value::stream_number (void) const |
|
276 { |
|
277 int retval = -1; |
|
278 gripe_wrong_type_arg ("octave_base_value::stream_number()", type_name ()); |
|
279 return retval; |
|
280 } |
|
281 |
2974
|
282 octave_function * |
|
283 octave_base_value::function_value (bool silent) |
|
284 { |
|
285 octave_function *retval = 0; |
|
286 |
|
287 if (! silent) |
|
288 gripe_wrong_type_arg ("octave_base_value::function_value()", |
|
289 type_name ()); |
|
290 return retval; |
|
291 } |
|
292 |
2882
|
293 octave_value_list |
|
294 octave_base_value::list_value (void) const |
|
295 { |
|
296 octave_value_list retval; |
|
297 gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
|
298 return retval; |
|
299 } |
|
300 |
2825
|
301 bool |
|
302 octave_base_value::bool_value (void) const |
|
303 { |
|
304 bool retval = false; |
|
305 gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
|
306 return retval; |
|
307 } |
|
308 |
|
309 boolMatrix |
|
310 octave_base_value::bool_matrix_value (void) const |
|
311 { |
|
312 boolMatrix retval; |
|
313 gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
|
314 type_name ()); |
|
315 return retval; |
|
316 } |
|
317 |
3203
|
318 CONVDECLX (matrix_conv) |
2376
|
319 { |
|
320 return new octave_matrix (); |
|
321 } |
|
322 |
3203
|
323 CONVDECLX (complex_matrix_conv) |
2376
|
324 { |
|
325 return new octave_complex_matrix (); |
|
326 } |
|
327 |
3203
|
328 CONVDECLX (string_conv) |
2376
|
329 { |
|
330 return new octave_char_matrix_str (); |
|
331 } |
|
332 |
|
333 void |
|
334 install_base_type_conversions (void) |
|
335 { |
|
336 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
337 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
338 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
339 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
340 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
341 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
|
342 |
|
343 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
344 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
345 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
|
346 } |
|
347 |
|
348 /* |
|
349 ;;; Local Variables: *** |
|
350 ;;; mode: C++ *** |
|
351 ;;; End: *** |
|
352 */ |