GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-str-str.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 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 
38 // string unary ops.
39 
40 DEFUNOP (transpose, char_matrix_str)
41 {
42  const octave_char_matrix_str& v
43  = dynamic_cast<const octave_char_matrix_str&> (a);
44 
45  if (v.ndims () > 2)
46  error ("transpose not defined for N-D objects");
47 
49  a.is_sq_string () ? '\'' : '"');
50 }
51 
52 // string by string ops.
53 
54 #define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f) \
55  static octave_value \
56  CONCAT2(oct_binop_, name) (const octave_base_value& a1, \
57  const octave_base_value& a2) \
58  { \
59  dim_vector a1_dims = a1.dims (); \
60  dim_vector a2_dims = a2.dims (); \
61  \
62  bool a1_is_scalar = a1_dims.all_ones (); \
63  bool a2_is_scalar = a2_dims.all_ones (); \
64  \
65  const octave_ ## t1& v1 = dynamic_cast<const octave_ ## t1&> (a1); \
66  const octave_ ## t2& v2 = dynamic_cast<const octave_ ## t2&> (a2); \
67  \
68  if (a1_is_scalar) \
69  { \
70  if (a2_is_scalar) \
71  return octave_value ((v1.e1 ## _value ())(0) \
72  op (v2.e2 ## _value ())(0)); \
73  else \
74  return octave_value (f ((v1.e1 ## _value ())(0), \
75  v2.e2 ## _value ())); \
76  } \
77  else \
78  { \
79  if (a2_is_scalar) \
80  return octave_value (f (v1.e1 ## _value (), \
81  (v2.e2 ## _value ())(0))); \
82  else \
83  return octave_value (f (v1.e1 ## _value (), \
84  v2.e2 ## _value ())); \
85  } \
86  }
87 
88 DEFCHARNDBINOP_FN (lt, <, char_matrix_str, char_matrix_str, char_array,
89  char_array, mx_el_lt)
90 DEFCHARNDBINOP_FN (le, <=, char_matrix_str, char_matrix_str, char_array,
91  char_array, mx_el_le)
92 DEFCHARNDBINOP_FN (eq, ==, char_matrix_str, char_matrix_str, char_array,
93  char_array, mx_el_eq)
94 DEFCHARNDBINOP_FN (ge, >=, char_matrix_str, char_matrix_str, char_array,
95  char_array, mx_el_ge)
96 DEFCHARNDBINOP_FN (gt, >, char_matrix_str, char_matrix_str, char_array,
97  char_array, mx_el_gt)
98 DEFCHARNDBINOP_FN (ne, !=, char_matrix_str, char_matrix_str, char_array,
99  char_array, mx_el_ne)
100 
101 DEFASSIGNOP (assign, char_matrix_str, char_matrix_str)
102 {
103  octave_char_matrix_str& v1 = dynamic_cast<octave_char_matrix_str&> (a1);
105  = dynamic_cast<const octave_char_matrix_str&> (a2);
106 
107  v1.assign (idx, v2.char_array_value ());
108  return octave_value ();
109 }
110 
111 DEFNULLASSIGNOP_FN (null_assign, char_matrix_str, delete_elements)
112 
113 DEFNDCHARCATOP_FN (str_str, char_matrix_str, char_matrix_str, concat)
114 
115 void
116 install_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);
202  octave_char_matrix_sq_str, assign);
203 
205  null_assign);
207  null_assign);
209  null_assign);
212  null_assign);
214  null_assign);
217  null_assign);
218 
219 }
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
charMatrix transpose(void) const
Definition: chMatrix.h:80
int ndims(void) const
Definition: ov-base-mat.h:116
void assign(const octave_value_list &idx, const MT &rhs)
Definition: ov-base-mat.cc:225
charMatrix char_matrix_value(bool=false) const
Definition: ov-ch-mat.h:142
charNDArray char_array_value(bool=false) const
Definition: ov-ch-mat.h:145
void error(const char *fmt,...)
Definition: error.cc:968
const octave_base_value & a2
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
const octave_char_matrix & v2
#define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f)
Definition: op-str-str.cc:54
void install_str_str_ops(octave::type_info &ti)
Definition: op-str-str.cc:116
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition: ops.h:100
#define DEFASSIGNOP(name, t1, t2)
Definition: ops.h:81
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:55
#define DEFUNOP(name, t)
Definition: ops.h:179
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:60
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:47
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition: ops.h:64
#define DEFNDCHARCATOP_FN(name, t1, t2, f)
Definition: ops.h:360
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1579
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1578
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1540
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1541
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1575
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1576
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1577
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1574
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:389