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