comparison src/ov.h @ 3203:bc61b0e8d60e

[project @ 1998-10-30 20:26:27 by jwe]
author jwe
date Fri, 30 Oct 1998 20:26:31 +0000
parents 44d82b369c78
children 81738e630f57
comparison
equal deleted inserted replaced
3202:44d82b369c78 3203:bc61b0e8d60e
60 60
61 class octave_value; 61 class octave_value;
62 62
63 // XXX FIXME XXX -- these should probably really be inside the scope 63 // XXX FIXME XXX -- these should probably really be inside the scope
64 // of the octave_value class, but the cygwin32 beta16 version of g++ 64 // of the octave_value class, but the cygwin32 beta16 version of g++
65 // can't handlt that. 65 // can't handle that.
66
67 typedef octave_value (*unary_op_fcn)
68 (const octave_value&);
69
70 typedef void (*non_const_unary_op_fcn)
71 (octave_value&);
66 72
67 typedef octave_value (*binary_op_fcn) 73 typedef octave_value (*binary_op_fcn)
68 (const octave_value&, const octave_value&); 74 (const octave_value&, const octave_value&);
69 75
70 typedef octave_value (*assign_op_fcn) 76 typedef octave_value (*assign_op_fcn)
74 80
75 class 81 class
76 octave_value 82 octave_value
77 { 83 {
78 public: 84 public:
85
86 enum unary_op
87 {
88 not,
89 uminus,
90 transpose,
91 hermitian,
92 incr,
93 decr,
94 num_unary_ops,
95 unknown_unary_op
96 };
79 97
80 enum binary_op 98 enum binary_op
81 { 99 {
82 add, 100 add,
83 sub, 101 sub,
119 el_or_eq, 137 el_or_eq,
120 num_assign_ops, 138 num_assign_ops,
121 unknown_assign_op 139 unknown_assign_op
122 }; 140 };
123 141
142 static string unary_op_as_string (unary_op);
143
124 static string binary_op_as_string (binary_op); 144 static string binary_op_as_string (binary_op);
125 145
126 static string assign_op_as_string (assign_op); 146 static string assign_op_as_string (assign_op);
127 147
128 enum magic_colon { magic_colon_t }; 148 enum magic_colon { magic_colon_t };
407 { return rep->bool_value (); } 427 { return rep->bool_value (); }
408 428
409 virtual boolMatrix bool_matrix_value (void) const 429 virtual boolMatrix bool_matrix_value (void) const
410 { return rep->bool_matrix_value (); } 430 { return rep->bool_matrix_value (); }
411 431
412 // Unary ops.
413
414 virtual octave_value not (void) const { return rep->not (); }
415
416 virtual octave_value uminus (void) const { return rep->uminus (); }
417
418 virtual octave_value transpose (void) const { return rep->transpose (); }
419
420 virtual octave_value hermitian (void) const { return rep->hermitian (); }
421
422 virtual void increment (void)
423 {
424 make_unique ();
425 rep->increment ();
426 }
427
428 virtual void decrement (void)
429 {
430 make_unique ();
431 rep->decrement ();
432 }
433
434 ColumnVector vector_value (bool frc_str_conv = false, 432 ColumnVector vector_value (bool frc_str_conv = false,
435 bool frc_vec_conv = false) const; 433 bool frc_vec_conv = false) const;
436 434
437 ComplexColumnVector 435 ComplexColumnVector
438 complex_vector_value (bool frc_str_conv = false, 436 complex_vector_value (bool frc_str_conv = false,
462 460
463 virtual int type_id (void) const { return rep->type_id (); } 461 virtual int type_id (void) const { return rep->type_id (); }
464 462
465 virtual string type_name (void) const { return rep->type_name (); } 463 virtual string type_name (void) const { return rep->type_name (); }
466 464
467 // Binary and unary operations. 465 // Unary and binary operations.
466
467 friend octave_value do_unary_op (octave_value::unary_op,
468 const octave_value&);
469
470 void do_non_const_unary_op (octave_value::unary_op);
468 471
469 friend octave_value do_binary_op (octave_value::binary_op, 472 friend octave_value do_binary_op (octave_value::binary_op,
470 const octave_value&, 473 const octave_value&,
471 const octave_value&); 474 const octave_value&);
472 475
513 const octave_value& rhs); 516 const octave_value& rhs);
514 517
515 static int curr_print_indent_level; 518 static int curr_print_indent_level;
516 static bool beginning_of_line; 519 static bool beginning_of_line;
517 }; 520 };
521
522 #define OV_UNOP_FN(name) \
523 inline octave_value \
524 name (const octave_value& a) \
525 { \
526 return do_unary_op (octave_value::name, a); \
527 }
528
529 #define OV_UNOP_OP(name, op) \
530 inline octave_value \
531 operator op (const octave_value& a) \
532 { \
533 return name (a); \
534 }
535
536 #define OV_UNOP_FN_OP(name, op) \
537 OV_UNOP_FN (name) \
538 OV_UNOP_OP (name, op)
539
540 OV_UNOP_FN_OP (not, !)
541 OV_UNOP_FN_OP (uminus, -)
542
543 OV_UNOP_FN (transpose)
544 OV_UNOP_FN (hermitian)
545
546 // No simple way to define these for prefix and suffix ops?
547 //
548 // incr
549 // decr
550
551 #define OV_BINOP_FN(name) \
552 inline octave_value \
553 name (const octave_value& a1, const octave_value& a2) \
554 { \
555 return do_binary_op (octave_value::name, a1, a2); \
556 }
557
558 #define OV_BINOP_OP(name, op) \
559 inline octave_value \
560 operator op (const octave_value& a1, const octave_value& a2) \
561 { \
562 return name (a1, a2); \
563 }
564
565 #define OV_BINOP_FN_OP(name, op) \
566 OV_BINOP_FN (name) \
567 OV_BINOP_OP (name, op)
568
569 OV_BINOP_FN_OP (add, +)
570 OV_BINOP_FN_OP (sub, -)
571 OV_BINOP_FN_OP (mul, *)
572 OV_BINOP_FN_OP (div, /)
573
574 OV_BINOP_FN (pow)
575 OV_BINOP_FN (ldiv)
576 OV_BINOP_FN (lshift)
577 OV_BINOP_FN (rshift)
578
579 OV_BINOP_FN_OP (lt, <)
580 OV_BINOP_FN_OP (le, <=)
581 OV_BINOP_FN_OP (eq, ==)
582 OV_BINOP_FN_OP (ge, >=)
583 OV_BINOP_FN_OP (gt, >)
584 OV_BINOP_FN_OP (ne, !=)
585
586 OV_BINOP_FN (el_mul)
587 OV_BINOP_FN (el_div)
588 OV_BINOP_FN (el_pow)
589 OV_BINOP_FN (el_ldiv)
590 OV_BINOP_FN (el_and)
591 OV_BINOP_FN (el_or)
592
593 OV_BINOP_FN (struct_ref)
518 594
519 // If TRUE, allow assignments like 595 // If TRUE, allow assignments like
520 // 596 //
521 // octave> A(1) = 3; A(2) = 5 597 // octave> A(1) = 3; A(2) = 5
522 // 598 //