Mercurial > octave-antonio
annotate libinterp/octave-value/ov-cell.cc @ 19697:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | 76478d2da117 |
children | 09ed6f7538dd |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1999-2015 John W. Eaton |
11523 | 4 Copyright (C) 2009-2010 VZLU Prague |
3353 | 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. | |
3353 | 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/>. | |
3353 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
5850 | 28 #include <iomanip> |
3503 | 29 #include <iostream> |
5765 | 30 #include <sstream> |
5164 | 31 #include <vector> |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
32 #include <queue> |
3353 | 33 |
5360 | 34 #include "Array-util.h" |
35 #include "byte-swap.h" | |
3353 | 36 #include "lo-utils.h" |
4153 | 37 #include "quit.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
38 #include "oct-locbuf.h" |
3353 | 39 |
40 #include "defun.h" | |
41 #include "error.h" | |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
42 #include "mxarray.h" |
3353 | 43 #include "ov-cell.h" |
3354 | 44 #include "oct-obj.h" |
3353 | 45 #include "unwind-prot.h" |
3354 | 46 #include "utils.h" |
3928 | 47 #include "ov-base-mat.h" |
48 #include "ov-base-mat.cc" | |
49 #include "ov-re-mat.h" | |
50 #include "ov-scalar.h" | |
5360 | 51 #include "pr-output.h" |
52 #include "ov-scalar.h" | |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
53 #include "gripes.h" |
3928 | 54 |
4687 | 55 #include "ls-oct-ascii.h" |
56 #include "ls-oct-binary.h" | |
57 #include "ls-hdf5.h" | |
58 #include "ls-utils.h" | |
59 | |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
60 // Cell is able to handle octave_value indexing by itself, so just forward |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
61 // everything. |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
62 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
63 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
64 octave_value |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
65 octave_base_matrix<Cell>::do_index_op (const octave_value_list& idx, |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
66 bool resize_ok) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
67 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
68 return matrix.index (idx, resize_ok); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
69 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
70 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
71 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
72 void |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
73 octave_base_matrix<Cell>::assign (const octave_value_list& idx, const Cell& rhs) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
74 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
75 matrix.assign (idx, rhs); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
76 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
77 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
78 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
79 void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 octave_base_matrix<Cell>::assign (const octave_value_list& idx, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 octave_value rhs) |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
82 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
83 // FIXME: Really? |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
84 if (rhs.is_cell ()) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
85 matrix.assign (idx, rhs.cell_value ()); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
86 else |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
87 matrix.assign (idx, Cell (rhs)); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
88 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
89 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
90 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
91 void |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
92 octave_base_matrix<Cell>::delete_elements (const octave_value_list& idx) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
93 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
94 matrix.delete_elements (idx); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
95 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
96 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
97 // FIXME: this list of specializations is becoming so long that we should |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
98 // really ask whether octave_cell should inherit from octave_base_matrix at all. |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
99 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
100 template <> |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
101 octave_value |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
102 octave_base_matrix<Cell>::fast_elem_extract (octave_idx_type n) const |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
103 { |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
104 if (n < matrix.numel ()) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
105 return Cell (matrix(n)); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
106 else |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
107 return octave_value (); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
108 } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
109 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
110 template <> |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
111 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
112 octave_base_matrix<Cell>::fast_elem_insert (octave_idx_type n, |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
113 const octave_value& x) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
114 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
115 const octave_cell *xrep = |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
116 dynamic_cast<const octave_cell *> (&x.get_rep ()); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
117 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
118 bool retval = xrep && xrep->matrix.numel () == 1 && n < matrix.numel (); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
119 if (retval) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
120 matrix(n) = xrep->matrix(0); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
121 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
122 return retval; |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
123 } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
124 |
3928 | 125 template class octave_base_matrix<Cell>; |
3353 | 126 |
127 | |
4612 | 128 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell"); |
3353 | 129 |
6833 | 130 static void |
131 gripe_failed_assignment (void) | |
132 { | |
133 error ("assignment to cell array failed"); | |
134 } | |
135 | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
136 octave_value_list |
4247 | 137 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 const std::list<octave_value_list>& idx, |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
139 int nargout, |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
140 const std::list<octave_lvalue> *lvalue_list) |
3933 | 141 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
142 octave_value_list retval; |
3933 | 143 |
144 switch (type[0]) | |
145 { | |
146 case '(': | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
147 retval(0) = do_index_op (idx.front ()); |
3933 | 148 break; |
149 | |
150 case '{': | |
151 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
152 octave_value tmp = do_index_op (idx.front ()); |
3933 | 153 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
155 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
156 Cell tcell = tmp.cell_value (); |
4582 | 157 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 if (tcell.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
159 retval(0) = tcell(0,0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 else |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
161 retval = octave_value (octave_value_list (tcell), true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
162 } |
3933 | 163 } |
164 break; | |
165 | |
166 case '.': | |
167 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
169 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 170 } |
171 break; | |
172 | |
173 default: | |
174 panic_impossible (); | |
175 } | |
176 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
177 // FIXME: perhaps there should be an |
4994 | 178 // octave_value_list::next_subsref member function? See also |
179 // octave_user_function::subsref. | |
180 | |
181 if (idx.size () > 1) | |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
182 retval = (lvalue_list |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
183 ? retval(0).next_subsref (nargout, type, idx, lvalue_list) |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15877
diff
changeset
|
184 : retval(0).next_subsref (nargout, type, idx)); |
4994 | 185 |
186 return retval; | |
3933 | 187 } |
188 | |
189 octave_value | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
190 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
191 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 bool auto_add) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
193 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
194 octave_value retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
195 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
196 switch (type[0]) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
197 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
198 case '(': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
199 retval = do_index_op (idx.front (), auto_add); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
200 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
201 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
202 case '{': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
203 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 octave_value tmp = do_index_op (idx.front (), auto_add); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
205 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
207 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
208 const Cell tcell = tmp.cell_value (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
209 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
210 if (tcell.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
211 retval = tcell(0,0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
212 else |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
213 retval = octave_value (octave_value_list (tcell), true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
214 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
215 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
216 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
217 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
218 case '.': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
219 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
220 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
221 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
222 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
223 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
224 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
225 default: |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
226 panic_impossible (); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
227 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
228 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
229 // FIXME: perhaps there should be an |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
230 // octave_value_list::next_subsref member function? See also |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
231 // octave_user_function::subsref. |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
232 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
233 if (idx.size () > 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
234 retval = retval.next_subsref (auto_add, type, idx); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
235 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
236 return retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
237 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
238 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
239 octave_value |
4247 | 240 octave_cell::subsasgn (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 const octave_value& rhs) |
3933 | 243 { |
244 octave_value retval; | |
245 | |
246 int n = type.length (); | |
247 | |
248 octave_value t_rhs = rhs; | |
249 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
250 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
251 |
9286
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
252 if (idx.front ().empty ()) |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
253 { |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
254 error ("missing index in indexed assignment"); |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
255 return retval; |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
256 } |
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
257 |
3933 | 258 if (n > 1) |
259 { | |
260 switch (type[0]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
262 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
263 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
264 if (is_empty () && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
265 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
266 // Allow conversion of empty cell array to some other |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
267 // type in cases like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 // |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
269 // x = {}; x(i).f = rhs |
3933 | 270 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
271 octave_value tmp = octave_value::empty_conv (type, rhs); |
3933 | 272 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
273 return tmp.subsasgn (type, idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
274 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
275 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
276 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 octave_value tmp = do_index_op (idx.front (), true); |
3933 | 278 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 if (! tmp.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 tmp = octave_value::empty_conv (type.substr (1), rhs); |
3933 | 281 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
283 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 std::list<octave_value_list> next_idx (idx); |
4362 | 285 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 next_idx.erase (next_idx.begin ()); |
6767 | 287 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 tmp.make_unique (); |
6767 | 289 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
290 t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
291 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 break; |
3933 | 295 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 { |
9106
1eb5b24186b6
fix nested cell assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
298 matrix.make_unique (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 Cell tmpc = matrix.index (idx.front (), true); |
3933 | 300 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 { |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
303 std::list<octave_value_list> next_idx (idx); |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
304 |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
305 next_idx.erase (next_idx.begin ()); |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
306 |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
307 std::string next_type = type.substr (1); |
3933 | 308 |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
309 if (tmpc.numel () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 octave_value tmp = tmpc(0); |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
312 tmpc = Cell (); |
3933 | 313 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 if (! tmp.is_defined () || tmp.is_zero_by_zero ()) |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
315 { |
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
316 tmp = octave_value::empty_conv (type.substr (1), rhs); |
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
317 tmp.make_unique (); // probably a no-op. |
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
318 } |
8452
d6a349c7bd39
fix {} assigment if error occurs on subsequent assignment component
Jaroslav Hajek <highegg@gmail.com>
parents:
8446
diff
changeset
|
319 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
320 // optimization: ignore copy still stored inside array. |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
321 tmp.make_unique (1); |
4519 | 322 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
323 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
324 t_rhs = tmp.subsasgn (next_type, next_idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
325 } |
8446
7b25349b32e6
avoid redundant copying in {} assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
326 else |
8579
7e0f36dfefbe
implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents:
8551
diff
changeset
|
327 gripe_indexed_cs_list (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
328 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
329 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 break; |
3933 | 331 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
332 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
333 { |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
334 if (is_empty ()) |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
335 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
336 // Do nothing; the next branch will handle it. |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
337 } |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
338 else |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
339 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
340 std::string nm = type_name (); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
341 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
342 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
343 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
344 break; |
3933 | 345 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 } |
3933 | 349 } |
350 | |
3940 | 351 if (! error_state) |
3933 | 352 { |
3940 | 353 switch (type[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
355 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
356 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
357 octave_value_list i = idx.front (); |
3933 | 358 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
359 if (t_rhs.is_cell ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 octave_base_matrix<Cell>::assign (i, t_rhs.cell_value ()); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
361 else if (t_rhs.is_null_value ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
362 octave_base_matrix<Cell>::delete_elements (i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
364 octave_base_matrix<Cell>::assign (i, Cell (t_rhs)); |
3933 | 365 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
373 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 break; |
3933 | 375 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
376 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
378 octave_value_list idxf = idx.front (); |
3933 | 379 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
380 if (t_rhs.is_cs_list ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
381 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 Cell tmp_cell = Cell (t_rhs.list_value ()); |
5846 | 383 |
8587
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
384 // Inquire the proper shape of the RHS. |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
385 |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
386 dim_vector didx = dims ().redim (idxf.length ()); |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
387 for (octave_idx_type k = 0; k < idxf.length (); k++) |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
388 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel (); |
7040 | 389 |
8587
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
390 if (didx.numel () == tmp_cell.numel ()) |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
391 tmp_cell = tmp_cell.reshape (didx); |
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
392 |
5846 | 393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
394 octave_base_matrix<Cell>::assign (idxf, tmp_cell); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
396 else if (idxf.all_scalars () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
397 || do_index_op (idxf, true).numel () == 1) |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8452
diff
changeset
|
398 // Regularize a null matrix if stored into a cell. |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
399 octave_base_matrix<Cell>::assign (idxf, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
400 Cell (t_rhs.storable_value ())); |
8455
fd11a08a9b31
disallow invalid {}-indexed assigments
Jaroslav Hajek <highegg@gmail.com>
parents:
8452
diff
changeset
|
401 else if (! error_state) |
10030
83bb2a78c07d
improve simple assignments error checks and messages
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
402 gripe_nonbraced_cs_list_assignment (); |
3933 | 403 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
404 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
408 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
410 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
411 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 break; |
3933 | 413 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
414 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
415 { |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
416 if (is_empty ()) |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
417 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
418 // Allow conversion of empty cell array to some other |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
419 // type in cases like |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
420 // |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
421 // x = {}; x.f = rhs |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
422 |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
423 octave_value tmp = octave_value::empty_conv (type, rhs); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
424 |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
425 return tmp.subsasgn (type, idx, rhs); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
426 } |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
427 else |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
428 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
429 std::string nm = type_name (); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
430 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
431 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
432 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
433 break; |
3933 | 434 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
435 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
436 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
437 } |
3933 | 438 } |
439 | |
440 return retval; | |
441 } | |
442 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
443 bool |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
444 octave_cell::is_cellstr (void) const |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
445 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
446 bool retval; |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
447 if (cellstr_cache.get ()) |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
448 retval = true; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
449 else |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
450 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
451 retval = matrix.is_cellstr (); |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
452 // Allocate empty cache to mark that this is indeed a cellstr. |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
453 if (retval) |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
454 cellstr_cache.reset (new Array<std::string> ()); |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
455 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
456 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
457 return retval; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
458 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
459 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
460 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
461 octave_cell::assign (const octave_value_list& idx, const Cell& rhs) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
462 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
463 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
464 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
465 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
466 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
467 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
468 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
469 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
470 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
471 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
472 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
473 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
474 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
475 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
476 octave_cell::delete_elements (const octave_value_list& idx) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
477 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
478 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
479 octave_base_matrix<Cell>::delete_elements (idx); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
480 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
481 |
4791 | 482 size_t |
483 octave_cell::byte_size (void) const | |
484 { | |
485 size_t retval = 0; | |
486 | |
5275 | 487 for (octave_idx_type i = 0; i < numel (); i++) |
4791 | 488 retval += matrix(i).byte_size (); |
489 | |
490 return retval; | |
491 } | |
492 | |
8732 | 493 octave_value |
494 octave_cell::sort (octave_idx_type dim, sortmode mode) const | |
495 { | |
496 octave_value retval; | |
497 | |
498 if (is_cellstr ()) | |
499 { | |
500 Array<std::string> tmp = cellstr_value (); | |
501 | |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
502 tmp = tmp.sort (dim, mode); |
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
503 |
8825
c3445f1c8cb4
reuse cellstr cache in strcmp
Jaroslav Hajek <highegg@gmail.com>
parents:
8824
diff
changeset
|
504 // We already have the cache. |
c3445f1c8cb4
reuse cellstr cache in strcmp
Jaroslav Hajek <highegg@gmail.com>
parents:
8824
diff
changeset
|
505 retval = new octave_cell (tmp); |
8732 | 506 } |
507 else | |
508 error ("sort: only cell arrays of character strings may be sorted"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
509 |
8732 | 510 return retval; |
511 } | |
512 | |
513 octave_value | |
514 octave_cell::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
515 sortmode mode) const |
8732 | 516 { |
517 octave_value retval; | |
518 | |
519 if (is_cellstr ()) | |
520 { | |
521 Array<std::string> tmp = cellstr_value (); | |
522 | |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
523 tmp = tmp.sort (sidx, dim, mode); |
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
524 |
9338
650c7efa7234
simplify octave_cell::sort
Jaroslav Hajek <highegg@gmail.com>
parents:
9286
diff
changeset
|
525 // We already have the cache. |
650c7efa7234
simplify octave_cell::sort
Jaroslav Hajek <highegg@gmail.com>
parents:
9286
diff
changeset
|
526 retval = new octave_cell (tmp); |
8732 | 527 } |
528 else | |
529 error ("sort: only cell arrays of character strings may be sorted"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
530 |
8732 | 531 return retval; |
532 } | |
533 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
534 sortmode |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
535 octave_cell::is_sorted (sortmode mode) const |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
536 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
537 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
538 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
539 if (is_cellstr ()) |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
540 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
541 Array<std::string> tmp = cellstr_value (); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
542 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
543 retval = tmp.is_sorted (mode); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
544 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
545 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
546 error ("issorted: A is not a cell array of strings"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
547 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
548 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
549 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
550 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
551 |
8732 | 552 Array<octave_idx_type> |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8732
diff
changeset
|
553 octave_cell::sort_rows_idx (sortmode mode) const |
8732 | 554 { |
555 Array<octave_idx_type> retval; | |
556 | |
557 if (is_cellstr ()) | |
558 { | |
559 Array<std::string> tmp = cellstr_value (); | |
560 | |
561 retval = tmp.sort_rows_idx (mode); | |
562 } | |
563 else | |
564 error ("sortrows: only cell arrays of character strings may be sorted"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
565 |
8732 | 566 return retval; |
567 } | |
568 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
569 sortmode |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
570 octave_cell::is_sorted_rows (sortmode mode) const |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
571 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
572 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
573 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
574 if (is_cellstr ()) |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
575 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
576 Array<std::string> tmp = cellstr_value (); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
577 |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
578 retval = tmp.is_sorted_rows (mode); |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
579 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
580 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
581 error ("issorted: A is not a cell array of strings"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
582 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
583 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
584 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
585 |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
586 bool |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
587 octave_cell::is_true (void) const |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
588 { |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
589 error ("invalid conversion from cell array to logical value"); |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
590 return false; |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
591 } |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
592 |
3933 | 593 octave_value_list |
594 octave_cell::list_value (void) const | |
595 { | |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
596 return octave_value_list (matrix); |
3933 | 597 } |
598 | |
4243 | 599 string_vector |
5715 | 600 octave_cell::all_strings (bool pad) const |
4243 | 601 { |
4358 | 602 string_vector retval; |
603 | |
7285 | 604 octave_idx_type nel = numel (); |
4243 | 605 |
4358 | 606 int n_elts = 0; |
607 | |
5275 | 608 octave_idx_type max_len = 0; |
4358 | 609 |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
610 std::queue<string_vector> strvec_queue; |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
611 |
7285 | 612 for (octave_idx_type i = 0; i < nel; i++) |
4358 | 613 { |
7285 | 614 string_vector s = matrix(i).all_strings (); |
615 | |
616 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
617 return retval; |
4358 | 618 |
7285 | 619 octave_idx_type s_len = s.length (); |
4358 | 620 |
7285 | 621 n_elts += s_len ? s_len : 1; |
4358 | 622 |
7285 | 623 octave_idx_type s_max_len = s.max_length (); |
4358 | 624 |
7285 | 625 if (s_max_len > max_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
626 max_len = s_max_len; |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
627 |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
628 strvec_queue.push (s); |
4358 | 629 } |
630 | |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
631 retval = string_vector (n_elts); |
4243 | 632 |
5275 | 633 octave_idx_type k = 0; |
4243 | 634 |
7285 | 635 for (octave_idx_type i = 0; i < nel; i++) |
4243 | 636 { |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
637 const string_vector s = strvec_queue.front (); |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
638 strvec_queue.pop (); |
7285 | 639 |
640 octave_idx_type s_len = s.length (); | |
4358 | 641 |
7285 | 642 if (s_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
643 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
644 for (octave_idx_type j = 0; j < s_len; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
645 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
646 std::string t = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
647 int t_len = t.length (); |
5715 | 648 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
649 if (pad && max_len > t_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
650 t += std::string (max_len - t_len, ' '); |
5715 | 651 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
652 retval[k++] = t; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
653 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
654 } |
7285 | 655 else if (pad) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
656 retval[k++] = std::string (max_len, ' '); |
7285 | 657 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
658 retval[k++] = std::string (); |
4243 | 659 } |
660 | |
661 return retval; | |
662 } | |
663 | |
8732 | 664 Array<std::string> |
665 octave_cell::cellstr_value (void) const | |
666 { | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
667 Array<std::string> retval; |
8732 | 668 |
669 if (is_cellstr ()) | |
670 { | |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
671 if (cellstr_cache->is_empty ()) |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
672 *cellstr_cache = matrix.cellstr_value (); |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
673 |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
674 return *cellstr_cache; |
8732 | 675 } |
676 else | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
677 error ("invalid conversion from cell array to array of strings"); |
8732 | 678 |
679 return retval; | |
680 } | |
681 | |
4604 | 682 bool |
683 octave_cell::print_as_scalar (void) const | |
684 { | |
11474 | 685 return true; |
4604 | 686 } |
687 | |
3933 | 688 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
689 octave_cell::print (std::ostream& os, bool) |
3933 | 690 { |
691 print_raw (os); | |
692 } | |
693 | |
694 void | |
695 octave_cell::print_raw (std::ostream& os, bool) const | |
696 { | |
4587 | 697 int nd = matrix.ndims (); |
4513 | 698 |
4587 | 699 if (nd == 2) |
4513 | 700 { |
5275 | 701 octave_idx_type nr = rows (); |
702 octave_idx_type nc = columns (); | |
4513 | 703 |
704 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
705 { |
11474 | 706 newline (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
707 indent (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
708 os << "{"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
709 newline (os); |
4513 | 710 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
711 increment_indent_level (); |
4513 | 712 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
713 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
714 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
715 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
716 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
717 octave_quit (); |
4513 | 718 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
719 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
720 buf << "[" << i+1 << "," << j+1 << "]"; |
3933 | 721 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
722 octave_value val = matrix(i,j); |
4513 | 723 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
724 val.print_with_name (os, buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
725 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 } |
4513 | 727 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
728 decrement_indent_level (); |
4513 | 729 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 indent (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
731 os << "}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
732 newline (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
733 } |
4513 | 734 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
735 { |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
736 indent (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
737 os << "{}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
738 if (Vprint_empty_dimensions) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
739 os << "(" << nr << "x" << nc << ")"; |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
740 newline (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
741 } |
4513 | 742 } |
743 else | |
3933 | 744 { |
745 indent (os); | |
4513 | 746 dim_vector dv = matrix.dims (); |
4587 | 747 os << "{" << dv.str () << " Cell Array}"; |
3933 | 748 newline (os); |
749 } | |
750 } | |
751 | |
17870 | 752 void |
753 octave_cell::short_disp (std::ostream& os) const | |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
754 { |
17874
28e9562d708b
Fix display of '{}' for empty cells in GUI Variable window.
Rik <rik@octave.org>
parents:
17870
diff
changeset
|
755 os << (matrix.is_empty () ? "{}" : "..."); |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
756 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
757 |
4687 | 758 #define CELL_ELT_TAG "<cell-element>" |
759 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
760 bool |
6974 | 761 octave_cell::save_ascii (std::ostream& os) |
4687 | 762 { |
763 dim_vector d = dims (); | |
764 if (d.length () > 2) | |
765 { | |
766 os << "# ndims: " << d.length () << "\n"; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
767 |
5275 | 768 for (int i = 0; i < d.length (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
769 os << " " << d (i); |
4687 | 770 os << "\n"; |
771 | |
772 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
773 |
5275 | 774 for (octave_idx_type i = 0; i < d.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
775 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
776 octave_value o_val = tmp.elem (i); |
4687 | 777 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 // Recurse to print sub-value. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
779 bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
780 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
781 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17874
diff
changeset
|
782 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
783 } |
4687 | 784 } |
785 else | |
786 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
787 // Keep this case, rather than use generic code above for backward |
4687 | 788 // compatiability. Makes load_ascii much more complex!! |
789 os << "# rows: " << rows () << "\n" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 << "# columns: " << columns () << "\n"; |
4687 | 791 |
792 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
793 |
5275 | 794 for (octave_idx_type j = 0; j < tmp.cols (); j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
795 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
796 for (octave_idx_type i = 0; i < tmp.rows (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
797 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 octave_value o_val = tmp.elem (i, j); |
4687 | 799 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
800 // Recurse to print sub-value. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
801 bool b = save_ascii_data (os, o_val, CELL_ELT_TAG, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
802 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
803 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17874
diff
changeset
|
804 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
805 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
806 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
807 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
808 } |
4687 | 809 } |
810 | |
811 return true; | |
812 } | |
813 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
814 bool |
4687 | 815 octave_cell::load_ascii (std::istream& is) |
816 { | |
817 bool success = true; | |
5099 | 818 |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
819 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
820 |
5099 | 821 string_vector keywords(2); |
4687 | 822 |
5099 | 823 keywords[0] = "ndims"; |
824 keywords[1] = "rows"; | |
825 | |
826 std::string kw; | |
5275 | 827 octave_idx_type val = 0; |
5099 | 828 |
829 if (extract_keyword (is, keywords, kw, val, true)) | |
4687 | 830 { |
5099 | 831 if (kw == "ndims") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
832 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
833 int mdims = static_cast<int> (val); |
4687 | 834 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
835 if (mdims >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
836 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
837 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
838 dv.resize (mdims); |
5099 | 839 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
840 for (int i = 0; i < mdims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
841 is >> dv(i); |
4687 | 842 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
843 Cell tmp(dv); |
4687 | 844 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
845 for (octave_idx_type i = 0; i < dv.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
846 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
847 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
848 bool dummy; |
5099 | 849 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
850 // recurse to read cell elements |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
851 std::string nm = read_ascii_data (is, std::string (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
852 dummy, t2, i); |
4687 | 853 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
854 if (nm == CELL_ELT_TAG) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
855 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
856 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
857 tmp.elem (i) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
858 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
859 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
860 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
861 error ("load: cell array element had unexpected name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
862 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
863 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
864 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
865 } |
4687 | 866 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
867 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
868 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
869 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
870 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
871 error ("load: failed to load matrix constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
872 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
873 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
875 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
876 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
877 error ("load: failed to extract number of rows and columns"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
878 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 } |
5099 | 881 else if (kw == "rows") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 octave_idx_type nr = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
884 octave_idx_type nc = 0; |
5099 | 885 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
886 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
888 if (nr > 0 && nc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
889 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
890 Cell tmp (nr, nc); |
5099 | 891 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
892 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
894 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
895 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
896 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
897 bool dummy; |
5099 | 898 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
899 // recurse to read cell elements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
900 std::string nm = read_ascii_data (is, std::string (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
901 dummy, t2, i); |
5099 | 902 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
903 if (nm == CELL_ELT_TAG) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
904 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
905 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
906 tmp.elem (i, j) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
907 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
909 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
910 error ("load: cell array element had unexpected name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
911 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
912 goto cell_read_error; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
913 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
915 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
916 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
917 cell_read_error: |
5099 | 918 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
919 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
920 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
921 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
922 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
923 error ("load: failed to load cell element"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
924 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
925 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
926 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
927 else if (nr == 0 || nc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
928 matrix = Cell (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
929 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
930 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
931 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
932 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
933 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
934 error ("load: failed to extract number of rows and columns for cell array"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
935 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
936 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
937 } |
4687 | 938 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
939 panic_impossible (); |
4687 | 940 } |
941 else | |
942 { | |
5099 | 943 error ("load: failed to extract number of rows and columns"); |
944 success = false; | |
4687 | 945 } |
946 | |
947 return success; | |
948 } | |
949 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
950 bool |
4687 | 951 octave_cell::save_binary (std::ostream& os, bool& save_as_floats) |
952 { | |
953 dim_vector d = dims (); | |
954 if (d.length () < 1) | |
955 return false; | |
956 | |
957 // Use negative value for ndims | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
958 int32_t di = - d.length (); |
5760 | 959 os.write (reinterpret_cast<char *> (&di), 4); |
5275 | 960 for (int i = 0; i < d.length (); i++) |
4687 | 961 { |
962 di = d(i); | |
5760 | 963 os.write (reinterpret_cast<char *> (&di), 4); |
4687 | 964 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
965 |
4687 | 966 Cell tmp = cell_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
967 |
5275 | 968 for (octave_idx_type i = 0; i < d.numel (); i++) |
4687 | 969 { |
970 octave_value o_val = tmp.elem (i); | |
971 | |
972 // Recurse to print sub-value. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
973 bool b = save_binary_data (os, o_val, CELL_ELT_TAG, "", 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
974 save_as_floats); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
975 |
4687 | 976 if (! b) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
977 return false; |
4687 | 978 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
979 |
4687 | 980 return true; |
981 } | |
982 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
983 bool |
4687 | 984 octave_cell::load_binary (std::istream& is, bool swap, |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
985 oct_mach_info::float_format fmt) |
4687 | 986 { |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
987 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
988 |
4687 | 989 bool success = true; |
5828 | 990 int32_t mdims; |
5760 | 991 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 992 return false; |
993 if (swap) | |
4944 | 994 swap_bytes<4> (&mdims); |
4687 | 995 if (mdims >= 0) |
996 return false; | |
997 | |
998 mdims = -mdims; | |
5828 | 999 int32_t di; |
4687 | 1000 dim_vector dv; |
1001 dv.resize (mdims); | |
1002 | |
1003 for (int i = 0; i < mdims; i++) | |
1004 { | |
5760 | 1005 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1006 return false; |
4687 | 1007 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1008 swap_bytes<4> (&di); |
4687 | 1009 dv(i) = di; |
1010 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1011 |
5157 | 1012 // Convert an array with a single dimension to be a row vector. |
1013 // Octave should never write files like this, other software | |
1014 // might. | |
1015 | |
1016 if (mdims == 1) | |
1017 { | |
1018 mdims = 2; | |
1019 dv.resize (mdims); | |
1020 dv(1) = dv(0); | |
1021 dv(0) = 1; | |
1022 } | |
1023 | |
5275 | 1024 octave_idx_type nel = dv.numel (); |
4687 | 1025 Cell tmp(dv); |
1026 | |
5275 | 1027 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 1028 { |
1029 octave_value t2; | |
1030 bool dummy; | |
1031 std::string doc; | |
1032 | |
1033 // recurse to read cell elements | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1034 std::string nm = read_binary_data (is, swap, fmt, std::string (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1035 dummy, t2, doc); |
4687 | 1036 |
1037 if (nm == CELL_ELT_TAG) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1038 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1039 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1040 tmp.elem (i) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1041 } |
4687 | 1042 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1043 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1044 error ("load: cell array element had unexpected name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1045 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1046 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1047 } |
4687 | 1048 } |
1049 | |
1050 if (is) | |
1051 matrix = tmp; | |
1052 else | |
1053 { | |
1054 error ("load: failed to load matrix constant"); | |
1055 success = false; | |
1056 } | |
1057 | |
1058 return success; | |
1059 } | |
1060 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1061 void * |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1062 octave_cell::mex_get_data (void) const |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1063 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1064 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1065 return matrix.mex_get_data (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1066 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1067 |
4687 | 1068 #if defined (HAVE_HDF5) |
4815 | 1069 |
4687 | 1070 bool |
1071 octave_cell::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) | |
1072 { | |
4814 | 1073 dim_vector dv = dims (); |
4837 | 1074 int empty = save_hdf5_empty (loc_id, name, dv); |
1075 if (empty) | |
1076 return (empty > 0); | |
1077 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1078 hsize_t rank = dv.length (); |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17874
diff
changeset
|
1079 hid_t space_hid, data_hid, size_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17874
diff
changeset
|
1080 space_hid = data_hid = size_hid = -1; |
4687 | 1081 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1082 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1083 data_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1084 #else |
4687 | 1085 data_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1086 #endif |
4815 | 1087 |
1088 if (data_hid < 0) | |
1089 return false; | |
4687 | 1090 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1091 // Have to save cell array shape, since can't have a |
4814 | 1092 // dataset of groups.... |
4815 | 1093 |
1094 space_hid = H5Screate_simple (1, &rank, 0); | |
1095 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1096 if (space_hid < 0) |
4687 | 1097 { |
1098 H5Gclose (data_hid); | |
1099 return false; | |
1100 } | |
1101 | |
5351 | 1102 OCTAVE_LOCAL_BUFFER (octave_idx_type, hdims, rank); |
4814 | 1103 |
1104 // Octave uses column-major, while HDF5 uses row-major ordering | |
4933 | 1105 for (hsize_t i = 0; i < rank; i++) |
4815 | 1106 hdims[i] = dv(rank-i-1); |
4814 | 1107 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1108 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1109 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1110 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1111 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1112 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1113 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1114 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1115 if (size_hid < 0) |
4687 | 1116 { |
1117 H5Sclose (space_hid); | |
1118 H5Gclose (data_hid); | |
1119 return false; | |
1120 } | |
1121 | |
6276 | 1122 if (H5Dwrite (size_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1123 H5P_DEFAULT, hdims) < 0) |
4687 | 1124 { |
1125 H5Dclose (size_hid); | |
1126 H5Sclose (space_hid); | |
1127 H5Gclose (data_hid); | |
1128 return false; | |
1129 } | |
4815 | 1130 |
4687 | 1131 H5Dclose (size_hid); |
1132 H5Sclose (space_hid); | |
1133 | |
4815 | 1134 // Recursively add each element of the cell to this group. |
1135 | |
4687 | 1136 Cell tmp = cell_value (); |
5850 | 1137 |
1138 octave_idx_type nel = dv.numel (); | |
1139 | |
1140 for (octave_idx_type i = 0; i < nel; i++) | |
4687 | 1141 { |
5765 | 1142 std::ostringstream buf; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1143 int digits = static_cast<int> (gnulib::floor (::log10 (static_cast<double> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1144 (nel)) + 1.0)); |
5850 | 1145 buf << "_" << std::setw (digits) << std::setfill ('0') << i; |
5765 | 1146 std::string s = buf.str (); |
4687 | 1147 |
5850 | 1148 if (! add_hdf5_data (data_hid, tmp.elem (i), s.c_str (), "", false, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1149 save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1150 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1151 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1152 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1153 } |
4687 | 1154 } |
1155 | |
1156 H5Gclose (data_hid); | |
4815 | 1157 |
4687 | 1158 return true; |
1159 } | |
1160 | |
1161 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9813
diff
changeset
|
1162 octave_cell::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 1163 { |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1164 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1165 |
4687 | 1166 bool retval = false; |
4837 | 1167 |
1168 dim_vector dv; | |
1169 int empty = load_hdf5_empty (loc_id, name, dv); | |
1170 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1171 matrix.resize (dv); |
4837 | 1172 if (empty) |
1173 return (empty > 0); | |
1174 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1175 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1176 hid_t group_id = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1177 #else |
4687 | 1178 hid_t group_id = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1179 #endif |
4687 | 1180 |
1181 if (group_id < 0) | |
1182 return false; | |
1183 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1184 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1185 hid_t data_hid = H5Dopen (group_id, "dims", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1186 #else |
4814 | 1187 hid_t data_hid = H5Dopen (group_id, "dims"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1188 #endif |
4687 | 1189 hid_t space_hid = H5Dget_space (data_hid); |
1190 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1191 if (rank != 1) |
4687 | 1192 { |
4837 | 1193 H5Dclose (data_hid); |
1194 H5Gclose (group_id); | |
4687 | 1195 return false; |
1196 } | |
1197 | |
4814 | 1198 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
1199 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
4815 | 1200 |
4814 | 1201 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
4687 | 1202 |
4815 | 1203 // Octave uses column-major, while HDF5 uses row-major ordering. |
1204 | |
4814 | 1205 dv.resize (hdims[0]); |
4815 | 1206 |
5351 | 1207 OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, hdims[0]); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1208 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1209 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1210 H5P_DEFAULT, tmp) < 0) |
4687 | 1211 { |
4837 | 1212 H5Dclose (data_hid); |
1213 H5Gclose (group_id); | |
4687 | 1214 return false; |
1215 } | |
4815 | 1216 |
4687 | 1217 H5Dclose (data_hid); |
1218 H5Gclose (group_id); | |
1219 | |
4815 | 1220 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--) |
4814 | 1221 dv(j) = tmp[i]; |
1222 | |
4687 | 1223 hdf5_callback_data dsub; |
1224 | |
1225 herr_t retval2 = -1; | |
4815 | 1226 |
4814 | 1227 Cell m (dv); |
4815 | 1228 |
4687 | 1229 int current_item = 0; |
4815 | 1230 |
4696 | 1231 hsize_t num_obj = 0; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1232 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1233 group_id = H5Gopen (loc_id, name, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1234 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1235 group_id = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1236 #endif |
5060 | 1237 H5Gget_num_objs (group_id, &num_obj); |
1238 H5Gclose (group_id); | |
4696 | 1239 |
5275 | 1240 for (octave_idx_type i = 0; i < dv.numel (); i++) |
4687 | 1241 { |
4696 | 1242 |
4814 | 1243 if (current_item >= static_cast<int> (num_obj)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1244 retval2 = -1; |
4814 | 1245 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1246 retval2 = H5Giterate (loc_id, name, ¤t_item, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1247 hdf5_read_next_data, &dsub); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1248 |
4687 | 1249 if (retval2 <= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1250 break; |
4814 | 1251 |
1252 octave_value ov = dsub.tc; | |
1253 m.elem (i) = ov; | |
1254 | |
4687 | 1255 } |
1256 | |
1257 if (retval2 >= 0) | |
1258 { | |
1259 matrix = m; | |
1260 retval = true; | |
1261 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1262 |
4687 | 1263 return retval; |
1264 } | |
4815 | 1265 |
4687 | 1266 #endif |
1267 | |
3354 | 1268 DEFUN (iscell, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1269 "-*- texinfo -*-\n\ |
3448 | 1270 @deftypefn {Built-in Function} {} iscell (@var{x})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1271 Return true if @var{x} is a cell array object.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1272 @seealso{ismatrix, isstruct, iscellstr, isa}\n\ |
3448 | 1273 @end deftypefn") |
3354 | 1274 { |
1275 octave_value retval; | |
1276 | |
1277 if (args.length () == 1) | |
1278 retval = args(0).is_cell (); | |
1279 else | |
5823 | 1280 print_usage (); |
3354 | 1281 |
1282 return retval; | |
1283 } | |
1284 | |
1285 DEFUN (cell, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1286 "-*- texinfo -*-\n\ |
12715
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1287 @deftypefn {Built-in Function} {} cell (@var{n})\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1288 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n})\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1289 @deftypefnx {Built-in Function} {} cell (@var{m}, @var{n}, @var{k}, @dots{})\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1290 @deftypefnx {Built-in Function} {} cell ([@var{m} @var{n} @dots{}])\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1291 Create a new cell array object.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1292 \n\ |
12715
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1293 If invoked with a single scalar integer argument, return a square\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1294 @nospell{NxN} cell array. If invoked with two or more scalar\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1295 integer arguments, or a vector of integer values, return an array with\n\ |
25f8acbb6be2
doc: Add additional calling forms to cell()
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1296 the given dimensions.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1297 @seealso{cellstr, mat2cell, num2cell, struct2cell}\n\ |
3448 | 1298 @end deftypefn") |
3354 | 1299 { |
1300 octave_value retval; | |
1301 | |
1302 int nargin = args.length (); | |
1303 | |
4563 | 1304 dim_vector dims; |
1305 | |
3354 | 1306 switch (nargin) |
1307 { | |
4563 | 1308 case 0: |
1309 dims = dim_vector (0, 0); | |
3354 | 1310 break; |
1311 | |
4563 | 1312 case 1: |
1313 get_dimensions (args(0), "cell", dims); | |
3354 | 1314 break; |
1315 | |
1316 default: | |
4563 | 1317 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1318 dims.resize (nargin); |
4563 | 1319 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1320 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1321 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1322 dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); |
4563 | 1323 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1324 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1325 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1326 error ("cell: expecting scalar arguments"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1327 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1328 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1329 } |
4563 | 1330 } |
3354 | 1331 break; |
1332 } | |
1333 | |
4563 | 1334 if (! error_state) |
1335 { | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1336 dims.chop_trailing_singletons (); |
4563 | 1337 |
1338 check_dimensions (dims, "cell"); | |
1339 | |
1340 if (! error_state) | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1341 retval = Cell (dims, Matrix ()); |
4563 | 1342 } |
1343 | |
3354 | 1344 return retval; |
1345 } | |
1346 | |
4610 | 1347 DEFUN (iscellstr, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1348 "-*- texinfo -*-\n\ |
4610 | 1349 @deftypefn {Built-in Function} {} iscellstr (@var{cell})\n\ |
1350 Return true if every element of the cell array @var{cell} is a\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1351 character string.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10871
diff
changeset
|
1352 @seealso{ischar}\n\ |
4610 | 1353 @end deftypefn") |
1354 { | |
4699 | 1355 octave_value retval; |
4610 | 1356 |
1357 if (args.length () == 1) | |
6116 | 1358 retval = args(0).is_cellstr (); |
4610 | 1359 else |
5823 | 1360 print_usage (); |
4610 | 1361 |
1362 return retval; | |
1363 } | |
1364 | |
4817 | 1365 // Note that since Fcellstr calls Fiscellstr, we need to have |
1366 // Fiscellstr defined first (to provide a declaration) and also we | |
1367 // should keep it in the same file (so we don't have to provide a | |
1368 // declaration) and so we don't have to use feval to call it. | |
1369 | |
1370 DEFUN (cellstr, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1371 "-*- texinfo -*-\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1372 @deftypefn {Built-in Function} {@var{cstr} =} cellstr (@var{strmat})\n\ |
4817 | 1373 Create a new cell array object from the elements of the string\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1374 array @var{strmat}.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1375 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1376 Each row of @var{strmat} becomes an element of @var{cstr}. Any trailing\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1377 spaces in a row are deleted before conversion.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1378 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1379 To convert back from a cellstr to a character array use @code{char}.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1380 @seealso{cell, char}\n\ |
4817 | 1381 @end deftypefn") |
1382 { | |
1383 octave_value retval; | |
1384 | |
1385 if (args.length () == 1) | |
1386 { | |
1387 octave_value_list tmp = Fiscellstr (args, 1); | |
1388 | |
1389 if (tmp(0).is_true ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1390 retval = args(0); |
4817 | 1391 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1392 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1393 string_vector s = args(0).all_strings (); |
4817 | 1394 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1395 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1396 retval = (s.is_empty () |
7813 | 1397 ? Cell (octave_value (std::string ())) |
1398 : Cell (s, true)); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1399 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1400 error ("cellstr: argument STRING must be a 2-D character array"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1401 } |
4817 | 1402 } |
1403 else | |
5823 | 1404 print_usage (); |
4817 | 1405 |
1406 return retval; | |
1407 } | |
1408 | |
4762 | 1409 DEFUN (struct2cell, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1410 "-*- texinfo -*-\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1411 @deftypefn {Built-in Function} {@var{c} =} struct2cell (@var{s})\n\ |
4762 | 1412 Create a new cell array from the objects stored in the struct object.\n\ |
4764 | 1413 If @var{f} is the number of fields in the structure, the resulting\n\ |
1414 cell array will have a dimension vector corresponding to\n\ | |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1415 @code{[@var{f} size(@var{s})]}. For example:\n\ |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1416 \n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1417 @example\n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1418 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1419 s = struct (\"name\", @{\"Peter\", \"Hannah\", \"Robert\"@},\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1420 \"age\", @{23, 16, 3@});\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1421 c = struct2cell (s)\n\ |
15877
596b26e11ddb
fix bug #38010 struct2cell documentation error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15195
diff
changeset
|
1422 @result{} c = @{2x1x3 Cell Array@}\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1423 c(1,1,:)(:)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1424 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1425 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1426 [1,1] = Peter\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1427 [2,1] = Hannah\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1428 [3,1] = Robert\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1429 @}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1430 c(2,1,:)(:)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1431 @result{}\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1432 @{\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1433 [1,1] = 23\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1434 [2,1] = 16\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1435 [3,1] = 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1436 @}\n\ |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1437 @end group\n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1438 @end example\n\ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1439 \n\ |
5642 | 1440 @seealso{cell2struct, fieldnames}\n\ |
1441 @end deftypefn") | |
4762 | 1442 { |
1443 octave_value retval; | |
4764 | 1444 |
4762 | 1445 int nargin = args.length (); |
4764 | 1446 |
4762 | 1447 if (nargin == 1) |
1448 { | |
10772 | 1449 const octave_map m = args(0).map_value (); |
4764 | 1450 |
4762 | 1451 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1452 { |
10772 | 1453 const dim_vector m_dv = m.dims (); |
4764 | 1454 |
10772 | 1455 octave_idx_type num_fields = m.nfields (); |
4764 | 1456 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1457 // The resulting dim_vector should have dimensions: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1458 // [numel(fields) size(struct)] |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1459 // except if the struct is a column vector. |
4764 | 1460 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1461 dim_vector result_dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1462 if (m_dv (m_dv.length () - 1) == 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1463 result_dv.resize (m_dv.length ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1464 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1465 result_dv.resize (m_dv.length () + 1); // Add 1 for the fields. |
4764 | 1466 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1467 result_dv(0) = num_fields; |
4762 | 1468 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1469 for (int i = 1; i < result_dv.length (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1470 result_dv(i) = m_dv(i-1); |
4764 | 1471 |
10772 | 1472 NoAlias<Cell> c (result_dv); |
4764 | 1473 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1474 octave_idx_type n_elts = m.numel (); |
4764 | 1475 |
10772 | 1476 // Fill c in one sweep. Note that thanks to octave_map structure, |
1477 // we don't need a key lookup at all. | |
1478 for (octave_idx_type j = 0; j < n_elts; j++) | |
1479 for (octave_idx_type i = 0; i < num_fields; i++) | |
1480 c(i,j) = m.contents(i)(j); | |
4762 | 1481 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1482 retval = c; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1483 } |
4762 | 1484 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1485 error ("struct2cell: argument S must be a structure"); |
4762 | 1486 } |
1487 else | |
5823 | 1488 print_usage (); |
4764 | 1489 |
4762 | 1490 return retval; |
1491 } | |
1492 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1493 /* |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1494 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1495 %! keys = cellstr (char (floor (rand (11,10)*24+65)))'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1496 %! vals = cellfun (@(x) mat2cell (rand (19,1), ones (19,1), 1), ... |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1497 %! mat2cell ([1:11]', ones (11,1), 1), "uniformoutput", false)'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1498 %! s = struct ([keys; vals]{:}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1499 %! t = cell2struct ([vals{:}], keys, 2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1500 %! assert (s, t); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1501 %! assert (struct2cell (s), [vals{:}]'); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1502 %! assert (fieldnames (s), keys'); |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1503 */ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1504 |
5900 | 1505 mxArray * |
1506 octave_cell::as_mxArray (void) const | |
1507 { | |
1508 mxArray *retval = new mxArray (dims ()); | |
1509 | |
1510 mxArray **elts = static_cast<mxArray **> (retval->get_data ()); | |
1511 | |
6686 | 1512 mwSize nel = numel (); |
5900 | 1513 |
1514 const octave_value *p = matrix.data (); | |
1515 | |
6686 | 1516 for (mwIndex i = 0; i < nel; i++) |
5900 | 1517 elts[i] = new mxArray (p[i]); |
1518 | |
1519 return retval; | |
1520 } | |
1521 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1522 octave_value |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1523 octave_cell::map (unary_mapper_t umap) const |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1524 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1525 switch (umap) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1526 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1527 #define FORWARD_MAPPER(UMAP) \ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1528 case umap_ ## UMAP: \ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1529 return matrix.UMAP () |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1530 FORWARD_MAPPER (xisalnum); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1531 FORWARD_MAPPER (xisalpha); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1532 FORWARD_MAPPER (xisascii); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1533 FORWARD_MAPPER (xiscntrl); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1534 FORWARD_MAPPER (xisdigit); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1535 FORWARD_MAPPER (xisgraph); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1536 FORWARD_MAPPER (xislower); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1537 FORWARD_MAPPER (xisprint); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1538 FORWARD_MAPPER (xispunct); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1539 FORWARD_MAPPER (xisspace); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1540 FORWARD_MAPPER (xisupper); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1541 FORWARD_MAPPER (xisxdigit); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1542 FORWARD_MAPPER (xtoascii); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1543 FORWARD_MAPPER (xtolower); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1544 FORWARD_MAPPER (xtoupper); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1545 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1546 default: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1547 return octave_base_value::map (umap); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1548 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1549 } |