GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
op-str-str.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
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
18 along with Octave; see the file COPYING. If not, see
19 <http://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
114 {
117 
120 
125  lt);
126 
131  le);
132 
137  eq);
138 
143  ge);
144 
149  gt);
150 
155  ne);
156 
161 
163  assign);
166  assign);
169  assign);
171  octave_char_matrix_sq_str, assign);
172 
174  null_assign);
176  null_assign);
178  null_assign);
180  null_assign);
182  null_assign);
184  null_assign);
185 
186 }
#define DEFUNOP(name, t)
Definition: ops.h:172
#define DEFNDCHARCATOP_FN(name, t1, t2, f)
Definition: ops.h:353
charMatrix transpose(void) const
Definition: chMatrix.h:75
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1524
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:93
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:382
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:655
boolMatrix mx_el_le(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:90
void error(const char *fmt,...)
Definition: error.cc:570
#define INSTALL_ASSIGNOP(op, t1, t2, f)
Definition: ops.h:57
void install_str_str_ops(void)
Definition: op-str-str.cc:113
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:398
#define INSTALL_BINOP(op, t1, t2, f)
Definition: ops.h:48
boolMatrix mx_el_ge(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:90
#define DEFASSIGNOP(name, t1, t2)
Definition: ops.h:74
boolMatrix mx_el_gt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:90
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1488
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:90
charMatrix char_matrix_value(bool=false) const
Definition: ov-ch-mat.h:142
int ndims(void) const
Definition: ov-base-mat.h:114
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1523
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1522
#define INSTALL_CATOP(t1, t2, f)
Definition: ops.h:53
const octave_char_matrix & v2
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1527
charNDArray char_array_value(bool=false) const
Definition: ov-ch-mat.h:145
#define INSTALL_UNOP(op, t, f)
Definition: ops.h:40
boolMatrix mx_el_lt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:90
#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:1489
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1525
boolMatrix mx_el_eq(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:90
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1526
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))