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-ch-mat.h"
34 #include "ov-scalar.h"
35 #include "ov-re-mat.h"
36 #include "ov-bool.h"
37 #include "ov-bool-mat.h"
38 #include "ov-typeinfo.h"
39 #include "ops.h"
40 
41 // char matrix unary ops.
42 
DEFUNOP(transpose,char_matrix)43 DEFUNOP (transpose, char_matrix)
44 {
45   const octave_char_matrix& v = dynamic_cast<const octave_char_matrix&> (a);
46 
47   return octave_value (v.matrix_value ().transpose ());
48 }
49 
DEFNDCATOP_FN(chm_chm,char_matrix,char_matrix,char_array,char_array,concat)50 DEFNDCATOP_FN (chm_chm, char_matrix, char_matrix, char_array, char_array,
51                concat)
52 
53 DEFCATOP (chm_s, char_matrix, scalar)
54 {
55   octave_char_matrix& v1 = dynamic_cast<octave_char_matrix&> (a1);
56   const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2);
57 
58   warn_implicit_conversion ("Octave:num-to-str",
59                             v2.type_name (), v1.type_name ());
60 
61   return octave_value (v1.char_array_value (). concat (v2.array_value (),
62                        ra_idx));
63 }
64 
DEFCATOP(chm_m,char_matrix,matrix)65 DEFCATOP (chm_m, char_matrix, matrix)
66 {
67   octave_char_matrix& v1 = dynamic_cast<octave_char_matrix&> (a1);
68   const octave_matrix& v2 = dynamic_cast<const octave_matrix&> (a2);
69 
70   warn_implicit_conversion ("Octave:num-to-str",
71                             v2.type_name (), v1.type_name ());
72 
73   return octave_value (v1.char_array_value (). concat (v2.array_value (),
74                        ra_idx));
75 }
76 
DEFCATOP(s_chm,scalar,char_matrix)77 DEFCATOP (s_chm, scalar, char_matrix)
78 {
79   octave_scalar& v1 = dynamic_cast<octave_scalar&> (a1);
80   const octave_char_matrix& v2 = dynamic_cast<const octave_char_matrix&> (a2);
81 
82   warn_implicit_conversion ("Octave:num-to-str",
83                             v1.type_name (), v2.type_name ());
84 
85   return octave_value (v1.array_value (). concat (v2.char_array_value (),
86                        ra_idx));
87 }
88 
DEFCATOP(m_chm,matrix,char_matrix)89 DEFCATOP (m_chm, matrix, char_matrix)
90 {
91   octave_matrix& v1 = dynamic_cast<octave_matrix&> (a1);
92   const octave_char_matrix& v2 = dynamic_cast<const octave_char_matrix&> (a2);
93 
94   warn_implicit_conversion ("Octave:num-to-str",
95                             v1.type_name (), v2.type_name ());
96 
97   return octave_value (v1.array_value (). concat (v2.char_array_value (),
98                        ra_idx));
99 }
100 
101 void
install_chm_ops(octave::type_info & ti)102 install_chm_ops (octave::type_info& ti)
103 {
104   INSTALL_UNOP_TI (ti, op_transpose, octave_char_matrix, transpose);
105   INSTALL_UNOP_TI (ti, op_hermitian, octave_char_matrix, transpose);
106 
107   INSTALL_CATOP_TI (ti, octave_char_matrix, octave_char_matrix, chm_chm);
108   INSTALL_CATOP_TI (ti, octave_char_matrix, octave_scalar, chm_s);
109   INSTALL_CATOP_TI (ti, octave_char_matrix, octave_matrix, chm_m);
110   INSTALL_CATOP_TI (ti, octave_scalar, octave_char_matrix, s_chm);
111   INSTALL_CATOP_TI (ti, octave_matrix, octave_char_matrix, m_chm);
112 }
113