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