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