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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_value_h) |
|
24 #define octave_value_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2376
|
33 #include <string> |
4219
|
34 #include <list> |
2376
|
35 |
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" |
|
43 |
3351
|
44 class Cell; |
4654
|
45 class fcn_handle_array; |
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; |
4342
|
51 class octave_fcn_handle; |
2376
|
52 class octave_value_list; |
2979
|
53 class octave_lvalue; |
2376
|
54 |
|
55 // Constants. |
|
56 |
|
57 // This just provides a way to avoid infinite recursion when building |
|
58 // octave_value objects. |
|
59 |
|
60 class |
|
61 octave_xvalue |
|
62 { |
|
63 public: |
|
64 |
|
65 octave_xvalue (void) { } |
|
66 }; |
|
67 |
2427
|
68 class octave_value; |
|
69 |
|
70 // XXX FIXME XXX -- these should probably really be inside the scope |
|
71 // of the octave_value class, but the cygwin32 beta16 version of g++ |
3203
|
72 // can't handle that. |
|
73 |
|
74 typedef octave_value (*unary_op_fcn) |
|
75 (const octave_value&); |
|
76 |
|
77 typedef void (*non_const_unary_op_fcn) |
|
78 (octave_value&); |
2427
|
79 |
|
80 typedef octave_value (*binary_op_fcn) |
|
81 (const octave_value&, const octave_value&); |
|
82 |
|
83 typedef octave_value (*assign_op_fcn) |
|
84 (octave_value&, const octave_value_list&, const octave_value&); |
|
85 |
|
86 typedef octave_value * (*type_conv_fcn) (const octave_value&); |
|
87 |
2376
|
88 class |
2974
|
89 octave_value |
2376
|
90 { |
|
91 public: |
|
92 |
3203
|
93 enum unary_op |
|
94 { |
3525
|
95 op_not, |
|
96 op_uminus, |
|
97 op_transpose, |
|
98 op_hermitian, |
|
99 op_incr, |
|
100 op_decr, |
3203
|
101 num_unary_ops, |
|
102 unknown_unary_op |
|
103 }; |
|
104 |
2376
|
105 enum binary_op |
|
106 { |
3525
|
107 op_add, |
|
108 op_sub, |
|
109 op_mul, |
|
110 op_div, |
|
111 op_pow, |
|
112 op_ldiv, |
|
113 op_lshift, |
|
114 op_rshift, |
|
115 op_lt, |
|
116 op_le, |
|
117 op_eq, |
|
118 op_ge, |
|
119 op_gt, |
|
120 op_ne, |
|
121 op_el_mul, |
|
122 op_el_div, |
|
123 op_el_pow, |
|
124 op_el_ldiv, |
|
125 op_el_and, |
|
126 op_el_or, |
|
127 op_struct_ref, |
2376
|
128 num_binary_ops, |
|
129 unknown_binary_op |
|
130 }; |
|
131 |
2880
|
132 enum assign_op |
|
133 { |
3525
|
134 op_asn_eq, |
|
135 op_add_eq, |
|
136 op_sub_eq, |
|
137 op_mul_eq, |
|
138 op_div_eq, |
|
139 op_ldiv_eq, |
4018
|
140 op_pow_eq, |
3525
|
141 op_lshift_eq, |
|
142 op_rshift_eq, |
|
143 op_el_mul_eq, |
|
144 op_el_div_eq, |
|
145 op_el_ldiv_eq, |
4018
|
146 op_el_pow_eq, |
3525
|
147 op_el_and_eq, |
|
148 op_el_or_eq, |
2880
|
149 num_assign_ops, |
|
150 unknown_assign_op |
|
151 }; |
|
152 |
3523
|
153 static std::string unary_op_as_string (unary_op); |
3203
|
154 |
3523
|
155 static std::string binary_op_as_string (binary_op); |
2376
|
156 |
3523
|
157 static std::string assign_op_as_string (assign_op); |
2880
|
158 |
3933
|
159 static octave_value empty_conv (const std::string& type, |
|
160 const octave_value& rhs = octave_value ()); |
|
161 |
2376
|
162 enum magic_colon { magic_colon_t }; |
|
163 enum all_va_args { all_va_args_t }; |
|
164 |
|
165 octave_value (void); |
4254
|
166 octave_value (short int i); |
|
167 octave_value (unsigned short int i); |
4233
|
168 octave_value (int i); |
4254
|
169 octave_value (unsigned int i); |
|
170 octave_value (long int i); |
|
171 octave_value (unsigned long int i); |
4353
|
172 |
|
173 // XXX FIXME XXX -- these are kluges. They turn into doubles |
|
174 // internally, which will break for very large values. We just use |
|
175 // them to store things like 64-bit ino_t, etc, and hope that those |
|
176 // values are never actually larger than can be represented exactly |
|
177 // in a double. |
|
178 |
|
179 #if defined (HAVE_LONG_LONG_INT) |
|
180 octave_value (long long int i); |
|
181 #endif |
4356
|
182 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
183 octave_value (unsigned long long int i); |
|
184 #endif |
|
185 |
4254
|
186 octave_value (octave_time t); |
2376
|
187 octave_value (double d); |
4532
|
188 octave_value (const ArrayN<octave_value>& a, bool is_cs_list = false); |
|
189 octave_value (const Cell& c, bool is_cs_list = false); |
2376
|
190 octave_value (const Matrix& m); |
4513
|
191 octave_value (const NDArray& nda); |
2376
|
192 octave_value (const DiagMatrix& d); |
3418
|
193 octave_value (const RowVector& v); |
|
194 octave_value (const ColumnVector& v); |
2376
|
195 octave_value (const Complex& C); |
|
196 octave_value (const ComplexMatrix& m); |
4513
|
197 octave_value (const ComplexNDArray& cnda); |
4478
|
198 octave_value (const ArrayN<Complex>& m); |
2376
|
199 octave_value (const ComplexDiagMatrix& d); |
3418
|
200 octave_value (const ComplexRowVector& v); |
|
201 octave_value (const ComplexColumnVector& v); |
2825
|
202 octave_value (bool b); |
|
203 octave_value (const boolMatrix& bm); |
4513
|
204 octave_value (const boolNDArray& bnda); |
3189
|
205 octave_value (char c); |
2376
|
206 octave_value (const char *s); |
3523
|
207 octave_value (const std::string& s); |
2376
|
208 octave_value (const string_vector& s); |
|
209 octave_value (const charMatrix& chm, bool is_string = false); |
4513
|
210 octave_value (const charNDArray& chnda, bool is_string = false); |
2376
|
211 octave_value (double base, double limit, double inc); |
|
212 octave_value (const Range& r); |
|
213 octave_value (const Octave_map& m); |
3340
|
214 octave_value (const octave_stream& s, int n); |
4643
|
215 octave_value (const streamoff_array& off); |
2974
|
216 octave_value (octave_function *f); |
4654
|
217 octave_value (const fcn_handle_array& fha); |
|
218 octave_value (octave_function *f, const std::string &nm); // function handle |
3977
|
219 octave_value (const octave_value_list& m, bool is_cs_list = false); |
2376
|
220 octave_value (octave_value::magic_colon); |
|
221 octave_value (octave_value::all_va_args); |
|
222 |
3933
|
223 octave_value (octave_value *new_rep, int count = 1); |
2376
|
224 |
|
225 // Copy constructor. |
|
226 |
|
227 octave_value (const octave_value& a) |
|
228 { |
|
229 rep = a.rep; |
|
230 rep->count++; |
|
231 } |
|
232 |
3933
|
233 // This should only be called for derived types. |
|
234 |
|
235 virtual octave_value *clone (void) const; |
|
236 |
|
237 virtual octave_value *empty_clone (void) const |
|
238 { return rep->empty_clone (); } |
|
239 |
2376
|
240 // Delete the representation of this constant if the count drops to |
|
241 // zero. |
|
242 |
|
243 virtual ~octave_value (void); |
|
244 |
|
245 void make_unique (void) |
|
246 { |
|
247 if (rep->count > 1) |
|
248 { |
|
249 --rep->count; |
|
250 rep = rep->clone (); |
|
251 rep->count = 1; |
|
252 } |
|
253 } |
|
254 |
|
255 // Simple assignment. |
|
256 |
|
257 octave_value& operator = (const octave_value& a) |
|
258 { |
|
259 if (rep != a.rep) |
|
260 { |
|
261 if (--rep->count == 0) |
|
262 delete rep; |
|
263 |
|
264 rep = a.rep; |
|
265 rep->count++; |
|
266 } |
|
267 |
|
268 return *this; |
|
269 } |
|
270 |
3933
|
271 int get_count (void) const { return rep->count; } |
3239
|
272 |
2409
|
273 virtual type_conv_fcn numeric_conversion_function (void) const |
2376
|
274 { return rep->numeric_conversion_function (); } |
|
275 |
2409
|
276 void maybe_mutate (void); |
|
277 |
4532
|
278 virtual octave_value squeeze (void) const |
|
279 { return rep->squeeze (); } |
|
280 |
2410
|
281 virtual octave_value *try_narrowing_conversion (void) |
|
282 { return rep->try_narrowing_conversion (); } |
2409
|
283 |
4271
|
284 octave_value single_subsref (const std::string& type, |
|
285 const octave_value_list& idx); |
|
286 |
4247
|
287 virtual octave_value subsref (const std::string& type, |
4219
|
288 const std::list<octave_value_list>& idx) |
3933
|
289 { return rep->subsref (type, idx); } |
|
290 |
4247
|
291 virtual octave_value_list subsref (const std::string& type, |
4219
|
292 const std::list<octave_value_list>& idx, |
3933
|
293 int nargout); |
|
294 |
4247
|
295 octave_value next_subsref (const std::string& type, const |
4219
|
296 std::list<octave_value_list>& idx, |
4233
|
297 size_t skip = 1); |
3933
|
298 |
|
299 virtual octave_value do_index_op (const octave_value_list& idx, |
|
300 int resize_ok) |
|
301 { return rep->do_index_op (idx, resize_ok); } |
|
302 |
|
303 octave_value do_index_op (const octave_value_list& idx) |
|
304 { return do_index_op (idx, 0); } |
2376
|
305 |
2974
|
306 virtual octave_value_list |
3544
|
307 do_multi_index_op (int nargout, const octave_value_list& idx); |
2974
|
308 |
4247
|
309 virtual octave_value subsasgn (const std::string& type, |
4219
|
310 const std::list<octave_value_list>& idx, |
3933
|
311 const octave_value& rhs); |
2376
|
312 |
4247
|
313 octave_value assign (assign_op op, const std::string& type, |
4219
|
314 const std::list<octave_value_list>& idx, |
3933
|
315 const octave_value& rhs); |
2948
|
316 |
3933
|
317 const octave_value& assign (assign_op, const octave_value& rhs); |
2948
|
318 |
2376
|
319 virtual idx_vector index_vector (void) const |
|
320 { return rep->index_vector (); } |
|
321 |
|
322 // Size. |
|
323 |
4513
|
324 virtual dim_vector dims (void) const |
|
325 { return rep->dims (); } |
|
326 |
4563
|
327 int rows (void) const; |
|
328 |
|
329 int columns (void) const; |
3195
|
330 |
4563
|
331 int length (void) const; |
4554
|
332 |
4563
|
333 int ndims (void) const; |
|
334 |
|
335 int numel (void) const; |
4559
|
336 |
4587
|
337 virtual octave_value reshape (const dim_vector& dv) const |
|
338 { return rep->reshape (dv); } |
4567
|
339 |
4593
|
340 virtual octave_value permute (const Array<int>& vec, bool inv = false) const |
|
341 { return rep->permute (vec, inv); } |
|
342 |
|
343 octave_value ipermute (const Array<int>& vec) const |
|
344 { return rep->permute (vec, true); } |
|
345 |
2376
|
346 // Does this constant have a type? Both of these are provided since |
|
347 // it is sometimes more natural to write is_undefined() instead of |
|
348 // ! is_defined(). |
|
349 |
|
350 virtual bool is_defined (void) const |
|
351 { return rep->is_defined (); } |
|
352 |
|
353 bool is_undefined (void) const |
|
354 { return ! is_defined (); } |
|
355 |
4559
|
356 bool is_empty (void) const |
|
357 { return numel () == 0; } |
|
358 |
3351
|
359 virtual bool is_cell (void) const |
|
360 { return rep->is_cell (); } |
|
361 |
2376
|
362 virtual bool is_real_scalar (void) const |
|
363 { return rep->is_real_scalar (); } |
|
364 |
|
365 virtual bool is_real_matrix (void) const |
|
366 { return rep->is_real_matrix (); } |
|
367 |
4505
|
368 virtual bool is_real_nd_array (void) const |
|
369 { return rep->is_real_nd_array (); } |
|
370 |
2376
|
371 virtual bool is_complex_scalar (void) const |
|
372 { return rep->is_complex_scalar (); } |
|
373 |
|
374 virtual bool is_complex_matrix (void) const |
|
375 { return rep->is_complex_matrix (); } |
|
376 |
4587
|
377 virtual bool is_bool_matrix (void) const |
|
378 { return rep->is_bool_matrix (); } |
|
379 |
2376
|
380 virtual bool is_char_matrix (void) const |
|
381 { return rep->is_char_matrix (); } |
|
382 |
|
383 virtual bool is_string (void) const |
|
384 { return rep->is_string (); } |
|
385 |
|
386 virtual bool is_range (void) const |
|
387 { return rep->is_range (); } |
|
388 |
|
389 virtual bool is_map (void) const |
|
390 { return rep->is_map (); } |
|
391 |
3340
|
392 virtual bool is_stream (void) const |
|
393 { return rep->is_stream (); } |
|
394 |
4643
|
395 virtual bool is_streamoff (void) const |
|
396 { return rep->is_streamoff (); } |
|
397 |
3977
|
398 virtual bool is_cs_list (void) const |
|
399 { return rep->is_cs_list (); } |
|
400 |
2880
|
401 virtual bool is_list (void) const |
|
402 { return rep->is_list (); } |
|
403 |
2376
|
404 virtual bool is_magic_colon (void) const |
|
405 { return rep->is_magic_colon (); } |
|
406 |
|
407 virtual bool is_all_va_args (void) const |
|
408 { return rep->is_all_va_args (); } |
|
409 |
|
410 // Are any or all of the elements in this constant nonzero? |
|
411 |
4015
|
412 virtual octave_value all (int dim = 0) const |
|
413 { return rep->all (dim); } |
2376
|
414 |
4015
|
415 virtual octave_value any (int dim = 0) const |
|
416 { return rep->any (dim); } |
2376
|
417 |
|
418 // Other type stuff. |
|
419 |
3209
|
420 virtual bool is_bool_type (void) const |
|
421 { return rep->is_bool_type (); } |
|
422 |
2376
|
423 virtual bool is_real_type (void) const |
|
424 { return rep->is_real_type (); } |
|
425 |
|
426 virtual bool is_complex_type (void) const |
|
427 { return rep->is_complex_type (); } |
|
428 |
|
429 virtual bool is_scalar_type (void) const |
|
430 { return rep->is_scalar_type (); } |
|
431 |
|
432 virtual bool is_matrix_type (void) const |
|
433 { return rep->is_matrix_type (); } |
|
434 |
|
435 virtual bool is_numeric_type (void) const |
|
436 { return rep->is_numeric_type (); } |
|
437 |
|
438 virtual bool valid_as_scalar_index (void) const |
|
439 { return rep->valid_as_scalar_index (); } |
|
440 |
|
441 virtual bool valid_as_zero_index (void) const |
|
442 { return rep->valid_as_zero_index (); } |
|
443 |
|
444 // Does this constant correspond to a truth value? |
|
445 |
|
446 virtual bool is_true (void) const |
|
447 { return rep->is_true (); } |
|
448 |
|
449 // Are the dimensions of this constant zero by zero? |
|
450 |
|
451 virtual bool is_zero_by_zero (void) const |
|
452 { return rep->is_zero_by_zero (); } |
|
453 |
2974
|
454 virtual bool is_constant (void) const |
|
455 { return rep->is_constant (); } |
|
456 |
4654
|
457 virtual bool is_function_handle (void) const |
|
458 { return rep->is_function_handle (); } |
|
459 |
2974
|
460 virtual bool is_function (void) const |
|
461 { return rep->is_function (); } |
2891
|
462 |
3325
|
463 virtual bool is_builtin_function (void) const |
|
464 { return rep->is_builtin_function (); } |
|
465 |
|
466 virtual bool is_dld_function (void) const |
|
467 { return rep->is_dld_function (); } |
|
468 |
2376
|
469 // Values. |
|
470 |
2891
|
471 octave_value eval (void) { return *this; } |
|
472 |
4254
|
473 virtual short int |
|
474 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
475 { return rep->short_value (req_int, frc_str_conv); } |
|
476 |
|
477 virtual unsigned short int |
|
478 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
479 { return rep->ushort_value (req_int, frc_str_conv); } |
|
480 |
3202
|
481 virtual int int_value (bool req_int = false, bool frc_str_conv = false) const |
|
482 { return rep->int_value (req_int, frc_str_conv); } |
|
483 |
4254
|
484 virtual unsigned int |
|
485 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
486 { return rep->uint_value (req_int, frc_str_conv); } |
|
487 |
3202
|
488 virtual int nint_value (bool frc_str_conv = false) const |
|
489 { return rep->nint_value (frc_str_conv); } |
|
490 |
4254
|
491 virtual long int |
|
492 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
493 { return rep->long_value (req_int, frc_str_conv); } |
|
494 |
|
495 virtual unsigned long int |
|
496 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
497 { return rep->ulong_value (req_int, frc_str_conv); } |
|
498 |
2376
|
499 virtual double double_value (bool frc_str_conv = false) const |
|
500 { return rep->double_value (frc_str_conv); } |
|
501 |
2916
|
502 virtual double scalar_value (bool frc_str_conv = false) const |
|
503 { return rep->scalar_value (frc_str_conv); } |
|
504 |
3351
|
505 virtual Cell cell_value (void) const; |
|
506 |
2376
|
507 virtual Matrix matrix_value (bool frc_str_conv = false) const |
|
508 { return rep->matrix_value (frc_str_conv); } |
|
509 |
4550
|
510 virtual NDArray array_value (bool frc_str_conv = false) const |
|
511 { return rep->array_value (frc_str_conv); } |
4505
|
512 |
2376
|
513 virtual Complex complex_value (bool frc_str_conv = false) const |
|
514 { return rep->complex_value (frc_str_conv); } |
|
515 |
|
516 virtual ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
|
517 { return rep->complex_matrix_value (frc_str_conv); } |
|
518 |
4550
|
519 virtual ComplexNDArray complex_array_value (bool frc_str_conv = false) const |
|
520 { return rep->complex_array_value (frc_str_conv); } |
|
521 |
|
522 virtual bool bool_value (void) const |
|
523 { return rep->bool_value (); } |
|
524 |
|
525 virtual boolMatrix bool_matrix_value (void) const |
|
526 { return rep->bool_matrix_value (); } |
|
527 |
|
528 virtual boolNDArray bool_array_value (void) const |
|
529 { return rep->bool_array_value (); } |
|
530 |
2376
|
531 virtual charMatrix char_matrix_value (bool frc_str_conv = false) const |
|
532 { return rep->char_matrix_value (frc_str_conv); } |
|
533 |
4550
|
534 virtual charNDArray char_array_value (bool frc_str_conv = false) const |
|
535 { return rep->char_array_value (frc_str_conv); } |
|
536 |
4457
|
537 virtual string_vector all_strings (bool pad = false, |
|
538 bool force = false) const |
4661
|
539 { return rep->all_strings (pad, force); } |
2376
|
540 |
4457
|
541 virtual std::string string_value (bool force = false) const |
4665
|
542 { return rep->string_value (force); } |
2376
|
543 |
|
544 virtual Range range_value (void) const |
|
545 { return rep->range_value (); } |
|
546 |
|
547 virtual Octave_map map_value (void) const; |
|
548 |
3933
|
549 virtual string_vector map_keys (void) const |
|
550 { return rep->map_keys (); } |
|
551 |
3340
|
552 virtual octave_stream stream_value (void) const; |
2903
|
553 |
|
554 virtual int stream_number (void) const; |
|
555 |
4645
|
556 virtual std::streamoff streamoff_value (void) const; |
|
557 |
|
558 virtual streamoff_array streamoff_array_value (void) const; |
4643
|
559 |
2974
|
560 virtual octave_function *function_value (bool silent = false); |
|
561 |
4346
|
562 virtual octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
563 |
2880
|
564 virtual octave_value_list list_value (void) const; |
|
565 |
3419
|
566 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
567 bool frc_vec_conv = false) const; |
|
568 |
|
569 ComplexColumnVector |
3419
|
570 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
571 bool frc_vec_conv = false) const; |
|
572 |
3419
|
573 RowVector row_vector_value (bool frc_str_conv = false, |
|
574 bool frc_vec_conv = false) const; |
|
575 |
|
576 ComplexRowVector |
|
577 complex_row_vector_value (bool frc_str_conv = false, |
|
578 bool frc_vec_conv = false) const; |
|
579 |
4044
|
580 Array<int> int_vector_value (bool req_int = false, |
|
581 bool frc_str_conv = false, |
|
582 bool frc_vec_conv = false) const; |
|
583 |
3419
|
584 Array<double> vector_value (bool frc_str_conv = false, |
|
585 bool frc_vec_conv = false) const; |
|
586 |
|
587 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
588 bool frc_vec_conv = false) const; |
|
589 |
2376
|
590 // Conversions. These should probably be private. If a user of this |
|
591 // class wants a certain kind of constant, he should simply ask for |
|
592 // it, and we should convert it if possible. |
|
593 |
4457
|
594 octave_value convert_to_str (bool pad = false, bool force = false) const; |
4452
|
595 |
4457
|
596 virtual octave_value convert_to_str_internal (bool pad, bool force) const |
|
597 { return rep->convert_to_str_internal (pad, force); } |
2376
|
598 |
|
599 virtual void convert_to_row_or_column_vector (void) |
|
600 { rep->convert_to_row_or_column_vector (); } |
|
601 |
4604
|
602 virtual bool print_as_scalar (void) const |
|
603 { return rep->print_as_scalar (); } |
|
604 |
3523
|
605 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
606 { rep->print (os, pr_as_read_syntax); } |
2376
|
607 |
4457
|
608 virtual void print_raw (std::ostream& os, |
|
609 bool pr_as_read_syntax = false) const |
2903
|
610 { rep->print_raw (os, pr_as_read_syntax); } |
|
611 |
3523
|
612 virtual bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
613 { return rep->print_name_tag (os, name); } |
2376
|
614 |
3523
|
615 void print_with_name (std::ostream& os, const std::string& name, |
2903
|
616 bool print_padding = true) const; |
2376
|
617 |
|
618 virtual int type_id (void) const { return rep->type_id (); } |
|
619 |
3523
|
620 virtual std::string type_name (void) const { return rep->type_name (); } |
2376
|
621 |
4612
|
622 virtual std::string class_name (void) const { return rep->class_name (); } |
|
623 |
3203
|
624 // Unary and binary operations. |
|
625 |
3933
|
626 friend octave_value do_unary_op (unary_op op, |
|
627 const octave_value& a); |
3203
|
628 |
3933
|
629 const octave_value& do_non_const_unary_op (unary_op op); |
|
630 |
|
631 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
632 |
4247
|
633 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
634 const std::list<octave_value_list>& idx); |
3205
|
635 |
3933
|
636 friend octave_value do_binary_op (binary_op op, |
|
637 const octave_value& a, |
|
638 const octave_value& b); |
2376
|
639 |
3301
|
640 const octave_value& get_rep (void) const { return *rep; } |
|
641 |
3933
|
642 virtual void print_info (std::ostream& os, |
|
643 const std::string& prefix = std::string ()) const; |
|
644 |
2376
|
645 protected: |
|
646 |
|
647 octave_value (const octave_xvalue&) : rep (0) { } |
|
648 |
3933
|
649 // This should only be called for derived types. |
|
650 |
4247
|
651 octave_value numeric_assign (const std::string& type, |
4219
|
652 const std::list<octave_value_list>& idx, |
3933
|
653 const octave_value& rhs); |
|
654 |
2903
|
655 void reset_indent_level (void) const |
|
656 { curr_print_indent_level = 0; } |
|
657 |
|
658 void increment_indent_level (void) const |
|
659 { curr_print_indent_level += 2; } |
|
660 |
|
661 void decrement_indent_level (void) const |
|
662 { curr_print_indent_level -= 2; } |
|
663 |
|
664 int current_print_indent_level (void) const |
|
665 { return curr_print_indent_level; } |
|
666 |
3523
|
667 void newline (std::ostream& os) const; |
2903
|
668 |
3523
|
669 void indent (std::ostream& os) const; |
2903
|
670 |
|
671 void reset (void) const; |
|
672 |
2376
|
673 union |
|
674 { |
|
675 octave_value *rep; // The real representation. |
|
676 int count; // A reference count. |
|
677 }; |
2413
|
678 |
3933
|
679 private: |
2903
|
680 |
|
681 static int curr_print_indent_level; |
|
682 static bool beginning_of_line; |
3204
|
683 |
3205
|
684 assign_op unary_op_to_assign_op (unary_op op); |
|
685 |
3204
|
686 binary_op op_eq_to_binary_op (assign_op op); |
|
687 |
3219
|
688 DECLARE_OCTAVE_ALLOCATOR |
4513
|
689 |
|
690 octave_value *nil_rep (void) const; |
2376
|
691 }; |
|
692 |
3203
|
693 #define OV_UNOP_FN(name) \ |
|
694 inline octave_value \ |
|
695 name (const octave_value& a) \ |
|
696 { \ |
|
697 return do_unary_op (octave_value::name, a); \ |
|
698 } |
|
699 |
|
700 #define OV_UNOP_OP(name, op) \ |
|
701 inline octave_value \ |
|
702 operator op (const octave_value& a) \ |
|
703 { \ |
|
704 return name (a); \ |
|
705 } |
|
706 |
|
707 #define OV_UNOP_FN_OP(name, op) \ |
|
708 OV_UNOP_FN (name) \ |
|
709 OV_UNOP_OP (name, op) |
|
710 |
3525
|
711 OV_UNOP_FN_OP (op_not, !) |
|
712 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
713 |
3525
|
714 OV_UNOP_FN (op_transpose) |
|
715 OV_UNOP_FN (op_hermitian) |
3203
|
716 |
|
717 // No simple way to define these for prefix and suffix ops? |
|
718 // |
|
719 // incr |
|
720 // decr |
|
721 |
|
722 #define OV_BINOP_FN(name) \ |
|
723 inline octave_value \ |
|
724 name (const octave_value& a1, const octave_value& a2) \ |
|
725 { \ |
|
726 return do_binary_op (octave_value::name, a1, a2); \ |
|
727 } |
|
728 |
|
729 #define OV_BINOP_OP(name, op) \ |
|
730 inline octave_value \ |
|
731 operator op (const octave_value& a1, const octave_value& a2) \ |
|
732 { \ |
|
733 return name (a1, a2); \ |
|
734 } |
|
735 |
|
736 #define OV_BINOP_FN_OP(name, op) \ |
|
737 OV_BINOP_FN (name) \ |
|
738 OV_BINOP_OP (name, op) |
|
739 |
3525
|
740 OV_BINOP_FN_OP (op_add, +) |
|
741 OV_BINOP_FN_OP (op_sub, -) |
|
742 OV_BINOP_FN_OP (op_mul, *) |
|
743 OV_BINOP_FN_OP (op_div, /) |
3203
|
744 |
3525
|
745 OV_BINOP_FN (op_pow) |
|
746 OV_BINOP_FN (op_ldiv) |
|
747 OV_BINOP_FN (op_lshift) |
|
748 OV_BINOP_FN (op_rshift) |
3203
|
749 |
3525
|
750 OV_BINOP_FN_OP (op_lt, <) |
|
751 OV_BINOP_FN_OP (op_le, <=) |
|
752 OV_BINOP_FN_OP (op_eq, ==) |
|
753 OV_BINOP_FN_OP (op_ge, >=) |
|
754 OV_BINOP_FN_OP (op_gt, >) |
|
755 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
756 |
3525
|
757 OV_BINOP_FN (op_el_mul) |
|
758 OV_BINOP_FN (op_el_div) |
|
759 OV_BINOP_FN (op_el_pow) |
|
760 OV_BINOP_FN (op_el_ldiv) |
|
761 OV_BINOP_FN (op_el_and) |
|
762 OV_BINOP_FN (op_el_or) |
3203
|
763 |
3525
|
764 OV_BINOP_FN (op_struct_ref) |
3203
|
765 |
3219
|
766 // T_ID is the type id of struct objects, set by register_type(). |
|
767 // T_NAME is the type name of struct objects. |
|
768 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \ |
|
769 public: \ |
|
770 int type_id (void) const { return t_id; } \ |
3523
|
771 std::string type_name (void) const { return t_name; } \ |
4612
|
772 std::string class_name (void) const { return c_name; } \ |
4252
|
773 static int static_type_id (void) { return t_id; } \ |
4640
|
774 static void register_type (void); \ |
3219
|
775 \ |
|
776 private: \ |
4252
|
777 static int t_id; \ |
4612
|
778 static const std::string t_name; \ |
|
779 static const std::string c_name; |
3219
|
780 |
4612
|
781 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \ |
4252
|
782 int t::t_id (-1); \ |
4612
|
783 const std::string t::t_name (n); \ |
4640
|
784 const std::string t::c_name (c); \ |
|
785 void t::register_type (void) \ |
|
786 { \ |
|
787 t_id = octave_value_typeinfo::register_type (t::t_name, \ |
|
788 t::c_name, \ |
4645
|
789 octave_value (new t ())); \ |
4640
|
790 } |
3219
|
791 |
4455
|
792 // If TRUE, print a warning for assignments like |
2376
|
793 // |
|
794 // octave> A(1) = 3; A(2) = 5 |
|
795 // |
|
796 // for A already defined and a matrix type. |
4455
|
797 extern bool Vwarn_fortran_indexing; |
2376
|
798 |
4452
|
799 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
800 // to a character string? |
|
801 extern bool Vwarn_num_to_str; |
4257
|
802 |
4452
|
803 // If TRUE, warn for operations like |
2376
|
804 // |
|
805 // octave> 'abc' + 0 |
|
806 // 97 98 99 |
|
807 // |
4452
|
808 extern int Vwarn_str_to_num; |
2376
|
809 |
4451
|
810 // Should we warn about conversions from complex to real? |
|
811 extern int Vwarn_imag_to_real; |
2376
|
812 |
|
813 // If TRUE, print the name along with the value. |
|
814 extern bool Vprint_answer_id_name; |
|
815 |
|
816 // How many levels of structure elements should we print? |
|
817 extern int Vstruct_levels_to_print; |
|
818 |
|
819 // Allow divide by zero errors to be suppressed. |
|
820 extern bool Vwarn_divide_by_zero; |
|
821 |
4461
|
822 // If TRUE, print a warning when a matrix is resized by an indexed |
|
823 // assignment with indices outside the current bounds. |
|
824 extern bool Vwarn_resize_on_range_error; |
3195
|
825 |
2376
|
826 // Indentation level for structures. |
|
827 extern int struct_indent; |
|
828 |
|
829 extern void increment_struct_indent (void); |
|
830 extern void decrement_struct_indent (void); |
|
831 |
2880
|
832 // Indentation level for lists. |
|
833 extern int list_indent; |
|
834 |
|
835 extern void increment_list_indent (void); |
|
836 extern void decrement_list_indent (void); |
|
837 |
2376
|
838 extern void install_types (void); |
|
839 |
|
840 #endif |
|
841 |
|
842 /* |
|
843 ;; Local Variables: *** |
|
844 ;; mode: C++ *** |
|
845 ;; End: *** |
|
846 */ |