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