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