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