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
ov-str-mat.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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 <http://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 class tree_walker;
47 
48 // Character matrix values with special properties for use as
49 // strings.
50 
51 class
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 
76  : octave_char_matrix (s) { }
77 
79  : octave_char_matrix (s) { }
80 
82  : octave_char_matrix (chm) { }
83 
85  : octave_char_matrix (chms) { }
86 
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 (matrix.squeeze ())); }
102 
103  octave_value reshape (const dim_vector& new_dims) const
104  { return octave_value (charNDArray (matrix.reshape (new_dims))); }
105 
106  octave_value permute (const Array<int>& vec, bool inv = false) const
107  { return octave_value (charNDArray (matrix.permute (vec, inv))); }
108 
109  octave_value resize (const dim_vector& dv, bool fill = false) const;
110 
112  { return octave_value (matrix.diag (k)); }
113 
114  bool is_string (void) const { return true; }
115 
116  bool is_numeric_type (void) const { return false; }
117 
118  double double_value (bool = false) const;
119 
120  Matrix matrix_value (bool = false) const;
121 
122  NDArray array_value (bool = false) const;
123 
124  Complex complex_value (bool = false) const;
125 
126  ComplexMatrix complex_matrix_value (bool = false) const;
127 
128  ComplexNDArray complex_array_value (bool = false) const;
129 
130  string_vector string_vector_value (bool pad = false) const;
131 
132  std::string string_value (bool force = false) const;
133 
134  std::string xstring_value (void) const { return string_value (); }
135 
136  Array<std::string> cellstr_value (void) const;
137 
139  { return octave_value (matrix.sort (dim, mode)); }
140 
142  sortmode mode = ASCENDING) const
143  { return octave_value (matrix.sort (sidx, dim, mode)); }
144 
145  bool print_as_scalar (void) const { return (rows () <= 1); }
146 
147  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
148 
149  void short_disp (std::ostream& os) const;
150 
151  bool save_ascii (std::ostream& os);
152 
153  bool load_ascii (std::istream& is);
154 
155  bool save_binary (std::ostream& os, bool& save_as_floats);
156 
157  bool load_binary (std::istream& is, bool swap,
159 
160  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
161 
162  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
163 
164  int write (octave_stream& os, int block_size,
165  oct_data_conv::data_type output_type, int skip,
167  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
168 
169 protected:
170 
171  octave_value do_index_op_internal (const octave_value_list& idx,
172  bool resize_ok, char type = '"');
173 
174 private:
175 
177 };
178 
180 
181 class
183 {
184 public:
185 
187  : octave_char_matrix_str () { }
188 
190  : octave_char_matrix_str (chm) { }
191 
193  : octave_char_matrix_str (chm) { }
194 
196  : octave_char_matrix_str (chm) { }
197 
199  : octave_char_matrix_str (c) { }
200 
202  : octave_char_matrix_str (s) { }
203 
205  : octave_char_matrix_str (s) { }
206 
208  : octave_char_matrix_str (s) { }
209 
211  : octave_char_matrix_str (chm) { }
212 
214  : octave_char_matrix_str (chms) { }
215 
217 
218  octave_base_value *clone (void) const
219  { return new octave_char_matrix_sq_str (*this); }
221  { return new octave_char_matrix_sq_str (); }
222 
223  octave_value squeeze (void) const
224  { return octave_value (charNDArray (matrix.squeeze ()), '\''); }
225 
226  octave_value reshape (const dim_vector& new_dims) const
227  { return octave_value (charNDArray (matrix.reshape (new_dims)), '\''); }
228 
229  octave_value permute (const Array<int>& vec, bool inv = false) const
230  { return octave_value (charNDArray (matrix.permute (vec, inv)), '\''); }
231 
232  octave_value resize (const dim_vector& dv, bool = false) const
233  {
235  retval.resize (dv);
236  return octave_value (retval, '\'');
237  }
238 
240  { return octave_value (matrix.diag (k), '\''); }
241 
242  bool is_sq_string (void) const { return true; }
243 
245  bool resize_ok = false)
246  { return do_index_op_internal (idx, resize_ok, '\''); }
247 
249  { return octave_value (matrix.sort (dim, mode), '\''); }
250 
252  sortmode mode = ASCENDING) const
253  { return octave_value (matrix.sort (sidx, dim, mode), '\''); }
254 
255 private:
256 
258 };
259 
260 #endif
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:111
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:229
octave_value squeeze(void) const
Definition: ov-str-mat.h:100
octave_char_matrix_sq_str(const char *s)
Definition: ov-str-mat.h:201
bool is_numeric_type(void) const
Definition: ov-str-mat.h:116
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:164
octave_base_value * empty_clone(void) const
Definition: ov-str-mat.h:220
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, octave::mach_info::float_format flt_fmt)
Definition: oct-stream.cc:6647
sortmode
Definition: oct-sort.h:105
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:6386
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:226
for large enough k
Definition: lu.cc:606
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the then the first element defines the pivoting tolerance for the unsymmetric the values defined such that for full matrix
Definition: lu.cc:138
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:138
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:106
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:251
octave_value resize(const dim_vector &dv, bool=false) const
Definition: ov-str-mat.h:232
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:723
octave_char_matrix_sq_str(const string_vector &s)
Definition: ov-str-mat.h:207
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:141
s
Definition: file-io.cc:2682
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-str-mat.h:244
bool print_as_scalar(void) const
Definition: ov-str-mat.h:145
bool is_sq_string(void) const
Definition: ov-str-mat.h:242
octave_char_matrix_str(const charMatrix &chm)
Definition: ov-str-mat.h:60
octave_char_matrix_sq_str(const charMatrix &chm)
Definition: ov-str-mat.h:189
bool swap
Definition: load-save.cc:725
octave_base_value * clone(void) const
Definition: ov-str-mat.h:218
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:148
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:248
octave_char_matrix_sq_str(const Array< char > &chm)
Definition: ov-str-mat.h:195
std::string xstring_value(void) const
Definition: ov-str-mat.h:134
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
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
#define OCTINTERP_API
Definition: mexproto.h:69
octave_base_value * clone(void) const
Definition: ov-str-mat.h:89
bool save_as_floats
Definition: load-save.cc:1581
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1028
octave_value retval
Definition: data.cc:6294
octave_char_matrix_sq_str(const octave_char_matrix_sq_str &chms)
Definition: ov-str-mat.h:213
int64_t octave_hdf5_id
idx type
Definition: ov.cc:3129
Definition: dMatrix.h:37
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:239
octave_char_matrix_str octave_char_matrix_dq_str
Definition: ov-str-mat.h:179
octave_char_matrix_str(const octave_char_matrix_str &chms)
Definition: ov-str-mat.h:84
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-str-mat.h:96
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_char_matrix_sq_str(const charNDArray &chm)
Definition: ov-str-mat.h:192
octave_char_matrix_sq_str(const std::string &s)
Definition: ov-str-mat.h:204
octave_char_matrix_str(const string_vector &s)
Definition: ov-str-mat.h:78
octave_char_matrix_str(const charNDArray &chm)
Definition: ov-str-mat.h:63
bool is_string(void) const
Definition: ov-str-mat.h:114
std::complex< double > Complex
Definition: oct-cmplx.h:31
octave_char_matrix_str(const char *s)
Definition: ov-str-mat.h:72
write the output to stdout if nargout is
Definition: load-save.cc:1576
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:103
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:854
dim_vector dv
Definition: sub2ind.cc:263
octave_char_matrix_str(const octave_char_matrix &chm)
Definition: ov-str-mat.h:81
octave_char_matrix_sq_str(const octave_char_matrix_str &chm)
Definition: ov-str-mat.h:210
octave_value squeeze(void) const
Definition: ov-str-mat.h:223
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))