GNU Octave  4.0.0
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-2015 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 <cstdlib>
28 
29 #include <iosfwd>
30 #include <string>
31 
32 #include "mx-base.h"
33 #include "str-vec.h"
34 
35 #include "error.h"
36 #include "oct-stream.h"
37 #include "ov.h"
38 #include "ov-ch-mat.h"
39 #include "ov-re-mat.h"
40 #include "ov-typeinfo.h"
41 
42 class octave_value_list;
43 
44 class tree_walker;
45 
46 // Character matrix values with special properties for use as
47 // strings.
48 
49 class
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 
73  octave_char_matrix_str (const std::string& s)
74  : octave_char_matrix (s) { }
75 
77  : octave_char_matrix (s) { }
78 
80  : octave_char_matrix (chm) { }
81 
83  : octave_char_matrix (chms) { }
84 
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 is_numeric_type (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 all_strings (bool pad = false) const;
129 
130  std::string string_value (bool force = false) const;
131 
132  Array<std::string> cellstr_value (void) const;
133 
135  { return octave_value (matrix.sort (dim, mode)); }
136 
138  sortmode mode = ASCENDING) const
139  { return octave_value (matrix.sort (sidx, dim, mode)); }
140 
141  bool print_as_scalar (void) const { return (rows () <= 1); }
142 
143  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
144 
145  void short_disp (std::ostream& os) const;
146 
147  bool save_ascii (std::ostream& os);
148 
149  bool load_ascii (std::istream& is);
150 
151  bool save_binary (std::ostream& os, bool& save_as_floats);
152 
153  bool load_binary (std::istream& is, bool swap,
155 
156  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
157 
158  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
159 
160  int write (octave_stream& os, int block_size,
161  oct_data_conv::data_type output_type, int skip,
162  oct_mach_info::float_format flt_fmt) const
163  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
164 
165 protected:
166 
167  octave_value do_index_op_internal (const octave_value_list& idx,
168  bool resize_ok, char type = '"');
169 
170 private:
171 
172 
174 };
175 
177 
178 class
180 {
181 public:
182 
184  : octave_char_matrix_str () { }
185 
187  : octave_char_matrix_str (chm) { }
188 
190  : octave_char_matrix_str (chm) { }
191 
193  : octave_char_matrix_str (chm) { }
194 
196  : octave_char_matrix_str (c) { }
197 
199  : octave_char_matrix_str (s) { }
200 
201  octave_char_matrix_sq_str (const std::string& s)
202  : octave_char_matrix_str (s) { }
203 
205  : octave_char_matrix_str (s) { }
206 
208  : octave_char_matrix_str (chm) { }
209 
211  : octave_char_matrix_str (chms) { }
212 
214 
215  octave_base_value *clone (void) const
216  { return new octave_char_matrix_sq_str (*this); }
218  { return new octave_char_matrix_sq_str (); }
219 
220  octave_value squeeze (void) const
221  { return octave_value (charNDArray (matrix.squeeze ()), '\''); }
222 
223  octave_value reshape (const dim_vector& new_dims) const
224  { return octave_value (charNDArray (matrix.reshape (new_dims)), '\''); }
225 
226  octave_value permute (const Array<int>& vec, bool inv = false) const
227  { return octave_value (charNDArray (matrix.permute (vec, inv)), '\''); }
228 
229  octave_value resize (const dim_vector& dv, bool = false) const
230  {
231  charNDArray retval (matrix);
232  retval.resize (dv);
233  return octave_value (retval, '\'');
234  }
235 
237  { return octave_value (matrix.diag (k), '\''); }
238 
239  bool is_sq_string (void) const { return true; }
240 
242  bool resize_ok = false)
243  { return do_index_op_internal (idx, resize_ok, '\''); }
244 
245 
247  { return octave_value (matrix.sort (dim, mode), '\''); }
248 
250  sortmode mode = ASCENDING) const
251  { return octave_value (matrix.sort (sidx, dim, mode), '\''); }
252 
253 private:
254 
255 
257 };
258 
259 #endif
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:109
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:226
octave_value squeeze(void) const
Definition: ov-str-mat.h:98
octave_char_matrix_sq_str(const char *s)
Definition: ov-str-mat.h:198
bool is_numeric_type(void) const
Definition: ov-str-mat.h:114
octave_base_value * empty_clone(void) const
Definition: ov-str-mat.h:217
sortmode
Definition: oct-sort.h:103
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:223
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:134
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-str-mat.h:104
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:249
octave_value resize(const dim_vector &dv, bool=false) const
Definition: ov-str-mat.h:229
octave_char_matrix_sq_str(const string_vector &s)
Definition: ov-str-mat.h:204
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:137
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov-str-mat.h:241
bool print_as_scalar(void) const
Definition: ov-str-mat.h:141
bool is_sq_string(void) const
Definition: ov-str-mat.h:239
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:186
octave_base_value * clone(void) const
Definition: ov-str-mat.h:215
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov-str-mat.h:246
octave_char_matrix_sq_str(const Array< char > &chm)
Definition: ov-str-mat.h:192
octave_char_matrix_str(const std::string &s)
Definition: ov-str-mat.h:73
octave_base_value * empty_clone(void) const
Definition: ov-str-mat.h:89
#define OCTINTERP_API
Definition: mexproto.h:66
octave_base_value * clone(void) const
Definition: ov-str-mat.h:87
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1033
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, oct_mach_info::float_format flt_fmt) const
Definition: ov-str-mat.h:160
octave_char_matrix_sq_str(const octave_char_matrix_sq_str &chms)
Definition: ov-str-mat.h:210
Definition: dMatrix.h:35
octave_value diag(octave_idx_type k=0) const
Definition: ov-str-mat.h:236
octave_char_matrix_str octave_char_matrix_dq_str
Definition: ov-str-mat.h:176
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:189
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, oct_mach_info::float_format flt_fmt)
Definition: oct-stream.cc:3546
octave_char_matrix_sq_str(const std::string &s)
Definition: ov-str-mat.h:201
octave_char_matrix_str(const string_vector &s)
Definition: ov-str-mat.h:76
octave_char_matrix_str(const charNDArray &chm)
Definition: ov-str-mat.h:61
bool is_string(void) const
Definition: ov-str-mat.h:112
std::complex< double > Complex
Definition: oct-cmplx.h:29
octave_char_matrix_str(const char *s)
Definition: ov-str-mat.h:70
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-str-mat.h:101
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:207
octave_value squeeze(void) const
Definition: ov-str-mat.h:220
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))