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