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