2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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 |
3503
|
29 #include <iostream> |
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" |
2376
|
38 #include "ov-ch-mat.h" |
|
39 #include "ov-typeinfo.h" |
|
40 |
|
41 class Octave_map; |
|
42 class octave_value_list; |
|
43 |
|
44 class tree_walker; |
|
45 |
2477
|
46 // Character matrix values with special properties for use as |
|
47 // strings. |
2376
|
48 |
|
49 class |
|
50 octave_char_matrix_str : public octave_char_matrix |
|
51 { |
|
52 public: |
|
53 |
|
54 octave_char_matrix_str (void) |
|
55 : octave_char_matrix () { } |
|
56 |
|
57 octave_char_matrix_str (const charMatrix& chm) |
|
58 : octave_char_matrix (chm) { } |
|
59 |
4513
|
60 octave_char_matrix_str (const charNDArray& chm) |
|
61 : octave_char_matrix (chm) { } |
|
62 |
3189
|
63 octave_char_matrix_str (char c) |
|
64 : octave_char_matrix (c) { } |
|
65 |
2376
|
66 octave_char_matrix_str (const char *s) |
|
67 : octave_char_matrix (s) { } |
|
68 |
3523
|
69 octave_char_matrix_str (const std::string& s) |
2376
|
70 : octave_char_matrix (s) { } |
|
71 |
|
72 octave_char_matrix_str (const string_vector& s) |
|
73 : octave_char_matrix (s) { } |
|
74 |
|
75 octave_char_matrix_str (const octave_char_matrix& chm) |
|
76 : octave_char_matrix (chm) { } |
|
77 |
|
78 octave_char_matrix_str (const octave_char_matrix_str& chms) |
|
79 : octave_char_matrix (chms) { } |
|
80 |
|
81 ~octave_char_matrix_str (void) { } |
|
82 |
3933
|
83 octave_value *clone (void) const { return new octave_char_matrix_str (*this); } |
|
84 octave_value *empty_clone (void) const { return new octave_char_matrix_str (); } |
2376
|
85 |
2412
|
86 type_conv_fcn numeric_conversion_function (void) const; |
2376
|
87 |
5400
|
88 octave_value do_index_op (const octave_value_list& idx, int resize_ok) |
|
89 { return do_index_op_internal (idx, resize_ok); } |
2407
|
90 |
|
91 void assign (const octave_value_list& idx, const charMatrix& rhs); |
|
92 |
4569
|
93 octave_value reshape (const dim_vector& new_dims) const |
|
94 { return octave_value (charNDArray (matrix.reshape (new_dims)), true); } |
|
95 |
5533
|
96 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
97 { return octave_value (charNDArray (matrix.permute (vec, inv)), true); } |
|
98 |
|
99 octave_value resize (const dim_vector& dv) const |
|
100 { |
|
101 charNDArray retval (matrix); |
|
102 retval.resize (dv); |
|
103 return octave_value (retval, true); |
|
104 } |
|
105 |
2376
|
106 bool is_string (void) const { return true; } |
|
107 |
4323
|
108 bool is_real_type (void) const { return false; } |
2376
|
109 |
4323
|
110 bool is_matrix_type (void) const { return false; } |
3202
|
111 |
4323
|
112 bool is_numeric_type (void) const { return false; } |
3221
|
113 |
2376
|
114 bool valid_as_scalar_index (void) const; |
|
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 |
3219
|
132 bool print_as_scalar (void) const { return (rows () <= 1); } |
2901
|
133 |
3523
|
134 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
135 |
4687
|
136 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
137 bool strip_nan_and_inf); |
|
138 |
|
139 bool load_ascii (std::istream& is); |
|
140 |
|
141 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
142 |
|
143 bool load_binary (std::istream& is, bool swap, |
|
144 oct_mach_info::float_format fmt); |
|
145 |
|
146 #if defined (HAVE_HDF5) |
|
147 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
148 |
|
149 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
150 #endif |
|
151 |
4944
|
152 int write (octave_stream& os, int block_size, |
|
153 oct_data_conv::data_type output_type, int skip, |
|
154 oct_mach_info::float_format flt_fmt) const |
|
155 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
|
156 |
5400
|
157 protected: |
|
158 |
|
159 octave_value do_index_op_internal (const octave_value_list& idx, |
|
160 int resize_ok, char type = '"'); |
|
161 |
2376
|
162 private: |
|
163 |
3219
|
164 DECLARE_OCTAVE_ALLOCATOR |
2376
|
165 |
3219
|
166 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
167 }; |
|
168 |
5279
|
169 typedef octave_char_matrix_str octave_char_matrix_dq_str; |
|
170 |
|
171 class |
|
172 octave_char_matrix_sq_str : public octave_char_matrix_str |
|
173 { |
|
174 public: |
|
175 |
|
176 octave_char_matrix_sq_str (void) |
|
177 : octave_char_matrix_str () { } |
|
178 |
|
179 octave_char_matrix_sq_str (const charMatrix& chm) |
|
180 : octave_char_matrix_str (chm) { } |
|
181 |
|
182 octave_char_matrix_sq_str (const charNDArray& chm) |
|
183 : octave_char_matrix_str (chm) { } |
|
184 |
|
185 octave_char_matrix_sq_str (char c) |
|
186 : octave_char_matrix_str (c) { } |
|
187 |
|
188 octave_char_matrix_sq_str (const char *s) |
|
189 : octave_char_matrix_str (s) { } |
|
190 |
|
191 octave_char_matrix_sq_str (const std::string& s) |
|
192 : octave_char_matrix_str (s) { } |
|
193 |
|
194 octave_char_matrix_sq_str (const string_vector& s) |
|
195 : octave_char_matrix_str (s) { } |
|
196 |
|
197 octave_char_matrix_sq_str (const octave_char_matrix_str& chm) |
|
198 : octave_char_matrix_str (chm) { } |
|
199 |
|
200 octave_char_matrix_sq_str (const octave_char_matrix_sq_str& chms) |
|
201 : octave_char_matrix_str (chms) { } |
|
202 |
|
203 ~octave_char_matrix_sq_str (void) { } |
|
204 |
|
205 octave_value *clone (void) const { return new octave_char_matrix_sq_str (*this); } |
|
206 octave_value *empty_clone (void) const { return new octave_char_matrix_sq_str (); } |
|
207 |
5533
|
208 octave_value reshape (const dim_vector& new_dims) const |
|
209 { return octave_value (charNDArray (matrix.reshape (new_dims)), true, '\''); } |
|
210 |
|
211 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
212 { return octave_value (charNDArray (matrix.permute (vec, inv)), true, '\''); } |
|
213 |
|
214 octave_value resize (const dim_vector& dv) const |
|
215 { |
|
216 charNDArray retval (matrix); |
|
217 retval.resize (dv); |
|
218 return octave_value (retval, true, '\''); |
|
219 } |
|
220 |
5279
|
221 bool is_sq_string (void) const { return true; } |
|
222 |
5400
|
223 octave_value do_index_op (const octave_value_list& idx, int resize_ok) |
|
224 { return do_index_op_internal (idx, resize_ok, '\''); } |
|
225 |
5279
|
226 private: |
|
227 |
|
228 DECLARE_OCTAVE_ALLOCATOR |
|
229 |
|
230 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
231 }; |
|
232 |
2376
|
233 #endif |
|
234 |
|
235 /* |
|
236 ;;; Local Variables: *** |
|
237 ;;; mode: C++ *** |
|
238 ;;; End: *** |
|
239 */ |