GNU Octave  4.4.1
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-2018 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_ov_str_mat_h)
25 #define octave_ov_str_mat_h 1
26 
27 #include "octave-config.h"
28 
29 #include <cstdlib>
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include "mx-base.h"
35 #include "str-vec.h"
36 
37 #include "error.h"
38 #include "oct-stream.h"
39 #include "ov.h"
40 #include "ov-ch-mat.h"
41 #include "ov-re-mat.h"
42 #include "ov-typeinfo.h"
43 
44 class octave_value_list;
45 
46 // Character matrix values with special properties for use as
47 // strings.
48 
49 class
50 OCTINTERP_API
52 {
53 public:
54 
56  : octave_char_matrix () { }
57 
59  : octave_char_matrix (chm) { }
60 
62  : octave_char_matrix (chm) { }
63 
65  : octave_char_matrix (chm) { }
66 
68  : octave_char_matrix (c) { }
69 
70  octave_char_matrix_str (const char *s)
71  : octave_char_matrix (s) { }
72 
74  : octave_char_matrix (s) { }
75 
77  : octave_char_matrix (s) { }
78 
80  : octave_char_matrix (chm) { }
81 
83  : octave_char_matrix (chms) { }
84 
85  ~octave_char_matrix_str (void) = default;
86 
87  octave_base_value * clone (void) const
88  { return new octave_char_matrix_str (*this); }
90  { return new octave_char_matrix_str (); }
91 
92  type_conv_info numeric_conversion_function (void) const;
93 
95  bool resize_ok = false)
96  { return do_index_op_internal (idx, resize_ok); }
97 
98  octave_value squeeze (void) const
99  { return octave_value (charNDArray (matrix.squeeze ())); }
100 
101  octave_value reshape (const dim_vector& new_dims) const
102  { return octave_value (charNDArray (matrix.reshape (new_dims))); }
103 
104  octave_value permute (const Array<int>& vec, bool inv = false) const
105  { return octave_value (charNDArray (matrix.permute (vec, inv))); }
106 
107  octave_value resize (const dim_vector& dv, bool fill = false) const;
108 
110  { return octave_value (matrix.diag (k)); }
111 
112  bool is_string (void) const { return true; }
113 
114  bool isnumeric (void) const { return false; }
115 
116  double double_value (bool = false) const;
117 
118  Matrix matrix_value (bool = false) const;
119 
120  NDArray array_value (bool = false) const;
121 
122  Complex complex_value (bool = false) const;
123 
124  ComplexMatrix complex_matrix_value (bool = false) const;
125 
126  ComplexNDArray complex_array_value (bool = false) const;
127 
128  string_vector string_vector_value (bool pad = false) const;
129 
130  std::string string_value (bool force = false) const;
131 
132  std::string xstring_value (void) const { return string_value (); }
133 
134  Array<std::string> cellstr_value (void) const;
135 
137  { return octave_value (matrix.sort (dim, mode)); }
138 
140  sortmode mode = ASCENDING) const
141  { return octave_value (matrix.sort (sidx, dim, mode)); }
142 
143  bool print_as_scalar (void) const { return (rows () <= 1); }
144 
145  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
146 
147  void short_disp (std::ostream& os) const;
148 
149  std::string edit_display (const float_display_format& fmt,
151 
152  bool save_ascii (std::ostream& os);
153 
154  bool load_ascii (std::istream& is);
155 
156  bool save_binary (std::ostream& os, bool& save_as_floats);
157 
158  bool load_binary (std::istream& is, bool swap,
160 
161  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
162 
163  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
164 
165  int write (octave::stream& os, int block_size,
166  oct_data_conv::data_type output_type, int skip,
168  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
169 
170 protected:
171 
172  octave_value do_index_op_internal (const octave_value_list& idx,
173  bool resize_ok, char type = '"');
174 
175 private:
176 
178 };
179 
181 
182 class
184 {
185 public:
186 
188  : octave_char_matrix_str () { }
189 
191  : octave_char_matrix_str (chm) { }
192 
194  : octave_char_matrix_str (chm) { }
195 
197  : octave_char_matrix_str (chm) { }
198 
200  : octave_char_matrix_str (c) { }
201 
203  : octave_char_matrix_str (s) { }
204 
206  : octave_char_matrix_str (s) { }
207 
209  : octave_char_matrix_str (s) { }
210 
212  : octave_char_matrix_str (chm) { }
213 
215  : octave_char_matrix_str (chms) { }
216 
217  ~octave_char_matrix_sq_str (void) = default;
218 
219  octave_base_value * clone (void) const
220  { return new octave_char_matrix_sq_str (*this); }
222  { return new octave_char_matrix_sq_str (); }
223 
224  octave_value squeeze (void) const
225  { return octave_value (charNDArray (matrix.squeeze ()), '\''); }
226 
227  octave_value reshape (const dim_vector& new_dims) const
228  { return octave_value (charNDArray (matrix.reshape (new_dims)), '\''); }
229 
230  octave_value permute (const Array<int>& vec, bool inv = false) const
231  { return octave_value (charNDArray (matrix.permute (vec, inv)), '\''); }
232 
233  octave_value resize (const dim_vector& dv, bool = false) const
234  {
236  retval.resize (dv);
237  return octave_value (retval, '\'');
238  }
239 
241  { return octave_value (matrix.diag (k), '\''); }
242 
243  bool is_sq_string (void) const { return true; }
244 
246  bool resize_ok = false)
247  { return do_index_op_internal (idx, resize_ok, '\''); }
248 
250  { return octave_value (matrix.sort (dim, mode), '\''); }
251 
253  sortmode mode = ASCENDING) const
254  { return octave_value (matrix.sort (sidx, dim, mode), '\''); }
255 
256 private:
257 
259 };
260 
261 #endif
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
Definition: oct-stream.cc:6704
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:240
octave_char_matrix_sq_str(const char *s)
Definition: ov-str-mat.h:202
characters Given a string matrix
Definition: hex2num.cc:155
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:139
sortmode
Definition: oct-sort.h:105
octave_value resize(const dim_vector &dv, bool=false) const
Definition: ov-str-mat.h:233
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
bool isnumeric(void) const
Definition: ov-str-mat.h:114
for large enough k
Definition: lu.cc:617
octave_base_value * clone(void) const
Definition: ov-str-mat.h:219
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:230
octave_value squeeze(void) const
Definition: ov-str-mat.h:98
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:136
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:736
octave_char_matrix_sq_str(const string_vector &s)
Definition: ov-str-mat.h:208
octave_base_value * empty_clone(void) const
Definition: ov-str-mat.h:221
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
s
Definition: file-io.cc:2729
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-str-mat.h:245
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:109
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:227
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:511
octave_char_matrix_str(const charMatrix &chm)
Definition: ov-str-mat.h:58
octave_char_matrix_sq_str(const charMatrix &chm)
Definition: ov-str-mat.h:190
bool swap
Definition: load-save.cc:738
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:165
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
octave_char_matrix_sq_str(const Array< char > &chm)
Definition: ov-str-mat.h:196
nd deftypefn *std::string name
Definition: sysdep.cc:647
octave_base_value * empty_clone(void) const
Definition: ov-str-mat.h:89
octave_char_matrix_str(const std::string &s)
Definition: ov-str-mat.h:73
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:104
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:101
octave_base_value * clone(void) const
Definition: ov-str-mat.h:87
Array< octave_value > array_value(void) const
Definition: ovl.h:86
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:249
bool save_as_floats
Definition: load-save.cc:1617
octave_value retval
Definition: data.cc:6246
octave_char_matrix_sq_str(const octave_char_matrix_sq_str &chms)
Definition: ov-str-mat.h:214
int64_t octave_hdf5_id
idx type
Definition: ov.cc:3114
Definition: dMatrix.h:36
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:252
octave_char_matrix_str octave_char_matrix_dq_str
Definition: ov-str-mat.h:180
std::string xstring_value(void) const
Definition: ov-str-mat.h:132
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_char_matrix_str(const octave_char_matrix_str &chms)
Definition: ov-str-mat.h:82
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-str-mat.h:94
octave_char_matrix_str(const Array< char > &chm)
Definition: ov-str-mat.h:64
octave_char_matrix_str(char c)
Definition: ov-str-mat.h:67
octave_char_matrix_sq_str(const charNDArray &chm)
Definition: ov-str-mat.h:193
octave_char_matrix_sq_str(const std::string &s)
Definition: ov-str-mat.h:205
octave_value squeeze(void) const
Definition: ov-str-mat.h:224
octave_char_matrix_str(const string_vector &s)
Definition: ov-str-mat.h:76
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
bool print_as_scalar(void) const
Definition: ov-str-mat.h:143
for i
Definition: data.cc:5264
octave_char_matrix_str(const charNDArray &chm)
Definition: ov-str-mat.h:61
std::complex< double > Complex
Definition: oct-cmplx.h:31
octave_char_matrix_str(const char *s)
Definition: ov-str-mat.h:70
write the output to stdout if nargout is
Definition: load-save.cc:1612
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
dim_vector dv
Definition: sub2ind.cc:263
octave_char_matrix_str(const octave_char_matrix &chm)
Definition: ov-str-mat.h:79
octave_char_matrix_sq_str(const octave_char_matrix_str &chm)
Definition: ov-str-mat.h:211
octave::stream os
Definition: file-io.cc:627
bool is_string(void) const
Definition: ov-str-mat.h:112
bool is_sq_string(void) const
Definition: ov-str-mat.h:243