GNU Octave  4.4.1
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-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "errwarn.h"
28 #include "ovl.h"
29 #include "ov.h"
30 #include "ov-str-mat.h"
31 #include "ov-typeinfo.h"
32 #include "ov-null-mat.h"
33 #include "ops.h"
34 
35 // string unary ops.
36 
37 DEFUNOP (transpose, char_matrix_str)
38 {
39  const octave_char_matrix_str& v
40  = dynamic_cast<const octave_char_matrix_str&> (a);
41 
42  if (v.ndims () > 2)
43  error ("transpose not defined for N-D objects");
44 
46  a.is_sq_string () ? '\'' : '"');
47 }
48 
49 // string by string ops.
50 
51 #define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f) \
52  static octave_value \
53  CONCAT2(oct_binop_, name) (const octave_base_value& a1, \
54  const octave_base_value& 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  const octave_ ## t1& v1 = dynamic_cast<const octave_ ## t1&> (a1); \
63  const octave_ ## t2& v2 = dynamic_cast<const octave_ ## t2&> (a2); \
64  \
65  if (a1_is_scalar) \
66  { \
67  if (a2_is_scalar) \
68  return octave_value ((v1.e1 ## _value ())(0) \
69  op (v2.e2 ## _value ())(0)); \
70  else \
71  return octave_value (f ((v1.e1 ## _value ())(0), \
72  v2.e2 ## _value ())); \
73  } \
74  else \
75  { \
76  if (a2_is_scalar) \
77  return octave_value (f (v1.e1 ## _value (), \
78  (v2.e2 ## _value ())(0))); \
79  else \
80  return octave_value (f (v1.e1 ## _value (), \
81  v2.e2 ## _value ())); \
82  } \
83  }
84 
85 DEFCHARNDBINOP_FN (lt, <, char_matrix_str, char_matrix_str, char_array,
86  char_array, mx_el_lt)
87 DEFCHARNDBINOP_FN (le, <=, char_matrix_str, char_matrix_str, char_array,
88  char_array, mx_el_le)
89 DEFCHARNDBINOP_FN (eq, ==, char_matrix_str, char_matrix_str, char_array,
90  char_array, mx_el_eq)
91 DEFCHARNDBINOP_FN (ge, >=, char_matrix_str, char_matrix_str, char_array,
92  char_array, mx_el_ge)
93 DEFCHARNDBINOP_FN (gt, >, char_matrix_str, char_matrix_str, char_array,
94  char_array, mx_el_gt)
95 DEFCHARNDBINOP_FN (ne, !=, char_matrix_str, char_matrix_str, char_array,
96  char_array, mx_el_ne)
97 
98 DEFASSIGNOP (assign, char_matrix_str, char_matrix_str)
99 {
100  octave_char_matrix_str& v1 = dynamic_cast<octave_char_matrix_str&> (a1);
102  = dynamic_cast<const octave_char_matrix_str&> (a2);
103 
104  v1.assign (idx, v2.char_array_value ());
105  return octave_value ();
106 }
107 
108 DEFNULLASSIGNOP_FN (null_assign, char_matrix_str, delete_elements)
109 
110 DEFNDCHARCATOP_FN (str_str, char_matrix_str, char_matrix_str, concat)
111 
112 void
113 install_str_str_ops (octave::type_info& ti)
114 {
117 
120 
122  lt);
124  lt);
126  lt);
129  lt);
130 
132  le);
134  le);
136  le);
139  le);
140 
142  eq);
144  eq);
146  eq);
149  eq);
150 
152  ge);
154  ge);
156  ge);
159  ge);
160 
162  gt);
164  gt);
166  gt);
169  gt);
170 
172  ne);
174  ne);
176  ne);
179  ne);
180 
183  str_str);
185  str_str);
187  str_str);
188 
191  assign);
194  assign);
197  assign);
199  octave_char_matrix_sq_str, assign);
200 
202  null_assign);
204  null_assign);
206  null_assign);
209  null_assign);
211  null_assign);
214  null_assign);
215 
216 }
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition: ops.h:62
#define DEFUNOP(name, t)
Definition: ops.h:213
#define DEFNDCHARCATOP_FN(name, t1, t2, f)
Definition: ops.h:394
void install_str_str_ops(octave::type_info &ti)
Definition: op-str-str.cc:113
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:53
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1613
void assign(const octave_value_list &idx, const MT &rhs)
Definition: ov-base-mat.cc:214
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition: ops.h:134
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:386
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:653
boolMatrix mx_el_le(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
void error(const char *fmt,...)
Definition: error.cc:578
const octave_base_value & a2
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:45
boolMatrix mx_el_ge(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
#define DEFASSIGNOP(name, t1, t2)
Definition: ops.h:115
charMatrix char_matrix_value(bool=false) const
Definition: ov-ch-mat.h:140
boolMatrix mx_el_gt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:58
charMatrix transpose(void) const
Definition: chMatrix.h:74
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1577
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1612
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1611
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
int ndims(void) const
Definition: ov-base-mat.h:109
const octave_char_matrix & v2
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1616
boolMatrix mx_el_lt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
#define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f)
Definition: op-str-str.cc:51
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1578
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1614
boolMatrix mx_el_eq(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1615
charNDArray char_array_value(bool=false) const
Definition: ov-ch-mat.h:143