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 |
5759
|
83 octave_base_value *clone (void) const { return new octave_char_matrix_str (*this); } |
|
84 octave_base_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 |
5885
|
88 octave_value do_index_op (const octave_value_list& idx, |
|
89 bool resize_ok = false) |
5400
|
90 { return do_index_op_internal (idx, resize_ok); } |
2407
|
91 |
|
92 void assign (const octave_value_list& idx, const charMatrix& rhs); |
|
93 |
4569
|
94 octave_value reshape (const dim_vector& new_dims) const |
|
95 { return octave_value (charNDArray (matrix.reshape (new_dims)), true); } |
|
96 |
5533
|
97 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
98 { return octave_value (charNDArray (matrix.permute (vec, inv)), true); } |
|
99 |
5731
|
100 octave_value resize (const dim_vector& dv, bool fill = false) const; |
5533
|
101 |
2376
|
102 bool is_string (void) const { return true; } |
|
103 |
4323
|
104 bool is_real_type (void) const { return false; } |
2376
|
105 |
4323
|
106 bool is_matrix_type (void) const { return false; } |
3202
|
107 |
4323
|
108 bool is_numeric_type (void) const { return false; } |
3221
|
109 |
2376
|
110 bool valid_as_scalar_index (void) const; |
|
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 |
3219
|
128 bool print_as_scalar (void) const { return (rows () <= 1); } |
2901
|
129 |
3523
|
130 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
131 |
4687
|
132 bool save_ascii (std::ostream& os, bool& infnan_warned, |
5863
|
133 bool strip_nan_and_inf); |
4687
|
134 |
|
135 bool load_ascii (std::istream& is); |
|
136 |
|
137 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
138 |
|
139 bool load_binary (std::istream& is, bool swap, |
|
140 oct_mach_info::float_format fmt); |
|
141 |
|
142 #if defined (HAVE_HDF5) |
|
143 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
144 |
|
145 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
146 #endif |
|
147 |
4944
|
148 int write (octave_stream& os, int block_size, |
|
149 oct_data_conv::data_type output_type, int skip, |
|
150 oct_mach_info::float_format flt_fmt) const |
|
151 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
|
152 |
5400
|
153 protected: |
|
154 |
|
155 octave_value do_index_op_internal (const octave_value_list& idx, |
5885
|
156 bool resize_ok, char type = '"'); |
5400
|
157 |
2376
|
158 private: |
|
159 |
3219
|
160 DECLARE_OCTAVE_ALLOCATOR |
2376
|
161 |
3219
|
162 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
163 }; |
|
164 |
5279
|
165 typedef octave_char_matrix_str octave_char_matrix_dq_str; |
|
166 |
|
167 class |
|
168 octave_char_matrix_sq_str : public octave_char_matrix_str |
|
169 { |
|
170 public: |
|
171 |
|
172 octave_char_matrix_sq_str (void) |
|
173 : octave_char_matrix_str () { } |
|
174 |
|
175 octave_char_matrix_sq_str (const charMatrix& chm) |
|
176 : octave_char_matrix_str (chm) { } |
|
177 |
|
178 octave_char_matrix_sq_str (const charNDArray& chm) |
|
179 : octave_char_matrix_str (chm) { } |
|
180 |
|
181 octave_char_matrix_sq_str (char c) |
|
182 : octave_char_matrix_str (c) { } |
|
183 |
|
184 octave_char_matrix_sq_str (const char *s) |
|
185 : octave_char_matrix_str (s) { } |
|
186 |
|
187 octave_char_matrix_sq_str (const std::string& s) |
|
188 : octave_char_matrix_str (s) { } |
|
189 |
|
190 octave_char_matrix_sq_str (const string_vector& s) |
|
191 : octave_char_matrix_str (s) { } |
|
192 |
|
193 octave_char_matrix_sq_str (const octave_char_matrix_str& chm) |
|
194 : octave_char_matrix_str (chm) { } |
|
195 |
|
196 octave_char_matrix_sq_str (const octave_char_matrix_sq_str& chms) |
|
197 : octave_char_matrix_str (chms) { } |
|
198 |
|
199 ~octave_char_matrix_sq_str (void) { } |
|
200 |
5759
|
201 octave_base_value *clone (void) const { return new octave_char_matrix_sq_str (*this); } |
|
202 octave_base_value *empty_clone (void) const { return new octave_char_matrix_sq_str (); } |
5279
|
203 |
5533
|
204 octave_value reshape (const dim_vector& new_dims) const |
|
205 { return octave_value (charNDArray (matrix.reshape (new_dims)), true, '\''); } |
|
206 |
|
207 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
208 { return octave_value (charNDArray (matrix.permute (vec, inv)), true, '\''); } |
|
209 |
|
210 octave_value resize (const dim_vector& dv) const |
|
211 { |
|
212 charNDArray retval (matrix); |
|
213 retval.resize (dv); |
|
214 return octave_value (retval, true, '\''); |
|
215 } |
|
216 |
5279
|
217 bool is_sq_string (void) const { return true; } |
|
218 |
5885
|
219 octave_value do_index_op (const octave_value_list& idx, |
|
220 bool resize_ok = false) |
5400
|
221 { return do_index_op_internal (idx, resize_ok, '\''); } |
|
222 |
5279
|
223 private: |
|
224 |
|
225 DECLARE_OCTAVE_ALLOCATOR |
|
226 |
|
227 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
228 }; |
|
229 |
2376
|
230 #endif |
|
231 |
|
232 /* |
|
233 ;;; Local Variables: *** |
|
234 ;;; mode: C++ *** |
|
235 ;;; End: *** |
|
236 */ |