Mercurial > hg > octave-nkf
annotate src/ov-str-mat.h @ 10291:fc879f361bda
make isreal matlab compatible
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 10 Feb 2010 07:29:53 +0100 |
parents | cd96d29c5efa |
children | f3b65e1ae355 |
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 |
2376 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_char_matrix_str_h) | |
25 #define octave_char_matrix_str_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
2376 | 30 #include <string> |
31 | |
32 #include "mx-base.h" | |
33 #include "str-vec.h" | |
34 | |
35 #include "error.h" | |
4944 | 36 #include "oct-stream.h" |
3202 | 37 #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
|
38 #include "ov-ch-mat.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
39 #include "ov-re-mat.h" |
2376 | 40 #include "ov-typeinfo.h" |
41 | |
42 class Octave_map; | |
43 class octave_value_list; | |
44 | |
45 class tree_walker; | |
46 | |
2477 | 47 // Character matrix values with special properties for use as |
48 // strings. | |
2376 | 49 |
50 class | |
6109 | 51 OCTINTERP_API |
2376 | 52 octave_char_matrix_str : public octave_char_matrix |
53 { | |
54 public: | |
55 | |
56 octave_char_matrix_str (void) | |
57 : octave_char_matrix () { } | |
58 | |
59 octave_char_matrix_str (const charMatrix& chm) | |
60 : octave_char_matrix (chm) { } | |
61 | |
4513 | 62 octave_char_matrix_str (const charNDArray& chm) |
63 : octave_char_matrix (chm) { } | |
64 | |
3189 | 65 octave_char_matrix_str (char c) |
66 : octave_char_matrix (c) { } | |
67 | |
2376 | 68 octave_char_matrix_str (const char *s) |
69 : octave_char_matrix (s) { } | |
70 | |
3523 | 71 octave_char_matrix_str (const std::string& s) |
2376 | 72 : octave_char_matrix (s) { } |
73 | |
74 octave_char_matrix_str (const string_vector& s) | |
75 : octave_char_matrix (s) { } | |
76 | |
77 octave_char_matrix_str (const octave_char_matrix& chm) | |
78 : octave_char_matrix (chm) { } | |
79 | |
80 octave_char_matrix_str (const octave_char_matrix_str& chms) | |
81 : octave_char_matrix (chms) { } | |
82 | |
83 ~octave_char_matrix_str (void) { } | |
84 | |
5759 | 85 octave_base_value *clone (void) const { return new octave_char_matrix_str (*this); } |
86 octave_base_value *empty_clone (void) const { return new octave_char_matrix_str (); } | |
2376 | 87 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
88 type_conv_info numeric_conversion_function (void) const; |
2376 | 89 |
5885 | 90 octave_value do_index_op (const octave_value_list& idx, |
91 bool resize_ok = false) | |
5400 | 92 { return do_index_op_internal (idx, resize_ok); } |
2407 | 93 |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
94 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
|
95 { 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
|
96 |
4569 | 97 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
|
98 { return octave_value (charNDArray (matrix.reshape (new_dims))); } |
4569 | 99 |
5533 | 100 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
|
101 { return octave_value (charNDArray (matrix.permute (vec, inv))); } |
5533 | 102 |
5731 | 103 octave_value resize (const dim_vector& dv, bool fill = false) const; |
5533 | 104 |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
105 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
|
106 { 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
|
107 |
2376 | 108 bool is_string (void) const { return true; } |
109 | |
4323 | 110 bool is_numeric_type (void) const { return false; } |
3221 | 111 |
4643 | 112 double double_value (bool = false) const; |
113 | |
2376 | 114 Matrix matrix_value (bool = false) const; |
115 | |
4668 | 116 NDArray array_value (bool = false) const; |
117 | |
118 Complex complex_value (bool = false) const; | |
119 | |
120 ComplexMatrix complex_matrix_value (bool = false) const; | |
121 | |
122 ComplexNDArray complex_array_value (bool = false) const; | |
123 | |
5715 | 124 string_vector all_strings (bool pad = false) const; |
2376 | 125 |
4457 | 126 std::string string_value (bool force = false) const; |
2376 | 127 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
128 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
|
129 { return octave_value (matrix.sort (dim, mode)); } |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
130 |
7433 | 131 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
132 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
|
133 { return octave_value (matrix.sort (sidx, dim, mode)); } |
7433 | 134 |
3219 | 135 bool print_as_scalar (void) const { return (rows () <= 1); } |
2901 | 136 |
3523 | 137 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 138 |
6974 | 139 bool save_ascii (std::ostream& os); |
4687 | 140 |
141 bool load_ascii (std::istream& is); | |
142 | |
143 bool save_binary (std::ostream& os, bool& save_as_floats); | |
144 | |
145 bool load_binary (std::istream& is, bool swap, | |
146 oct_mach_info::float_format fmt); | |
147 | |
148 #if defined (HAVE_HDF5) | |
149 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
150 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9689
diff
changeset
|
151 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 152 #endif |
153 | |
4944 | 154 int write (octave_stream& os, int block_size, |
155 oct_data_conv::data_type output_type, int skip, | |
156 oct_mach_info::float_format flt_fmt) const | |
157 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } | |
158 | |
5400 | 159 protected: |
160 | |
161 octave_value do_index_op_internal (const octave_value_list& idx, | |
5885 | 162 bool resize_ok, char type = '"'); |
5400 | 163 |
2376 | 164 private: |
165 | |
3219 | 166 DECLARE_OCTAVE_ALLOCATOR |
2376 | 167 |
3219 | 168 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 169 }; |
170 | |
5279 | 171 typedef octave_char_matrix_str octave_char_matrix_dq_str; |
172 | |
173 class | |
174 octave_char_matrix_sq_str : public octave_char_matrix_str | |
175 { | |
176 public: | |
177 | |
178 octave_char_matrix_sq_str (void) | |
179 : octave_char_matrix_str () { } | |
180 | |
181 octave_char_matrix_sq_str (const charMatrix& chm) | |
182 : octave_char_matrix_str (chm) { } | |
183 | |
184 octave_char_matrix_sq_str (const charNDArray& chm) | |
185 : octave_char_matrix_str (chm) { } | |
186 | |
187 octave_char_matrix_sq_str (char c) | |
188 : octave_char_matrix_str (c) { } | |
189 | |
190 octave_char_matrix_sq_str (const char *s) | |
191 : octave_char_matrix_str (s) { } | |
192 | |
193 octave_char_matrix_sq_str (const std::string& s) | |
194 : octave_char_matrix_str (s) { } | |
195 | |
196 octave_char_matrix_sq_str (const string_vector& s) | |
197 : octave_char_matrix_str (s) { } | |
198 | |
199 octave_char_matrix_sq_str (const octave_char_matrix_str& chm) | |
200 : octave_char_matrix_str (chm) { } | |
201 | |
202 octave_char_matrix_sq_str (const octave_char_matrix_sq_str& chms) | |
203 : octave_char_matrix_str (chms) { } | |
204 | |
205 ~octave_char_matrix_sq_str (void) { } | |
206 | |
5759 | 207 octave_base_value *clone (void) const { return new octave_char_matrix_sq_str (*this); } |
208 octave_base_value *empty_clone (void) const { return new octave_char_matrix_sq_str (); } | |
5279 | 209 |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
210 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
|
211 { 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
|
212 |
5533 | 213 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
|
214 { return octave_value (charNDArray (matrix.reshape (new_dims)), '\''); } |
5533 | 215 |
216 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
|
217 { return octave_value (charNDArray (matrix.permute (vec, inv)), '\''); } |
5533 | 218 |
5890 | 219 octave_value resize (const dim_vector& dv, bool = false) const |
5533 | 220 { |
221 charNDArray retval (matrix); | |
222 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
|
223 return octave_value (retval, '\''); |
5533 | 224 } |
225 | |
9688
90abfd8a2895
make squeeze and diag return char for char argument
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
226 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
|
227 { 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
|
228 |
5279 | 229 bool is_sq_string (void) const { return true; } |
230 | |
5885 | 231 octave_value do_index_op (const octave_value_list& idx, |
232 bool resize_ok = false) | |
5400 | 233 { return do_index_op_internal (idx, resize_ok, '\''); } |
234 | |
7433 | 235 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
236 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
|
237 { return octave_value (matrix.sort (dim, mode), '\''); } |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
238 |
7433 | 239 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
240 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
|
241 { return octave_value (matrix.sort (sidx, dim, mode), '\''); } |
7433 | 242 |
5279 | 243 private: |
244 | |
245 DECLARE_OCTAVE_ALLOCATOR | |
246 | |
247 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
248 }; | |
249 | |
2376 | 250 #endif |