2928
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2007 |
|
4 John W. Eaton |
2928
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2928
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "gripes.h" |
4055
|
29 #include "oct-obj.h" |
2928
|
30 #include "ov.h" |
|
31 #include "ov-str-mat.h" |
|
32 #include "ov-typeinfo.h" |
|
33 #include "ops.h" |
|
34 |
3203
|
35 // string unary ops. |
|
36 |
5279
|
37 DEFUNOP (transpose, char_matrix_str) |
3203
|
38 { |
|
39 CAST_UNOP_ARG (const octave_char_matrix_str&); |
|
40 |
4673
|
41 if (v.ndims () > 2) |
|
42 { |
|
43 error ("transpose not defined for N-d objects"); |
|
44 return octave_value (); |
|
45 } |
|
46 else |
5279
|
47 return octave_value (v.char_matrix_value().transpose (), true, |
|
48 a.is_sq_string () ? '\'' : '"'); |
3203
|
49 } |
|
50 |
2928
|
51 // string by string ops. |
|
52 |
6456
|
53 #define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f) \ |
|
54 BINOPDECL (name, a1, a2) \ |
|
55 { \ |
|
56 dim_vector a1_dims = a1.dims (); \ |
|
57 dim_vector a2_dims = a2.dims (); \ |
|
58 \ |
|
59 bool a1_is_scalar = a1_dims.all_ones (); \ |
|
60 bool a2_is_scalar = a2_dims.all_ones (); \ |
|
61 \ |
|
62 CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ |
|
63 \ |
|
64 if (a1_is_scalar) \ |
|
65 { \ |
|
66 if (a2_is_scalar) \ |
|
67 return octave_value ((v1.e1 ## _value ())(0) op (v2.e2 ## _value ())(0)); \ |
|
68 else \ |
|
69 return octave_value (f ((v1.e1 ## _value ())(0), v2.e2 ## _value ())); \ |
|
70 } \ |
|
71 else \ |
|
72 { \ |
|
73 if (a2_is_scalar) \ |
|
74 return octave_value (f (v1.e1 ## _value (), (v2.e2 ## _value ())(0))); \ |
|
75 else \ |
|
76 return octave_value (f (v1.e1 ## _value (), v2.e2 ## _value ())); \ |
|
77 } \ |
|
78 } |
2928
|
79 |
6456
|
80 DEFCHARNDBINOP_FN (lt, <, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_lt) |
|
81 DEFCHARNDBINOP_FN (le, <=, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_le) |
|
82 DEFCHARNDBINOP_FN (eq, ==, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_eq) |
|
83 DEFCHARNDBINOP_FN (ge, >=, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_ge) |
|
84 DEFCHARNDBINOP_FN (gt, >, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_gt) |
|
85 DEFCHARNDBINOP_FN (ne, !=, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_ne) |
2928
|
86 |
|
87 DEFASSIGNOP (assign, char_matrix_str, char_matrix_str) |
|
88 { |
|
89 CAST_BINOP_ARGS (octave_char_matrix_str&, const octave_char_matrix_str&); |
|
90 |
|
91 v1.assign (idx, v2.char_matrix_value ()); |
|
92 return octave_value (); |
|
93 } |
|
94 |
5533
|
95 DEFNDCHARCATOP_FN (str_str, char_matrix_str, char_matrix_str, concat) |
4915
|
96 |
2928
|
97 void |
|
98 install_str_str_ops (void) |
|
99 { |
3538
|
100 INSTALL_UNOP (op_transpose, octave_char_matrix_str, transpose); |
5279
|
101 INSTALL_UNOP (op_transpose, octave_char_matrix_sq_str, transpose); |
|
102 |
3538
|
103 INSTALL_UNOP (op_hermitian, octave_char_matrix_str, transpose); |
5279
|
104 INSTALL_UNOP (op_hermitian, octave_char_matrix_sq_str, transpose); |
3203
|
105 |
6456
|
106 INSTALL_BINOP (op_lt, octave_char_matrix_str, octave_char_matrix_str, lt); |
|
107 INSTALL_BINOP (op_lt, octave_char_matrix_str, octave_char_matrix_sq_str, lt); |
|
108 INSTALL_BINOP (op_lt, octave_char_matrix_sq_str, octave_char_matrix_str, lt); |
|
109 INSTALL_BINOP (op_lt, octave_char_matrix_sq_str, octave_char_matrix_sq_str, lt); |
|
110 |
|
111 INSTALL_BINOP (op_le, octave_char_matrix_str, octave_char_matrix_str, le); |
|
112 INSTALL_BINOP (op_le, octave_char_matrix_str, octave_char_matrix_sq_str, le); |
|
113 INSTALL_BINOP (op_le, octave_char_matrix_sq_str, octave_char_matrix_str, le); |
|
114 INSTALL_BINOP (op_le, octave_char_matrix_sq_str, octave_char_matrix_sq_str, le); |
|
115 |
3538
|
116 INSTALL_BINOP (op_eq, octave_char_matrix_str, octave_char_matrix_str, eq); |
5279
|
117 INSTALL_BINOP (op_eq, octave_char_matrix_str, octave_char_matrix_sq_str, eq); |
|
118 INSTALL_BINOP (op_eq, octave_char_matrix_sq_str, octave_char_matrix_str, eq); |
|
119 INSTALL_BINOP (op_eq, octave_char_matrix_sq_str, octave_char_matrix_sq_str, eq); |
6456
|
120 |
|
121 INSTALL_BINOP (op_ge, octave_char_matrix_str, octave_char_matrix_str, ge); |
|
122 INSTALL_BINOP (op_ge, octave_char_matrix_str, octave_char_matrix_sq_str, ge); |
|
123 INSTALL_BINOP (op_ge, octave_char_matrix_sq_str, octave_char_matrix_str, ge); |
|
124 INSTALL_BINOP (op_ge, octave_char_matrix_sq_str, octave_char_matrix_sq_str, ge); |
|
125 |
|
126 INSTALL_BINOP (op_gt, octave_char_matrix_str, octave_char_matrix_str, gt); |
|
127 INSTALL_BINOP (op_gt, octave_char_matrix_str, octave_char_matrix_sq_str, gt); |
|
128 INSTALL_BINOP (op_gt, octave_char_matrix_sq_str, octave_char_matrix_str, gt); |
|
129 INSTALL_BINOP (op_gt, octave_char_matrix_sq_str, octave_char_matrix_sq_str, gt); |
|
130 |
3538
|
131 INSTALL_BINOP (op_ne, octave_char_matrix_str, octave_char_matrix_str, ne); |
5279
|
132 INSTALL_BINOP (op_ne, octave_char_matrix_str, octave_char_matrix_sq_str, ne); |
|
133 INSTALL_BINOP (op_ne, octave_char_matrix_sq_str, octave_char_matrix_str, ne); |
|
134 INSTALL_BINOP (op_ne, octave_char_matrix_sq_str, octave_char_matrix_sq_str, ne); |
2928
|
135 |
4915
|
136 INSTALL_CATOP (octave_char_matrix_str, octave_char_matrix_str, str_str); |
5279
|
137 INSTALL_CATOP (octave_char_matrix_str, octave_char_matrix_sq_str, str_str); |
|
138 INSTALL_CATOP (octave_char_matrix_sq_str, octave_char_matrix_str, str_str); |
|
139 INSTALL_CATOP (octave_char_matrix_sq_str, octave_char_matrix_sq_str, str_str); |
4915
|
140 |
3538
|
141 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_char_matrix_str, assign); |
5279
|
142 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_char_matrix_sq_str, assign); |
|
143 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_char_matrix_str, assign); |
|
144 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_char_matrix_sq_str, assign); |
2928
|
145 } |
|
146 |
|
147 /* |
|
148 ;;; Local Variables: *** |
|
149 ;;; mode: C++ *** |
|
150 ;;; End: *** |
|
151 */ |