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