GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-str-mat.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 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 (octave_ov_str_mat_h)
27 #define octave_ov_str_mat_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <iosfwd>
34 #include <string>
35 
36 #include "mx-base.h"
37 #include "str-vec.h"
38 
39 #include "error.h"
40 #include "oct-stream.h"
41 #include "ov.h"
42 #include "ov-ch-mat.h"
43 #include "ov-re-mat.h"
44 #include "ov-typeinfo.h"
45 
46 class octave_value_list;
47 
48 // Character matrix values with special properties for use as
49 // strings.
50 
51 class
52 OCTINTERP_API
54 {
55 public:
56 
58  : octave_char_matrix () { }
59 
61  : octave_char_matrix (chm) { }
62 
64  : octave_char_matrix (chm) { }
65 
67  : octave_char_matrix (chm) { }
68 
70  : octave_char_matrix (c) { }
71 
72  octave_char_matrix_str (const char *s)
73  : octave_char_matrix (s) { }
74 
75  octave_char_matrix_str (const std::string& s)
76  : octave_char_matrix (s) { }
77 
79  : octave_char_matrix (s) { }
80 
82  : octave_char_matrix (chm) { }
83 
85  : octave_char_matrix (chms) { }
86 
87  ~octave_char_matrix_str (void) = default;
88 
89  octave_base_value * clone (void) const
90  { return new octave_char_matrix_str (*this); }
92  { return new octave_char_matrix_str (); }
93 
94  type_conv_info numeric_conversion_function (void) const;
95 
97  bool resize_ok = false)
98  { return do_index_op_internal (idx, resize_ok); }
99 
100  octave_value squeeze (void) const
101  { return octave_value (charNDArray (m_matrix.squeeze ())); }
102 
103  octave_value reshape (const dim_vector& new_dims) const
104  { return octave_value (charNDArray (m_matrix.reshape (new_dims))); }
105 
106  octave_value permute (const Array<int>& vec, bool inv = false) const
107  { return octave_value (charNDArray (m_matrix.permute (vec, inv))); }
108 
109  octave_value resize (const dim_vector& dv, bool fill = false) const;
110 
111  // We don't need to override both forms of the diag method. The using
112  // declaration will avoid warnings about partially-overloaded virtual
113  // functions.
115 
117  { return octave_value (m_matrix.diag (k)); }
118 
119  bool is_string (void) const { return true; }
120 
121  bool isnumeric (void) const { return false; }
122 
123  double double_value (bool = false) const;
124 
125  Matrix matrix_value (bool = false) const;
126 
127  NDArray array_value (bool = false) const;
128 
129  Complex complex_value (bool = false) const;
130 
131  ComplexMatrix complex_matrix_value (bool = false) const;
132 
133  ComplexNDArray complex_array_value (bool = false) const;
134 
135  string_vector string_vector_value (bool pad = false) const;
136 
137  std::string string_value (bool force = false) const;
138 
139  std::string xstring_value (void) const { return string_value (); }
140 
141  Array<std::string> cellstr_value (void) const;
142 
144  { return octave_value (m_matrix.sort (dim, mode)); }
145 
147  sortmode mode = ASCENDING) const
148  { return octave_value (m_matrix.sort (sidx, dim, mode)); }
149 
150  bool print_as_scalar (void) const { return (rows () <= 1); }
151 
152  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
153 
154  void short_disp (std::ostream& os) const;
155 
156  std::string edit_display (const float_display_format& fmt,
157  octave_idx_type i, octave_idx_type j) const;
158 
159  bool save_ascii (std::ostream& os);
160 
161  bool load_ascii (std::istream& is);
162 
163  bool save_binary (std::ostream& os, bool save_as_floats);
164 
165  bool load_binary (std::istream& is, bool swap,
167 
168  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
169 
170  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
171 
172  int write (octave::stream& os, int block_size,
173  oct_data_conv::data_type output_type, int skip,
174  octave::mach_info::float_format flt_fmt) const
175  { return os.write (m_matrix, block_size, output_type, skip, flt_fmt); }
176 
177 protected:
178 
179  octave_value do_index_op_internal (const octave_value_list& idx,
180  bool resize_ok, char type = '"');
181 
182 private:
183 
185 };
186 
188 
189 class
191 {
192 public:
193 
195  : octave_char_matrix_str () { }
196 
198  : octave_char_matrix_str (chm) { }
199 
201  : octave_char_matrix_str (chm) { }
202 
204  : octave_char_matrix_str (chm) { }
205 
207  : octave_char_matrix_str (c) { }
208 
210  : octave_char_matrix_str (s) { }
211 
212  octave_char_matrix_sq_str (const std::string& s)
213  : octave_char_matrix_str (s) { }
214 
216  : octave_char_matrix_str (s) { }
217 
219  : octave_char_matrix_str (chm) { }
220 
222  : octave_char_matrix_str (chms) { }
223 
224  ~octave_char_matrix_sq_str (void) = default;
225 
226  octave_base_value * clone (void) const
227  { return new octave_char_matrix_sq_str (*this); }
229  { return new octave_char_matrix_sq_str (); }
230 
231  octave_value squeeze (void) const
232  { return octave_value (charNDArray (m_matrix.squeeze ()), '\''); }
233 
234  octave_value reshape (const dim_vector& new_dims) const
235  { return octave_value (charNDArray (m_matrix.reshape (new_dims)), '\''); }
236 
237  octave_value permute (const Array<int>& vec, bool inv = false) const
238  { return octave_value (charNDArray (m_matrix.permute (vec, inv)), '\''); }
239 
240  octave_value resize (const dim_vector& dv, bool = false) const
241  {
242  charNDArray retval (m_matrix);
243  retval.resize (dv);
244  return octave_value (retval, '\'');
245  }
246 
247  // We don't need to override both forms of the diag method. The using
248  // declaration will avoid warnings about partially-overloaded virtual
249  // functions.
251 
253  { return octave_value (m_matrix.diag (k), '\''); }
254 
255  bool is_sq_string (void) const { return true; }
256 
258  bool resize_ok = false)
259  { return do_index_op_internal (idx, resize_ok, '\''); }
260 
262  { return octave_value (m_matrix.sort (dim, mode), '\''); }
263 
265  sortmode mode = ASCENDING) const
266  { return octave_value (m_matrix.sort (sidx, dim, mode), '\''); }
267 
268 private:
269 
271 };
272 
273 #endif
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array-base.cc:1032
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
octave_value diag(octave_idx_type k=0) const
Definition: ov-base-mat.h:139
octave_base_value * empty_clone(void) const
Definition: ov-str-mat.h:228
octave_char_matrix_sq_str(const octave_char_matrix_sq_str &chms)
Definition: ov-str-mat.h:221
octave_char_matrix_sq_str(const char *s)
Definition: ov-str-mat.h:209
octave_char_matrix_sq_str(const octave_char_matrix_str &chm)
Definition: ov-str-mat.h:218
~octave_char_matrix_sq_str(void)=default
octave_value resize(const dim_vector &dv, bool=false) const
Definition: ov-str-mat.h:240
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:264
octave_char_matrix_sq_str(const std::string &s)
Definition: ov-str-mat.h:212
octave_char_matrix_sq_str(const charMatrix &chm)
Definition: ov-str-mat.h:197
octave_char_matrix_sq_str(const Array< char > &chm)
Definition: ov-str-mat.h:203
octave_value squeeze(void) const
Definition: ov-str-mat.h:231
bool is_sq_string(void) const
Definition: ov-str-mat.h:255
octave_char_matrix_sq_str(const string_vector &s)
Definition: ov-str-mat.h:215
octave_base_value * clone(void) const
Definition: ov-str-mat.h:226
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:234
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-str-mat.h:257
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:261
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:252
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:237
octave_char_matrix_sq_str(const charNDArray &chm)
Definition: ov-str-mat.h:200
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:106
bool isnumeric(void) const
Definition: ov-str-mat.h:121
octave_char_matrix_str(const Array< char > &chm)
Definition: ov-str-mat.h:66
octave_char_matrix_str(char c)
Definition: ov-str-mat.h:69
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:146
octave_char_matrix_str(const string_vector &s)
Definition: ov-str-mat.h:78
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:103
int write(octave::stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
Definition: ov-str-mat.h:172
std::string xstring_value(void) const
Definition: ov-str-mat.h:139
octave_char_matrix_str(const std::string &s)
Definition: ov-str-mat.h:75
octave_base_value * empty_clone(void) const
Definition: ov-str-mat.h:91
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:116
octave_base_value * clone(void) const
Definition: ov-str-mat.h:89
bool is_string(void) const
Definition: ov-str-mat.h:119
octave_char_matrix_str(const octave_char_matrix &chm)
Definition: ov-str-mat.h:81
octave_value squeeze(void) const
Definition: ov-str-mat.h:100
octave_char_matrix_str(const charMatrix &chm)
Definition: ov-str-mat.h:60
~octave_char_matrix_str(void)=default
octave_char_matrix_str(const octave_char_matrix_str &chms)
Definition: ov-str-mat.h:84
octave_char_matrix_str(const char *s)
Definition: ov-str-mat.h:72
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:143
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-str-mat.h:96
bool print_as_scalar(void) const
Definition: ov-str-mat.h:150
octave_char_matrix_str(const charNDArray &chm)
Definition: ov-str-mat.h:63
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:117
Array< octave_value > array_value(void) const
Definition: ovl.h:90
float_format
Definition: mach-info.h:38
std::complex< double > Complex
Definition: oct-cmplx.h:33
int64_t octave_hdf5_id
sortmode
Definition: oct-sort.h:97
@ ASCENDING
Definition: oct-sort.h:97
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:181
octave_char_matrix_str octave_char_matrix_dq_str
Definition: ov-str-mat.h:187