2376
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
2376
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2376
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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); |
7064
|
210 octave_value (const ArrayN<octave_int8>& inda); |
4910
|
211 octave_value (const int16NDArray& inda); |
7064
|
212 octave_value (const ArrayN<octave_int16>& inda); |
4910
|
213 octave_value (const int32NDArray& inda); |
7064
|
214 octave_value (const ArrayN<octave_int32>& inda); |
4910
|
215 octave_value (const int64NDArray& inda); |
7064
|
216 octave_value (const ArrayN<octave_int64>& inda); |
4901
|
217 octave_value (const uint8NDArray& inda); |
7064
|
218 octave_value (const ArrayN<octave_uint8>& inda); |
4901
|
219 octave_value (const uint16NDArray& inda); |
7064
|
220 octave_value (const ArrayN<octave_uint16>& inda); |
4901
|
221 octave_value (const uint32NDArray& inda); |
7064
|
222 octave_value (const ArrayN<octave_uint32>& inda); |
4901
|
223 octave_value (const uint64NDArray& inda); |
7064
|
224 octave_value (const ArrayN<octave_uint64>& inda); |
2376
|
225 octave_value (double base, double limit, double inc); |
|
226 octave_value (const Range& r); |
|
227 octave_value (const Octave_map& m); |
4643
|
228 octave_value (const streamoff_array& off); |
3977
|
229 octave_value (const octave_value_list& m, bool is_cs_list = false); |
2376
|
230 octave_value (octave_value::magic_colon); |
|
231 |
5759
|
232 octave_value (octave_base_value *new_rep); |
2376
|
233 |
|
234 // Copy constructor. |
|
235 |
|
236 octave_value (const octave_value& a) |
|
237 { |
|
238 rep = a.rep; |
|
239 rep->count++; |
|
240 } |
|
241 |
3933
|
242 // This should only be called for derived types. |
|
243 |
5759
|
244 octave_base_value *clone (void) const; |
3933
|
245 |
5759
|
246 octave_base_value *empty_clone (void) const |
3933
|
247 { return rep->empty_clone (); } |
|
248 |
2376
|
249 // Delete the representation of this constant if the count drops to |
|
250 // zero. |
|
251 |
6338
|
252 ~octave_value (void) |
|
253 { |
|
254 if (--rep->count == 0) |
|
255 delete rep; |
|
256 } |
2376
|
257 |
|
258 void make_unique (void) |
|
259 { |
|
260 if (rep->count > 1) |
|
261 { |
|
262 --rep->count; |
|
263 rep = rep->clone (); |
|
264 rep->count = 1; |
|
265 } |
|
266 } |
|
267 |
|
268 // Simple assignment. |
|
269 |
|
270 octave_value& operator = (const octave_value& a) |
|
271 { |
|
272 if (rep != a.rep) |
|
273 { |
|
274 if (--rep->count == 0) |
|
275 delete rep; |
|
276 |
|
277 rep = a.rep; |
|
278 rep->count++; |
|
279 } |
|
280 |
|
281 return *this; |
|
282 } |
|
283 |
3933
|
284 int get_count (void) const { return rep->count; } |
3239
|
285 |
5759
|
286 octave_base_value::type_conv_fcn numeric_conversion_function (void) const |
2376
|
287 { return rep->numeric_conversion_function (); } |
|
288 |
2409
|
289 void maybe_mutate (void); |
|
290 |
5759
|
291 octave_value squeeze (void) const |
4532
|
292 { return rep->squeeze (); } |
|
293 |
5759
|
294 octave_base_value *try_narrowing_conversion (void) |
2410
|
295 { return rep->try_narrowing_conversion (); } |
2409
|
296 |
4271
|
297 octave_value single_subsref (const std::string& type, |
|
298 const octave_value_list& idx); |
|
299 |
5759
|
300 octave_value subsref (const std::string& type, |
4219
|
301 const std::list<octave_value_list>& idx) |
3933
|
302 { return rep->subsref (type, idx); } |
|
303 |
5759
|
304 octave_value_list subsref (const std::string& type, |
4219
|
305 const std::list<octave_value_list>& idx, |
3933
|
306 int nargout); |
|
307 |
4247
|
308 octave_value next_subsref (const std::string& type, const |
4219
|
309 std::list<octave_value_list>& idx, |
4233
|
310 size_t skip = 1); |
3933
|
311 |
4994
|
312 octave_value_list next_subsref (int nargout, |
|
313 const std::string& type, const |
|
314 std::list<octave_value_list>& idx, |
|
315 size_t skip = 1); |
|
316 |
5759
|
317 octave_value do_index_op (const octave_value_list& idx, |
5885
|
318 bool resize_ok = false) |
3933
|
319 { return rep->do_index_op (idx, resize_ok); } |
|
320 |
5759
|
321 octave_value_list |
3544
|
322 do_multi_index_op (int nargout, const octave_value_list& idx); |
2974
|
323 |
5759
|
324 octave_value subsasgn (const std::string& type, |
4219
|
325 const std::list<octave_value_list>& idx, |
3933
|
326 const octave_value& rhs); |
2376
|
327 |
4247
|
328 octave_value assign (assign_op op, const std::string& type, |
4219
|
329 const std::list<octave_value_list>& idx, |
3933
|
330 const octave_value& rhs); |
2948
|
331 |
3933
|
332 const octave_value& assign (assign_op, const octave_value& rhs); |
2948
|
333 |
5759
|
334 idx_vector index_vector (void) const |
2376
|
335 { return rep->index_vector (); } |
|
336 |
|
337 // Size. |
|
338 |
5759
|
339 dim_vector dims (void) const |
4513
|
340 { return rep->dims (); } |
|
341 |
5759
|
342 octave_idx_type rows (void) const { return rep->rows (); } |
4563
|
343 |
5759
|
344 octave_idx_type columns (void) const { return rep->columns (); } |
3195
|
345 |
5275
|
346 octave_idx_type length (void) const; |
4554
|
347 |
5759
|
348 int ndims (void) const { return rep->ndims (); } |
4563
|
349 |
5164
|
350 bool all_zero_dims (void) const { return dims().all_zero (); } |
|
351 |
5759
|
352 octave_idx_type numel (void) const |
5080
|
353 { return rep->numel (); } |
4559
|
354 |
5759
|
355 octave_idx_type capacity (void) const |
5164
|
356 { return rep->capacity (); } |
|
357 |
5659
|
358 Matrix size (void) const; |
|
359 |
5759
|
360 size_t byte_size (void) const |
4791
|
361 { return rep->byte_size (); } |
|
362 |
5759
|
363 octave_idx_type nnz (void) const { return rep->nnz (); } |
5602
|
364 |
5759
|
365 octave_idx_type nzmax (void) const { return rep->nzmax (); } |
5604
|
366 |
5900
|
367 octave_idx_type nfields (void) const { return rep->nfields (); } |
|
368 |
5759
|
369 octave_value reshape (const dim_vector& dv) const |
4587
|
370 { return rep->reshape (dv); } |
4567
|
371 |
5759
|
372 octave_value permute (const Array<int>& vec, bool inv = false) const |
4593
|
373 { return rep->permute (vec, inv); } |
|
374 |
|
375 octave_value ipermute (const Array<int>& vec) const |
|
376 { return rep->permute (vec, true); } |
|
377 |
5759
|
378 octave_value resize (const dim_vector& dv, bool fill = false) const |
|
379 { return rep->resize (dv, fill);} |
4915
|
380 |
5785
|
381 MatrixType matrix_type (void) const |
|
382 { return rep->matrix_type (); } |
|
383 |
|
384 MatrixType matrix_type (const MatrixType& typ) const |
|
385 { return rep->matrix_type (typ); } |
|
386 |
2376
|
387 // Does this constant have a type? Both of these are provided since |
|
388 // it is sometimes more natural to write is_undefined() instead of |
|
389 // ! is_defined(). |
|
390 |
5759
|
391 bool is_defined (void) const |
2376
|
392 { return rep->is_defined (); } |
|
393 |
|
394 bool is_undefined (void) const |
|
395 { return ! is_defined (); } |
|
396 |
4559
|
397 bool is_empty (void) const |
5759
|
398 { return rep->is_empty (); } |
4559
|
399 |
5759
|
400 bool is_cell (void) const |
3351
|
401 { return rep->is_cell (); } |
|
402 |
6116
|
403 bool is_cellstr (void) const |
|
404 { return rep->is_cellstr (); } |
|
405 |
5759
|
406 bool is_real_scalar (void) const |
2376
|
407 { return rep->is_real_scalar (); } |
|
408 |
5759
|
409 bool is_real_matrix (void) const |
2376
|
410 { return rep->is_real_matrix (); } |
|
411 |
5759
|
412 bool is_real_nd_array (void) const |
4505
|
413 { return rep->is_real_nd_array (); } |
|
414 |
5759
|
415 bool is_complex_scalar (void) const |
2376
|
416 { return rep->is_complex_scalar (); } |
|
417 |
5759
|
418 bool is_complex_matrix (void) const |
2376
|
419 { return rep->is_complex_matrix (); } |
|
420 |
5881
|
421 bool is_bool_scalar (void) const |
|
422 { return rep->is_bool_scalar (); } |
|
423 |
5759
|
424 bool is_bool_matrix (void) const |
4587
|
425 { return rep->is_bool_matrix (); } |
|
426 |
5759
|
427 bool is_char_matrix (void) const |
2376
|
428 { return rep->is_char_matrix (); } |
|
429 |
5759
|
430 bool is_string (void) const |
2376
|
431 { return rep->is_string (); } |
|
432 |
5759
|
433 bool is_sq_string (void) const |
5279
|
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 |
5759
|
439 bool is_range (void) const |
2376
|
440 { return rep->is_range (); } |
|
441 |
5759
|
442 bool is_map (void) const |
2376
|
443 { return rep->is_map (); } |
|
444 |
5759
|
445 bool is_streamoff (void) const |
4643
|
446 { return rep->is_streamoff (); } |
|
447 |
5759
|
448 bool is_cs_list (void) const |
3977
|
449 { return rep->is_cs_list (); } |
|
450 |
5759
|
451 bool is_list (void) const |
2880
|
452 { return rep->is_list (); } |
|
453 |
5759
|
454 bool is_magic_colon (void) const |
2376
|
455 { return rep->is_magic_colon (); } |
|
456 |
|
457 // Are any or all of the elements in this constant nonzero? |
|
458 |
5759
|
459 octave_value all (int dim = 0) const |
4015
|
460 { return rep->all (dim); } |
2376
|
461 |
5759
|
462 octave_value any (int dim = 0) const |
4015
|
463 { return rep->any (dim); } |
2376
|
464 |
5895
|
465 // Floating point types. |
|
466 |
|
467 bool is_double_type (void) const |
|
468 { return rep->is_double_type (); } |
|
469 |
|
470 bool is_single_type (void) const |
|
471 { return rep->is_single_type (); } |
|
472 |
|
473 // Integer types. |
|
474 |
|
475 bool is_int8_type (void) const |
|
476 { return rep->is_int8_type (); } |
|
477 |
|
478 bool is_int16_type (void) const |
|
479 { return rep->is_int16_type (); } |
|
480 |
|
481 bool is_int32_type (void) const |
|
482 { return rep->is_int32_type (); } |
|
483 |
|
484 bool is_int64_type (void) const |
|
485 { return rep->is_int64_type (); } |
|
486 |
|
487 bool is_uint8_type (void) const |
|
488 { return rep->is_uint8_type (); } |
|
489 |
|
490 bool is_uint16_type (void) const |
|
491 { return rep->is_uint16_type (); } |
|
492 |
|
493 bool is_uint32_type (void) const |
|
494 { return rep->is_uint32_type (); } |
|
495 |
|
496 bool is_uint64_type (void) const |
|
497 { return rep->is_uint64_type (); } |
|
498 |
2376
|
499 // Other type stuff. |
|
500 |
5759
|
501 bool is_bool_type (void) const |
3209
|
502 { return rep->is_bool_type (); } |
|
503 |
6223
|
504 bool is_integer_type (void) const |
|
505 { return rep->is_integer_type (); } |
|
506 |
5759
|
507 bool is_real_type (void) const |
2376
|
508 { return rep->is_real_type (); } |
|
509 |
5759
|
510 bool is_complex_type (void) const |
2376
|
511 { return rep->is_complex_type (); } |
|
512 |
5759
|
513 bool is_scalar_type (void) const |
2376
|
514 { return rep->is_scalar_type (); } |
|
515 |
5759
|
516 bool is_matrix_type (void) const |
2376
|
517 { return rep->is_matrix_type (); } |
|
518 |
5759
|
519 bool is_numeric_type (void) const |
2376
|
520 { return rep->is_numeric_type (); } |
|
521 |
5759
|
522 bool is_sparse_type (void) const |
5631
|
523 { return rep->is_sparse_type (); } |
|
524 |
5759
|
525 bool valid_as_scalar_index (void) const |
2376
|
526 { return rep->valid_as_scalar_index (); } |
|
527 |
5759
|
528 bool valid_as_zero_index (void) const |
2376
|
529 { return rep->valid_as_zero_index (); } |
|
530 |
|
531 // Does this constant correspond to a truth value? |
|
532 |
5759
|
533 bool is_true (void) const |
2376
|
534 { return rep->is_true (); } |
|
535 |
|
536 // Are the dimensions of this constant zero by zero? |
|
537 |
5759
|
538 bool is_zero_by_zero (void) const |
|
539 { return (rows () == 0 && columns () == 0); } |
2376
|
540 |
5759
|
541 bool is_constant (void) const |
2974
|
542 { return rep->is_constant (); } |
|
543 |
5759
|
544 bool is_function_handle (void) const |
4654
|
545 { return rep->is_function_handle (); } |
|
546 |
5759
|
547 bool is_inline_function (void) const |
4954
|
548 { return rep->is_inline_function (); } |
|
549 |
5759
|
550 bool is_function (void) const |
2974
|
551 { return rep->is_function (); } |
2891
|
552 |
5759
|
553 bool is_builtin_function (void) const |
3325
|
554 { return rep->is_builtin_function (); } |
|
555 |
5759
|
556 bool is_dld_function (void) const |
3325
|
557 { return rep->is_dld_function (); } |
|
558 |
5864
|
559 bool is_mex_function (void) const |
|
560 { return rep->is_mex_function (); } |
|
561 |
2376
|
562 // Values. |
|
563 |
2891
|
564 octave_value eval (void) { return *this; } |
|
565 |
5759
|
566 short int |
4254
|
567 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
568 { return rep->short_value (req_int, frc_str_conv); } |
|
569 |
5759
|
570 unsigned short int |
4254
|
571 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
572 { return rep->ushort_value (req_int, frc_str_conv); } |
|
573 |
5759
|
574 int int_value (bool req_int = false, bool frc_str_conv = false) const |
3202
|
575 { return rep->int_value (req_int, frc_str_conv); } |
|
576 |
5759
|
577 unsigned int |
4254
|
578 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
579 { return rep->uint_value (req_int, frc_str_conv); } |
|
580 |
5759
|
581 int nint_value (bool frc_str_conv = false) const |
3202
|
582 { return rep->nint_value (frc_str_conv); } |
|
583 |
5759
|
584 long int |
4254
|
585 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
586 { return rep->long_value (req_int, frc_str_conv); } |
|
587 |
5759
|
588 unsigned long int |
4254
|
589 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
590 { return rep->ulong_value (req_int, frc_str_conv); } |
|
591 |
6133
|
592 octave_idx_type |
|
593 idx_type_value (bool req_int = false, bool frc_str_conv = false) const |
|
594 { |
|
595 #if SIZEOF_OCTAVE_IDX_TYPE == SIZEOF_LONG |
|
596 return long_value (req_int, frc_str_conv); |
|
597 #elif SIZEOF_OCTAVE_IDX_TYPE == SIZEOF_INT |
|
598 return int_value (req_int, frc_str_conv); |
|
599 #else |
|
600 #error "no octave_value extractor for octave_idx_type" |
|
601 #endif |
|
602 } |
|
603 |
5759
|
604 double double_value (bool frc_str_conv = false) const |
2376
|
605 { return rep->double_value (frc_str_conv); } |
|
606 |
5759
|
607 double scalar_value (bool frc_str_conv = false) const |
2916
|
608 { return rep->scalar_value (frc_str_conv); } |
|
609 |
5759
|
610 Cell cell_value (void) const; |
3351
|
611 |
5759
|
612 Matrix matrix_value (bool frc_str_conv = false) const |
2376
|
613 { return rep->matrix_value (frc_str_conv); } |
|
614 |
5759
|
615 NDArray array_value (bool frc_str_conv = false) const |
4550
|
616 { return rep->array_value (frc_str_conv); } |
4505
|
617 |
5759
|
618 Complex complex_value (bool frc_str_conv = false) const |
2376
|
619 { return rep->complex_value (frc_str_conv); } |
|
620 |
5759
|
621 ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
2376
|
622 { return rep->complex_matrix_value (frc_str_conv); } |
|
623 |
5759
|
624 ComplexNDArray complex_array_value (bool frc_str_conv = false) const |
4550
|
625 { return rep->complex_array_value (frc_str_conv); } |
|
626 |
5943
|
627 bool bool_value (bool warn = false) const |
|
628 { return rep->bool_value (warn); } |
4550
|
629 |
5943
|
630 boolMatrix bool_matrix_value (bool warn = false) const |
|
631 { return rep->bool_matrix_value (warn); } |
4550
|
632 |
5943
|
633 boolNDArray bool_array_value (bool warn = false) const |
|
634 { return rep->bool_array_value (warn); } |
4550
|
635 |
5759
|
636 charMatrix char_matrix_value (bool frc_str_conv = false) const |
2376
|
637 { return rep->char_matrix_value (frc_str_conv); } |
|
638 |
5759
|
639 charNDArray char_array_value (bool frc_str_conv = false) const |
4550
|
640 { return rep->char_array_value (frc_str_conv); } |
|
641 |
5759
|
642 SparseMatrix sparse_matrix_value (bool frc_str_conv = false) const |
|
643 { return rep->sparse_matrix_value (frc_str_conv); } |
5164
|
644 |
5759
|
645 SparseComplexMatrix sparse_complex_matrix_value (bool frc_str_conv = false) const |
|
646 { return rep->sparse_complex_matrix_value (frc_str_conv); } |
5164
|
647 |
5759
|
648 SparseBoolMatrix sparse_bool_matrix_value (bool frc_str_conv = false) const |
|
649 { return rep->sparse_bool_matrix_value (frc_str_conv); } |
5164
|
650 |
5759
|
651 octave_int8 int8_scalar_value (void) const |
4910
|
652 { return rep->int8_scalar_value (); } |
|
653 |
5759
|
654 octave_int16 int16_scalar_value (void) const |
4910
|
655 { return rep->int16_scalar_value (); } |
|
656 |
5759
|
657 octave_int32 int32_scalar_value (void) const |
4910
|
658 { return rep->int32_scalar_value (); } |
|
659 |
5759
|
660 octave_int64 int64_scalar_value (void) const |
4910
|
661 { return rep->int64_scalar_value (); } |
|
662 |
5759
|
663 octave_uint8 uint8_scalar_value (void) const |
4910
|
664 { return rep->uint8_scalar_value (); } |
|
665 |
5759
|
666 octave_uint16 uint16_scalar_value (void) const |
4910
|
667 { return rep->uint16_scalar_value (); } |
|
668 |
5759
|
669 octave_uint32 uint32_scalar_value (void) const |
4910
|
670 { return rep->uint32_scalar_value (); } |
|
671 |
5759
|
672 octave_uint64 uint64_scalar_value (void) const |
4910
|
673 { return rep->uint64_scalar_value (); } |
|
674 |
5759
|
675 int8NDArray int8_array_value (void) const |
4906
|
676 { return rep->int8_array_value (); } |
|
677 |
5759
|
678 int16NDArray int16_array_value (void) const |
4906
|
679 { return rep->int16_array_value (); } |
|
680 |
5759
|
681 int32NDArray int32_array_value (void) const |
4906
|
682 { return rep->int32_array_value (); } |
|
683 |
5759
|
684 int64NDArray int64_array_value (void) const |
4906
|
685 { return rep->int64_array_value (); } |
|
686 |
5759
|
687 uint8NDArray uint8_array_value (void) const |
4906
|
688 { return rep->uint8_array_value (); } |
|
689 |
5759
|
690 uint16NDArray uint16_array_value (void) const |
4906
|
691 { return rep->uint16_array_value (); } |
|
692 |
5759
|
693 uint32NDArray uint32_array_value (void) const |
4906
|
694 { return rep->uint32_array_value (); } |
|
695 |
5759
|
696 uint64NDArray uint64_array_value (void) const |
4906
|
697 { return rep->uint64_array_value (); } |
|
698 |
5759
|
699 string_vector all_strings (bool pad = false) const |
5715
|
700 { return rep->all_strings (pad); } |
2376
|
701 |
5759
|
702 std::string string_value (bool force = false) const |
4665
|
703 { return rep->string_value (force); } |
2376
|
704 |
5759
|
705 Range range_value (void) const |
2376
|
706 { return rep->range_value (); } |
|
707 |
5759
|
708 Octave_map map_value (void) const; |
2376
|
709 |
5759
|
710 string_vector map_keys (void) const |
3933
|
711 { return rep->map_keys (); } |
|
712 |
5759
|
713 std::streamoff streamoff_value (void) const; |
4645
|
714 |
5759
|
715 streamoff_array streamoff_array_value (void) const; |
4643
|
716 |
5759
|
717 octave_function *function_value (bool silent = false); |
2974
|
718 |
5759
|
719 octave_user_function *user_function_value (bool silent = false); |
4700
|
720 |
5759
|
721 octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
722 |
5759
|
723 octave_fcn_inline *fcn_inline_value (bool silent = false); |
4933
|
724 |
5759
|
725 octave_value_list list_value (void) const; |
2880
|
726 |
3419
|
727 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
728 bool frc_vec_conv = false) const; |
|
729 |
|
730 ComplexColumnVector |
3419
|
731 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
732 bool frc_vec_conv = false) const; |
|
733 |
3419
|
734 RowVector row_vector_value (bool frc_str_conv = false, |
|
735 bool frc_vec_conv = false) const; |
|
736 |
|
737 ComplexRowVector |
|
738 complex_row_vector_value (bool frc_str_conv = false, |
|
739 bool frc_vec_conv = false) const; |
|
740 |
4044
|
741 Array<int> int_vector_value (bool req_int = false, |
|
742 bool frc_str_conv = false, |
|
743 bool frc_vec_conv = false) const; |
|
744 |
3419
|
745 Array<double> vector_value (bool frc_str_conv = false, |
|
746 bool frc_vec_conv = false) const; |
|
747 |
|
748 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
749 bool frc_vec_conv = false) const; |
|
750 |
2376
|
751 // Conversions. These should probably be private. If a user of this |
|
752 // class wants a certain kind of constant, he should simply ask for |
|
753 // it, and we should convert it if possible. |
|
754 |
5279
|
755 octave_value convert_to_str (bool pad = false, bool force = false, |
5759
|
756 char type = '"') const |
|
757 { return rep->convert_to_str (pad, force, type); } |
4452
|
758 |
5759
|
759 octave_value |
5279
|
760 convert_to_str_internal (bool pad, bool force, char type) const |
|
761 { return rep->convert_to_str_internal (pad, force, type); } |
2376
|
762 |
5759
|
763 void convert_to_row_or_column_vector (void) |
2376
|
764 { rep->convert_to_row_or_column_vector (); } |
|
765 |
5759
|
766 bool print_as_scalar (void) const |
4604
|
767 { return rep->print_as_scalar (); } |
|
768 |
5759
|
769 void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
770 { rep->print (os, pr_as_read_syntax); } |
2376
|
771 |
5759
|
772 void print_raw (std::ostream& os, |
4457
|
773 bool pr_as_read_syntax = false) const |
2903
|
774 { rep->print_raw (os, pr_as_read_syntax); } |
|
775 |
5759
|
776 bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
777 { return rep->print_name_tag (os, name); } |
2376
|
778 |
3523
|
779 void print_with_name (std::ostream& os, const std::string& name, |
5759
|
780 bool print_padding = true) const |
|
781 { rep->print_with_name (os, name, print_padding); } |
2376
|
782 |
5759
|
783 int type_id (void) const { return rep->type_id (); } |
2376
|
784 |
5759
|
785 std::string type_name (void) const { return rep->type_name (); } |
|
786 |
|
787 std::string class_name (void) const { return rep->class_name (); } |
4612
|
788 |
3203
|
789 // Unary and binary operations. |
|
790 |
6109
|
791 friend OCTINTERP_API octave_value do_unary_op (unary_op op, |
3933
|
792 const octave_value& a); |
3203
|
793 |
3933
|
794 const octave_value& do_non_const_unary_op (unary_op op); |
|
795 |
|
796 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
797 |
4247
|
798 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
799 const std::list<octave_value_list>& idx); |
3205
|
800 |
6109
|
801 friend OCTINTERP_API octave_value do_binary_op (binary_op op, |
3933
|
802 const octave_value& a, |
|
803 const octave_value& b); |
2376
|
804 |
6109
|
805 friend OCTINTERP_API octave_value do_cat_op (const octave_value& a, |
4915
|
806 const octave_value& b, |
6867
|
807 const Array<octave_idx_type>& ra_idx); |
4915
|
808 |
5759
|
809 const octave_base_value& get_rep (void) const { return *rep; } |
3301
|
810 |
5759
|
811 void print_info (std::ostream& os, |
3933
|
812 const std::string& prefix = std::string ()) const; |
|
813 |
6974
|
814 bool save_ascii (std::ostream& os) { return rep->save_ascii (os); } |
4687
|
815 |
6974
|
816 bool load_ascii (std::istream& is) { return rep->load_ascii (is); } |
4687
|
817 |
5759
|
818 bool save_binary (std::ostream& os, bool& save_as_floats) |
4687
|
819 { return rep->save_binary (os, save_as_floats); } |
|
820 |
5759
|
821 bool load_binary (std::istream& is, bool swap, |
4687
|
822 oct_mach_info::float_format fmt) |
|
823 { return rep->load_binary (is, swap, fmt); } |
|
824 |
|
825 #if defined (HAVE_HDF5) |
5759
|
826 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
4687
|
827 { return rep->save_hdf5 (loc_id, name, save_as_floats); } |
|
828 |
5759
|
829 bool load_hdf5 (hid_t loc_id, const char *name, |
4687
|
830 bool have_h5giterate_bug) |
|
831 { return rep->load_hdf5 (loc_id, name, have_h5giterate_bug); } |
|
832 #endif |
|
833 |
5759
|
834 int write (octave_stream& os, int block_size, |
4944
|
835 oct_data_conv::data_type output_type, int skip, |
|
836 oct_mach_info::float_format flt_fmt) const; |
|
837 |
5759
|
838 octave_base_value *internal_rep (void) const { return rep; } |
4901
|
839 |
5900
|
840 // Unsafe. These functions exist to support the MEX interface. |
|
841 // You should not use them anywhere else. |
|
842 void *mex_get_data (void) const { return rep->mex_get_data (); } |
|
843 |
|
844 octave_idx_type *mex_get_ir (void) const { return rep->mex_get_ir (); } |
|
845 |
|
846 octave_idx_type *mex_get_jc (void) const { return rep->mex_get_jc (); } |
|
847 |
|
848 mxArray *as_mxArray (void) const { return rep->as_mxArray (); } |
|
849 |
2376
|
850 protected: |
|
851 |
5759
|
852 // The real representation. |
|
853 octave_base_value *rep; |
2413
|
854 |
3933
|
855 private: |
2903
|
856 |
3205
|
857 assign_op unary_op_to_assign_op (unary_op op); |
|
858 |
3204
|
859 binary_op op_eq_to_binary_op (assign_op op); |
|
860 |
3219
|
861 DECLARE_OCTAVE_ALLOCATOR |
2376
|
862 }; |
|
863 |
5508
|
864 // Publish externally used friend functions. |
|
865 |
6109
|
866 extern OCTINTERP_API octave_value |
5508
|
867 do_unary_op (octave_value::unary_op op, const octave_value& a); |
|
868 |
6109
|
869 extern OCTINTERP_API octave_value |
5508
|
870 do_binary_op (octave_value::binary_op op, |
|
871 const octave_value& a, const octave_value& b); |
|
872 |
3203
|
873 #define OV_UNOP_FN(name) \ |
|
874 inline octave_value \ |
|
875 name (const octave_value& a) \ |
|
876 { \ |
|
877 return do_unary_op (octave_value::name, a); \ |
|
878 } |
|
879 |
|
880 #define OV_UNOP_OP(name, op) \ |
|
881 inline octave_value \ |
|
882 operator op (const octave_value& a) \ |
|
883 { \ |
|
884 return name (a); \ |
|
885 } |
|
886 |
|
887 #define OV_UNOP_FN_OP(name, op) \ |
|
888 OV_UNOP_FN (name) \ |
|
889 OV_UNOP_OP (name, op) |
|
890 |
3525
|
891 OV_UNOP_FN_OP (op_not, !) |
6518
|
892 OV_UNOP_FN_OP (op_uplus, +) |
3525
|
893 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
894 |
3525
|
895 OV_UNOP_FN (op_transpose) |
|
896 OV_UNOP_FN (op_hermitian) |
3203
|
897 |
|
898 // No simple way to define these for prefix and suffix ops? |
|
899 // |
|
900 // incr |
|
901 // decr |
|
902 |
|
903 #define OV_BINOP_FN(name) \ |
|
904 inline octave_value \ |
|
905 name (const octave_value& a1, const octave_value& a2) \ |
|
906 { \ |
|
907 return do_binary_op (octave_value::name, a1, a2); \ |
|
908 } |
|
909 |
|
910 #define OV_BINOP_OP(name, op) \ |
|
911 inline octave_value \ |
|
912 operator op (const octave_value& a1, const octave_value& a2) \ |
|
913 { \ |
|
914 return name (a1, a2); \ |
|
915 } |
|
916 |
|
917 #define OV_BINOP_FN_OP(name, op) \ |
|
918 OV_BINOP_FN (name) \ |
|
919 OV_BINOP_OP (name, op) |
|
920 |
3525
|
921 OV_BINOP_FN_OP (op_add, +) |
|
922 OV_BINOP_FN_OP (op_sub, -) |
|
923 OV_BINOP_FN_OP (op_mul, *) |
|
924 OV_BINOP_FN_OP (op_div, /) |
3203
|
925 |
3525
|
926 OV_BINOP_FN (op_pow) |
|
927 OV_BINOP_FN (op_ldiv) |
|
928 OV_BINOP_FN (op_lshift) |
|
929 OV_BINOP_FN (op_rshift) |
3203
|
930 |
3525
|
931 OV_BINOP_FN_OP (op_lt, <) |
|
932 OV_BINOP_FN_OP (op_le, <=) |
|
933 OV_BINOP_FN_OP (op_eq, ==) |
|
934 OV_BINOP_FN_OP (op_ge, >=) |
|
935 OV_BINOP_FN_OP (op_gt, >) |
|
936 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
937 |
3525
|
938 OV_BINOP_FN (op_el_mul) |
|
939 OV_BINOP_FN (op_el_div) |
|
940 OV_BINOP_FN (op_el_pow) |
|
941 OV_BINOP_FN (op_el_ldiv) |
|
942 OV_BINOP_FN (op_el_and) |
|
943 OV_BINOP_FN (op_el_or) |
3203
|
944 |
3525
|
945 OV_BINOP_FN (op_struct_ref) |
3203
|
946 |
6109
|
947 extern OCTINTERP_API void install_types (void); |
2376
|
948 |
5775
|
949 // FIXME -- these trait classes probably belong somehwere else... |
4946
|
950 |
|
951 template <typename T> |
|
952 class |
|
953 octave_type_traits |
|
954 { |
|
955 public: |
|
956 typedef T val_type; |
|
957 }; |
|
958 |
|
959 #define OCTAVE_TYPE_TRAIT(T, VAL_T) \ |
|
960 template <> \ |
|
961 class \ |
|
962 octave_type_traits<T> \ |
|
963 { \ |
|
964 public: \ |
|
965 typedef VAL_T val_type; \ |
|
966 } |
|
967 |
|
968 OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); |
|
969 OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); |
|
970 OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); |
|
971 OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); |
|
972 OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); |
|
973 OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); |
|
974 OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); |
|
975 OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); |
|
976 |
|
977 template <typename T> |
|
978 class octave_array_type_traits |
|
979 { |
|
980 public: |
|
981 typedef T element_type; |
|
982 }; |
|
983 |
|
984 #define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ |
|
985 template <> \ |
|
986 class \ |
|
987 octave_array_type_traits<T> \ |
|
988 { \ |
|
989 public: \ |
|
990 typedef ELT_T element_type; \ |
|
991 } |
|
992 |
|
993 OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); |
4970
|
994 OCTAVE_ARRAY_TYPE_TRAIT (boolNDArray, bool); |
4946
|
995 OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); |
|
996 OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); |
|
997 OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); |
|
998 OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); |
|
999 OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); |
|
1000 OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); |
|
1001 OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); |
|
1002 OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); |
|
1003 OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); |
|
1004 |
5759
|
1005 // This will eventually go away, but for now it can be used to |
|
1006 // simplify the transition to the new octave_value class hierarchy, |
|
1007 // which uses octave_base_value instead of octave_value for the type |
|
1008 // of octave_value::rep. |
|
1009 #define OV_REP_TYPE octave_base_value |
|
1010 |
2376
|
1011 #endif |
|
1012 |
|
1013 /* |
6705
|
1014 ;;; Local Variables: *** |
|
1015 ;;; mode: C++ *** |
|
1016 ;;; End: *** |
2376
|
1017 */ |