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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2376
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2376
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_char_matrix_str_h) |
|
24 #define octave_char_matrix_str_h 1 |
|
25 |
|
26 #include <cstdlib> |
|
27 |
3503
|
28 #include <iostream> |
2376
|
29 #include <string> |
|
30 |
|
31 #include "mx-base.h" |
|
32 #include "str-vec.h" |
|
33 |
|
34 #include "error.h" |
4944
|
35 #include "oct-stream.h" |
3202
|
36 #include "ov.h" |
2376
|
37 #include "ov-ch-mat.h" |
|
38 #include "ov-typeinfo.h" |
|
39 |
|
40 class Octave_map; |
|
41 class octave_value_list; |
|
42 |
|
43 class tree_walker; |
|
44 |
2477
|
45 // Character matrix values with special properties for use as |
|
46 // strings. |
2376
|
47 |
|
48 class |
6109
|
49 OCTINTERP_API |
2376
|
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 |
6974
|
132 bool save_ascii (std::ostream& os); |
4687
|
133 |
|
134 bool load_ascii (std::istream& is); |
|
135 |
|
136 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
137 |
|
138 bool load_binary (std::istream& is, bool swap, |
|
139 oct_mach_info::float_format fmt); |
|
140 |
|
141 #if defined (HAVE_HDF5) |
|
142 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
143 |
|
144 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
145 #endif |
|
146 |
4944
|
147 int write (octave_stream& os, int block_size, |
|
148 oct_data_conv::data_type output_type, int skip, |
|
149 oct_mach_info::float_format flt_fmt) const |
|
150 { return os.write (matrix, block_size, output_type, skip, flt_fmt); } |
|
151 |
5400
|
152 protected: |
|
153 |
|
154 octave_value do_index_op_internal (const octave_value_list& idx, |
5885
|
155 bool resize_ok, char type = '"'); |
5400
|
156 |
2376
|
157 private: |
|
158 |
3219
|
159 DECLARE_OCTAVE_ALLOCATOR |
2376
|
160 |
3219
|
161 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
162 }; |
|
163 |
5279
|
164 typedef octave_char_matrix_str octave_char_matrix_dq_str; |
|
165 |
|
166 class |
|
167 octave_char_matrix_sq_str : public octave_char_matrix_str |
|
168 { |
|
169 public: |
|
170 |
|
171 octave_char_matrix_sq_str (void) |
|
172 : octave_char_matrix_str () { } |
|
173 |
|
174 octave_char_matrix_sq_str (const charMatrix& chm) |
|
175 : octave_char_matrix_str (chm) { } |
|
176 |
|
177 octave_char_matrix_sq_str (const charNDArray& chm) |
|
178 : octave_char_matrix_str (chm) { } |
|
179 |
|
180 octave_char_matrix_sq_str (char c) |
|
181 : octave_char_matrix_str (c) { } |
|
182 |
|
183 octave_char_matrix_sq_str (const char *s) |
|
184 : octave_char_matrix_str (s) { } |
|
185 |
|
186 octave_char_matrix_sq_str (const std::string& s) |
|
187 : octave_char_matrix_str (s) { } |
|
188 |
|
189 octave_char_matrix_sq_str (const string_vector& s) |
|
190 : octave_char_matrix_str (s) { } |
|
191 |
|
192 octave_char_matrix_sq_str (const octave_char_matrix_str& chm) |
|
193 : octave_char_matrix_str (chm) { } |
|
194 |
|
195 octave_char_matrix_sq_str (const octave_char_matrix_sq_str& chms) |
|
196 : octave_char_matrix_str (chms) { } |
|
197 |
|
198 ~octave_char_matrix_sq_str (void) { } |
|
199 |
5759
|
200 octave_base_value *clone (void) const { return new octave_char_matrix_sq_str (*this); } |
|
201 octave_base_value *empty_clone (void) const { return new octave_char_matrix_sq_str (); } |
5279
|
202 |
5533
|
203 octave_value reshape (const dim_vector& new_dims) const |
|
204 { return octave_value (charNDArray (matrix.reshape (new_dims)), true, '\''); } |
|
205 |
|
206 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
207 { return octave_value (charNDArray (matrix.permute (vec, inv)), true, '\''); } |
|
208 |
5890
|
209 octave_value resize (const dim_vector& dv, bool = false) const |
5533
|
210 { |
|
211 charNDArray retval (matrix); |
|
212 retval.resize (dv); |
|
213 return octave_value (retval, true, '\''); |
|
214 } |
|
215 |
5279
|
216 bool is_sq_string (void) const { return true; } |
|
217 |
5885
|
218 octave_value do_index_op (const octave_value_list& idx, |
|
219 bool resize_ok = false) |
5400
|
220 { return do_index_op_internal (idx, resize_ok, '\''); } |
|
221 |
5279
|
222 private: |
|
223 |
|
224 DECLARE_OCTAVE_ALLOCATOR |
|
225 |
|
226 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
|
227 }; |
|
228 |
2376
|
229 #endif |
|
230 |
|
231 /* |
|
232 ;;; Local Variables: *** |
|
233 ;;; mode: C++ *** |
|
234 ;;; End: *** |
|
235 */ |