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