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