Mercurial > hg > octave-nkf
annotate libinterp/operators/op-class.cc @ 19840:c5270263d466 gui-release
close gui-release branch
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Jan 2015 17:41:50 -0500 |
parents | 175b392e91fe |
children | 4197fc428c7d |
rev | line source |
---|---|
7338 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 2007-2013 John W. Eaton |
7338 | 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 | |
7444 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
7338 | 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 | |
7444 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
7338 | 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 { \ | |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
53 octave_value_list args; \ |
7338 | 54 \ |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
55 args(0) = a; \ |
7338 | 56 \ |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
57 octave_value_list tmp = feval (meth.function_value (), args, 1); \ |
7338 | 58 \ |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
59 if (tmp.length () > 0) \ |
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
60 retval = tmp(0); \ |
7338 | 61 } \ |
62 else \ | |
63 error ("%s method not defined for %s class", \ | |
64 #name, class_name.c_str ()); \ | |
65 \ | |
66 return retval; \ | |
67 } | |
68 | |
69 DEF_CLASS_UNOP (not) | |
70 DEF_CLASS_UNOP (uplus) | |
71 DEF_CLASS_UNOP (uminus) | |
72 DEF_CLASS_UNOP (transpose) | |
73 DEF_CLASS_UNOP (ctranspose) | |
74 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 // FIXME: we need to handle precedence in the binop function. |
7338 | 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 { \ | |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
90 octave_value_list args; \ |
7338 | 91 \ |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
92 args(1) = a2; \ |
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
93 args(0) = a1; \ |
7338 | 94 \ |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
95 octave_value_list tmp = feval (meth.function_value (), args, 1); \ |
7338 | 96 \ |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
97 if (tmp.length () > 0) \ |
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
98 retval = tmp(0); \ |
7338 | 99 } \ |
100 else \ | |
101 error ("%s method not defined for %s class", \ | |
102 #name, dispatch_type.c_str ()); \ | |
103 \ | |
104 return retval; \ | |
105 } | |
106 | |
107 DEF_CLASS_BINOP (plus) | |
108 DEF_CLASS_BINOP (minus) | |
109 DEF_CLASS_BINOP (mtimes) | |
110 DEF_CLASS_BINOP (mrdivide) | |
111 DEF_CLASS_BINOP (mpower) | |
112 DEF_CLASS_BINOP (mldivide) | |
113 DEF_CLASS_BINOP (lt) | |
114 DEF_CLASS_BINOP (le) | |
115 DEF_CLASS_BINOP (eq) | |
116 DEF_CLASS_BINOP (ge) | |
117 DEF_CLASS_BINOP (gt) | |
118 DEF_CLASS_BINOP (ne) | |
119 DEF_CLASS_BINOP (times) | |
120 DEF_CLASS_BINOP (rdivide) | |
121 DEF_CLASS_BINOP (power) | |
122 DEF_CLASS_BINOP (ldivide) | |
123 DEF_CLASS_BINOP (and) | |
124 DEF_CLASS_BINOP (or) | |
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 | |
135 install_class_ops (void) | |
136 { | |
137 INSTALL_CLASS_UNOP (op_not, not); | |
138 INSTALL_CLASS_UNOP (op_uplus, uplus); | |
139 INSTALL_CLASS_UNOP (op_uminus, uminus); | |
140 INSTALL_CLASS_UNOP (op_transpose, transpose); | |
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); | |
149 INSTALL_CLASS_BINOP (op_lt, lt); | |
150 INSTALL_CLASS_BINOP (op_le, le); | |
151 INSTALL_CLASS_BINOP (op_eq, eq); | |
152 INSTALL_CLASS_BINOP (op_ge, ge); | |
153 INSTALL_CLASS_BINOP (op_gt, gt); | |
154 INSTALL_CLASS_BINOP (op_ne, ne); | |
155 INSTALL_CLASS_BINOP (op_el_mul, times); | |
156 INSTALL_CLASS_BINOP (op_el_div, rdivide); | |
157 INSTALL_CLASS_BINOP (op_el_pow, power); | |
158 INSTALL_CLASS_BINOP (op_el_ldiv, ldivide); | |
159 INSTALL_CLASS_BINOP (op_el_and, and); | |
160 INSTALL_CLASS_BINOP (op_el_or, or); | |
161 } |