Mercurial > hg > octave-nkf
annotate src/ov-str-mat.h @ 10729:172253d75d94
implement cellstr extractors for char matrices
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 24 Jun 2010 14:39:32 +0200 |
parents | 4d1fc073fbb7 |
children | d9e57045b9e1 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 2007, 2008 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10351
diff
changeset
|
5 Copyright (C) 2009, 2010 VZLU Prague |
2376 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
2376 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
2376 | 22 |
23 */ | |
24 | |
25 #if !defined (octave_char_matrix_str_h) | |
26 #define octave_char_matrix_str_h 1 | |
27 | |
28 #include <cstdlib> | |
29 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
30 #include <iosfwd> |
2376 | 31 #include <string> |
32 | |
33 #include "mx-base.h" | |
34 #include "str-vec.h" | |
35 | |
36 #include "error.h" | |
4944 | 37 #include "oct-stream.h" |
3202 | 38 #include "ov.h" |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
39 #include "ov-ch-mat.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
40 #include "ov-re-mat.h" |
2376 | 41 #include "ov-typeinfo.h" |
42 | |
43 class Octave_map; | |
44 class octave_value_list; | |
45 | |
46 class tree_walker; | |
47 | |
2477 | 48 // Character matrix values with special properties for use as |
49 // strings. | |
2376 | 50 |
51 class | |
6109 | 52 OCTINTERP_API |
2376 | 53 octave_char_matrix_str : public octave_char_matrix |
54 { | |
55 public: | |
56 | |
57 octave_char_matrix_str (void) | |
58 : octave_char_matrix () { } | |
59 | |
60 octave_char_matrix_str (const charMatrix& chm) | |
61 : octave_char_matrix (chm) { } | |
62 | |
4513 | 63 octave_char_matrix_str (const charNDArray& chm) |
64 : octave_char_matrix (chm) { } | |
65 | |
10351
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
66 octave_char_matrix_str (const Array<char>& chm) |
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
67 : octave_char_matrix (chm) { } |
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
68 |
3189 | 69 octave_char_matrix_str (char c) |
70 : octave_char_matrix (c) { } | |
71 | |
2376 | 72 octave_char_matrix_str (const char *s) |
73 : octave_char_matrix (s) { } | |
74 | |
3523 | 75 octave_char_matrix_str (const std::string& s) |
2376 | 76 : octave_char_matrix (s) { } |
77 | |
78 octave_char_matrix_str (const string_vector& s) | |
79 : octave_char_matrix (s) { } | |
80 | |
81 octave_char_matrix_str (const octave_char_matrix& chm) | |
82 : octave_char_matrix (chm) { } | |
83 | |
84 octave_char_matrix_str (const octave_char_matrix_str& chms) | |
85 : octave_char_matrix (chms) { } | |
86 | |
87 ~octave_char_matrix_str (void) { } | |
88 | |
5759 | 89 octave_base_value *clone (void) const { return new octave_char_matrix_str (*this); } |
90 octave_base_value *empty_clone (void) const { return new octave_char_matrix_str (); } | |
2376 | 91 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
92 type_conv_info numeric_conversion_function (void) const; |
2376 | 93 |
5885 | 94 octave_value do_index_op (const octave_value_list& idx, |
10313 | 95 bool resize_ok = false) |
5400 | 96 { return do_index_op_internal (idx, resize_ok); } |
2407 | 97 |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
98 octave_value squeeze (void) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
99 { return octave_value (charNDArray (matrix.squeeze ())); } |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
100 |
4569 | 101 octave_value reshape (const dim_vector& new_dims) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
102 { return octave_value (charNDArray (matrix.reshape (new_dims))); } |
4569 | 103 |
5533 | 104 octave_value permute (const Array<int>& vec, bool inv = false) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
105 { return octave_value (charNDArray (matrix.permute (vec, inv))); } |
5533 | 106 |
5731 | 107 octave_value resize (const dim_vector& dv, bool fill = false) const; |
5533 | 108 |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
109 octave_value diag (octave_idx_type k = 0) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
110 { return octave_value (matrix.diag (k)); } |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
111 |
2376 | 112 bool is_string (void) const { return true; } |
113 | |
4323 | 114 bool is_numeric_type (void) const { return false; } |
3221 | 115 |
4643 | 116 double double_value (bool = false) const; |
117 | |
2376 | 118 Matrix matrix_value (bool = false) const; |
119 | |
4668 | 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 | |
5715 | 128 string_vector all_strings (bool pad = false) const; |
2376 | 129 |
4457 | 130 std::string string_value (bool force = false) const; |
2376 | 131 |
10729
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
132 Array<std::string> cellstr_value (void) const; |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
133 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
134 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
135 { return octave_value (matrix.sort (dim, mode)); } |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
136 |
7433 | 137 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
10313 | 138 sortmode mode = ASCENDING) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
139 { return octave_value (matrix.sort (sidx, dim, mode)); } |
7433 | 140 |
3219 | 141 bool print_as_scalar (void) const { return (rows () <= 1); } |
2901 | 142 |
3523 | 143 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 144 |
6974 | 145 bool save_ascii (std::ostream& os); |
4687 | 146 |
147 bool load_ascii (std::istream& is); | |
148 | |
149 bool save_binary (std::ostream& os, bool& save_as_floats); | |
150 | |
151 bool load_binary (std::istream& is, bool swap, | |
10313 | 152 oct_mach_info::float_format fmt); |
4687 | 153 |
154 #if defined (HAVE_HDF5) | |
155 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
156 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9689
diff
changeset
|
157 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 158 #endif |
159 | |
4944 | 160 int write (octave_stream& os, int block_size, |
10313 | 161 oct_data_conv::data_type output_type, int skip, |
162 oct_mach_info::float_format flt_fmt) const | |
4944 | 163 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
164 | |
5400 | 165 protected: |
166 | |
167 octave_value do_index_op_internal (const octave_value_list& idx, | |
10313 | 168 bool resize_ok, char type = '"'); |
5400 | 169 |
2376 | 170 private: |
171 | |
3219 | 172 DECLARE_OCTAVE_ALLOCATOR |
2376 | 173 |
3219 | 174 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 175 }; |
176 | |
5279 | 177 typedef octave_char_matrix_str octave_char_matrix_dq_str; |
178 | |
179 class | |
180 octave_char_matrix_sq_str : public octave_char_matrix_str | |
181 { | |
182 public: | |
183 | |
184 octave_char_matrix_sq_str (void) | |
185 : octave_char_matrix_str () { } | |
186 | |
187 octave_char_matrix_sq_str (const charMatrix& chm) | |
188 : octave_char_matrix_str (chm) { } | |
189 | |
190 octave_char_matrix_sq_str (const charNDArray& chm) | |
191 : octave_char_matrix_str (chm) { } | |
192 | |
10351
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
193 octave_char_matrix_sq_str (const Array<char>& chm) |
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
194 : octave_char_matrix_str (chm) { } |
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
195 |
5279 | 196 octave_char_matrix_sq_str (char c) |
197 : octave_char_matrix_str (c) { } | |
198 | |
199 octave_char_matrix_sq_str (const char *s) | |
200 : octave_char_matrix_str (s) { } | |
201 | |
202 octave_char_matrix_sq_str (const std::string& s) | |
203 : octave_char_matrix_str (s) { } | |
204 | |
205 octave_char_matrix_sq_str (const string_vector& s) | |
206 : octave_char_matrix_str (s) { } | |
207 | |
208 octave_char_matrix_sq_str (const octave_char_matrix_str& chm) | |
209 : octave_char_matrix_str (chm) { } | |
210 | |
211 octave_char_matrix_sq_str (const octave_char_matrix_sq_str& chms) | |
212 : octave_char_matrix_str (chms) { } | |
213 | |
214 ~octave_char_matrix_sq_str (void) { } | |
215 | |
5759 | 216 octave_base_value *clone (void) const { return new octave_char_matrix_sq_str (*this); } |
217 octave_base_value *empty_clone (void) const { return new octave_char_matrix_sq_str (); } | |
5279 | 218 |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
219 octave_value squeeze (void) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
220 { return octave_value (charNDArray (matrix.squeeze ()), '\''); } |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
221 |
5533 | 222 octave_value reshape (const dim_vector& new_dims) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
223 { return octave_value (charNDArray (matrix.reshape (new_dims)), '\''); } |
5533 | 224 |
225 octave_value permute (const Array<int>& vec, bool inv = false) const | |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
226 { return octave_value (charNDArray (matrix.permute (vec, inv)), '\''); } |
5533 | 227 |
5890 | 228 octave_value resize (const dim_vector& dv, bool = false) const |
5533 | 229 { |
230 charNDArray retval (matrix); | |
231 retval.resize (dv); | |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
232 return octave_value (retval, '\''); |
5533 | 233 } |
234 | |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
235 octave_value diag (octave_idx_type k = 0) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
236 { return octave_value (matrix.diag (k), '\''); } |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
237 |
5279 | 238 bool is_sq_string (void) const { return true; } |
239 | |
5885 | 240 octave_value do_index_op (const octave_value_list& idx, |
10313 | 241 bool resize_ok = false) |
5400 | 242 { return do_index_op_internal (idx, resize_ok, '\''); } |
243 | |
7433 | 244 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
245 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
246 { return octave_value (matrix.sort (dim, mode), '\''); } |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
247 |
7433 | 248 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
10313 | 249 sortmode mode = ASCENDING) const |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9688
diff
changeset
|
250 { return octave_value (matrix.sort (sidx, dim, mode), '\''); } |
7433 | 251 |
5279 | 252 private: |
253 | |
254 DECLARE_OCTAVE_ALLOCATOR | |
255 | |
256 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
257 }; | |
258 | |
2376 | 259 #endif |