2376
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 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 |
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 |
6109
|
50 OCTINTERP_API |
2376
|
51 octave_char_matrix_str : public octave_char_matrix |
|
52 { |
|
53 public: |
|
54 |
|
55 octave_char_matrix_str (void) |
|
56 : octave_char_matrix () { } |
|
57 |
|
58 octave_char_matrix_str (const charMatrix& chm) |
|
59 : octave_char_matrix (chm) { } |
|
60 |
4513
|
61 octave_char_matrix_str (const charNDArray& chm) |
|
62 : octave_char_matrix (chm) { } |
|
63 |
3189
|
64 octave_char_matrix_str (char c) |
|
65 : octave_char_matrix (c) { } |
|
66 |
2376
|
67 octave_char_matrix_str (const char *s) |
|
68 : octave_char_matrix (s) { } |
|
69 |
3523
|
70 octave_char_matrix_str (const std::string& s) |
2376
|
71 : octave_char_matrix (s) { } |
|
72 |
|
73 octave_char_matrix_str (const string_vector& s) |
|
74 : octave_char_matrix (s) { } |
|
75 |
|
76 octave_char_matrix_str (const octave_char_matrix& chm) |
|
77 : octave_char_matrix (chm) { } |
|
78 |
|
79 octave_char_matrix_str (const octave_char_matrix_str& chms) |
|
80 : octave_char_matrix (chms) { } |
|
81 |
|
82 ~octave_char_matrix_str (void) { } |
|
83 |
5759
|
84 octave_base_value *clone (void) const { return new octave_char_matrix_str (*this); } |
|
85 octave_base_value *empty_clone (void) const { return new octave_char_matrix_str (); } |
2376
|
86 |
2412
|
87 type_conv_fcn numeric_conversion_function (void) const; |
2376
|
88 |
5885
|
89 octave_value do_index_op (const octave_value_list& idx, |
|
90 bool resize_ok = false) |
5400
|
91 { return do_index_op_internal (idx, resize_ok); } |
2407
|
92 |
|
93 void assign (const octave_value_list& idx, const charMatrix& rhs); |
|
94 |
4569
|
95 octave_value reshape (const dim_vector& new_dims) const |
|
96 { return octave_value (charNDArray (matrix.reshape (new_dims)), true); } |
|
97 |
5533
|
98 octave_value permute (const Array<int>& vec, bool inv = false) const |
|
99 { return octave_value (charNDArray (matrix.permute (vec, inv)), true); } |
|
100 |
5731
|
101 octave_value resize (const dim_vector& dv, bool fill = false) const; |
5533
|
102 |
2376
|
103 bool is_string (void) const { return true; } |
|
104 |
4323
|
105 bool is_real_type (void) const { return false; } |
2376
|
106 |
4323
|
107 bool is_matrix_type (void) const { return false; } |
3202
|
108 |
4323
|
109 bool is_numeric_type (void) const { return false; } |
3221
|
110 |
2376
|
111 bool valid_as_scalar_index (void) const; |
|
112 |
4643
|
113 double double_value (bool = false) const; |
|
114 |
2376
|
115 Matrix matrix_value (bool = false) const; |
|
116 |
4668
|
117 NDArray array_value (bool = false) const; |
|
118 |
|
119 Complex complex_value (bool = false) const; |
|
120 |
|
121 ComplexMatrix complex_matrix_value (bool = false) const; |
|
122 |
|
123 ComplexNDArray complex_array_value (bool = false) const; |
|
124 |
5715
|
125 string_vector all_strings (bool pad = false) const; |
2376
|
126 |
4457
|
127 std::string string_value (bool force = false) const; |
2376
|
128 |
3219
|
129 bool print_as_scalar (void) const { return (rows () <= 1); } |
2901
|
130 |
3523
|
131 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
132 |
6974
|
133 bool save_ascii (std::ostream& os); |
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 |
5890
|
210 octave_value resize (const dim_vector& dv, bool = false) const |
5533
|
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 */ |