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