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 |
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 { |
|
216 double retval = octave_NaN; |
|
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 { |
|
240 Complex retval (octave_NaN, octave_NaN); |
|
241 gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
|
242 return retval; |
|
243 } |
|
244 |
|
245 ComplexMatrix |
|
246 octave_base_value::complex_matrix_value (bool) const |
|
247 { |
|
248 ComplexMatrix retval; |
|
249 gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
|
250 type_name ()); |
|
251 return retval; |
|
252 } |
|
253 |
|
254 charMatrix |
|
255 octave_base_value::char_matrix_value (bool) const |
|
256 { |
|
257 charMatrix retval; |
|
258 gripe_wrong_type_arg ("octave_base_value::char_matrix_value()", |
|
259 type_name ()); |
|
260 return retval; |
|
261 } |
|
262 |
2493
|
263 string_vector |
2376
|
264 octave_base_value::all_strings (void) const |
|
265 { |
2493
|
266 string_vector retval; |
2376
|
267 gripe_wrong_type_arg ("octave_base_value::all_strings()", type_name ()); |
|
268 return retval; |
|
269 } |
|
270 |
3536
|
271 std::string |
2376
|
272 octave_base_value::string_value (void) const |
|
273 { |
3523
|
274 std::string retval; |
2376
|
275 gripe_wrong_type_arg ("octave_base_value::string_value()", type_name ()); |
|
276 return retval; |
|
277 } |
|
278 |
|
279 Range |
|
280 octave_base_value::range_value (void) const |
|
281 { |
|
282 Range retval; |
|
283 gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
|
284 return retval; |
|
285 } |
|
286 |
|
287 Octave_map |
|
288 octave_base_value::map_value (void) const |
|
289 { |
|
290 Octave_map retval; |
|
291 gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
|
292 return retval; |
|
293 } |
|
294 |
3933
|
295 string_vector |
|
296 octave_base_value::map_keys (void) const |
|
297 { |
|
298 string_vector retval; |
|
299 gripe_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); |
|
300 return retval; |
|
301 } |
|
302 |
3340
|
303 octave_stream |
2901
|
304 octave_base_value::stream_value (void) const |
|
305 { |
3340
|
306 octave_stream retval; |
2901
|
307 gripe_wrong_type_arg ("octave_base_value::stream_value()", type_name ()); |
|
308 return retval; |
|
309 } |
|
310 |
|
311 int |
|
312 octave_base_value::stream_number (void) const |
|
313 { |
|
314 int retval = -1; |
|
315 gripe_wrong_type_arg ("octave_base_value::stream_number()", type_name ()); |
|
316 return retval; |
|
317 } |
|
318 |
2974
|
319 octave_function * |
|
320 octave_base_value::function_value (bool silent) |
|
321 { |
|
322 octave_function *retval = 0; |
|
323 |
|
324 if (! silent) |
|
325 gripe_wrong_type_arg ("octave_base_value::function_value()", |
|
326 type_name ()); |
|
327 return retval; |
|
328 } |
|
329 |
2882
|
330 octave_value_list |
|
331 octave_base_value::list_value (void) const |
|
332 { |
|
333 octave_value_list retval; |
|
334 gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
|
335 return retval; |
|
336 } |
|
337 |
2825
|
338 bool |
|
339 octave_base_value::bool_value (void) const |
|
340 { |
|
341 bool retval = false; |
|
342 gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
|
343 return retval; |
|
344 } |
|
345 |
|
346 boolMatrix |
|
347 octave_base_value::bool_matrix_value (void) const |
|
348 { |
|
349 boolMatrix retval; |
|
350 gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
|
351 type_name ()); |
|
352 return retval; |
|
353 } |
|
354 |
3203
|
355 CONVDECLX (matrix_conv) |
2376
|
356 { |
|
357 return new octave_matrix (); |
|
358 } |
|
359 |
3203
|
360 CONVDECLX (complex_matrix_conv) |
2376
|
361 { |
|
362 return new octave_complex_matrix (); |
|
363 } |
|
364 |
3203
|
365 CONVDECLX (string_conv) |
2376
|
366 { |
|
367 return new octave_char_matrix_str (); |
|
368 } |
|
369 |
3928
|
370 CONVDECLX (cell_conv) |
|
371 { |
|
372 return new octave_cell (); |
|
373 } |
|
374 |
2376
|
375 void |
|
376 install_base_type_conversions (void) |
|
377 { |
|
378 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
379 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
380 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
381 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
382 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
383 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
3928
|
384 INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); |
2376
|
385 |
|
386 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
387 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
388 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
3928
|
389 INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); |
2376
|
390 } |
|
391 |
|
392 /* |
|
393 ;;; Local Variables: *** |
|
394 ;;; mode: C++ *** |
|
395 ;;; End: *** |
|
396 */ |