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, |
3933
|
302 int resize_ok) |
|
303 { return rep->do_index_op (idx, resize_ok); } |
|
304 |
|
305 octave_value do_index_op (const octave_value_list& idx) |
|
306 { return do_index_op (idx, 0); } |
2376
|
307 |
5759
|
308 octave_value_list |
3544
|
309 do_multi_index_op (int nargout, const octave_value_list& idx); |
2974
|
310 |
5759
|
311 octave_value subsasgn (const std::string& type, |
4219
|
312 const std::list<octave_value_list>& idx, |
3933
|
313 const octave_value& rhs); |
2376
|
314 |
4247
|
315 octave_value assign (assign_op op, const std::string& type, |
4219
|
316 const std::list<octave_value_list>& idx, |
3933
|
317 const octave_value& rhs); |
2948
|
318 |
3933
|
319 const octave_value& assign (assign_op, const octave_value& rhs); |
2948
|
320 |
5759
|
321 idx_vector index_vector (void) const |
2376
|
322 { return rep->index_vector (); } |
|
323 |
|
324 // Size. |
|
325 |
5759
|
326 dim_vector dims (void) const |
4513
|
327 { return rep->dims (); } |
|
328 |
5759
|
329 octave_idx_type rows (void) const { return rep->rows (); } |
4563
|
330 |
5759
|
331 octave_idx_type columns (void) const { return rep->columns (); } |
3195
|
332 |
5275
|
333 octave_idx_type length (void) const; |
4554
|
334 |
5759
|
335 int ndims (void) const { return rep->ndims (); } |
4563
|
336 |
5164
|
337 bool all_zero_dims (void) const { return dims().all_zero (); } |
|
338 |
5759
|
339 octave_idx_type numel (void) const |
5080
|
340 { return rep->numel (); } |
4559
|
341 |
5759
|
342 octave_idx_type capacity (void) const |
5164
|
343 { return rep->capacity (); } |
|
344 |
5659
|
345 Matrix size (void) const; |
|
346 |
5759
|
347 size_t byte_size (void) const |
4791
|
348 { return rep->byte_size (); } |
|
349 |
5759
|
350 octave_idx_type nnz (void) const { return rep->nnz (); } |
5602
|
351 |
5759
|
352 octave_idx_type nzmax (void) const { return rep->nzmax (); } |
5604
|
353 |
5759
|
354 octave_value reshape (const dim_vector& dv) const |
4587
|
355 { return rep->reshape (dv); } |
4567
|
356 |
5759
|
357 octave_value permute (const Array<int>& vec, bool inv = false) const |
4593
|
358 { return rep->permute (vec, inv); } |
|
359 |
|
360 octave_value ipermute (const Array<int>& vec) const |
|
361 { return rep->permute (vec, true); } |
|
362 |
5759
|
363 octave_value resize (const dim_vector& dv, bool fill = false) const |
|
364 { return rep->resize (dv, fill);} |
4915
|
365 |
5785
|
366 MatrixType matrix_type (void) const |
|
367 { return rep->matrix_type (); } |
|
368 |
|
369 MatrixType matrix_type (const MatrixType& typ) const |
|
370 { return rep->matrix_type (typ); } |
|
371 |
2376
|
372 // Does this constant have a type? Both of these are provided since |
|
373 // it is sometimes more natural to write is_undefined() instead of |
|
374 // ! is_defined(). |
|
375 |
5759
|
376 bool is_defined (void) const |
2376
|
377 { return rep->is_defined (); } |
|
378 |
|
379 bool is_undefined (void) const |
|
380 { return ! is_defined (); } |
|
381 |
4559
|
382 bool is_empty (void) const |
5759
|
383 { return rep->is_empty (); } |
4559
|
384 |
5759
|
385 bool is_cell (void) const |
3351
|
386 { return rep->is_cell (); } |
|
387 |
5759
|
388 bool is_real_scalar (void) const |
2376
|
389 { return rep->is_real_scalar (); } |
|
390 |
5759
|
391 bool is_real_matrix (void) const |
2376
|
392 { return rep->is_real_matrix (); } |
|
393 |
5759
|
394 bool is_real_nd_array (void) const |
4505
|
395 { return rep->is_real_nd_array (); } |
|
396 |
5759
|
397 bool is_complex_scalar (void) const |
2376
|
398 { return rep->is_complex_scalar (); } |
|
399 |
5759
|
400 bool is_complex_matrix (void) const |
2376
|
401 { return rep->is_complex_matrix (); } |
|
402 |
5881
|
403 bool is_bool_scalar (void) const |
|
404 { return rep->is_bool_scalar (); } |
|
405 |
5759
|
406 bool is_bool_matrix (void) const |
4587
|
407 { return rep->is_bool_matrix (); } |
|
408 |
5759
|
409 bool is_char_matrix (void) const |
2376
|
410 { return rep->is_char_matrix (); } |
|
411 |
5759
|
412 bool is_string (void) const |
2376
|
413 { return rep->is_string (); } |
|
414 |
5759
|
415 bool is_sq_string (void) const |
5279
|
416 { return rep->is_sq_string (); } |
|
417 |
5280
|
418 bool is_dq_string (void) const |
|
419 { return rep->is_string () && ! rep->is_sq_string (); } |
|
420 |
5759
|
421 bool is_range (void) const |
2376
|
422 { return rep->is_range (); } |
|
423 |
5759
|
424 bool is_map (void) const |
2376
|
425 { return rep->is_map (); } |
|
426 |
5759
|
427 bool is_streamoff (void) const |
4643
|
428 { return rep->is_streamoff (); } |
|
429 |
5759
|
430 bool is_cs_list (void) const |
3977
|
431 { return rep->is_cs_list (); } |
|
432 |
5759
|
433 bool is_list (void) const |
2880
|
434 { return rep->is_list (); } |
|
435 |
5759
|
436 bool is_magic_colon (void) const |
2376
|
437 { return rep->is_magic_colon (); } |
|
438 |
|
439 // Are any or all of the elements in this constant nonzero? |
|
440 |
5759
|
441 octave_value all (int dim = 0) const |
4015
|
442 { return rep->all (dim); } |
2376
|
443 |
5759
|
444 octave_value any (int dim = 0) const |
4015
|
445 { return rep->any (dim); } |
2376
|
446 |
|
447 // Other type stuff. |
|
448 |
5759
|
449 bool is_bool_type (void) const |
3209
|
450 { return rep->is_bool_type (); } |
|
451 |
5759
|
452 bool is_real_type (void) const |
2376
|
453 { return rep->is_real_type (); } |
|
454 |
5759
|
455 bool is_complex_type (void) const |
2376
|
456 { return rep->is_complex_type (); } |
|
457 |
5759
|
458 bool is_scalar_type (void) const |
2376
|
459 { return rep->is_scalar_type (); } |
|
460 |
5759
|
461 bool is_matrix_type (void) const |
2376
|
462 { return rep->is_matrix_type (); } |
|
463 |
5759
|
464 bool is_numeric_type (void) const |
2376
|
465 { return rep->is_numeric_type (); } |
|
466 |
5759
|
467 bool is_sparse_type (void) const |
5631
|
468 { return rep->is_sparse_type (); } |
|
469 |
5759
|
470 bool valid_as_scalar_index (void) const |
2376
|
471 { return rep->valid_as_scalar_index (); } |
|
472 |
5759
|
473 bool valid_as_zero_index (void) const |
2376
|
474 { return rep->valid_as_zero_index (); } |
|
475 |
|
476 // Does this constant correspond to a truth value? |
|
477 |
5759
|
478 bool is_true (void) const |
2376
|
479 { return rep->is_true (); } |
|
480 |
|
481 // Are the dimensions of this constant zero by zero? |
|
482 |
5759
|
483 bool is_zero_by_zero (void) const |
|
484 { return (rows () == 0 && columns () == 0); } |
2376
|
485 |
5759
|
486 bool is_constant (void) const |
2974
|
487 { return rep->is_constant (); } |
|
488 |
5759
|
489 bool is_function_handle (void) const |
4654
|
490 { return rep->is_function_handle (); } |
|
491 |
5759
|
492 bool is_inline_function (void) const |
4954
|
493 { return rep->is_inline_function (); } |
|
494 |
5759
|
495 bool is_function (void) const |
2974
|
496 { return rep->is_function (); } |
2891
|
497 |
5759
|
498 bool is_builtin_function (void) const |
3325
|
499 { return rep->is_builtin_function (); } |
|
500 |
5759
|
501 bool is_dld_function (void) const |
3325
|
502 { return rep->is_dld_function (); } |
|
503 |
5864
|
504 bool is_mex_function (void) const |
|
505 { return rep->is_mex_function (); } |
|
506 |
2376
|
507 // Values. |
|
508 |
2891
|
509 octave_value eval (void) { return *this; } |
|
510 |
5759
|
511 short int |
4254
|
512 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
513 { return rep->short_value (req_int, frc_str_conv); } |
|
514 |
5759
|
515 unsigned short int |
4254
|
516 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
517 { return rep->ushort_value (req_int, frc_str_conv); } |
|
518 |
5759
|
519 int int_value (bool req_int = false, bool frc_str_conv = false) const |
3202
|
520 { return rep->int_value (req_int, frc_str_conv); } |
|
521 |
5759
|
522 unsigned int |
4254
|
523 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
524 { return rep->uint_value (req_int, frc_str_conv); } |
|
525 |
5759
|
526 int nint_value (bool frc_str_conv = false) const |
3202
|
527 { return rep->nint_value (frc_str_conv); } |
|
528 |
5759
|
529 long int |
4254
|
530 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
531 { return rep->long_value (req_int, frc_str_conv); } |
|
532 |
5759
|
533 unsigned long int |
4254
|
534 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
535 { return rep->ulong_value (req_int, frc_str_conv); } |
|
536 |
5759
|
537 double double_value (bool frc_str_conv = false) const |
2376
|
538 { return rep->double_value (frc_str_conv); } |
|
539 |
5759
|
540 double scalar_value (bool frc_str_conv = false) const |
2916
|
541 { return rep->scalar_value (frc_str_conv); } |
|
542 |
5759
|
543 Cell cell_value (void) const; |
3351
|
544 |
5759
|
545 Matrix matrix_value (bool frc_str_conv = false) const |
2376
|
546 { return rep->matrix_value (frc_str_conv); } |
|
547 |
5759
|
548 NDArray array_value (bool frc_str_conv = false) const |
4550
|
549 { return rep->array_value (frc_str_conv); } |
4505
|
550 |
5759
|
551 Complex complex_value (bool frc_str_conv = false) const |
2376
|
552 { return rep->complex_value (frc_str_conv); } |
|
553 |
5759
|
554 ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
2376
|
555 { return rep->complex_matrix_value (frc_str_conv); } |
|
556 |
5759
|
557 ComplexNDArray complex_array_value (bool frc_str_conv = false) const |
4550
|
558 { return rep->complex_array_value (frc_str_conv); } |
|
559 |
5759
|
560 bool bool_value (void) const |
4550
|
561 { return rep->bool_value (); } |
|
562 |
5759
|
563 boolMatrix bool_matrix_value (void) const |
4550
|
564 { return rep->bool_matrix_value (); } |
|
565 |
5759
|
566 boolNDArray bool_array_value (void) const |
4550
|
567 { return rep->bool_array_value (); } |
|
568 |
5759
|
569 charMatrix char_matrix_value (bool frc_str_conv = false) const |
2376
|
570 { return rep->char_matrix_value (frc_str_conv); } |
|
571 |
5759
|
572 charNDArray char_array_value (bool frc_str_conv = false) const |
4550
|
573 { return rep->char_array_value (frc_str_conv); } |
|
574 |
5759
|
575 SparseMatrix sparse_matrix_value (bool frc_str_conv = false) const |
|
576 { return rep->sparse_matrix_value (frc_str_conv); } |
5164
|
577 |
5759
|
578 SparseComplexMatrix sparse_complex_matrix_value (bool frc_str_conv = false) const |
|
579 { return rep->sparse_complex_matrix_value (frc_str_conv); } |
5164
|
580 |
5759
|
581 SparseBoolMatrix sparse_bool_matrix_value (bool frc_str_conv = false) const |
|
582 { return rep->sparse_bool_matrix_value (frc_str_conv); } |
5164
|
583 |
5759
|
584 octave_int8 int8_scalar_value (void) const |
4910
|
585 { return rep->int8_scalar_value (); } |
|
586 |
5759
|
587 octave_int16 int16_scalar_value (void) const |
4910
|
588 { return rep->int16_scalar_value (); } |
|
589 |
5759
|
590 octave_int32 int32_scalar_value (void) const |
4910
|
591 { return rep->int32_scalar_value (); } |
|
592 |
5759
|
593 octave_int64 int64_scalar_value (void) const |
4910
|
594 { return rep->int64_scalar_value (); } |
|
595 |
5759
|
596 octave_uint8 uint8_scalar_value (void) const |
4910
|
597 { return rep->uint8_scalar_value (); } |
|
598 |
5759
|
599 octave_uint16 uint16_scalar_value (void) const |
4910
|
600 { return rep->uint16_scalar_value (); } |
|
601 |
5759
|
602 octave_uint32 uint32_scalar_value (void) const |
4910
|
603 { return rep->uint32_scalar_value (); } |
|
604 |
5759
|
605 octave_uint64 uint64_scalar_value (void) const |
4910
|
606 { return rep->uint64_scalar_value (); } |
|
607 |
5759
|
608 int8NDArray int8_array_value (void) const |
4906
|
609 { return rep->int8_array_value (); } |
|
610 |
5759
|
611 int16NDArray int16_array_value (void) const |
4906
|
612 { return rep->int16_array_value (); } |
|
613 |
5759
|
614 int32NDArray int32_array_value (void) const |
4906
|
615 { return rep->int32_array_value (); } |
|
616 |
5759
|
617 int64NDArray int64_array_value (void) const |
4906
|
618 { return rep->int64_array_value (); } |
|
619 |
5759
|
620 uint8NDArray uint8_array_value (void) const |
4906
|
621 { return rep->uint8_array_value (); } |
|
622 |
5759
|
623 uint16NDArray uint16_array_value (void) const |
4906
|
624 { return rep->uint16_array_value (); } |
|
625 |
5759
|
626 uint32NDArray uint32_array_value (void) const |
4906
|
627 { return rep->uint32_array_value (); } |
|
628 |
5759
|
629 uint64NDArray uint64_array_value (void) const |
4906
|
630 { return rep->uint64_array_value (); } |
|
631 |
5759
|
632 string_vector all_strings (bool pad = false) const |
5715
|
633 { return rep->all_strings (pad); } |
2376
|
634 |
5759
|
635 std::string string_value (bool force = false) const |
4665
|
636 { return rep->string_value (force); } |
2376
|
637 |
5759
|
638 Range range_value (void) const |
2376
|
639 { return rep->range_value (); } |
|
640 |
5759
|
641 Octave_map map_value (void) const; |
2376
|
642 |
5759
|
643 string_vector map_keys (void) const |
3933
|
644 { return rep->map_keys (); } |
|
645 |
5759
|
646 std::streamoff streamoff_value (void) const; |
4645
|
647 |
5759
|
648 streamoff_array streamoff_array_value (void) const; |
4643
|
649 |
5759
|
650 octave_function *function_value (bool silent = false); |
2974
|
651 |
5759
|
652 octave_user_function *user_function_value (bool silent = false); |
4700
|
653 |
5759
|
654 octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
655 |
5759
|
656 octave_fcn_inline *fcn_inline_value (bool silent = false); |
4933
|
657 |
5759
|
658 octave_value_list list_value (void) const; |
2880
|
659 |
3419
|
660 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
661 bool frc_vec_conv = false) const; |
|
662 |
|
663 ComplexColumnVector |
3419
|
664 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
665 bool frc_vec_conv = false) const; |
|
666 |
3419
|
667 RowVector row_vector_value (bool frc_str_conv = false, |
|
668 bool frc_vec_conv = false) const; |
|
669 |
|
670 ComplexRowVector |
|
671 complex_row_vector_value (bool frc_str_conv = false, |
|
672 bool frc_vec_conv = false) const; |
|
673 |
4044
|
674 Array<int> int_vector_value (bool req_int = false, |
|
675 bool frc_str_conv = false, |
|
676 bool frc_vec_conv = false) const; |
|
677 |
3419
|
678 Array<double> vector_value (bool frc_str_conv = false, |
|
679 bool frc_vec_conv = false) const; |
|
680 |
|
681 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
682 bool frc_vec_conv = false) const; |
|
683 |
2376
|
684 // Conversions. These should probably be private. If a user of this |
|
685 // class wants a certain kind of constant, he should simply ask for |
|
686 // it, and we should convert it if possible. |
|
687 |
5279
|
688 octave_value convert_to_str (bool pad = false, bool force = false, |
5759
|
689 char type = '"') const |
|
690 { return rep->convert_to_str (pad, force, type); } |
4452
|
691 |
5759
|
692 octave_value |
5279
|
693 convert_to_str_internal (bool pad, bool force, char type) const |
|
694 { return rep->convert_to_str_internal (pad, force, type); } |
2376
|
695 |
5759
|
696 void convert_to_row_or_column_vector (void) |
2376
|
697 { rep->convert_to_row_or_column_vector (); } |
|
698 |
5759
|
699 bool print_as_scalar (void) const |
4604
|
700 { return rep->print_as_scalar (); } |
|
701 |
5759
|
702 void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
703 { rep->print (os, pr_as_read_syntax); } |
2376
|
704 |
5759
|
705 void print_raw (std::ostream& os, |
4457
|
706 bool pr_as_read_syntax = false) const |
2903
|
707 { rep->print_raw (os, pr_as_read_syntax); } |
|
708 |
5759
|
709 bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
710 { return rep->print_name_tag (os, name); } |
2376
|
711 |
3523
|
712 void print_with_name (std::ostream& os, const std::string& name, |
5759
|
713 bool print_padding = true) const |
|
714 { rep->print_with_name (os, name, print_padding); } |
2376
|
715 |
5759
|
716 int type_id (void) const { return rep->type_id (); } |
2376
|
717 |
5759
|
718 std::string type_name (void) const { return rep->type_name (); } |
|
719 |
|
720 std::string class_name (void) const { return rep->class_name (); } |
4612
|
721 |
3203
|
722 // Unary and binary operations. |
|
723 |
3933
|
724 friend octave_value do_unary_op (unary_op op, |
|
725 const octave_value& a); |
3203
|
726 |
3933
|
727 const octave_value& do_non_const_unary_op (unary_op op); |
|
728 |
|
729 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
730 |
4247
|
731 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
732 const std::list<octave_value_list>& idx); |
3205
|
733 |
3933
|
734 friend octave_value do_binary_op (binary_op op, |
|
735 const octave_value& a, |
|
736 const octave_value& b); |
2376
|
737 |
4915
|
738 friend octave_value do_cat_op (const octave_value& a, |
|
739 const octave_value& b, |
|
740 const Array<int>& ra_idx); |
|
741 |
5759
|
742 const octave_base_value& get_rep (void) const { return *rep; } |
3301
|
743 |
5759
|
744 void print_info (std::ostream& os, |
3933
|
745 const std::string& prefix = std::string ()) const; |
|
746 |
5759
|
747 bool save_ascii (std::ostream& os, bool& infnan_warned, |
4687
|
748 bool strip_nan_and_inf) |
|
749 { return rep->save_ascii (os, infnan_warned, strip_nan_and_inf); } |
|
750 |
5759
|
751 bool load_ascii (std::istream& is) |
4687
|
752 { return rep->load_ascii (is); } |
|
753 |
5759
|
754 bool save_binary (std::ostream& os, bool& save_as_floats) |
4687
|
755 { return rep->save_binary (os, save_as_floats); } |
|
756 |
5759
|
757 bool load_binary (std::istream& is, bool swap, |
4687
|
758 oct_mach_info::float_format fmt) |
|
759 { return rep->load_binary (is, swap, fmt); } |
|
760 |
|
761 #if defined (HAVE_HDF5) |
5759
|
762 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
4687
|
763 { return rep->save_hdf5 (loc_id, name, save_as_floats); } |
|
764 |
5759
|
765 bool load_hdf5 (hid_t loc_id, const char *name, |
4687
|
766 bool have_h5giterate_bug) |
|
767 { return rep->load_hdf5 (loc_id, name, have_h5giterate_bug); } |
|
768 #endif |
|
769 |
5759
|
770 int write (octave_stream& os, int block_size, |
4944
|
771 oct_data_conv::data_type output_type, int skip, |
|
772 oct_mach_info::float_format flt_fmt) const; |
|
773 |
5759
|
774 octave_base_value *internal_rep (void) const { return rep; } |
4901
|
775 |
2376
|
776 protected: |
|
777 |
5759
|
778 // The real representation. |
|
779 octave_base_value *rep; |
2413
|
780 |
3933
|
781 private: |
2903
|
782 |
3205
|
783 assign_op unary_op_to_assign_op (unary_op op); |
|
784 |
3204
|
785 binary_op op_eq_to_binary_op (assign_op op); |
|
786 |
3219
|
787 DECLARE_OCTAVE_ALLOCATOR |
2376
|
788 }; |
|
789 |
5508
|
790 // Publish externally used friend functions. |
|
791 |
|
792 extern octave_value |
|
793 do_unary_op (octave_value::unary_op op, const octave_value& a); |
|
794 |
|
795 extern octave_value |
|
796 do_binary_op (octave_value::binary_op op, |
|
797 const octave_value& a, const octave_value& b); |
|
798 |
3203
|
799 #define OV_UNOP_FN(name) \ |
|
800 inline octave_value \ |
|
801 name (const octave_value& a) \ |
|
802 { \ |
|
803 return do_unary_op (octave_value::name, a); \ |
|
804 } |
|
805 |
|
806 #define OV_UNOP_OP(name, op) \ |
|
807 inline octave_value \ |
|
808 operator op (const octave_value& a) \ |
|
809 { \ |
|
810 return name (a); \ |
|
811 } |
|
812 |
|
813 #define OV_UNOP_FN_OP(name, op) \ |
|
814 OV_UNOP_FN (name) \ |
|
815 OV_UNOP_OP (name, op) |
|
816 |
3525
|
817 OV_UNOP_FN_OP (op_not, !) |
|
818 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
819 |
3525
|
820 OV_UNOP_FN (op_transpose) |
|
821 OV_UNOP_FN (op_hermitian) |
3203
|
822 |
|
823 // No simple way to define these for prefix and suffix ops? |
|
824 // |
|
825 // incr |
|
826 // decr |
|
827 |
|
828 #define OV_BINOP_FN(name) \ |
|
829 inline octave_value \ |
|
830 name (const octave_value& a1, const octave_value& a2) \ |
|
831 { \ |
|
832 return do_binary_op (octave_value::name, a1, a2); \ |
|
833 } |
|
834 |
|
835 #define OV_BINOP_OP(name, op) \ |
|
836 inline octave_value \ |
|
837 operator op (const octave_value& a1, const octave_value& a2) \ |
|
838 { \ |
|
839 return name (a1, a2); \ |
|
840 } |
|
841 |
|
842 #define OV_BINOP_FN_OP(name, op) \ |
|
843 OV_BINOP_FN (name) \ |
|
844 OV_BINOP_OP (name, op) |
|
845 |
3525
|
846 OV_BINOP_FN_OP (op_add, +) |
|
847 OV_BINOP_FN_OP (op_sub, -) |
|
848 OV_BINOP_FN_OP (op_mul, *) |
|
849 OV_BINOP_FN_OP (op_div, /) |
3203
|
850 |
3525
|
851 OV_BINOP_FN (op_pow) |
|
852 OV_BINOP_FN (op_ldiv) |
|
853 OV_BINOP_FN (op_lshift) |
|
854 OV_BINOP_FN (op_rshift) |
3203
|
855 |
3525
|
856 OV_BINOP_FN_OP (op_lt, <) |
|
857 OV_BINOP_FN_OP (op_le, <=) |
|
858 OV_BINOP_FN_OP (op_eq, ==) |
|
859 OV_BINOP_FN_OP (op_ge, >=) |
|
860 OV_BINOP_FN_OP (op_gt, >) |
|
861 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
862 |
3525
|
863 OV_BINOP_FN (op_el_mul) |
|
864 OV_BINOP_FN (op_el_div) |
|
865 OV_BINOP_FN (op_el_pow) |
|
866 OV_BINOP_FN (op_el_ldiv) |
|
867 OV_BINOP_FN (op_el_and) |
|
868 OV_BINOP_FN (op_el_or) |
3203
|
869 |
3525
|
870 OV_BINOP_FN (op_struct_ref) |
3203
|
871 |
2376
|
872 extern void install_types (void); |
|
873 |
5775
|
874 // FIXME -- these trait classes probably belong somehwere else... |
4946
|
875 |
|
876 template <typename T> |
|
877 class |
|
878 octave_type_traits |
|
879 { |
|
880 public: |
|
881 typedef T val_type; |
|
882 }; |
|
883 |
|
884 #define OCTAVE_TYPE_TRAIT(T, VAL_T) \ |
|
885 template <> \ |
|
886 class \ |
|
887 octave_type_traits<T> \ |
|
888 { \ |
|
889 public: \ |
|
890 typedef VAL_T val_type; \ |
|
891 } |
|
892 |
|
893 OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); |
|
894 OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); |
|
895 OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); |
|
896 OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); |
|
897 OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); |
|
898 OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); |
|
899 OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); |
|
900 OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); |
|
901 |
|
902 template <typename T> |
|
903 class octave_array_type_traits |
|
904 { |
|
905 public: |
|
906 typedef T element_type; |
|
907 }; |
|
908 |
|
909 #define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ |
|
910 template <> \ |
|
911 class \ |
|
912 octave_array_type_traits<T> \ |
|
913 { \ |
|
914 public: \ |
|
915 typedef ELT_T element_type; \ |
|
916 } |
|
917 |
|
918 OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); |
4970
|
919 OCTAVE_ARRAY_TYPE_TRAIT (boolNDArray, bool); |
4946
|
920 OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); |
|
921 OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); |
|
922 OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); |
|
923 OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); |
|
924 OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); |
|
925 OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); |
|
926 OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); |
|
927 OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); |
|
928 OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); |
|
929 |
5759
|
930 // This will eventually go away, but for now it can be used to |
|
931 // simplify the transition to the new octave_value class hierarchy, |
|
932 // which uses octave_base_value instead of octave_value for the type |
|
933 // of octave_value::rep. |
|
934 #define OV_REP_TYPE octave_base_value |
|
935 |
2376
|
936 #endif |
|
937 |
|
938 /* |
|
939 ;; Local Variables: *** |
|
940 ;; mode: C++ *** |
|
941 ;; End: *** |
|
942 */ |