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