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 (octave_value_h) |
|
24 #define octave_value_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2376
|
33 #include <string> |
4219
|
34 #include <list> |
2376
|
35 |
4687
|
36 #if defined (HAVE_HDF5) |
|
37 #include <hdf5.h> |
|
38 #endif |
4507
|
39 |
2376
|
40 #include "Range.h" |
|
41 #include "idx-vector.h" |
|
42 #include "mx-base.h" |
2477
|
43 #include "oct-alloc.h" |
4254
|
44 #include "oct-time.h" |
2942
|
45 #include "str-vec.h" |
|
46 |
3351
|
47 class Cell; |
4654
|
48 class fcn_handle_array; |
4643
|
49 class streamoff_array; |
2376
|
50 class Octave_map; |
2903
|
51 class octave_stream; |
4643
|
52 class octave_streamoff; |
2974
|
53 class octave_function; |
4700
|
54 class octave_user_function; |
4342
|
55 class octave_fcn_handle; |
2376
|
56 class octave_value_list; |
2979
|
57 class octave_lvalue; |
2376
|
58 |
|
59 // Constants. |
|
60 |
|
61 // This just provides a way to avoid infinite recursion when building |
|
62 // octave_value objects. |
|
63 |
|
64 class |
|
65 octave_xvalue |
|
66 { |
|
67 public: |
|
68 |
|
69 octave_xvalue (void) { } |
|
70 }; |
|
71 |
2427
|
72 class octave_value; |
|
73 |
|
74 // XXX FIXME XXX -- these should probably really be inside the scope |
|
75 // of the octave_value class, but the cygwin32 beta16 version of g++ |
3203
|
76 // can't handle that. |
|
77 |
|
78 typedef octave_value (*unary_op_fcn) |
|
79 (const octave_value&); |
|
80 |
|
81 typedef void (*non_const_unary_op_fcn) |
|
82 (octave_value&); |
2427
|
83 |
|
84 typedef octave_value (*binary_op_fcn) |
|
85 (const octave_value&, const octave_value&); |
|
86 |
|
87 typedef octave_value (*assign_op_fcn) |
|
88 (octave_value&, const octave_value_list&, const octave_value&); |
|
89 |
|
90 typedef octave_value * (*type_conv_fcn) (const octave_value&); |
|
91 |
2376
|
92 class |
2974
|
93 octave_value |
2376
|
94 { |
|
95 public: |
|
96 |
3203
|
97 enum unary_op |
|
98 { |
3525
|
99 op_not, |
|
100 op_uminus, |
|
101 op_transpose, |
|
102 op_hermitian, |
|
103 op_incr, |
|
104 op_decr, |
3203
|
105 num_unary_ops, |
|
106 unknown_unary_op |
|
107 }; |
|
108 |
2376
|
109 enum binary_op |
|
110 { |
3525
|
111 op_add, |
|
112 op_sub, |
|
113 op_mul, |
|
114 op_div, |
|
115 op_pow, |
|
116 op_ldiv, |
|
117 op_lshift, |
|
118 op_rshift, |
|
119 op_lt, |
|
120 op_le, |
|
121 op_eq, |
|
122 op_ge, |
|
123 op_gt, |
|
124 op_ne, |
|
125 op_el_mul, |
|
126 op_el_div, |
|
127 op_el_pow, |
|
128 op_el_ldiv, |
|
129 op_el_and, |
|
130 op_el_or, |
|
131 op_struct_ref, |
2376
|
132 num_binary_ops, |
|
133 unknown_binary_op |
|
134 }; |
|
135 |
2880
|
136 enum assign_op |
|
137 { |
3525
|
138 op_asn_eq, |
|
139 op_add_eq, |
|
140 op_sub_eq, |
|
141 op_mul_eq, |
|
142 op_div_eq, |
|
143 op_ldiv_eq, |
4018
|
144 op_pow_eq, |
3525
|
145 op_lshift_eq, |
|
146 op_rshift_eq, |
|
147 op_el_mul_eq, |
|
148 op_el_div_eq, |
|
149 op_el_ldiv_eq, |
4018
|
150 op_el_pow_eq, |
3525
|
151 op_el_and_eq, |
|
152 op_el_or_eq, |
2880
|
153 num_assign_ops, |
|
154 unknown_assign_op |
|
155 }; |
|
156 |
3523
|
157 static std::string unary_op_as_string (unary_op); |
3203
|
158 |
3523
|
159 static std::string binary_op_as_string (binary_op); |
2376
|
160 |
3523
|
161 static std::string assign_op_as_string (assign_op); |
2880
|
162 |
3933
|
163 static octave_value empty_conv (const std::string& type, |
|
164 const octave_value& rhs = octave_value ()); |
|
165 |
2376
|
166 enum magic_colon { magic_colon_t }; |
|
167 enum all_va_args { all_va_args_t }; |
|
168 |
|
169 octave_value (void); |
4254
|
170 octave_value (short int i); |
|
171 octave_value (unsigned short int i); |
4233
|
172 octave_value (int i); |
4254
|
173 octave_value (unsigned int i); |
|
174 octave_value (long int i); |
|
175 octave_value (unsigned long int i); |
4353
|
176 |
|
177 // XXX FIXME XXX -- these are kluges. They turn into doubles |
|
178 // internally, which will break for very large values. We just use |
|
179 // them to store things like 64-bit ino_t, etc, and hope that those |
|
180 // values are never actually larger than can be represented exactly |
|
181 // in a double. |
|
182 |
|
183 #if defined (HAVE_LONG_LONG_INT) |
|
184 octave_value (long long int i); |
|
185 #endif |
4356
|
186 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
187 octave_value (unsigned long long int i); |
|
188 #endif |
|
189 |
4254
|
190 octave_value (octave_time t); |
2376
|
191 octave_value (double d); |
4532
|
192 octave_value (const ArrayN<octave_value>& a, bool is_cs_list = false); |
|
193 octave_value (const Cell& c, bool is_cs_list = false); |
2376
|
194 octave_value (const Matrix& m); |
4513
|
195 octave_value (const NDArray& nda); |
2376
|
196 octave_value (const DiagMatrix& d); |
3418
|
197 octave_value (const RowVector& v); |
|
198 octave_value (const ColumnVector& v); |
2376
|
199 octave_value (const Complex& C); |
|
200 octave_value (const ComplexMatrix& m); |
4513
|
201 octave_value (const ComplexNDArray& cnda); |
4478
|
202 octave_value (const ArrayN<Complex>& m); |
2376
|
203 octave_value (const ComplexDiagMatrix& d); |
3418
|
204 octave_value (const ComplexRowVector& v); |
|
205 octave_value (const ComplexColumnVector& v); |
2825
|
206 octave_value (bool b); |
|
207 octave_value (const boolMatrix& bm); |
4513
|
208 octave_value (const boolNDArray& bnda); |
3189
|
209 octave_value (char c); |
2376
|
210 octave_value (const char *s); |
3523
|
211 octave_value (const std::string& s); |
2376
|
212 octave_value (const string_vector& s); |
|
213 octave_value (const charMatrix& chm, bool is_string = false); |
4513
|
214 octave_value (const charNDArray& chnda, bool is_string = false); |
4901
|
215 octave_value (const octave_int8& i); |
|
216 octave_value (const octave_uint8& i); |
|
217 octave_value (const octave_int16& i); |
|
218 octave_value (const octave_uint16& i); |
|
219 octave_value (const octave_int32& i); |
|
220 octave_value (const octave_uint32& i); |
|
221 octave_value (const octave_int64& i); |
|
222 octave_value (const octave_uint64& i); |
|
223 octave_value (const int8NDArray& inda); |
|
224 octave_value (const uint8NDArray& inda); |
|
225 octave_value (const int16NDArray& inda); |
|
226 octave_value (const uint16NDArray& inda); |
|
227 octave_value (const int32NDArray& inda); |
|
228 octave_value (const uint32NDArray& inda); |
|
229 octave_value (const int64NDArray& inda); |
|
230 octave_value (const uint64NDArray& inda); |
2376
|
231 octave_value (double base, double limit, double inc); |
|
232 octave_value (const Range& r); |
|
233 octave_value (const Octave_map& m); |
3340
|
234 octave_value (const octave_stream& s, int n); |
4643
|
235 octave_value (const streamoff_array& off); |
2974
|
236 octave_value (octave_function *f); |
4654
|
237 octave_value (const fcn_handle_array& fha); |
|
238 octave_value (octave_function *f, const std::string &nm); // function handle |
3977
|
239 octave_value (const octave_value_list& m, bool is_cs_list = false); |
2376
|
240 octave_value (octave_value::magic_colon); |
|
241 octave_value (octave_value::all_va_args); |
|
242 |
3933
|
243 octave_value (octave_value *new_rep, int count = 1); |
2376
|
244 |
|
245 // Copy constructor. |
|
246 |
|
247 octave_value (const octave_value& a) |
|
248 { |
|
249 rep = a.rep; |
|
250 rep->count++; |
|
251 } |
|
252 |
3933
|
253 // This should only be called for derived types. |
|
254 |
|
255 virtual octave_value *clone (void) const; |
|
256 |
|
257 virtual octave_value *empty_clone (void) const |
|
258 { return rep->empty_clone (); } |
|
259 |
2376
|
260 // Delete the representation of this constant if the count drops to |
|
261 // zero. |
|
262 |
|
263 virtual ~octave_value (void); |
|
264 |
|
265 void make_unique (void) |
|
266 { |
|
267 if (rep->count > 1) |
|
268 { |
|
269 --rep->count; |
|
270 rep = rep->clone (); |
|
271 rep->count = 1; |
|
272 } |
|
273 } |
|
274 |
|
275 // Simple assignment. |
|
276 |
|
277 octave_value& operator = (const octave_value& a) |
|
278 { |
|
279 if (rep != a.rep) |
|
280 { |
|
281 if (--rep->count == 0) |
|
282 delete rep; |
|
283 |
|
284 rep = a.rep; |
|
285 rep->count++; |
|
286 } |
|
287 |
|
288 return *this; |
|
289 } |
|
290 |
3933
|
291 int get_count (void) const { return rep->count; } |
3239
|
292 |
2409
|
293 virtual type_conv_fcn numeric_conversion_function (void) const |
2376
|
294 { return rep->numeric_conversion_function (); } |
|
295 |
2409
|
296 void maybe_mutate (void); |
|
297 |
4532
|
298 virtual octave_value squeeze (void) const |
|
299 { return rep->squeeze (); } |
|
300 |
2410
|
301 virtual octave_value *try_narrowing_conversion (void) |
|
302 { return rep->try_narrowing_conversion (); } |
2409
|
303 |
4271
|
304 octave_value single_subsref (const std::string& type, |
|
305 const octave_value_list& idx); |
|
306 |
4247
|
307 virtual octave_value subsref (const std::string& type, |
4219
|
308 const std::list<octave_value_list>& idx) |
3933
|
309 { return rep->subsref (type, idx); } |
|
310 |
4247
|
311 virtual octave_value_list subsref (const std::string& type, |
4219
|
312 const std::list<octave_value_list>& idx, |
3933
|
313 int nargout); |
|
314 |
4247
|
315 octave_value next_subsref (const std::string& type, const |
4219
|
316 std::list<octave_value_list>& idx, |
4233
|
317 size_t skip = 1); |
3933
|
318 |
|
319 virtual octave_value do_index_op (const octave_value_list& idx, |
|
320 int resize_ok) |
|
321 { return rep->do_index_op (idx, resize_ok); } |
|
322 |
|
323 octave_value do_index_op (const octave_value_list& idx) |
|
324 { return do_index_op (idx, 0); } |
2376
|
325 |
2974
|
326 virtual octave_value_list |
3544
|
327 do_multi_index_op (int nargout, const octave_value_list& idx); |
2974
|
328 |
4247
|
329 virtual octave_value subsasgn (const std::string& type, |
4219
|
330 const std::list<octave_value_list>& idx, |
3933
|
331 const octave_value& rhs); |
2376
|
332 |
4247
|
333 octave_value assign (assign_op op, const std::string& type, |
4219
|
334 const std::list<octave_value_list>& idx, |
3933
|
335 const octave_value& rhs); |
2948
|
336 |
3933
|
337 const octave_value& assign (assign_op, const octave_value& rhs); |
2948
|
338 |
2376
|
339 virtual idx_vector index_vector (void) const |
|
340 { return rep->index_vector (); } |
|
341 |
|
342 // Size. |
|
343 |
4513
|
344 virtual dim_vector dims (void) const |
|
345 { return rep->dims (); } |
|
346 |
4563
|
347 int rows (void) const; |
|
348 |
|
349 int columns (void) const; |
3195
|
350 |
4563
|
351 int length (void) const; |
4554
|
352 |
4563
|
353 int ndims (void) const; |
|
354 |
|
355 int numel (void) const; |
4559
|
356 |
4791
|
357 virtual size_t byte_size (void) const |
|
358 { return rep->byte_size (); } |
|
359 |
4587
|
360 virtual octave_value reshape (const dim_vector& dv) const |
|
361 { return rep->reshape (dv); } |
4567
|
362 |
4593
|
363 virtual octave_value permute (const Array<int>& vec, bool inv = false) const |
|
364 { return rep->permute (vec, inv); } |
|
365 |
|
366 octave_value ipermute (const Array<int>& vec) const |
|
367 { return rep->permute (vec, true); } |
|
368 |
2376
|
369 // Does this constant have a type? Both of these are provided since |
|
370 // it is sometimes more natural to write is_undefined() instead of |
|
371 // ! is_defined(). |
|
372 |
|
373 virtual bool is_defined (void) const |
|
374 { return rep->is_defined (); } |
|
375 |
|
376 bool is_undefined (void) const |
|
377 { return ! is_defined (); } |
|
378 |
4559
|
379 bool is_empty (void) const |
|
380 { return numel () == 0; } |
|
381 |
3351
|
382 virtual bool is_cell (void) const |
|
383 { return rep->is_cell (); } |
|
384 |
2376
|
385 virtual bool is_real_scalar (void) const |
|
386 { return rep->is_real_scalar (); } |
|
387 |
|
388 virtual bool is_real_matrix (void) const |
|
389 { return rep->is_real_matrix (); } |
|
390 |
4505
|
391 virtual bool is_real_nd_array (void) const |
|
392 { return rep->is_real_nd_array (); } |
|
393 |
2376
|
394 virtual bool is_complex_scalar (void) const |
|
395 { return rep->is_complex_scalar (); } |
|
396 |
|
397 virtual bool is_complex_matrix (void) const |
|
398 { return rep->is_complex_matrix (); } |
|
399 |
4587
|
400 virtual bool is_bool_matrix (void) const |
|
401 { return rep->is_bool_matrix (); } |
|
402 |
2376
|
403 virtual bool is_char_matrix (void) const |
|
404 { return rep->is_char_matrix (); } |
|
405 |
|
406 virtual bool is_string (void) const |
|
407 { return rep->is_string (); } |
|
408 |
|
409 virtual bool is_range (void) const |
|
410 { return rep->is_range (); } |
|
411 |
|
412 virtual bool is_map (void) const |
|
413 { return rep->is_map (); } |
|
414 |
3340
|
415 virtual bool is_stream (void) const |
|
416 { return rep->is_stream (); } |
|
417 |
4643
|
418 virtual bool is_streamoff (void) const |
|
419 { return rep->is_streamoff (); } |
|
420 |
3977
|
421 virtual bool is_cs_list (void) const |
|
422 { return rep->is_cs_list (); } |
|
423 |
2880
|
424 virtual bool is_list (void) const |
|
425 { return rep->is_list (); } |
|
426 |
2376
|
427 virtual bool is_magic_colon (void) const |
|
428 { return rep->is_magic_colon (); } |
|
429 |
|
430 virtual bool is_all_va_args (void) const |
|
431 { return rep->is_all_va_args (); } |
|
432 |
|
433 // Are any or all of the elements in this constant nonzero? |
|
434 |
4015
|
435 virtual octave_value all (int dim = 0) const |
|
436 { return rep->all (dim); } |
2376
|
437 |
4015
|
438 virtual octave_value any (int dim = 0) const |
|
439 { return rep->any (dim); } |
2376
|
440 |
|
441 // Other type stuff. |
|
442 |
3209
|
443 virtual bool is_bool_type (void) const |
|
444 { return rep->is_bool_type (); } |
|
445 |
2376
|
446 virtual bool is_real_type (void) const |
|
447 { return rep->is_real_type (); } |
|
448 |
|
449 virtual bool is_complex_type (void) const |
|
450 { return rep->is_complex_type (); } |
|
451 |
|
452 virtual bool is_scalar_type (void) const |
|
453 { return rep->is_scalar_type (); } |
|
454 |
|
455 virtual bool is_matrix_type (void) const |
|
456 { return rep->is_matrix_type (); } |
|
457 |
|
458 virtual bool is_numeric_type (void) const |
|
459 { return rep->is_numeric_type (); } |
|
460 |
|
461 virtual bool valid_as_scalar_index (void) const |
|
462 { return rep->valid_as_scalar_index (); } |
|
463 |
|
464 virtual bool valid_as_zero_index (void) const |
|
465 { return rep->valid_as_zero_index (); } |
|
466 |
|
467 // Does this constant correspond to a truth value? |
|
468 |
|
469 virtual bool is_true (void) const |
|
470 { return rep->is_true (); } |
|
471 |
|
472 // Are the dimensions of this constant zero by zero? |
|
473 |
|
474 virtual bool is_zero_by_zero (void) const |
|
475 { return rep->is_zero_by_zero (); } |
|
476 |
2974
|
477 virtual bool is_constant (void) const |
|
478 { return rep->is_constant (); } |
|
479 |
4654
|
480 virtual bool is_function_handle (void) const |
|
481 { return rep->is_function_handle (); } |
|
482 |
2974
|
483 virtual bool is_function (void) const |
|
484 { return rep->is_function (); } |
2891
|
485 |
3325
|
486 virtual bool is_builtin_function (void) const |
|
487 { return rep->is_builtin_function (); } |
|
488 |
|
489 virtual bool is_dld_function (void) const |
|
490 { return rep->is_dld_function (); } |
|
491 |
2376
|
492 // Values. |
|
493 |
2891
|
494 octave_value eval (void) { return *this; } |
|
495 |
4254
|
496 virtual short int |
|
497 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
498 { return rep->short_value (req_int, frc_str_conv); } |
|
499 |
|
500 virtual unsigned short int |
|
501 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
502 { return rep->ushort_value (req_int, frc_str_conv); } |
|
503 |
3202
|
504 virtual int int_value (bool req_int = false, bool frc_str_conv = false) const |
|
505 { return rep->int_value (req_int, frc_str_conv); } |
|
506 |
4254
|
507 virtual unsigned int |
|
508 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
509 { return rep->uint_value (req_int, frc_str_conv); } |
|
510 |
3202
|
511 virtual int nint_value (bool frc_str_conv = false) const |
|
512 { return rep->nint_value (frc_str_conv); } |
|
513 |
4254
|
514 virtual long int |
|
515 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
516 { return rep->long_value (req_int, frc_str_conv); } |
|
517 |
|
518 virtual unsigned long int |
|
519 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
520 { return rep->ulong_value (req_int, frc_str_conv); } |
|
521 |
2376
|
522 virtual double double_value (bool frc_str_conv = false) const |
|
523 { return rep->double_value (frc_str_conv); } |
|
524 |
2916
|
525 virtual double scalar_value (bool frc_str_conv = false) const |
|
526 { return rep->scalar_value (frc_str_conv); } |
|
527 |
3351
|
528 virtual Cell cell_value (void) const; |
|
529 |
2376
|
530 virtual Matrix matrix_value (bool frc_str_conv = false) const |
|
531 { return rep->matrix_value (frc_str_conv); } |
|
532 |
4550
|
533 virtual NDArray array_value (bool frc_str_conv = false) const |
|
534 { return rep->array_value (frc_str_conv); } |
4505
|
535 |
2376
|
536 virtual Complex complex_value (bool frc_str_conv = false) const |
|
537 { return rep->complex_value (frc_str_conv); } |
|
538 |
|
539 virtual ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
|
540 { return rep->complex_matrix_value (frc_str_conv); } |
|
541 |
4550
|
542 virtual ComplexNDArray complex_array_value (bool frc_str_conv = false) const |
|
543 { return rep->complex_array_value (frc_str_conv); } |
|
544 |
|
545 virtual bool bool_value (void) const |
|
546 { return rep->bool_value (); } |
|
547 |
|
548 virtual boolMatrix bool_matrix_value (void) const |
|
549 { return rep->bool_matrix_value (); } |
|
550 |
|
551 virtual boolNDArray bool_array_value (void) const |
|
552 { return rep->bool_array_value (); } |
|
553 |
2376
|
554 virtual charMatrix char_matrix_value (bool frc_str_conv = false) const |
|
555 { return rep->char_matrix_value (frc_str_conv); } |
|
556 |
4550
|
557 virtual charNDArray char_array_value (bool frc_str_conv = false) const |
|
558 { return rep->char_array_value (frc_str_conv); } |
|
559 |
4906
|
560 virtual int8NDArray int8_array_value (void) const |
|
561 { return rep->int8_array_value (); } |
|
562 |
|
563 virtual int16NDArray int16_array_value (void) const |
|
564 { return rep->int16_array_value (); } |
|
565 |
|
566 virtual int32NDArray int32_array_value (void) const |
|
567 { return rep->int32_array_value (); } |
|
568 |
|
569 virtual int64NDArray int64_array_value (void) const |
|
570 { return rep->int64_array_value (); } |
|
571 |
|
572 virtual uint8NDArray uint8_array_value (void) const |
|
573 { return rep->uint8_array_value (); } |
|
574 |
|
575 virtual uint16NDArray uint16_array_value (void) const |
|
576 { return rep->uint16_array_value (); } |
|
577 |
|
578 virtual uint32NDArray uint32_array_value (void) const |
|
579 { return rep->uint32_array_value (); } |
|
580 |
|
581 virtual uint64NDArray uint64_array_value (void) const |
|
582 { return rep->uint64_array_value (); } |
|
583 |
4457
|
584 virtual string_vector all_strings (bool pad = false, |
|
585 bool force = false) const |
4661
|
586 { return rep->all_strings (pad, force); } |
2376
|
587 |
4457
|
588 virtual std::string string_value (bool force = false) const |
4665
|
589 { return rep->string_value (force); } |
2376
|
590 |
|
591 virtual Range range_value (void) const |
|
592 { return rep->range_value (); } |
|
593 |
|
594 virtual Octave_map map_value (void) const; |
|
595 |
3933
|
596 virtual string_vector map_keys (void) const |
|
597 { return rep->map_keys (); } |
|
598 |
3340
|
599 virtual octave_stream stream_value (void) const; |
2903
|
600 |
|
601 virtual int stream_number (void) const; |
|
602 |
4645
|
603 virtual std::streamoff streamoff_value (void) const; |
|
604 |
|
605 virtual streamoff_array streamoff_array_value (void) const; |
4643
|
606 |
2974
|
607 virtual octave_function *function_value (bool silent = false); |
|
608 |
4700
|
609 virtual octave_user_function *user_function_value (bool silent = false); |
|
610 |
4346
|
611 virtual octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
612 |
2880
|
613 virtual octave_value_list list_value (void) const; |
|
614 |
3419
|
615 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
616 bool frc_vec_conv = false) const; |
|
617 |
|
618 ComplexColumnVector |
3419
|
619 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
620 bool frc_vec_conv = false) const; |
|
621 |
3419
|
622 RowVector row_vector_value (bool frc_str_conv = false, |
|
623 bool frc_vec_conv = false) const; |
|
624 |
|
625 ComplexRowVector |
|
626 complex_row_vector_value (bool frc_str_conv = false, |
|
627 bool frc_vec_conv = false) const; |
|
628 |
4044
|
629 Array<int> int_vector_value (bool req_int = false, |
|
630 bool frc_str_conv = false, |
|
631 bool frc_vec_conv = false) const; |
|
632 |
3419
|
633 Array<double> vector_value (bool frc_str_conv = false, |
|
634 bool frc_vec_conv = false) const; |
|
635 |
|
636 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
637 bool frc_vec_conv = false) const; |
|
638 |
2376
|
639 // Conversions. These should probably be private. If a user of this |
|
640 // class wants a certain kind of constant, he should simply ask for |
|
641 // it, and we should convert it if possible. |
|
642 |
4457
|
643 octave_value convert_to_str (bool pad = false, bool force = false) const; |
4452
|
644 |
4457
|
645 virtual octave_value convert_to_str_internal (bool pad, bool force) const |
|
646 { return rep->convert_to_str_internal (pad, force); } |
2376
|
647 |
|
648 virtual void convert_to_row_or_column_vector (void) |
|
649 { rep->convert_to_row_or_column_vector (); } |
|
650 |
4604
|
651 virtual bool print_as_scalar (void) const |
|
652 { return rep->print_as_scalar (); } |
|
653 |
3523
|
654 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
655 { rep->print (os, pr_as_read_syntax); } |
2376
|
656 |
4457
|
657 virtual void print_raw (std::ostream& os, |
|
658 bool pr_as_read_syntax = false) const |
2903
|
659 { rep->print_raw (os, pr_as_read_syntax); } |
|
660 |
3523
|
661 virtual bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
662 { return rep->print_name_tag (os, name); } |
2376
|
663 |
3523
|
664 void print_with_name (std::ostream& os, const std::string& name, |
2903
|
665 bool print_padding = true) const; |
2376
|
666 |
|
667 virtual int type_id (void) const { return rep->type_id (); } |
|
668 |
3523
|
669 virtual std::string type_name (void) const { return rep->type_name (); } |
2376
|
670 |
4612
|
671 virtual std::string class_name (void) const { return rep->class_name (); } |
|
672 |
3203
|
673 // Unary and binary operations. |
|
674 |
3933
|
675 friend octave_value do_unary_op (unary_op op, |
|
676 const octave_value& a); |
3203
|
677 |
3933
|
678 const octave_value& do_non_const_unary_op (unary_op op); |
|
679 |
|
680 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
681 |
4247
|
682 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
683 const std::list<octave_value_list>& idx); |
3205
|
684 |
3933
|
685 friend octave_value do_binary_op (binary_op op, |
|
686 const octave_value& a, |
|
687 const octave_value& b); |
2376
|
688 |
3301
|
689 const octave_value& get_rep (void) const { return *rep; } |
|
690 |
3933
|
691 virtual void print_info (std::ostream& os, |
|
692 const std::string& prefix = std::string ()) const; |
|
693 |
4687
|
694 virtual bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
695 bool strip_nan_and_inf) |
|
696 { return rep->save_ascii (os, infnan_warned, strip_nan_and_inf); } |
|
697 |
|
698 virtual bool load_ascii (std::istream& is) |
|
699 { return rep->load_ascii (is); } |
|
700 |
|
701 virtual bool save_binary (std::ostream& os, bool& save_as_floats) |
|
702 { return rep->save_binary (os, save_as_floats); } |
|
703 |
|
704 virtual bool load_binary (std::istream& is, bool swap, |
|
705 oct_mach_info::float_format fmt) |
|
706 { return rep->load_binary (is, swap, fmt); } |
|
707 |
|
708 #if defined (HAVE_HDF5) |
|
709 virtual bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
|
710 { return rep->save_hdf5 (loc_id, name, save_as_floats); } |
|
711 |
|
712 virtual bool load_hdf5 (hid_t loc_id, const char *name, |
|
713 bool have_h5giterate_bug) |
|
714 { return rep->load_hdf5 (loc_id, name, have_h5giterate_bug); } |
|
715 #endif |
|
716 |
4901
|
717 octave_value *internal_rep (void) const { return rep; } |
|
718 |
2376
|
719 protected: |
|
720 |
|
721 octave_value (const octave_xvalue&) : rep (0) { } |
|
722 |
3933
|
723 // This should only be called for derived types. |
|
724 |
4247
|
725 octave_value numeric_assign (const std::string& type, |
4219
|
726 const std::list<octave_value_list>& idx, |
3933
|
727 const octave_value& rhs); |
|
728 |
2903
|
729 void reset_indent_level (void) const |
|
730 { curr_print_indent_level = 0; } |
|
731 |
|
732 void increment_indent_level (void) const |
|
733 { curr_print_indent_level += 2; } |
|
734 |
|
735 void decrement_indent_level (void) const |
|
736 { curr_print_indent_level -= 2; } |
|
737 |
|
738 int current_print_indent_level (void) const |
|
739 { return curr_print_indent_level; } |
|
740 |
3523
|
741 void newline (std::ostream& os) const; |
2903
|
742 |
3523
|
743 void indent (std::ostream& os) const; |
2903
|
744 |
|
745 void reset (void) const; |
|
746 |
2376
|
747 union |
|
748 { |
|
749 octave_value *rep; // The real representation. |
|
750 int count; // A reference count. |
|
751 }; |
2413
|
752 |
3933
|
753 private: |
2903
|
754 |
|
755 static int curr_print_indent_level; |
|
756 static bool beginning_of_line; |
3204
|
757 |
3205
|
758 assign_op unary_op_to_assign_op (unary_op op); |
|
759 |
3204
|
760 binary_op op_eq_to_binary_op (assign_op op); |
|
761 |
3219
|
762 DECLARE_OCTAVE_ALLOCATOR |
4513
|
763 |
|
764 octave_value *nil_rep (void) const; |
2376
|
765 }; |
|
766 |
3203
|
767 #define OV_UNOP_FN(name) \ |
|
768 inline octave_value \ |
|
769 name (const octave_value& a) \ |
|
770 { \ |
|
771 return do_unary_op (octave_value::name, a); \ |
|
772 } |
|
773 |
|
774 #define OV_UNOP_OP(name, op) \ |
|
775 inline octave_value \ |
|
776 operator op (const octave_value& a) \ |
|
777 { \ |
|
778 return name (a); \ |
|
779 } |
|
780 |
|
781 #define OV_UNOP_FN_OP(name, op) \ |
|
782 OV_UNOP_FN (name) \ |
|
783 OV_UNOP_OP (name, op) |
|
784 |
3525
|
785 OV_UNOP_FN_OP (op_not, !) |
|
786 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
787 |
3525
|
788 OV_UNOP_FN (op_transpose) |
|
789 OV_UNOP_FN (op_hermitian) |
3203
|
790 |
|
791 // No simple way to define these for prefix and suffix ops? |
|
792 // |
|
793 // incr |
|
794 // decr |
|
795 |
|
796 #define OV_BINOP_FN(name) \ |
|
797 inline octave_value \ |
|
798 name (const octave_value& a1, const octave_value& a2) \ |
|
799 { \ |
|
800 return do_binary_op (octave_value::name, a1, a2); \ |
|
801 } |
|
802 |
|
803 #define OV_BINOP_OP(name, op) \ |
|
804 inline octave_value \ |
|
805 operator op (const octave_value& a1, const octave_value& a2) \ |
|
806 { \ |
|
807 return name (a1, a2); \ |
|
808 } |
|
809 |
|
810 #define OV_BINOP_FN_OP(name, op) \ |
|
811 OV_BINOP_FN (name) \ |
|
812 OV_BINOP_OP (name, op) |
|
813 |
3525
|
814 OV_BINOP_FN_OP (op_add, +) |
|
815 OV_BINOP_FN_OP (op_sub, -) |
|
816 OV_BINOP_FN_OP (op_mul, *) |
|
817 OV_BINOP_FN_OP (op_div, /) |
3203
|
818 |
3525
|
819 OV_BINOP_FN (op_pow) |
|
820 OV_BINOP_FN (op_ldiv) |
|
821 OV_BINOP_FN (op_lshift) |
|
822 OV_BINOP_FN (op_rshift) |
3203
|
823 |
3525
|
824 OV_BINOP_FN_OP (op_lt, <) |
|
825 OV_BINOP_FN_OP (op_le, <=) |
|
826 OV_BINOP_FN_OP (op_eq, ==) |
|
827 OV_BINOP_FN_OP (op_ge, >=) |
|
828 OV_BINOP_FN_OP (op_gt, >) |
|
829 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
830 |
3525
|
831 OV_BINOP_FN (op_el_mul) |
|
832 OV_BINOP_FN (op_el_div) |
|
833 OV_BINOP_FN (op_el_pow) |
|
834 OV_BINOP_FN (op_el_ldiv) |
|
835 OV_BINOP_FN (op_el_and) |
|
836 OV_BINOP_FN (op_el_or) |
3203
|
837 |
3525
|
838 OV_BINOP_FN (op_struct_ref) |
3203
|
839 |
3219
|
840 // T_ID is the type id of struct objects, set by register_type(). |
|
841 // T_NAME is the type name of struct objects. |
|
842 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \ |
|
843 public: \ |
|
844 int type_id (void) const { return t_id; } \ |
3523
|
845 std::string type_name (void) const { return t_name; } \ |
4612
|
846 std::string class_name (void) const { return c_name; } \ |
4252
|
847 static int static_type_id (void) { return t_id; } \ |
4901
|
848 static std::string static_type_name (void) { return t_name; } \ |
|
849 static std::string static_class_name (void) { return c_name; } \ |
4640
|
850 static void register_type (void); \ |
3219
|
851 \ |
|
852 private: \ |
4252
|
853 static int t_id; \ |
4612
|
854 static const std::string t_name; \ |
|
855 static const std::string c_name; |
3219
|
856 |
4612
|
857 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \ |
4252
|
858 int t::t_id (-1); \ |
4612
|
859 const std::string t::t_name (n); \ |
4640
|
860 const std::string t::c_name (c); \ |
|
861 void t::register_type (void) \ |
|
862 { \ |
|
863 t_id = octave_value_typeinfo::register_type (t::t_name, \ |
|
864 t::c_name, \ |
4645
|
865 octave_value (new t ())); \ |
4640
|
866 } |
3219
|
867 |
4455
|
868 // If TRUE, print a warning for assignments like |
2376
|
869 // |
|
870 // octave> A(1) = 3; A(2) = 5 |
|
871 // |
|
872 // for A already defined and a matrix type. |
4455
|
873 extern bool Vwarn_fortran_indexing; |
2376
|
874 |
4452
|
875 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
876 // to a character string? |
|
877 extern bool Vwarn_num_to_str; |
4257
|
878 |
4452
|
879 // If TRUE, warn for operations like |
2376
|
880 // |
|
881 // octave> 'abc' + 0 |
|
882 // 97 98 99 |
|
883 // |
4452
|
884 extern int Vwarn_str_to_num; |
2376
|
885 |
4451
|
886 // Should we warn about conversions from complex to real? |
|
887 extern int Vwarn_imag_to_real; |
2376
|
888 |
|
889 // If TRUE, print the name along with the value. |
|
890 extern bool Vprint_answer_id_name; |
|
891 |
|
892 // How many levels of structure elements should we print? |
|
893 extern int Vstruct_levels_to_print; |
|
894 |
|
895 // Allow divide by zero errors to be suppressed. |
|
896 extern bool Vwarn_divide_by_zero; |
|
897 |
4461
|
898 // If TRUE, print a warning when a matrix is resized by an indexed |
|
899 // assignment with indices outside the current bounds. |
|
900 extern bool Vwarn_resize_on_range_error; |
3195
|
901 |
2376
|
902 // Indentation level for structures. |
|
903 extern int struct_indent; |
|
904 |
|
905 extern void increment_struct_indent (void); |
|
906 extern void decrement_struct_indent (void); |
|
907 |
2880
|
908 // Indentation level for lists. |
|
909 extern int list_indent; |
|
910 |
|
911 extern void increment_list_indent (void); |
|
912 extern void decrement_list_indent (void); |
|
913 |
2376
|
914 extern void install_types (void); |
|
915 |
|
916 #endif |
|
917 |
|
918 /* |
|
919 ;; Local Variables: *** |
|
920 ;; mode: C++ *** |
|
921 ;; End: *** |
|
922 */ |