GNU Octave  3.8.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-2013 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); }
89  octave_base_value *empty_clone (void) const
90  { return new octave_char_matrix_str (); }
91 
92  type_conv_info numeric_conversion_function (void) const;
93 
94  octave_value do_index_op (const octave_value_list& idx,
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 
109  octave_value diag (octave_idx_type k = 0) const
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 
134  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
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 #if defined (HAVE_HDF5)
157  bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
158 
159  bool load_hdf5 (hid_t loc_id, const char *name);
160 #endif
161 
162  int write (octave_stream& os, int block_size,
163  oct_data_conv::data_type output_type, int skip,
164  oct_mach_info::float_format flt_fmt) const
165  { return os.write (matrix, block_size, output_type, skip, flt_fmt); }
166 
167 protected:
168 
169  octave_value do_index_op_internal (const octave_value_list& idx,
170  bool resize_ok, char type = '"');
171 
172 private:
173 
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 
204  octave_char_matrix_sq_str (const std::string& s)
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); }
220  octave_base_value *empty_clone (void) const
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  {
234  charNDArray retval (matrix);
235  retval.resize (dv);
236  return octave_value (retval, '\'');
237  }
238 
239  octave_value diag (octave_idx_type k = 0) const
240  { return octave_value (matrix.diag (k), '\''); }
241 
242  bool is_sq_string (void) const { return true; }
243 
244  octave_value do_index_op (const octave_value_list& idx,
245  bool resize_ok = false)
246  { return do_index_op_internal (idx, resize_ok, '\''); }
247 
248 
249  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
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 
261 };
262 
263 #endif