GNU Octave  4.2.1
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-2017 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 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "oct-time.h"
28 
29 #include "errwarn.h"
30 #include "load-path.h"
31 #include "ovl.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_undefined ()) \
52  error ("%s method not defined for %s class", #name, \
53  class_name.c_str ()); \
54  \
55  octave_value_list args; \
56  \
57  args(0) = a; \
58  \
59  octave_value_list tmp = feval (meth.function_value (), args, 1); \
60  \
61  if (tmp.length () > 0) \
62  retval = tmp(0); \
63  \
64  return retval; \
65  }
66 
71 DEF_CLASS_UNOP (ctranspose)
72 
73 // FIXME: we need to handle precedence in the binop function.
74 
75 #define DEF_CLASS_BINOP(name) \
76  static octave_value \
77  oct_binop_ ## name (const octave_value& a1, const octave_value& a2) \
78  { \
79  octave_value retval; \
80  \
81  std::string dispatch_type \
82  = a1.is_object () ? a1.class_name () : a2.class_name (); \
83  \
84  octave_value meth = symbol_table::find_method (#name, dispatch_type); \
85  \
86  if (meth.is_undefined ()) \
87  error ("%s method not defined for %s class", #name, \
88  dispatch_type.c_str ()); \
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  return retval; \
101  }
102 
106 DEF_CLASS_BINOP (mrdivide)
108 DEF_CLASS_BINOP (mldivide)
121 
122 #define INSTALL_CLASS_UNOP(op, f) \
123  octave_value_typeinfo::register_unary_class_op \
124  (octave_value::op, oct_unop_ ## f)
125 
126 #define INSTALL_CLASS_BINOP(op, f) \
127  octave_value_typeinfo::register_binary_class_op \
128  (octave_value::op, oct_binop_ ## f)
129 
130 void
132 {
133  INSTALL_CLASS_UNOP (op_not, not);
134  INSTALL_CLASS_UNOP (op_uplus, uplus);
135  INSTALL_CLASS_UNOP (op_uminus, uminus);
137  INSTALL_CLASS_UNOP (op_hermitian, ctranspose);
138 
139  INSTALL_CLASS_BINOP (op_add, plus);
140  INSTALL_CLASS_BINOP (op_sub, minus);
141  INSTALL_CLASS_BINOP (op_mul, mtimes);
142  INSTALL_CLASS_BINOP (op_div, mrdivide);
143  INSTALL_CLASS_BINOP (op_pow, mpower);
144  INSTALL_CLASS_BINOP (op_ldiv, mldivide);
152  INSTALL_CLASS_BINOP (op_el_div, rdivide);
154  INSTALL_CLASS_BINOP (op_el_ldiv, ldivide);
157 }
#define DEF_CLASS_BINOP(name)
Definition: op-class.cc:75
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1485
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1531
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1524
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:582
#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:1532
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:1519
#define INSTALL_CLASS_BINOP(op, f)
Definition: op-class.cc:126
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1517
void install_class_ops(void)
Definition: op-class.cc:131
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1534
octave_value op_not(const octave_value &a)
Definition: ov.h:1484
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1488
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1533
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1523
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1522
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1530
Restrict the maximum order of the solution method This option must be between and
Definition: DASPK-opts.cc:739
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1527
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:608
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1514
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1520
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1515
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1529
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1489
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1525
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1486
#define INSTALL_CLASS_UNOP(op, f)
Definition: op-class.cc:122
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1516
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1526