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