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