GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
op-str-str.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "errwarn.h"
31#include "ovl.h"
32#include "ov.h"
33#include "ov-str-mat.h"
34#include "ov-typeinfo.h"
35#include "ov-null-mat.h"
36#include "ops.h"
37
39
40// string unary ops.
41
42DEFUNOP (transpose, char_matrix_str)
43{
45
46 if (v.ndims () > 2)
47 error ("transpose not defined for N-D objects");
48
49 return octave_value (v.char_matrix_value ().transpose (),
50 a.is_sq_string () ? '\'' : '"');
51}
52
53// string by string ops.
54
55#define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f) \
56 static octave_value \
57 CONCAT2(oct_binop_, name) (const octave_base_value& a1, \
58 const octave_base_value& a2) \
59 { \
60 const dim_vector& a1_dims = a1.dims (); \
61 const dim_vector& a2_dims = a2.dims (); \
62 \
63 bool a1_is_scalar = a1_dims.all_ones (); \
64 bool a2_is_scalar = a2_dims.all_ones (); \
65 \
66 OCTAVE_CAST_BASE_VALUE (const octave_ ## t1&, v1, a1); \
67 OCTAVE_CAST_BASE_VALUE (const octave_ ## t2&, v2, a2); \
68 \
69 if (a1_is_scalar) \
70 { \
71 if (a2_is_scalar) \
72 return octave_value ((v1.e1 ## _value ())(0) \
73 op (v2.e2 ## _value ())(0)); \
74 else \
75 return octave_value (f ((v1.e1 ## _value ())(0), \
76 v2.e2 ## _value ())); \
77 } \
78 else \
79 { \
80 if (a2_is_scalar) \
81 return octave_value (f (v1.e1 ## _value (), \
82 (v2.e2 ## _value ())(0))); \
83 else \
84 return octave_value (f (v1.e1 ## _value (), \
85 v2.e2 ## _value ())); \
86 } \
87 }
88
89DEFCHARNDBINOP_FN (lt, <, char_matrix_str, char_matrix_str, char_array,
90 char_array, mx_el_lt)
91DEFCHARNDBINOP_FN (le, <=, char_matrix_str, char_matrix_str, char_array,
92 char_array, mx_el_le)
93DEFCHARNDBINOP_FN (eq, ==, char_matrix_str, char_matrix_str, char_array,
94 char_array, mx_el_eq)
95DEFCHARNDBINOP_FN (ge, >=, char_matrix_str, char_matrix_str, char_array,
96 char_array, mx_el_ge)
97DEFCHARNDBINOP_FN (gt, >, char_matrix_str, char_matrix_str, char_array,
98 char_array, mx_el_gt)
99DEFCHARNDBINOP_FN (ne, !=, char_matrix_str, char_matrix_str, char_array,
100 char_array, mx_el_ne)
101
102DEFASSIGNOP (assign, char_matrix_str, char_matrix_str)
103{
106
107 v1.assign (idx, v2.char_array_value ());
108 return octave_value ();
109}
110
111DEFNULLASSIGNOP_FN (null_assign, char_matrix_str, delete_elements)
112
113DEFNDCHARCATOP_FN (str_str, char_matrix_str, char_matrix_str, concat)
114
115void
116install_str_str_ops (octave::type_info& ti)
117{
120
123
125 lt);
127 lt);
129 lt);
132 lt);
133
135 le);
137 le);
139 le);
142 le);
143
145 eq);
147 eq);
149 eq);
152 eq);
153
155 ge);
157 ge);
159 ge);
162 ge);
163
165 gt);
167 gt);
169 gt);
172 gt);
173
175 ne);
177 ne);
179 ne);
182 ne);
183
186 str_str);
188 str_str);
190 str_str);
191
194 assign);
197 assign);
200 assign);
203
205 null_assign);
207 null_assign);
209 null_assign);
212 null_assign);
214 null_assign);
217 null_assign);
218
219}
220
221OCTAVE_END_NAMESPACE(octave)
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition CNDArray.cc:418
boolMatrix mx_el_le(const boolMatrix &m1, const boolMatrix &m2)
Definition boolMatrix.cc:91
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition boolMatrix.cc:91
boolMatrix mx_el_gt(const boolMatrix &m1, const boolMatrix &m2)
Definition boolMatrix.cc:91
boolMatrix mx_el_eq(const boolMatrix &m1, const boolMatrix &m2)
Definition boolMatrix.cc:91
boolMatrix mx_el_lt(const boolMatrix &m1, const boolMatrix &m2)
Definition boolMatrix.cc:91
boolMatrix mx_el_ge(const boolMatrix &m1, const boolMatrix &m2)
Definition boolMatrix.cc:91
charNDArray char_array_value(bool=false) const
Definition ov-ch-mat.h:146
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003
const octave_base_value & a2
const octave_char_matrix & v2
#define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f)
Definition op-str-str.cc:55
void install_str_str_ops(octave::type_info &ti)
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition ops.h:115
#define DEFASSIGNOP(name, t1, t2)
Definition ops.h:96
#define OCTAVE_CAST_BASE_VALUE(T, T_VAL, BASE_VAL)
Definition ops.h:52
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition ops.h:70
#define DEFUNOP(name, t)
Definition ops.h:197
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition ops.h:75
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition ops.h:62
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition ops.h:79
#define DEFNDCHARCATOP_FN(name, t1, t2, f)
Definition ops.h:379
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition ov.h:1691
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition ov.h:1690
octave_value op_transpose(const octave_value &a)
Definition ov.h:1652
octave_value op_hermitian(const octave_value &a)
Definition ov.h:1653
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition ov.h:1687
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition ov.h:1688
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition ov.h:1689
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition ov.h:1686