GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
op-class.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2007-2015 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "oct-time.h"
28 
29 #include "gripes.h"
30 #include "load-path.h"
31 #include "oct-obj.h"
32 #include "ov.h"
33 #include "ov-class.h"
34 #include "ov-typeinfo.h"
35 #include "ops.h"
36 #include "symtab.h"
37 #include "parse.h"
38 
39 // class ops.
40 
41 #define DEF_CLASS_UNOP(name) \
42  static octave_value \
43  oct_unop_ ## name (const octave_value& a) \
44  { \
45  octave_value retval; \
46  \
47  std::string class_name = a.class_name (); \
48  \
49  octave_value meth = symbol_table::find_method (#name, class_name); \
50  \
51  if (meth.is_defined ()) \
52  { \
53  octave_value_list args; \
54  \
55  args(0) = a; \
56  \
57  octave_value_list tmp = feval (meth.function_value (), args, 1); \
58  \
59  if (tmp.length () > 0) \
60  retval = tmp(0); \
61  } \
62  else \
63  error ("%s method not defined for %s class", \
64  #name, class_name.c_str ()); \
65  \
66  return retval; \
67  }
68 
73 DEF_CLASS_UNOP (ctranspose)
74 
75 // FIXME: we need to handle precedence in the binop function.
76 
77 #define DEF_CLASS_BINOP(name) \
78  static octave_value \
79  oct_binop_ ## name (const octave_value& a1, const octave_value& a2) \
80  { \
81  octave_value retval; \
82  \
83  std::string dispatch_type \
84  = a1.is_object () ? a1.class_name () : a2.class_name (); \
85  \
86  octave_value meth = symbol_table::find_method (#name, dispatch_type); \
87  \
88  if (meth.is_defined ()) \
89  { \
90  octave_value_list args; \
91  \
92  args(1) = a2; \
93  args(0) = a1; \
94  \
95  octave_value_list tmp = feval (meth.function_value (), args, 1); \
96  \
97  if (tmp.length () > 0) \
98  retval = tmp(0); \
99  } \
100  else \
101  error ("%s method not defined for %s class", \
102  #name, dispatch_type.c_str ()); \
103  \
104  return retval; \
105  }
106 
110 DEF_CLASS_BINOP (mrdivide)
112 DEF_CLASS_BINOP (mldivide)
125 
126 #define INSTALL_CLASS_UNOP(op, f) \
127  octave_value_typeinfo::register_unary_class_op \
128  (octave_value::op, oct_unop_ ## f)
129 
130 #define INSTALL_CLASS_BINOP(op, f) \
131  octave_value_typeinfo::register_binary_class_op \
132  (octave_value::op, oct_binop_ ## f)
133 
134 void
136 {
137  INSTALL_CLASS_UNOP (op_not, not);
138  INSTALL_CLASS_UNOP (op_uplus, uplus);
139  INSTALL_CLASS_UNOP (op_uminus, uminus);
141  INSTALL_CLASS_UNOP (op_hermitian, ctranspose);
142 
143  INSTALL_CLASS_BINOP (op_add, plus);
144  INSTALL_CLASS_BINOP (op_sub, minus);
145  INSTALL_CLASS_BINOP (op_mul, mtimes);
146  INSTALL_CLASS_BINOP (op_div, mrdivide);
147  INSTALL_CLASS_BINOP (op_pow, mpower);
148  INSTALL_CLASS_BINOP (op_ldiv, mldivide);
156  INSTALL_CLASS_BINOP (op_el_div, rdivide);
158  INSTALL_CLASS_BINOP (op_el_ldiv, ldivide);
161 }
#define DEF_CLASS_BINOP(name)
Definition: op-class.cc:77
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1294
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1342
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1335
#define DEF_CLASS_UNOP(name)
Definition: op-class.cc:41
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1343
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Definition: symrcm.cc:382
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1328
#define INSTALL_CLASS_BINOP(op, f)
Definition: op-class.cc:130
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1326
void install_class_ops(void)
Definition: op-class.cc:135
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1345
octave_value op_not(const octave_value &a)
Definition: ov.h:1293
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1297
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1344
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1334
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1333
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1341
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1338
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1323
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1329
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1324
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1340
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1298
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1336
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1295
#define INSTALL_CLASS_UNOP(op, f)
Definition: op-class.cc:126
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1325
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1337