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 |
4066
|
23 #if defined (__GNUG__) && ! defined (NO_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
2901
|
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" |
3340
|
39 #include "oct-stream.h" |
2376
|
40 #include "ops.h" |
|
41 #include "ov-base.h" |
3928
|
42 #include "ov-cell.h" |
|
43 #include "ov-ch-mat.h" |
2376
|
44 #include "ov-complex.h" |
|
45 #include "ov-cx-mat.h" |
3928
|
46 #include "ov-list.h" |
|
47 #include "ov-range.h" |
|
48 #include "ov-re-mat.h" |
|
49 #include "ov-scalar.h" |
2376
|
50 #include "ov-str-mat.h" |
2948
|
51 #include "variables.h" |
2376
|
52 |
3219
|
53 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, "<unknown type>"); |
2376
|
54 |
|
55 octave_value |
3933
|
56 octave_base_value::subsref (const std::string, |
|
57 const SLList<octave_value_list>&) |
|
58 { |
|
59 std::string nm = type_name (); |
|
60 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
61 return octave_value (); |
|
62 } |
|
63 |
|
64 octave_value_list |
|
65 octave_base_value::subsref (const std::string, |
|
66 const SLList<octave_value_list>&, int) |
|
67 { |
|
68 std::string nm = type_name (); |
|
69 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
70 return octave_value (); |
|
71 } |
|
72 |
|
73 octave_value |
|
74 octave_base_value::do_index_op (const octave_value_list&, int) |
2974
|
75 { |
3523
|
76 std::string nm = type_name (); |
2974
|
77 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
78 return octave_value (); |
|
79 } |
|
80 |
|
81 octave_value_list |
3544
|
82 octave_base_value::do_multi_index_op (int, const octave_value_list&) |
2376
|
83 { |
3523
|
84 std::string nm = type_name (); |
2376
|
85 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
86 return octave_value (); |
|
87 } |
|
88 |
|
89 idx_vector |
|
90 octave_base_value::index_vector (void) const |
|
91 { |
3523
|
92 std::string nm = type_name (); |
2376
|
93 error ("%s type invalid as index value", nm.c_str ()); |
|
94 return idx_vector (); |
|
95 } |
|
96 |
|
97 octave_value |
3933
|
98 octave_base_value::subsasgn (const std::string type, |
|
99 const SLList<octave_value_list>& idx, |
|
100 const octave_value& rhs) |
2376
|
101 { |
3933
|
102 octave_value retval; |
2376
|
103 |
3933
|
104 if (is_defined ()) |
|
105 { |
|
106 std::string nm = type_name (); |
|
107 error ("can't perform indexed assignment for %s type", nm.c_str ()); |
|
108 } |
|
109 else |
|
110 { |
|
111 // Create new object of appropriate type for given index and rhs |
|
112 // types and then call subsasgn again for that object. |
|
113 |
|
114 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
115 |
|
116 retval = tmp.subsasgn (type, idx, rhs); |
|
117 } |
|
118 |
|
119 return retval; |
2376
|
120 } |
|
121 |
|
122 octave_value |
|
123 octave_base_value::convert_to_str (void) const |
|
124 { |
|
125 gripe_wrong_type_arg ("octave_base_value::convert_to_str ()", |
|
126 type_name ()); |
|
127 return octave_value (); |
|
128 } |
|
129 |
|
130 void |
|
131 octave_base_value::convert_to_row_or_column_vector (void) |
|
132 { |
|
133 gripe_wrong_type_arg |
|
134 ("octave_base_value::convert_to_row_or_column_vector ()", |
|
135 type_name ()); |
|
136 } |
|
137 |
|
138 void |
3523
|
139 octave_base_value::print (std::ostream&, bool) const |
2376
|
140 { |
3195
|
141 gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); |
2376
|
142 } |
|
143 |
2901
|
144 void |
3523
|
145 octave_base_value::print_raw (std::ostream&, bool) const |
2901
|
146 { |
3195
|
147 gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ()); |
2901
|
148 } |
|
149 |
|
150 bool |
3523
|
151 octave_base_value::print_name_tag (std::ostream& os, const std::string& name) const |
2901
|
152 { |
|
153 indent (os); |
|
154 os << name << " ="; |
|
155 newline (os); |
|
156 newline (os); |
|
157 return true; |
|
158 } |
|
159 |
3933
|
160 void |
|
161 octave_base_value::print_info (std::ostream& os, |
|
162 const std::string& prefix) const |
|
163 { |
|
164 os << "no info for type: " << type_name () << "\n"; |
|
165 } |
|
166 |
3195
|
167 int |
3202
|
168 octave_base_value::int_value (bool require_int, bool frc_str_conv) const |
|
169 { |
|
170 int retval = 0; |
|
171 |
|
172 double d = double_value (frc_str_conv); |
|
173 |
|
174 if (! error_state) |
|
175 { |
|
176 if (require_int && D_NINT (d) != d) |
|
177 { |
|
178 error ("conversion to integer value failed"); |
|
179 return retval; |
|
180 } |
|
181 |
|
182 retval = static_cast<int> (d); |
|
183 } |
|
184 else |
|
185 gripe_wrong_type_arg ("octave_base_value::int_value ()", type_name ()); |
|
186 |
|
187 return retval; |
|
188 } |
|
189 |
|
190 int |
|
191 octave_base_value::nint_value (bool frc_str_conv) const |
|
192 { |
|
193 int retval = 0; |
|
194 |
|
195 double d = double_value (frc_str_conv); |
|
196 |
|
197 if (! error_state) |
|
198 { |
|
199 if (xisnan (d)) |
|
200 { |
|
201 error ("conversion of NaN to integer value failed"); |
|
202 return retval; |
|
203 } |
|
204 |
|
205 retval = NINT (d); |
|
206 } |
|
207 else |
|
208 gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ()); |
|
209 |
|
210 return retval; |
|
211 } |
|
212 |
2376
|
213 double |
|
214 octave_base_value::double_value (bool) const |
|
215 { |
4102
|
216 double retval = lo_ieee_nan_value (); |
2376
|
217 gripe_wrong_type_arg ("octave_base_value::double_value ()", type_name ()); |
|
218 return retval; |
|
219 } |
|
220 |
3351
|
221 Cell |
3539
|
222 octave_base_value::cell_value () const |
3351
|
223 { |
|
224 Cell retval; |
|
225 gripe_wrong_type_arg ("octave_base_value::cell_value()", type_name ()); |
|
226 return retval; |
|
227 } |
|
228 |
2376
|
229 Matrix |
|
230 octave_base_value::matrix_value (bool) const |
|
231 { |
|
232 Matrix retval; |
|
233 gripe_wrong_type_arg ("octave_base_value::matrix_value()", type_name ()); |
|
234 return retval; |
|
235 } |
|
236 |
|
237 Complex |
|
238 octave_base_value::complex_value (bool) const |
|
239 { |
4102
|
240 double tmp = lo_ieee_nan_value (); |
|
241 Complex retval (tmp, tmp); |
2376
|
242 gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
|
243 return retval; |
|
244 } |
|
245 |
|
246 ComplexMatrix |
|
247 octave_base_value::complex_matrix_value (bool) const |
|
248 { |
|
249 ComplexMatrix retval; |
|
250 gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
|
251 type_name ()); |
|
252 return retval; |
|
253 } |
|
254 |
|
255 charMatrix |
|
256 octave_base_value::char_matrix_value (bool) const |
|
257 { |
|
258 charMatrix retval; |
|
259 gripe_wrong_type_arg ("octave_base_value::char_matrix_value()", |
|
260 type_name ()); |
|
261 return retval; |
|
262 } |
|
263 |
2493
|
264 string_vector |
2376
|
265 octave_base_value::all_strings (void) const |
|
266 { |
2493
|
267 string_vector retval; |
2376
|
268 gripe_wrong_type_arg ("octave_base_value::all_strings()", type_name ()); |
|
269 return retval; |
|
270 } |
|
271 |
3536
|
272 std::string |
2376
|
273 octave_base_value::string_value (void) const |
|
274 { |
3523
|
275 std::string retval; |
2376
|
276 gripe_wrong_type_arg ("octave_base_value::string_value()", type_name ()); |
|
277 return retval; |
|
278 } |
|
279 |
|
280 Range |
|
281 octave_base_value::range_value (void) const |
|
282 { |
|
283 Range retval; |
|
284 gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
|
285 return retval; |
|
286 } |
|
287 |
|
288 Octave_map |
|
289 octave_base_value::map_value (void) const |
|
290 { |
|
291 Octave_map retval; |
|
292 gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
|
293 return retval; |
|
294 } |
|
295 |
3933
|
296 string_vector |
|
297 octave_base_value::map_keys (void) const |
|
298 { |
|
299 string_vector retval; |
|
300 gripe_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); |
|
301 return retval; |
|
302 } |
|
303 |
3340
|
304 octave_stream |
2901
|
305 octave_base_value::stream_value (void) const |
|
306 { |
3340
|
307 octave_stream retval; |
2901
|
308 gripe_wrong_type_arg ("octave_base_value::stream_value()", type_name ()); |
|
309 return retval; |
|
310 } |
|
311 |
|
312 int |
|
313 octave_base_value::stream_number (void) const |
|
314 { |
|
315 int retval = -1; |
|
316 gripe_wrong_type_arg ("octave_base_value::stream_number()", type_name ()); |
|
317 return retval; |
|
318 } |
|
319 |
2974
|
320 octave_function * |
|
321 octave_base_value::function_value (bool silent) |
|
322 { |
|
323 octave_function *retval = 0; |
|
324 |
|
325 if (! silent) |
|
326 gripe_wrong_type_arg ("octave_base_value::function_value()", |
|
327 type_name ()); |
|
328 return retval; |
|
329 } |
|
330 |
2882
|
331 octave_value_list |
|
332 octave_base_value::list_value (void) const |
|
333 { |
|
334 octave_value_list retval; |
|
335 gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
|
336 return retval; |
|
337 } |
|
338 |
2825
|
339 bool |
|
340 octave_base_value::bool_value (void) const |
|
341 { |
|
342 bool retval = false; |
|
343 gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
|
344 return retval; |
|
345 } |
|
346 |
|
347 boolMatrix |
|
348 octave_base_value::bool_matrix_value (void) const |
|
349 { |
|
350 boolMatrix retval; |
|
351 gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
|
352 type_name ()); |
|
353 return retval; |
|
354 } |
|
355 |
3203
|
356 CONVDECLX (matrix_conv) |
2376
|
357 { |
|
358 return new octave_matrix (); |
|
359 } |
|
360 |
3203
|
361 CONVDECLX (complex_matrix_conv) |
2376
|
362 { |
|
363 return new octave_complex_matrix (); |
|
364 } |
|
365 |
3203
|
366 CONVDECLX (string_conv) |
2376
|
367 { |
|
368 return new octave_char_matrix_str (); |
|
369 } |
|
370 |
3928
|
371 CONVDECLX (cell_conv) |
|
372 { |
|
373 return new octave_cell (); |
|
374 } |
|
375 |
2376
|
376 void |
|
377 install_base_type_conversions (void) |
|
378 { |
|
379 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
380 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
381 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
382 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
383 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
384 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
3928
|
385 INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); |
2376
|
386 |
|
387 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
388 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
389 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
3928
|
390 INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); |
2376
|
391 } |
|
392 |
|
393 /* |
|
394 ;;; Local Variables: *** |
|
395 ;;; mode: C++ *** |
|
396 ;;; End: *** |
|
397 */ |