GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-class.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2007-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "oct-time.h"
28 
29 #include "errwarn.h"
30 #include "interpreter-private.h"
31 #include "load-path.h"
32 #include "ovl.h"
33 #include "ov.h"
34 #include "ov-class.h"
35 #include "ov-typeinfo.h"
36 #include "ops.h"
37 #include "symtab.h"
38 #include "parse.h"
39 
40 // class ops.
41 
42 #define DEF_CLASS_UNOP(name) \
43  static octave_value \
44  oct_unop_ ## name (const octave_value& a) \
45  { \
46  octave_value retval; \
47  \
48  std::string class_name = a.class_name (); \
49  \
50  octave::symbol_table& symtab \
51  = octave::__get_symbol_table__ ("oct_unop_" #name); \
52  \
53  octave_value meth = symtab.find_method (#name, class_name); \
54  \
55  if (meth.is_undefined ()) \
56  error ("%s method not defined for %s class", #name, \
57  class_name.c_str ()); \
58  \
59  octave_value_list args; \
60  \
61  args(0) = a; \
62  \
63  octave_value_list tmp = octave::feval (meth.function_value (), args, 1); \
64  \
65  if (tmp.length () > 0) \
66  retval = tmp(0); \
67  \
68  return retval; \
69  }
70 
75 DEF_CLASS_UNOP (ctranspose)
76 
77 // FIXME: we need to handle precedence in the binop function.
78 
79 #define DEF_CLASS_BINOP(name) \
80  static octave_value \
81  oct_binop_ ## name (const octave_value& a1, const octave_value& a2) \
82  { \
83  octave_value retval; \
84  \
85  std::string dispatch_type \
86  = (a1.isobject () ? a1.class_name () : a2.class_name ()); \
87  \
88  octave::symbol_table& symtab \
89  = octave::__get_symbol_table__ ("oct_unop_" #name); \
90  \
91  octave_value meth = symtab.find_method (#name, dispatch_type); \
92  \
93  if (meth.is_undefined ()) \
94  error ("%s method not defined for %s class", #name, \
95  dispatch_type.c_str ()); \
96  \
97  octave_value_list args; \
98  \
99  args(1) = a2; \
100  args(0) = a1; \
101  \
102  octave_value_list tmp = octave::feval (meth.function_value (), args, 1); \
103  \
104  if (tmp.length () > 0) \
105  retval = tmp(0); \
106  \
107  return retval; \
108  }
109 
113 DEF_CLASS_BINOP (mrdivide)
115 DEF_CLASS_BINOP (mldivide)
128 
129 #define INSTALL_CLASS_UNOP_TI(ti, op, f) \
130  ti.install_unary_class_op (octave_value::op, oct_unop_ ## f)
131 
132 #define INSTALL_CLASS_BINOP_TI(ti, op, f) \
133  ti.install_binary_class_op (octave_value::op, oct_binop_ ## f)
134 
135 void
137 {
138  INSTALL_CLASS_UNOP_TI (ti, op_not, not);
139  INSTALL_CLASS_UNOP_TI (ti, op_uplus, uplus);
140  INSTALL_CLASS_UNOP_TI (ti, op_uminus, uminus);
142  INSTALL_CLASS_UNOP_TI (ti, op_hermitian, ctranspose);
143 
144  INSTALL_CLASS_BINOP_TI (ti, op_add, plus);
145  INSTALL_CLASS_BINOP_TI (ti, op_sub, minus);
146  INSTALL_CLASS_BINOP_TI (ti, op_mul, mtimes);
147  INSTALL_CLASS_BINOP_TI (ti, op_div, mrdivide);
148  INSTALL_CLASS_BINOP_TI (ti, op_pow, mpower);
149  INSTALL_CLASS_BINOP_TI (ti, op_ldiv, mldivide);
150  INSTALL_CLASS_BINOP_TI (ti, op_lt, lt);
151  INSTALL_CLASS_BINOP_TI (ti, op_le, le);
152  INSTALL_CLASS_BINOP_TI (ti, op_eq, eq);
153  INSTALL_CLASS_BINOP_TI (ti, op_ge, ge);
154  INSTALL_CLASS_BINOP_TI (ti, op_gt, gt);
155  INSTALL_CLASS_BINOP_TI (ti, op_ne, ne);
157  INSTALL_CLASS_BINOP_TI (ti, op_el_div, rdivide);
158  INSTALL_CLASS_BINOP_TI (ti, op_el_pow, power);
159  INSTALL_CLASS_BINOP_TI (ti, op_el_ldiv, ldivide);
162 }
#define DEF_CLASS_BINOP(name)
Definition: op-class.cc:79
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1574
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1620
void install_class_ops(octave::type_info &ti)
Definition: op-class.cc:136
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1613
#define DEF_CLASS_UNOP(name)
Definition: op-class.cc:42
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1621
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:386
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1608
OCTAVE_EXPORT octave_value_list or class The return code an ordinary file in Octave s or(after appending @samp{.m}) a function file in Octave 's ode
Definition: variables.cc:593
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1606
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1623
octave_value op_not(const octave_value &a)
Definition: ov.h:1573
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1577
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1622
#define INSTALL_CLASS_UNOP_TI(ti, op, f)
Definition: op-class.cc:129
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1612
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1611
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1619
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1616
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several times
Definition: file-io.cc:587
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1603
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1609
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1604
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1618
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1578
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1614
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1575
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1605
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1615
#define INSTALL_CLASS_BINOP_TI(ti, op, f)
Definition: op-class.cc:132