Mercurial > octave
annotate libinterp/octave-value/ov-struct.cc @ 24700:aaf7bcea71dd
Silence build warnings about unused parameters.
* libinterp/octave-value/ov-base-diag.cc (octave_base_diag<DMT, MT>::edit_display),
libinterp/octave-value/ov-base-scalar.cc (octave_base_scalar<ST>::edit_display),
libinterp/octave-value/ov-cell.cc (octave_base_matrix<Cell>::edit_display),
libinterp/octave-value/ov-perm.cc (octave_perm_matrix::edit_display),
libinterp/octave-value/ov-str-mat.cc (octave_char_matrix_str::edit_display),
libinterp/octave-value/ov-struct.cc (octave_struct::edit_display,
octave_scalar_struct::edit_display): Remove identifier of unused parameter "fmt"
to silence many build warnings.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Wed, 07 Feb 2018 11:34:13 +0100 |
parents | d4dd741b2794 |
children | 6652d3823428 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 John W. Eaton |
2376 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23880
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23880
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
11 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2376 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23880
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2376 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21211
diff
changeset
|
24 # include "config.h" |
2376 | 25 #endif |
26 | |
3503 | 27 #include <iostream> |
2376 | 28 |
3933 | 29 #include "Cell.h" |
23454
30b6eccd6708
use builtin-defun-decls.h to ensure declarations of interpreter functions
John W. Eaton <jwe@octave.org>
parents:
23450
diff
changeset
|
30 #include "builtin-defun-decls.h" |
4358 | 31 #include "defun.h" |
2376 | 32 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
33 #include "errwarn.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
|
34 #include "mxarray.h" |
2979 | 35 #include "oct-lvalue.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
36 #include "oct-hdf5.h" |
2376 | 37 #include "ov-struct.h" |
38 #include "unwind-prot.h" | |
6811 | 39 #include "utils.h" |
2948 | 40 #include "variables.h" |
2376 | 41 |
4750 | 42 #include "Array-util.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
43 #include "oct-locbuf.h" |
4750 | 44 |
4687 | 45 #include "byte-swap.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
46 #include "ls-oct-text.h" |
4687 | 47 #include "ls-oct-binary.h" |
48 #include "ls-hdf5.h" | |
49 #include "ls-utils.h" | |
5759 | 50 #include "pr-output.h" |
4687 | 51 |
2376 | 52 |
4612 | 53 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_struct, "struct", "struct"); |
2376 | 54 |
11474 | 55 // How many levels of structure elements should we print? |
56 static int Vstruct_levels_to_print = 2; | |
57 | |
58 // TRUE means print struct array contents, up to the number of levels | |
59 // specified by struct_levels_to_print. | |
60 static bool Vprint_struct_array_contents = false; | |
61 | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
62 octave_base_value * |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
63 octave_struct::try_narrowing_conversion (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
64 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23454
diff
changeset
|
65 octave_base_value *retval = nullptr; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
66 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
67 if (numel () == 1) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
68 retval = new octave_scalar_struct (map.checkelem (0)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
69 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
70 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
71 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
72 |
4513 | 73 Cell |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
74 octave_struct::dotref (const octave_value_list& idx, bool auto_add) |
2962 | 75 { |
4513 | 76 Cell retval; |
3933 | 77 |
78 assert (idx.length () == 1); | |
2962 | 79 |
3933 | 80 std::string nm = idx(0).string_value (); |
81 | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
82 octave_map::const_iterator p = map.seek (nm); |
2376 | 83 |
4219 | 84 if (p != map.end ()) |
3933 | 85 retval = map.contents (p); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
86 else if (auto_add) |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
87 retval = (isempty ()) ? Cell (dim_vector (1, 1)) : Cell (dims ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
88 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
89 error_with_id ("Octave:invalid-indexing", |
15731
18f168880226
error_ids: Adding ids and documentation
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
15614
diff
changeset
|
90 "structure has no member '%s'", nm.c_str ()); |
2376 | 91 |
92 return retval; | |
93 } | |
94 | |
3933 | 95 static void |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
96 err_invalid_index_for_assignment (void) |
3933 | 97 { |
98 error ("invalid index for structure array assignment"); | |
99 } | |
100 | |
101 static void | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
102 err_invalid_index_type (const std::string& nm, char t) |
3933 | 103 { |
104 error ("%s cannot be indexed with %c", nm.c_str (), t); | |
105 } | |
106 | |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
107 static void |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
108 maybe_warn_invalid_field_name (const std::string& key, const char *who) |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
109 { |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
110 if (! valid_identifier (key)) |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
111 { |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
112 if (who) |
19852
e9a0bd0b125c
Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
113 warning_with_id ("Octave:language-extension", |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
114 "%s: invalid structure field name '%s'", |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
115 who, key.c_str ()); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
116 else |
19852
e9a0bd0b125c
Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
117 warning_with_id ("Octave:language-extension", |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
118 "invalid structure field name '%s'", |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
119 key.c_str ()); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
120 } |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
121 } |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
122 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
123 octave_value_list |
4247 | 124 octave_struct::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
125 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
126 int nargout) |
3933 | 127 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
128 octave_value_list retval; |
3933 | 129 |
130 int skip = 1; | |
131 | |
132 switch (type[0]) | |
133 { | |
134 case '(': | |
135 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
136 if (type.length () > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
137 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
138 std::list<octave_value_list>::const_iterator p = idx.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
139 octave_value_list key_idx = *++p; |
3933 | 140 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
141 const Cell tmp = dotref (key_idx); |
3933 | 142 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
143 const Cell t = tmp.index (idx.front ()); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
144 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
145 retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
146 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
147 // We handled two index elements, so tell |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
148 // next_subsref to skip both of them. |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
149 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
150 skip++; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
151 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
152 else |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
153 retval(0) = do_index_op (idx.front ()); |
3933 | 154 } |
155 break; | |
156 | |
157 case '.': | |
158 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14625
diff
changeset
|
159 if (map.numel () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
160 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
161 const Cell t = dotref (idx.front ()); |
3933 | 162 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
163 retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
164 } |
3933 | 165 } |
166 break; | |
167 | |
168 case '{': | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
169 err_invalid_index_type (type_name (), type[0]); |
3933 | 170 break; |
171 | |
172 default: | |
173 panic_impossible (); | |
174 } | |
175 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
176 // FIXME: perhaps there should be an |
4994 | 177 // octave_value_list::next_subsref member function? See also |
178 // octave_user_function::subsref. | |
179 | |
180 if (idx.size () > 1) | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
181 retval = retval(0).next_subsref (nargout, type, idx, skip); |
3933 | 182 |
183 return retval; | |
184 } | |
185 | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
186 octave_value |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
187 octave_struct::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
188 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
189 bool auto_add) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
190 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
191 octave_value retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
192 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
193 int skip = 1; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
194 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
195 switch (type[0]) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
196 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
197 case '(': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
198 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
199 if (type.length () > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
201 std::list<octave_value_list>::const_iterator p = idx.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
202 octave_value_list key_idx = *++p; |
8551
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:
10258
diff
changeset
|
204 const Cell tmp = dotref (key_idx, auto_add); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
205 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
206 const Cell t = tmp.index (idx.front (), auto_add); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
207 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
208 retval = (t.numel () == 1) ? t(0) : octave_value (t, true); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
209 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
210 // We handled two index elements, so tell |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
211 // next_subsref to skip both of them. |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
212 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
213 skip++; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
214 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
215 else |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
216 retval = 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
|
217 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
218 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
219 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
220 case '.': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
221 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14625
diff
changeset
|
222 if (map.numel () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
223 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
224 const Cell t = dotref (idx.front (), auto_add); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
225 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
226 retval = (t.numel () == 1) ? t(0) : octave_value (t, true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
227 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
228 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
229 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
230 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
231 case '{': |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
232 err_invalid_index_type (type_name (), type[0]); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
233 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
234 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
235 default: |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
236 panic_impossible (); |
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 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
239 // FIXME: perhaps there should be an |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
240 // 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
|
241 // octave_user_function::subsref. |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
242 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
243 if (idx.size () > 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
244 retval = retval.next_subsref (auto_add, type, idx, skip); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
245 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
246 return retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
247 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
248 |
8031
d9987dbdf91b
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
249 /* |
d9987dbdf91b
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
250 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
251 %! x(1).a.a = 1; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
252 %! x(2).a.a = 2; |
8031
d9987dbdf91b
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
253 %! assert (size (x), [1, 2]); |
d9987dbdf91b
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
254 %! assert (x(1).a.a, 1); |
d9987dbdf91b
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
255 %! assert (x(2).a.a, 2); |
d9987dbdf91b
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
256 */ |
d9987dbdf91b
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
257 |
3933 | 258 octave_value |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
259 octave_struct::numeric_conv (const octave_value& val, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
260 const std::string& type) |
3933 | 261 { |
262 octave_value retval; | |
263 | |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
264 if (type.length () > 0 && type[0] == '.' && ! val.isstruct ()) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
265 retval = octave_map (); |
3933 | 266 else |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
267 retval = val; |
3933 | 268 |
269 return retval; | |
270 } | |
271 | |
272 octave_value | |
4247 | 273 octave_struct::subsasgn (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
274 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
275 const octave_value& rhs) |
2376 | 276 { |
3933 | 277 octave_value retval; |
278 | |
279 int n = type.length (); | |
280 | |
281 octave_value t_rhs = rhs; | |
282 | |
9286
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9190
diff
changeset
|
283 if (idx.front ().empty ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
284 error ("missing index in indexed assignment"); |
9286
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9190
diff
changeset
|
285 |
3933 | 286 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) |
287 { | |
288 switch (type[0]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
289 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
290 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
292 if (type.length () > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
293 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
294 std::list<octave_value_list>::const_iterator p = idx.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
295 octave_value_list t_idx = *p; |
3933 | 296 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
297 octave_value_list key_idx = *++p; |
4513 | 298 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
299 assert (key_idx.length () == 1); |
3933 | 300 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
301 std::string key = key_idx(0).string_value (); |
3933 | 302 |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
303 maybe_warn_invalid_field_name (key, "subsasgn"); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
304 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
305 std::list<octave_value_list> next_idx (idx); |
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 // We handled two index elements, so subsasgn to |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
308 // needs to skip both of them. |
3933 | 309 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
310 next_idx.erase (next_idx.begin ()); |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
311 next_idx.erase (next_idx.begin ()); |
8456
c1709a45b45b
optimize structure components access
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
312 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
313 std::string next_type = type.substr (2); |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
314 |
9087
961410931a4f
fix nested struct assignments
Jaroslav Hajek <highegg@gmail.com>
parents:
9036
diff
changeset
|
315 Cell tmpc (1, 1); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
316 octave_map::iterator pkey = map.seek (key); |
9087
961410931a4f
fix nested struct assignments
Jaroslav Hajek <highegg@gmail.com>
parents:
9036
diff
changeset
|
317 if (pkey != map.end ()) |
961410931a4f
fix nested struct assignments
Jaroslav Hajek <highegg@gmail.com>
parents:
9036
diff
changeset
|
318 { |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
319 map.contents (pkey).make_unique (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
320 tmpc = map.contents (pkey).index (idx.front (), true); |
9087
961410931a4f
fix nested struct assignments
Jaroslav Hajek <highegg@gmail.com>
parents:
9036
diff
changeset
|
321 } |
3933 | 322 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
323 // FIXME: better code reuse? |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
324 // cf. octave_cell::subsasgn and the case below. |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
325 if (tmpc.numel () != 1) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
326 err_indexed_cs_list (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
327 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
328 octave_value& tmp = tmpc(0); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
329 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
330 bool orig_undefined = tmp.is_undefined (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
331 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
332 if (orig_undefined || tmp.is_zero_by_zero ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
333 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
334 tmp = octave_value::empty_conv (next_type, rhs); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
335 tmp.make_unique (); // probably a no-op. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
336 } |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
337 else |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
338 // optimization: ignore the copy |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
339 // still stored inside our map. |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
340 tmp.make_unique (1); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
341 |
21943
2fc1ce5deae4
fix misleading indentation
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
342 t_rhs =(orig_undefined |
2fc1ce5deae4
fix misleading indentation
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
343 ? tmp.undef_subsasgn (next_type, next_idx, rhs) |
2fc1ce5deae4
fix misleading indentation
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
344 : tmp.subsasgn (next_type, next_idx, rhs)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
345 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
346 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
347 err_invalid_index_for_assignment (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
348 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
349 break; |
3933 | 350 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
351 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
352 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
353 octave_value_list key_idx = idx.front (); |
3933 | 354 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
355 assert (key_idx.length () == 1); |
3933 | 356 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
357 std::string key = key_idx(0).string_value (); |
3933 | 358 |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
359 maybe_warn_invalid_field_name (key, "subsasgn"); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
360 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
361 std::list<octave_value_list> next_idx (idx); |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
362 |
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
363 next_idx.erase (next_idx.begin ()); |
3933 | 364 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
365 std::string next_type = type.substr (1); |
8456
c1709a45b45b
optimize structure components access
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
366 |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
367 Cell tmpc (1, 1); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
368 octave_map::iterator pkey = map.seek (key); |
9087
961410931a4f
fix nested struct assignments
Jaroslav Hajek <highegg@gmail.com>
parents:
9036
diff
changeset
|
369 if (pkey != map.end ()) |
961410931a4f
fix nested struct assignments
Jaroslav Hajek <highegg@gmail.com>
parents:
9036
diff
changeset
|
370 { |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
371 map.contents (pkey).make_unique (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
372 tmpc = map.contents (pkey); |
9087
961410931a4f
fix nested struct assignments
Jaroslav Hajek <highegg@gmail.com>
parents:
9036
diff
changeset
|
373 } |
3933 | 374 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
375 // FIXME: better code reuse? |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
376 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
377 if (tmpc.numel () == 1) |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
378 { |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
379 octave_value& tmp = tmpc(0); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
380 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
381 bool orig_undefined = tmp.is_undefined (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
382 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
383 if (orig_undefined || tmp.is_zero_by_zero ()) |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
384 { |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
385 tmp = octave_value::empty_conv (next_type, rhs); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
386 tmp.make_unique (); // probably a no-op. |
8456
c1709a45b45b
optimize structure components access
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
387 } |
c1709a45b45b
optimize structure components access
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
388 else |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
389 // optimization: ignore the copy |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
390 // still stored inside our map. |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
391 tmp.make_unique (1); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
392 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
393 t_rhs = (orig_undefined |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
394 ? tmp.undef_subsasgn (next_type, next_idx, rhs) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
395 : tmp.subsasgn (next_type, next_idx, rhs)); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
396 } |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
397 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
398 err_indexed_cs_list (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
399 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
400 break; |
3933 | 401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
402 case '{': |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
403 err_invalid_index_type (type_name (), type[0]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
404 break; |
3933 | 405 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
406 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
407 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
408 } |
3933 | 409 } |
410 | |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
411 switch (type[0]) |
3933 | 412 { |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
413 case '(': |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
414 { |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
415 if (n > 1 && type[1] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
416 { |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
417 std::list<octave_value_list>::const_iterator p = idx.begin (); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
418 octave_value_list key_idx = *++p; |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
419 octave_value_list idxf = idx.front (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
420 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
421 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
422 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
423 std::string key = key_idx(0).string_value (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
424 |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
425 maybe_warn_invalid_field_name (key, "subsasgn"); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
426 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
427 if (t_rhs.is_cs_list ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
428 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
429 Cell tmp_cell = Cell (t_rhs.list_value ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
430 |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
431 // Inquire the proper shape of the RHS. |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
432 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
433 dim_vector didx = dims ().redim (idxf.length ()); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
434 for (octave_idx_type k = 0; k < idxf.length (); k++) |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
435 if (! idxf(k).is_magic_colon ()) |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
436 didx(k) = idxf(k).numel (); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
437 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
438 if (didx.numel () == tmp_cell.numel ()) |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
439 tmp_cell = tmp_cell.reshape (didx); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
440 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
441 map.assign (idxf, key, tmp_cell); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
442 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
443 count++; |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
444 retval = octave_value (this); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
445 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
446 else |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
447 { |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
448 const octave_map& cmap = |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
449 const_cast<const octave_map &> (map); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
450 // cast to const reference, avoid forced key insertion. |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
451 if (idxf.all_scalars () |
21098
99d373870017
Fix assigning to trailing singletons for structs and cell (bug #39789, bug #35841)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21022
diff
changeset
|
452 || cmap.contents (key).index (idxf, true).numel () == 1) |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
453 { |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
454 map.assign (idxf, |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
455 key, Cell (t_rhs.storable_value ())); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
456 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
457 count++; |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
458 retval = octave_value (this); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
459 } |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
460 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
461 err_nonbraced_cs_list_assignment (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
462 } |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
463 } |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
464 else |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
465 { |
23587
0c468af9dc00
maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
466 if (t_rhs.isstruct () || t_rhs.isobject ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
467 { |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
468 octave_map rhs_map = t_rhs.xmap_value ("invalid structure assignment"); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
469 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
470 map.assign (idx.front (), rhs_map); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
471 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
472 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
473 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
474 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
475 else |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
476 { |
23589
63950abd2f81
maint: Deprecate is_null_type and replace with isnull.
Rik <rik@octave.org>
parents:
23587
diff
changeset
|
477 if (! t_rhs.isnull ()) |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
478 error ("invalid structure assignment"); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
479 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
480 map.delete_elements (idx.front ()); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
481 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
482 count++; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
483 retval = octave_value (this); |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
484 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
485 } |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
486 } |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
487 break; |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
488 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
489 case '.': |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
490 { |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
491 octave_value_list key_idx = idx.front (); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
492 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
493 assert (key_idx.length () == 1); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
494 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
495 std::string key = key_idx(0).string_value (); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
496 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
497 maybe_warn_invalid_field_name (key, "subsasgn"); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
498 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
499 if (t_rhs.is_cs_list ()) |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
500 { |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
501 Cell tmp_cell = Cell (t_rhs.list_value ()); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
502 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
503 // The shape of the RHS is irrelevant, we just want |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
504 // the number of elements to agree and to preserve the |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
505 // shape of the left hand side of the assignment. |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
506 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
507 if (numel () == tmp_cell.numel ()) |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
508 tmp_cell = tmp_cell.reshape (dims ()); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
509 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
510 map.setfield (key, tmp_cell); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
511 } |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
512 else |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
513 { |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
514 Cell tmp_cell(1, 1); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
515 tmp_cell(0) = t_rhs.storable_value (); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
516 map.setfield (key, tmp_cell); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
517 } |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
518 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
519 count++; |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
520 retval = octave_value (this); |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
521 } |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
522 break; |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
523 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
524 case '{': |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21098
diff
changeset
|
525 err_invalid_index_type (type_name (), type[0]); |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
526 break; |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
527 |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
528 default: |
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
529 panic_impossible (); |
3933 | 530 } |
531 | |
10754
92eb5fb58ebc
fix resize with structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
532 retval.maybe_mutate (); |
92eb5fb58ebc
fix resize with structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
533 |
3933 | 534 return retval; |
2376 | 535 } |
536 | |
7046 | 537 octave_value |
538 octave_struct::do_index_op (const octave_value_list& idx, bool resize_ok) | |
539 { | |
23880
1b232c0c19e6
Empty indexing of a struct should return the entire struct (bug #51633).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
540 if (idx.length () == 0) |
1b232c0c19e6
Empty indexing of a struct should return the entire struct (bug #51633).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
541 return map; |
1b232c0c19e6
Empty indexing of a struct should return the entire struct (bug #51633).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
542 else // octave_map handles indexing itself. |
1b232c0c19e6
Empty indexing of a struct should return the entire struct (bug #51633).
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
543 return map.index (idx, resize_ok); |
7046 | 544 } |
545 | |
4791 | 546 size_t |
547 octave_struct::byte_size (void) const | |
548 { | |
549 // Neglect the size of the fieldnames. | |
550 | |
551 size_t retval = 0; | |
552 | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
553 for (octave_map::const_iterator p = map.begin (); p != map.end (); p++) |
4791 | 554 { |
555 std::string key = map.key (p); | |
556 | |
557 octave_value val = octave_value (map.contents (p)); | |
558 | |
559 retval += val.byte_size (); | |
560 } | |
561 | |
562 return retval; | |
563 } | |
564 | |
2376 | 565 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18384
diff
changeset
|
566 octave_struct::print (std::ostream& os, bool) |
2901 | 567 { |
568 print_raw (os); | |
569 } | |
570 | |
571 void | |
3523 | 572 octave_struct::print_raw (std::ostream& os, bool) const |
2376 | 573 { |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
574 octave::unwind_protect frame; |
2376 | 575 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
576 frame.protect_var (Vstruct_levels_to_print); |
2376 | 577 |
3961 | 578 if (Vstruct_levels_to_print >= 0) |
2376 | 579 { |
11474 | 580 bool max_depth_reached = Vstruct_levels_to_print-- == 0; |
3961 | 581 |
11474 | 582 bool print_fieldnames_only |
583 = (max_depth_reached || ! Vprint_struct_array_contents); | |
2376 | 584 |
2901 | 585 increment_indent_level (); |
2376 | 586 |
11474 | 587 indent (os); |
588 dim_vector dv = dims (); | |
589 os << dv.str () << " struct array containing the fields:"; | |
590 newline (os); | |
3932 | 591 |
11474 | 592 increment_indent_level (); |
4604 | 593 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
594 string_vector key_list = map.fieldnames (); |
5880 | 595 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
596 for (octave_idx_type i = 0; i < key_list.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
597 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
598 std::string key = key_list[i]; |
5880 | 599 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
600 Cell val = map.contents (key); |
2376 | 601 |
23354
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
602 if (i > 0 || ! Vcompact_format) |
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
603 newline (os); |
3961 | 604 |
11474 | 605 if (print_fieldnames_only) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
606 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
607 indent (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
608 os << key; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
609 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
610 else |
11474 | 611 { |
612 octave_value tmp (val); | |
613 tmp.print_with_name (os, key); | |
614 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
615 } |
2376 | 616 |
11474 | 617 if (print_fieldnames_only) |
618 newline (os); | |
4604 | 619 |
2901 | 620 decrement_indent_level (); |
11474 | 621 decrement_indent_level (); |
2376 | 622 } |
623 else | |
2901 | 624 { |
3961 | 625 indent (os); |
626 os << "<structure>"; | |
2901 | 627 newline (os); |
628 } | |
2376 | 629 } |
630 | |
2901 | 631 bool |
3523 | 632 octave_struct::print_name_tag (std::ostream& os, const std::string& name) const |
2901 | 633 { |
3961 | 634 bool retval = false; |
635 | |
2901 | 636 indent (os); |
3961 | 637 |
638 if (Vstruct_levels_to_print < 0) | |
639 os << name << " = "; | |
640 else | |
641 { | |
642 os << name << " ="; | |
643 newline (os); | |
23354
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
644 if (! Vcompact_format) |
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
645 newline (os); |
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
646 |
3961 | 647 retval = true; |
648 } | |
649 | |
650 return retval; | |
2901 | 651 } |
652 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
653 static bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
654 scalar (const dim_vector& dims) |
4744 | 655 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
656 return dims.ndims () == 2 && dims(0) == 1 && dims(1) == 1; |
4744 | 657 } |
658 | |
24660
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
659 std::string |
24700
aaf7bcea71dd
Silence build warnings about unused parameters.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24668
diff
changeset
|
660 octave_struct::edit_display (const float_display_format&, |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24660
diff
changeset
|
661 octave_idx_type r, octave_idx_type c) const |
24660
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
662 { |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
663 octave_value val; |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
664 if (map.rows () == 1 || map.columns () == 1) |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
665 { |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
666 // Vector struct. Columns are fields, rows are values. |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
667 |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
668 Cell cval = map.contents (c); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
669 |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
670 val = cval(r); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
671 } |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
672 else |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
673 { |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
674 // 2-d struct array. Rows and columns index individual |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
675 // scalar structs. |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
676 |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
677 val = map(r,c); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
678 } |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
679 |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
680 std::string tname = val.type_name (); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
681 dim_vector dv = val.dims (); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
682 std::string dimstr = dv.str (); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
683 return "[" + dimstr + " " + tname + "]"; |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
684 } |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
685 |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
686 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
687 bool |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
688 octave_struct::save_ascii (std::ostream& os) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
689 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
690 octave_map m = map_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
691 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
692 octave_idx_type nf = m.nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
693 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
694 const dim_vector dv = dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
695 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
696 os << "# ndims: " << dv.ndims () << "\n"; |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
697 |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
698 for (int i = 0; i < dv.ndims (); i++) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
699 os << ' ' << dv(i); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
700 os << "\n"; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
701 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
702 os << "# length: " << nf << "\n"; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
703 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
704 // Iterating over the list of keys will preserve the order of the |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
705 // fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
706 string_vector keys = m.fieldnames (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
707 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
708 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
709 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
710 std::string key = keys(i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
711 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
712 octave_value val = map.contents (key); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
713 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
714 bool b = save_text_data (os, val, key, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
715 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
716 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
717 return ! os.fail (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
718 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
719 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
720 return true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
721 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
722 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
723 bool |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
724 octave_struct::load_ascii (std::istream& is) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
725 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
726 octave_idx_type len = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
727 dim_vector dv (1, 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
728 bool success = true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
729 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
730 // KLUGE: earlier Octave versions did not save extra dimensions with struct, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
731 // and as a result did not preserve dimensions for empty structs. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
732 // The default dimensions were 1x1, which we want to preserve. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
733 string_vector keywords(2); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
734 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
735 keywords[0] = "ndims"; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
736 keywords[1] = "length"; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
737 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
738 std::string kw; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
739 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
740 if (extract_keyword (is, keywords, kw, len, true)) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
741 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
742 if (kw == keywords[0]) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
743 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
744 int mdims = std::max (static_cast<int> (len), 2); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
745 dv.resize (mdims); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
746 for (int i = 0; i < mdims; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
747 is >> dv(i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
748 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
749 success = extract_keyword (is, keywords[1], len); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
750 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
751 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
752 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
753 success = false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
754 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
755 if (! success || len < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
756 error ("load: failed to extract number of elements in structure"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
757 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
758 if (len > 0) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
759 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
760 octave_map m (dv); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
761 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
762 for (octave_idx_type j = 0; j < len; j++) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
763 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
764 octave_value t2; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
765 bool dummy; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
766 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
767 // recurse to read cell elements |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
768 std::string nm |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
769 = read_text_data (is, "", dummy, t2, j); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
770 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
771 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
772 break; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
773 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
774 Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2)); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
775 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
776 m.setfield (nm, tcell); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
777 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
778 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
779 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
780 error ("load: failed to load structure"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
781 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
782 map = m; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
783 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
784 else if (len == 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
785 map = octave_map (dv); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
786 else |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
787 panic_impossible (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
788 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
789 return success; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
790 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
791 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
792 bool |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
793 octave_struct::save_binary (std::ostream& os, bool& save_as_floats) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
794 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
795 octave_map m = map_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
796 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
797 octave_idx_type nf = m.nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
798 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
799 dim_vector dv = dims (); |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
800 if (dv.ndims () < 1) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
801 return false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
802 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
803 // Use negative value for ndims |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
804 int32_t di = - dv.ndims (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
805 os.write (reinterpret_cast<char *> (&di), 4); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
806 for (int i = 0; i < dv.ndims (); i++) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
807 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
808 di = dv(i); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
809 os.write (reinterpret_cast<char *> (&di), 4); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
810 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
811 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
812 int32_t len = nf; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
813 os.write (reinterpret_cast<char *> (&len), 4); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
814 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
815 // Iterating over the list of keys will preserve the order of the |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
816 // fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
817 string_vector keys = m.fieldnames (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
818 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
819 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
820 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
821 std::string key = keys(i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
822 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
823 octave_value val = map.contents (key); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
824 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
825 bool b = save_binary_data (os, val, key, "", 0, save_as_floats); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
826 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
827 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
828 return ! os.fail (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
829 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
830 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
831 return true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
832 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
833 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
834 bool |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
835 octave_struct::load_binary (std::istream& is, bool swap, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
836 octave::mach_info::float_format fmt) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
837 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
838 bool success = true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
839 int32_t len; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
840 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
841 return false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
842 if (swap) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
843 swap_bytes<4> (&len); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
844 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
845 dim_vector dv (1, 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
846 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
847 if (len < 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
848 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
849 // We have explicit dimensions. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
850 int mdims = -len; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
851 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
852 int32_t di; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
853 dv.resize (mdims); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
854 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
855 for (int i = 0; i < mdims; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
856 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
857 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
858 return false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
859 if (swap) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
860 swap_bytes<4> (&di); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
861 dv(i) = di; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
862 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
863 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
864 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
865 return false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
866 if (swap) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
867 swap_bytes<4> (&len); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
868 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
869 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
870 if (len > 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
871 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
872 octave_map m (dv); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
873 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
874 for (octave_idx_type j = 0; j < len; j++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
875 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
876 octave_value t2; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
877 bool dummy; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
878 std::string doc; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
879 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
880 // recurse to read cell elements |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
881 std::string nm = read_binary_data (is, swap, fmt, "", |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
882 dummy, t2, doc); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
883 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20952
diff
changeset
|
884 if (! is) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
885 break; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
886 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
887 Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2)); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
888 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
889 m.setfield (nm, tcell); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
890 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
891 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
892 if (! is) |
20952
072559bd31f2
maint: Eliminate useless statements after error().
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
893 error ("load: failed to load structure"); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
894 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
895 map = m; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
896 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
897 else if (len == 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
898 map = octave_map (dv); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
899 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
900 success = false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
901 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
902 return success; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
903 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
904 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
905 bool |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
906 octave_struct::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
907 bool save_as_floats) |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
908 { |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
909 #if defined (HAVE_HDF5) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
910 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
911 hid_t data_hid = -1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
912 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
913 #if defined (HAVE_HDF5_18) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
914 data_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
915 octave_H5P_DEFAULT); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
916 #else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
917 data_hid = H5Gcreate (loc_id, name, 0); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
918 #endif |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
919 if (data_hid < 0) return false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
920 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
921 // recursively add each element of the structure to this group |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
922 octave_map m = map_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
923 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
924 octave_idx_type nf = m.nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
925 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
926 // Iterating over the list of keys will preserve the order of the |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
927 // fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
928 string_vector keys = m.fieldnames (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
929 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
930 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
931 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
932 std::string key = keys(i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
933 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
934 octave_value val = map.contents (key); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
935 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
936 bool retval2 = add_hdf5_data (data_hid, val, key, "", false, |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
937 save_as_floats); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
938 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
939 if (! retval2) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
940 break; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
941 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
942 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
943 H5Gclose (data_hid); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
944 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
945 return true; |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
946 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
947 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
948 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
949 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
950 octave_unused_parameter (save_as_floats); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
951 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
952 warn_save ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
953 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
954 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
955 #endif |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
956 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
957 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
958 bool |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
959 octave_struct::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
960 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
961 bool retval = false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
962 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
963 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
964 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
965 hdf5_callback_data dsub; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
966 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
967 herr_t retval2 = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
968 octave_map m (dim_vector (1, 1)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
969 int current_item = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
970 hsize_t num_obj = 0; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
971 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
972 hid_t group_id = H5Gopen (loc_id, name, octave_H5P_DEFAULT); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
973 #else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
974 hid_t group_id = H5Gopen (loc_id, name); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
975 #endif |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
976 H5Gget_num_objs (group_id, &num_obj); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
977 H5Gclose (group_id); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
978 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
979 // FIXME: fields appear to be sorted alphabetically on loading. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
980 // Why is that happening? |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
981 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
982 while (current_item < static_cast<int> (num_obj) |
22028
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
983 && (retval2 = hdf5_h5g_iterate (loc_id, name, ¤t_item, |
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
984 &dsub)) > 0) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
985 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
986 octave_value t2 = dsub.tc; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
987 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
988 Cell tcell = (t2.iscell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2)); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
989 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
990 m.setfield (dsub.name, tcell); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
991 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
992 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
993 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
994 if (retval2 >= 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
995 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
996 map = m; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
997 retval = true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
998 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
999 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1000 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1001 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1002 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1003 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1004 warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1005 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1006 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1007 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1008 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1009 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1010 mxArray * |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1011 octave_struct::as_mxArray (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1012 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1013 int nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1014 string_vector kv = map_keys (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1015 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1016 OCTAVE_LOCAL_BUFFER (const char *, f, nf); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1017 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1018 for (int i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1019 f[i] = kv[i].c_str (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1020 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1021 mxArray *retval = new mxArray (dims (), nf, f); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1022 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1023 mxArray **elts = static_cast<mxArray **> (retval->get_data ()); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1024 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1025 mwSize nel = numel (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1026 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1027 mwSize ntot = nf * nel; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1028 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1029 for (int i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1030 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1031 Cell c = map.contents (kv[i]); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1032 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1033 const octave_value *p = c.data (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1034 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1035 mwIndex k = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1036 for (mwIndex j = i; j < ntot; j += nf) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1037 elts[j] = new mxArray (p[k++]); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1038 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1039 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1040 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1041 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1042 |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1043 octave_value |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1044 octave_struct::fast_elem_extract (octave_idx_type n) const |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1045 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1046 if (n < map.numel ()) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1047 return map.checkelem (n); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1048 else |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1049 return octave_value (); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1050 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1051 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1052 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1053 octave_struct::fast_elem_insert (octave_idx_type n, |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1054 const octave_value& x) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1055 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1056 bool retval = false; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1057 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1058 if (n < map.numel ()) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1059 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1060 // To avoid copying the scalar struct, it just stores a pointer to |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1061 // itself. |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1062 const octave_scalar_map *sm_ptr; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1063 void *here = reinterpret_cast<void *>(&sm_ptr); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14625
diff
changeset
|
1064 return (x.get_rep ().fast_elem_insert_self (here, btyp_struct) |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1065 && map.fast_elem_insert (n, *sm_ptr)); |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1066 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1067 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1068 return retval; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1069 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1070 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1071 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_scalar_struct, "scalar struct", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1072 "struct"); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1073 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1074 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1075 octave_scalar_struct::dotref (const octave_value_list& idx, bool auto_add) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1076 { |
15613
126285fce876
check for allowed struct field names in subsref and subsasgn
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15534
diff
changeset
|
1077 octave_value retval; |
126285fce876
check for allowed struct field names in subsref and subsasgn
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15534
diff
changeset
|
1078 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1079 assert (idx.length () == 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1080 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1081 std::string nm = idx(0).string_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1082 |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
1083 maybe_warn_invalid_field_name (nm, "subsref"); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
1084 |
15613
126285fce876
check for allowed struct field names in subsref and subsasgn
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15534
diff
changeset
|
1085 retval = map.getfield (nm); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1086 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1087 if (! auto_add && retval.is_undefined ()) |
15731
18f168880226
error_ids: Adding ids and documentation
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
15614
diff
changeset
|
1088 error_with_id ("Octave:invalid-indexing", |
18f168880226
error_ids: Adding ids and documentation
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
15614
diff
changeset
|
1089 "structure has no member '%s'", nm.c_str ()); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1090 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1091 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1092 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1093 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1094 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1095 octave_scalar_struct::subsref (const std::string& type, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1096 const std::list<octave_value_list>& idx) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1097 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1098 octave_value retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1099 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1100 if (type[0] == '.') |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1101 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1102 int skip = 1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1103 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1104 retval = dotref (idx.front ()); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1105 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1106 if (idx.size () > 1) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1107 retval = retval.next_subsref (type, idx, skip); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1108 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1109 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1110 retval = to_array ().subsref (type, idx); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1111 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1112 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1113 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1114 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1115 octave_value_list |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1116 octave_scalar_struct::subsref (const std::string& type, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1117 const std::list<octave_value_list>& idx, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1118 int nargout) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1119 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1120 octave_value_list retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1121 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1122 if (type[0] == '.') |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1123 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1124 int skip = 1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1125 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1126 retval(0) = dotref (idx.front ()); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1127 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1128 if (idx.size () > 1) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1129 retval = retval(0).next_subsref (nargout, type, idx, skip); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1130 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1131 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1132 retval = to_array ().subsref (type, idx, nargout); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1133 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1134 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1135 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1136 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1137 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1138 octave_scalar_struct::subsref (const std::string& type, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1139 const std::list<octave_value_list>& idx, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1140 bool auto_add) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1141 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1142 octave_value retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1143 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1144 if (type[0] == '.') |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1145 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1146 int skip = 1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1147 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1148 retval = dotref (idx.front (), auto_add); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1149 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1150 if (idx.size () > 1) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1151 retval = retval.next_subsref (auto_add, type, idx, skip); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1152 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1153 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1154 retval = to_array ().subsref (type, idx, auto_add); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1155 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1156 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1157 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1158 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1159 /* |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1160 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1161 %! x(1).a.a = 1; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1162 %! x(2).a.a = 2; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1163 %! assert (size (x), [1, 2]); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1164 %! assert (x(1).a.a, 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1165 %! assert (x(2).a.a, 2); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1166 */ |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1167 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1168 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1169 octave_scalar_struct::numeric_conv (const octave_value& val, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1170 const std::string& type) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1171 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1172 octave_value retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1173 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1174 if (type.length () > 0 && type[0] == '.' && ! val.isstruct ()) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1175 retval = octave_map (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1176 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1177 retval = val; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1178 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1179 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1180 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1181 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1182 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1183 octave_scalar_struct::subsasgn (const std::string& type, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1184 const std::list<octave_value_list>& idx, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1185 const octave_value& rhs) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1186 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1187 octave_value retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1188 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1189 if (idx.front ().empty ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1190 error ("missing index in indexed assignment"); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1191 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1192 if (type[0] == '.') |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1193 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1194 int n = type.length (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1195 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1196 octave_value t_rhs = rhs; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1197 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1198 octave_value_list key_idx = idx.front (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1199 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1200 assert (key_idx.length () == 1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1201 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1202 std::string key = key_idx(0).string_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1203 |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
1204 maybe_warn_invalid_field_name (key, "subsasgn"); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
1205 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1206 if (n > 1) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1207 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1208 std::list<octave_value_list> next_idx (idx); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1209 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1210 next_idx.erase (next_idx.begin ()); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1211 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1212 std::string next_type = type.substr (1); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1213 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1214 octave_value tmp; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1215 octave_map::iterator pkey = map.seek (key); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1216 if (pkey != map.end ()) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1217 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1218 map.contents (pkey).make_unique (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1219 tmp = map.contents (pkey); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1220 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1221 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1222 bool orig_undefined = tmp.is_undefined (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1223 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1224 if (orig_undefined || tmp.is_zero_by_zero ()) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1225 { |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1226 tmp = octave_value::empty_conv (next_type, rhs); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1227 tmp.make_unique (); // probably a no-op. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1228 } |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1229 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1230 // optimization: ignore the copy still stored inside our map. |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1231 tmp.make_unique (1); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1232 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1233 t_rhs = (orig_undefined |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1234 ? tmp.undef_subsasgn (next_type, next_idx, rhs) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
1235 : tmp.subsasgn (next_type, next_idx, rhs)); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1236 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1237 |
20740
bba1a5fd4d8c
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1238 map.setfield (key, t_rhs.storable_value ()); |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10747
diff
changeset
|
1239 |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10747
diff
changeset
|
1240 count++; |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10747
diff
changeset
|
1241 retval = this; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1242 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1243 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1244 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1245 // Forward this case to octave_struct. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1246 octave_value tmp (new octave_struct (octave_map (map))); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1247 retval = tmp.subsasgn (type, idx, rhs); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1248 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1249 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1250 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1251 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1252 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1253 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1254 octave_scalar_struct::do_index_op (const octave_value_list& idx, bool resize_ok) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1255 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1256 // octave_map handles indexing itself. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1257 return octave_map (map).index (idx, resize_ok); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1258 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1259 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1260 size_t |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1261 octave_scalar_struct::byte_size (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1262 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1263 // Neglect the size of the fieldnames. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1264 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1265 size_t retval = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1266 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1267 for (octave_map::const_iterator p = map.begin (); p != map.end (); p++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1268 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1269 std::string key = map.key (p); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1270 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1271 octave_value val = octave_value (map.contents (p)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1272 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1273 retval += val.byte_size (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1274 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1275 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1276 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1277 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1278 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1279 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18384
diff
changeset
|
1280 octave_scalar_struct::print (std::ostream& os, bool) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1281 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1282 print_raw (os); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1283 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1284 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1285 void |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1286 octave_scalar_struct::print_raw (std::ostream& os, bool) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1287 { |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
1288 octave::unwind_protect frame; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1289 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1290 frame.protect_var (Vstruct_levels_to_print); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1291 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1292 if (Vstruct_levels_to_print >= 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1293 { |
11474 | 1294 bool max_depth_reached = Vstruct_levels_to_print-- == 0; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1295 |
11474 | 1296 bool print_fieldnames_only = max_depth_reached; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1297 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1298 increment_indent_level (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1299 |
11474 | 1300 indent (os); |
1301 os << "scalar structure containing the fields:"; | |
1302 newline (os); | |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
1303 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
1304 newline (os); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1305 |
11474 | 1306 increment_indent_level (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1307 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1308 string_vector key_list = map.fieldnames (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1309 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
1310 for (octave_idx_type i = 0; i < key_list.numel (); i++) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1311 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1312 std::string key = key_list[i]; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1313 |
12143
ed129a03f93c
octave_scalar_struct::print_raw: avoid unnecessary conversion of map contents to Cell
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1314 octave_value val = map.contents (key); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1315 |
11474 | 1316 if (print_fieldnames_only) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1317 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1318 indent (os); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1319 os << key; |
12143
ed129a03f93c
octave_scalar_struct::print_raw: avoid unnecessary conversion of map contents to Cell
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1320 dim_vector dv = val.dims (); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1321 os << ": " << dv.str () << ' ' << val.type_name (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1322 newline (os); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1323 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1324 else |
12143
ed129a03f93c
octave_scalar_struct::print_raw: avoid unnecessary conversion of map contents to Cell
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1325 val.print_with_name (os, key); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1326 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1327 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1328 decrement_indent_level (); |
11474 | 1329 decrement_indent_level (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1330 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1331 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1332 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1333 indent (os); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1334 os << "<structure>"; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1335 newline (os); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1336 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1337 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1338 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1339 bool |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1340 octave_scalar_struct::print_name_tag (std::ostream& os, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1341 const std::string& name) const |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1342 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1343 bool retval = false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1344 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1345 indent (os); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1346 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1347 if (Vstruct_levels_to_print < 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1348 os << name << " = "; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1349 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1350 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1351 os << name << " ="; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1352 newline (os); |
23354
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1353 if (! Vcompact_format) |
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1354 newline (os); |
1a2941fb8ffd
Change display of structs to respect compact format.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1355 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1356 retval = true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1357 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1358 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1359 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1360 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1361 |
24660
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1362 std::string |
24700
aaf7bcea71dd
Silence build warnings about unused parameters.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24668
diff
changeset
|
1363 octave_scalar_struct::edit_display (const float_display_format&, |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24660
diff
changeset
|
1364 octave_idx_type r, octave_idx_type) const |
24660
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1365 { |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1366 // Scalar struct. Rows are fields, single column for values. |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1367 |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1368 octave_value val = map.contents (r); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1369 |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1370 std::string tname = val.type_name (); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1371 dim_vector dv = val.dims (); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1372 std::string dimstr = dv.str (); |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1373 return "[" + dimstr + " " + tname + "]"; |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1374 } |
a4ea36915e38
handle structure arrays in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1375 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1376 bool |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1377 octave_scalar_struct::save_ascii (std::ostream& os) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1378 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1379 octave_map m = map_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1380 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1381 octave_idx_type nf = m.nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1382 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1383 const dim_vector dv = dims (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1384 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
1385 os << "# ndims: " << dv.ndims () << "\n"; |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
1386 |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
1387 for (int i = 0; i < dv.ndims (); i++) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1388 os << ' ' << dv(i); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1389 os << "\n"; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1390 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1391 os << "# length: " << nf << "\n"; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1392 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1393 // Iterating over the list of keys will preserve the order of the |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1394 // fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1395 string_vector keys = m.fieldnames (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1396 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1397 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1398 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1399 std::string key = keys(i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1400 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1401 octave_value val = map.contents (key); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1402 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1403 bool b = save_text_data (os, val, key, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1404 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1405 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
1406 return ! os.fail (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1407 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1408 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1409 return true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1410 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1411 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1412 bool |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1413 octave_scalar_struct::load_ascii (std::istream& is) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1414 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1415 octave_idx_type len = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1416 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1417 if (! extract_keyword (is, "length", len) || len < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1418 error ("load: failed to extract number of elements in structure"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1419 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1420 if (len > 0) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1421 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1422 octave_scalar_map m; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1423 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1424 for (octave_idx_type j = 0; j < len; j++) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1425 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1426 octave_value t2; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1427 bool dummy; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1428 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1429 // recurse to read cell elements |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1430 std::string nm |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
1431 = read_text_data (is, "", dummy, t2, j); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1432 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1433 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1434 break; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1435 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1436 m.setfield (nm, t2); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1437 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1438 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1439 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1440 error ("load: failed to load structure"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1441 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1442 map = m; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1443 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1444 else if (len == 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1445 map = octave_scalar_map (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1446 else |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1447 panic_impossible (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1448 |
21124
95f8c8cdbffe
maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1449 return true; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1450 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1451 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1452 bool |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1453 octave_scalar_struct::save_binary (std::ostream& os, bool& save_as_floats) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1454 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1455 octave_map m = map_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1456 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1457 octave_idx_type nf = m.nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1458 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1459 int32_t len = nf; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1460 os.write (reinterpret_cast<char *> (&len), 4); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1461 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1462 // Iterating over the list of keys will preserve the order of the |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1463 // fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1464 string_vector keys = m.fieldnames (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1465 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1466 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1467 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1468 std::string key = keys(i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1469 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1470 octave_value val = map.contents (key); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1471 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1472 bool b = save_binary_data (os, val, key, "", 0, save_as_floats); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1473 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1474 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
1475 return ! os.fail (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1476 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1477 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1478 return true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1479 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1480 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1481 bool |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1482 octave_scalar_struct::load_binary (std::istream& is, bool swap, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1483 octave::mach_info::float_format fmt) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1484 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1485 bool success = true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1486 int32_t len; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1487 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1488 return false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1489 if (swap) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1490 swap_bytes<4> (&len); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1491 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1492 if (len > 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1493 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1494 octave_scalar_map m; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1495 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1496 for (octave_idx_type j = 0; j < len; j++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1497 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1498 octave_value t2; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1499 bool dummy; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1500 std::string doc; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1501 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1502 // recurse to read cell elements |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
1503 std::string nm = read_binary_data (is, swap, fmt, "", |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1504 dummy, t2, doc); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1505 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20952
diff
changeset
|
1506 if (! is) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1507 break; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1508 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1509 m.setfield (nm, t2); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1510 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1511 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1512 if (! is) |
20952
072559bd31f2
maint: Eliminate useless statements after error().
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
1513 error ("load: failed to load structure"); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1514 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
1515 map = m; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1516 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1517 else if (len == 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1518 map = octave_scalar_map (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1519 else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1520 success = false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1521 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1522 return success; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1523 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1524 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1525 bool |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1526 octave_scalar_struct::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1527 bool save_as_floats) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1528 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1529 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1530 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1531 hid_t data_hid = -1; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1532 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1533 #if defined (HAVE_HDF5_18) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1534 data_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1535 octave_H5P_DEFAULT); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1536 #else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1537 data_hid = H5Gcreate (loc_id, name, 0); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1538 #endif |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1539 if (data_hid < 0) return false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1540 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1541 // recursively add each element of the structure to this group |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1542 octave_scalar_map m = scalar_map_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1543 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1544 octave_idx_type nf = m.nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1545 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1546 // Iterating over the list of keys will preserve the order of the |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1547 // fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1548 string_vector keys = m.fieldnames (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1549 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1550 for (octave_idx_type i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1551 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1552 std::string key = keys(i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1553 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1554 octave_value val = map.contents (key); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1555 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1556 bool retval2 = add_hdf5_data (data_hid, val, key, "", false, |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1557 save_as_floats); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1558 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1559 if (! retval2) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1560 break; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1561 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1562 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1563 H5Gclose (data_hid); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1564 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1565 return true; |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1566 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1567 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1568 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1569 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1570 octave_unused_parameter (save_as_floats); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1571 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1572 warn_save ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1573 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1574 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1575 #endif |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1576 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1577 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1578 bool |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1579 octave_scalar_struct::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1580 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1581 bool retval = false; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1582 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1583 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1584 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1585 hdf5_callback_data dsub; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1586 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1587 herr_t retval2 = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1588 octave_scalar_map m; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1589 int current_item = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1590 hsize_t num_obj = 0; |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1591 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1592 hid_t group_id = H5Gopen (loc_id, name, octave_H5P_DEFAULT); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1593 #else |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1594 hid_t group_id = H5Gopen (loc_id, name); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1595 #endif |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1596 H5Gget_num_objs (group_id, &num_obj); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1597 H5Gclose (group_id); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1598 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1599 // FIXME: fields appear to be sorted alphabetically on loading. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1600 // Why is that happening? |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1601 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1602 while (current_item < static_cast<int> (num_obj) |
22028
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
1603 && (retval2 = hdf5_h5g_iterate (loc_id, name, ¤t_item, |
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
1604 &dsub)) > 0) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1605 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1606 octave_value t2 = dsub.tc; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1607 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1608 m.setfield (dsub.name, t2); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1609 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1610 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1611 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1612 if (retval2 >= 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1613 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1614 map = m; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1615 retval = true; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1616 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1617 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1618 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1619 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1620 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1621 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1622 warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1623 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19852
diff
changeset
|
1624 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1625 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1626 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1627 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1628 mxArray * |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1629 octave_scalar_struct::as_mxArray (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1630 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1631 int nf = nfields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1632 string_vector kv = map_keys (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1633 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1634 OCTAVE_LOCAL_BUFFER (const char *, f, nf); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1635 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1636 for (int i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1637 f[i] = kv[i].c_str (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1638 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1639 mxArray *retval = new mxArray (dims (), nf, f); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1640 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1641 mxArray **elts = static_cast<mxArray **> (retval->get_data ()); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1642 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1643 mwSize nel = numel (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1644 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1645 mwSize ntot = nf * nel; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1646 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1647 for (int i = 0; i < nf; i++) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1648 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1649 Cell c = map.contents (kv[i]); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1650 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1651 const octave_value *p = c.data (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1652 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1653 mwIndex k = 0; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1654 for (mwIndex j = i; j < ntot; j += nf) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1655 elts[j] = new mxArray (p[k++]); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1656 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1657 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1658 return retval; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1659 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1660 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1661 octave_value |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1662 octave_scalar_struct::to_array (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1663 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1664 return new octave_struct (octave_map (map)); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1665 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1666 |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1667 bool |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1668 octave_scalar_struct::fast_elem_insert_self (void *where, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1669 builtin_type_t btyp) const |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1670 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1671 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1672 if (btyp == btyp_struct) |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1673 { |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1674 *(reinterpret_cast<const octave_scalar_map **>(where)) = ↦ |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1675 return true; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1676 } |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1677 else |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1678 return false; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10754
diff
changeset
|
1679 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1680 |
4744 | 1681 DEFUN (struct, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1682 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1683 @deftypefn {} {@var{s} =} struct () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1684 @deftypefnx {} {@var{s} =} struct (@var{field1}, @var{value1}, @var{field2}, @var{value2}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1685 @deftypefnx {} {@var{s} =} struct (@var{obj}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1686 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1687 Create a scalar or array structure and initialize its values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1688 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1689 The @var{field1}, @var{field2}, @dots{} variables are strings specifying the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1690 names of the fields and the @var{value1}, @var{value2}, @dots{} variables |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1691 can be of any type. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1692 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1693 If the values are cell arrays, create a structure array and initialize its |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1694 values. The dimensions of each cell array of values must match. Singleton |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1695 cells and non-cell values are repeated so that they fill the entire array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1696 If the cells are empty, create an empty structure array with the specified |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1697 field names. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1698 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1699 If the argument is an object, return the underlying struct. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1700 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1701 Observe that the syntax is optimized for struct @strong{arrays}. Consider |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1702 the following examples: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1703 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1704 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1705 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1706 struct ("foo", 1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1707 @result{} scalar structure containing the fields: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1708 foo = 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1709 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1710 struct ("foo", @{@}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1711 @result{} 0x0 struct array containing the fields: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1712 foo |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1713 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1714 struct ("foo", @{ @{@} @}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1715 @result{} scalar structure containing the fields: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1716 foo = @{@}(0x0) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1717 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1718 struct ("foo", @{1, 2, 3@}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1719 @result{} 1x3 struct array containing the fields: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1720 foo |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1721 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1722 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1723 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1724 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1725 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1726 The first case is an ordinary scalar struct---one field, one value. The |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1727 second produces an empty struct array with one field and no values, since |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1728 being passed an empty cell array of struct array values. When the value is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1729 a cell array containing a single entry, this becomes a scalar struct with |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1730 that single entry as the value of the field. That single entry happens |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1731 to be an empty cell array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1732 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1733 Finally, if the value is a non-scalar cell array, then @code{struct} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1734 produces a struct @strong{array}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1735 @seealso{cell2struct, fieldnames, getfield, setfield, rmfield, isfield, orderfields, isstruct, structfun} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1736 @end deftypefn */) |
4744 | 1737 { |
1738 int nargin = args.length (); | |
1739 | |
5444 | 1740 // struct ([]) returns an empty struct. |
1741 | |
1742 // struct (empty_matrix) returns an empty struct with the same | |
1743 // dimensions as the empty matrix. | |
1744 | |
1745 // Note that struct () creates a 1x1 struct with no fields for | |
1746 // compatibility with Matlab. | |
4744 | 1747 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1748 if (nargin == 1 && args(0).isstruct ()) |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
1749 return ovl (args(0)); |
10747
58c1b5402588
fix a showstopping bug in octave_fields reference counting
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1750 |
23587
0c468af9dc00
maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
1751 if (nargin == 1 && args(0).isobject ()) |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
1752 return ovl (args(0).map_value ()); |
9190 | 1753 |
6946 | 1754 if ((nargin == 1 || nargin == 2) |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
1755 && args(0).isempty () && args(0).is_real_matrix ()) |
6946 | 1756 { |
1757 if (nargin == 2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1758 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
1759 Array<std::string> cstr = args(1).xcellstr_value ("struct: second argument should be a cell array of field names"); |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20619
diff
changeset
|
1760 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
1761 return ovl (octave_map (args(0).dims (), cstr)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1762 } |
6946 | 1763 else |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
1764 return ovl (octave_map (args(0).dims ())); |
6946 | 1765 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1766 |
4744 | 1767 // Check for "field", VALUE pairs. |
1768 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1769 for (int i = 0; i < nargin; i += 2) |
4744 | 1770 { |
1771 if (! args(i).is_string () || i + 1 >= nargin) | |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23589
diff
changeset
|
1772 error (R"(struct: additional arguments must occur as "field", VALUE pairs)"); |
4744 | 1773 } |
1774 | |
1775 // Check that the dimensions of the values correspond. | |
1776 | |
1777 dim_vector dims (1, 1); | |
1778 | |
1779 int first_dimensioned_value = 0; | |
1780 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1781 for (int i = 1; i < nargin; i += 2) |
4744 | 1782 { |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
1783 if (args(i).iscell ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1784 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1785 dim_vector argdims (args(i).dims ()); |
4744 | 1786 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1787 if (! scalar (argdims)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1788 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1789 if (! first_dimensioned_value) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1790 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1791 dims = argdims; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1792 first_dimensioned_value = i + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1793 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1794 else if (dims != argdims) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1795 { |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
1796 error ("struct: dimensions of parameter %d " |
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
1797 "do not match those of parameter %d", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1798 first_dimensioned_value, i+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1799 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1800 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1801 } |
4744 | 1802 } |
1803 | |
1804 // Create the return value. | |
1805 | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1806 octave_map map (dims); |
4744 | 1807 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1808 for (int i = 0; i < nargin; i+= 2) |
4744 | 1809 { |
1810 // Get key. | |
1811 | |
1812 std::string key (args(i).string_value ()); | |
1813 | |
15614
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
1814 maybe_warn_invalid_field_name (key, "struct"); |
f2b8f90052fd
warn instead of throwing an error for invalid structure field names
John W. Eaton <jwe@octave.org>
parents:
15613
diff
changeset
|
1815 |
4744 | 1816 // Value may be v, { v }, or { v1, v2, ... } |
1817 // In the first two cases, we need to create a cell array of | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1818 // the appropriate dimensions filled with v. In the last case, |
4744 | 1819 // the cell array has already been determined to be of the |
1820 // correct dimensions. | |
1821 | |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
1822 if (args(i+1).iscell ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1823 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1824 const Cell c (args(i+1).cell_value ()); |
4744 | 1825 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1826 if (scalar (c.dims ())) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1827 map.setfield (key, Cell (dims, c(0))); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1828 else |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1829 map.setfield (key, c); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1830 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1831 else |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10691
diff
changeset
|
1832 map.setfield (key, Cell (dims, args(i+1))); |
4744 | 1833 } |
6946 | 1834 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
1835 return ovl (map); |
4744 | 1836 } |
1837 | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1838 /* |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1839 %!shared x |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1840 %! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1841 %!assert (struct ("a",1, "b",3), x(1)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1842 %!assert (isempty (x([]))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1843 %!assert (isempty (struct ("a",{}, "b",{}))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1844 %!assert (struct ("a",{1,2}, "b",{3,3}), x) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1845 %!assert (struct ("a",{1,2}, "b",3), x) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1846 %!assert (struct ("a",{1,2}, "b",{3}), x) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1847 %!assert (struct ("b",3, "a",{1,2}), x) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1848 %!assert (struct ("b",{3}, "a",{1,2}), x) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1849 %!test x = struct ([]); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1850 %!assert (size (x), [0,0]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1851 %!assert (isstruct (x)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1852 %!assert (isempty (fieldnames (x))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1853 %!fail ('struct ("a",{1,2},"b",{1,2,3})', 'dimensions of parameter 2 do not match those of parameter 4') |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
1854 %!error <arguments must occur as "field", VALUE pairs> struct (1,2,3,4) |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
1855 %!fail ('struct ("1",2,"3")', 'struct: additional arguments must occur as "field", VALUE pairs') |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1856 */ |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1857 |
4358 | 1858 DEFUN (isstruct, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1859 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1860 @deftypefn {} {} isstruct (@var{x}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1861 Return true if @var{x} is a structure or a structure array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1862 @seealso{ismatrix, iscell, isa} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1863 @end deftypefn */) |
4358 | 1864 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1865 if (args.length () != 1) |
5823 | 1866 print_usage (); |
4358 | 1867 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1868 return ovl (args(0).isstruct ()); |
4358 | 1869 } |
1870 | |
15781
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1871 DEFUN (__fieldnames__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1872 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1873 @deftypefn {} {} __fieldnames__ (@var{struct}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1874 @deftypefnx {} {} __fieldnames__ (@var{obj}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1875 Internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1876 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1877 Implements @code{fieldnames()} for structures and Octave objects. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1878 @seealso{fieldnames} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1879 @end deftypefn */) |
4358 | 1880 { |
1881 octave_value retval; | |
1882 | |
15781
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1883 // Input validation has already been done in fieldnames.m. |
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1884 octave_value arg = args(0); |
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1885 |
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1886 octave_map m = arg.map_value (); |
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1887 |
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1888 string_vector keys = m.fieldnames (); |
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1889 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
1890 if (keys.isempty ()) |
15781
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1891 retval = Cell (0, 1); |
4358 | 1892 else |
15781
c33594eefda7
Add fieldnames.m which extensds fieldnames() to work on Java objects.
Rik <rik@octave.org>
parents:
15731
diff
changeset
|
1893 retval = Cell (keys); |
4358 | 1894 |
1895 return retval; | |
1896 } | |
1897 | |
1898 DEFUN (isfield, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1899 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1900 @deftypefn {} {} isfield (@var{x}, "@var{name}") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1901 @deftypefnx {} {} isfield (@var{x}, @var{name}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1902 Return true if the @var{x} is a structure and it includes an element named |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1903 @var{name}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1904 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1905 If @var{name} is a cell array of strings then a logical array of equal |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1906 dimension is returned. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1907 @seealso{fieldnames} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1908 @end deftypefn */) |
4358 | 1909 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20807
diff
changeset
|
1910 if (args.length () != 2) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1911 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1912 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1913 octave_value retval = false; |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1914 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1915 if (args(0).isstruct ()) |
4358 | 1916 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1917 octave_map m = args(0).map_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1918 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1919 // FIXME: should this work for all types that can do |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1920 // structure reference operations? |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1921 if (args(1).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1922 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1923 std::string key = args(1).string_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1924 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1925 retval = m.isfield (key); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1926 } |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
1927 else if (args(1).iscell ()) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1928 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1929 Cell c = args(1).cell_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1930 boolNDArray bm (c.dims ()); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1931 octave_idx_type n = bm.numel (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1932 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1933 for (octave_idx_type i = 0; i < n; i++) |
10691
e0ba186b242b
Fisfield: Accept cell arrays as name argument.
David Grundberg <davidg@cs.umu.se>
parents:
10370
diff
changeset
|
1934 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1935 if (c(i).is_string ()) |
10691
e0ba186b242b
Fisfield: Accept cell arrays as name argument.
David Grundberg <davidg@cs.umu.se>
parents:
10370
diff
changeset
|
1936 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1937 std::string key = c(i).string_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1938 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1939 bm(i) = m.isfield (key); |
10691
e0ba186b242b
Fisfield: Accept cell arrays as name argument.
David Grundberg <davidg@cs.umu.se>
parents:
10370
diff
changeset
|
1940 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1941 else |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1942 bm(i) = false; |
10691
e0ba186b242b
Fisfield: Accept cell arrays as name argument.
David Grundberg <davidg@cs.umu.se>
parents:
10370
diff
changeset
|
1943 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1944 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1945 retval = bm; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
1946 } |
4358 | 1947 } |
1948 | |
1949 return retval; | |
1950 } | |
1951 | |
18538
fcd87f68af4f
Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1952 DEFUN (numfields, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1953 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1954 @deftypefn {} {} numfields (@var{s}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1955 Return the number of fields of the structure @var{s}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1956 @seealso{fieldnames} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1957 @end deftypefn */) |
9784 | 1958 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20807
diff
changeset
|
1959 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1960 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1961 |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1962 if (! args(0).isstruct ()) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1963 error ("numfields: argument must be a struct"); |
9784 | 1964 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1965 return ovl (static_cast<double> (args(0).nfields ())); |
9784 | 1966 } |
1967 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
1968 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1969 ## test isfield |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
1970 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1971 %! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1972 %! assert (isfield (x, "b")); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1973 %!assert (isfield (struct ("a", "1"), "a")) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1974 %!assert (isfield ({1}, "c"), false) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1975 %!assert (isfield (struct ("a", "1"), 10), false) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1976 %!assert (isfield (struct ("a", "b"), "a "), false) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1977 %!assert (isfield (struct ("a", 1, "b", 2), {"a", "c"}), [true, false]) |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
1978 */ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
1979 |
4750 | 1980 DEFUN (cell2struct, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1981 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1982 @deftypefn {} {} cell2struct (@var{cell}, @var{fields}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1983 @deftypefnx {} {} cell2struct (@var{cell}, @var{fields}, @var{dim}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1984 Convert @var{cell} to a structure. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1985 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1986 The number of fields in @var{fields} must match the number of elements in |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1987 @var{cell} along dimension @var{dim}, that is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1988 @code{numel (@var{fields}) == size (@var{cell}, @var{dim})}. If @var{dim} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1989 is omitted, a value of 1 is assumed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1990 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1991 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1992 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1993 A = cell2struct (@{"Peter", "Hannah", "Robert"; |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1994 185, 170, 168@}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1995 @{"Name","Height"@}, 1); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1996 A(1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1997 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1998 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
1999 Name = Peter |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2000 Height = 185 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2001 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2002 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2003 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2004 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2005 @seealso{struct2cell, cell2mat, struct} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2006 @end deftypefn */) |
4750 | 2007 { |
13868
87f78c11d725
cell2struct: if DIM is omitted, use a default value of 1.
John W. Eaton <jwe@octave.org>
parents:
13706
diff
changeset
|
2008 int nargin = args.length (); |
87f78c11d725
cell2struct: if DIM is omitted, use a default value of 1.
John W. Eaton <jwe@octave.org>
parents:
13706
diff
changeset
|
2009 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2010 if (nargin < 2 || nargin > 3) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2011 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2012 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
2013 if (! args(0).iscell ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2014 error ("cell2struct: argument CELL must be of type cell"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2015 |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
2016 if (! (args(1).iscellstr () || args(1).is_char_matrix ())) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2017 error ("cell2struct: FIELDS must be a cell array of strings or a character matrix"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2018 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2019 int dim = 0; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2020 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2021 if (nargin == 3) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2022 { |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2023 if (! args(2).is_real_scalar ()) |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2024 error ("cell2struct: DIM must be a real scalar"); |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2025 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23354
diff
changeset
|
2026 dim = (nargin == 2 ? 0 : args(2).int_value () - 1); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2027 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2028 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2029 if (dim < 0) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2030 error ("cell2struct: DIM must be a valid dimension"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2031 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2032 const Cell vals = args(0).cell_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2033 const Array<std::string> fields = args(1).cellstr_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2034 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23354
diff
changeset
|
2035 octave_idx_type ext = (vals.ndims () > dim ? vals.dims ()(dim) : 1); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2036 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2037 if (ext != fields.numel ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
2038 error ("cell2struct: number of FIELDS does not match dimension"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2039 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2040 int nd = std::max (dim+1, vals.ndims ()); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2041 // result dimensions. |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2042 dim_vector rdv = vals.dims ().redim (nd); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2043 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2044 assert (ext == rdv(dim)); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2045 if (nd == 2) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2046 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2047 rdv(0) = rdv(1-dim); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2048 rdv(1) = 1; |
4750 | 2049 } |
4751 | 2050 else |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2051 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
2052 for (int i = dim + 1; i < nd; i++) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2053 rdv(i-1) = rdv(i); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2054 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2055 rdv.resize (nd-1); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2056 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2057 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2058 octave_map map (rdv); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2059 Array<idx_vector> ia (dim_vector (nd, 1), idx_vector::colon); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2060 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2061 for (octave_idx_type i = 0; i < ext; i++) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2062 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2063 ia(dim) = i; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2064 map.setfield (fields(i), vals.index (ia).reshape (rdv)); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2065 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2066 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2067 return ovl (map); |
4750 | 2068 } |
2069 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2070 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2071 ## test cell2struct versus struct2cell |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2072 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2073 %! keys = cellstr (char (floor (rand (100,10)*24+65)))'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2074 %! vals = mat2cell (rand (100,1), ones (100,1), 1)'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2075 %! s = struct ([keys; vals]{:}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2076 %! t = cell2struct (vals, keys, 2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2077 %! assert (s, t); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2078 %! assert (struct2cell (s), vals'); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2079 %! assert (fieldnames (s), keys'); |
13868
87f78c11d725
cell2struct: if DIM is omitted, use a default value of 1.
John W. Eaton <jwe@octave.org>
parents:
13706
diff
changeset
|
2080 |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
2081 %!assert (cell2struct ({1; 2}, {"a"; "b"}), struct ("a", 1, "b", 2)) |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
2082 |
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
2083 %!assert (cell2struct ({}, {"f"}, 3), struct ("f", {})) |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2084 */ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2085 |
4817 | 2086 DEFUN (rmfield, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2087 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2088 @deftypefn {} {@var{sout} =} rmfield (@var{s}, "@var{f}") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2089 @deftypefnx {} {@var{sout} =} rmfield (@var{s}, @var{f}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2090 Return a @emph{copy} of the structure (array) @var{s} with the field @var{f} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2091 removed. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2092 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2093 If @var{f} is a cell array of strings or a character array, remove each of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2094 the named fields. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2095 @seealso{orderfields, fieldnames, isfield} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2096 @end deftypefn */) |
4817 | 2097 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20807
diff
changeset
|
2098 if (args.length () != 2) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2099 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2100 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2101 octave_map m = args(0).xmap_value ("rmfield: first argument must be a struct"); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2102 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2103 octave_value_list fval = Fcellstr (args(1), 1); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2104 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2105 Cell fcell = fval(0).cell_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2106 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2107 for (int i = 0; i < fcell.numel (); i++) |
4817 | 2108 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2109 std::string key = fcell(i).string_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2110 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
2111 if (! m.isfield (key)) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2112 error ("rmfield: structure does not contain field %s", key.c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
2113 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20974
diff
changeset
|
2114 m.rmfield (key); |
4817 | 2115 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
2116 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2117 return ovl (m); |
4817 | 2118 } |
2119 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2120 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2121 ## test rmfield |
15534
360adb4a3136
doc: Update docstring form rmfield() and add another %!test.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2122 %!shared x |
360adb4a3136
doc: Update docstring form rmfield() and add another %!test.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2123 %! x(3).d=1; x(2).a=2; x(1).b=3; x(2).c=3; x(6).f="abc123"; |
360adb4a3136
doc: Update docstring form rmfield() and add another %!test.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2124 %! |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2125 %!test |
15534
360adb4a3136
doc: Update docstring form rmfield() and add another %!test.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2126 %! y = rmfield (x, "c"); |
360adb4a3136
doc: Update docstring form rmfield() and add another %!test.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2127 %! assert (fieldnames (y), {"d"; "a"; "b"; "f"}); |
360adb4a3136
doc: Update docstring form rmfield() and add another %!test.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2128 %! assert (size (y), [1, 6]); |
360adb4a3136
doc: Update docstring form rmfield() and add another %!test.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2129 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2130 %! y = rmfield (x, {"a", "f"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2131 %! assert (fieldnames (y), {"d"; "b"; "c"}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
2132 %! assert (size (y), [1, 6]); |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2133 */ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10066
diff
changeset
|
2134 |
11474 | 2135 DEFUN (struct_levels_to_print, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2136 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2137 @deftypefn {} {@var{val} =} struct_levels_to_print () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2138 @deftypefnx {} {@var{old_val} =} struct_levels_to_print (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2139 @deftypefnx {} {} struct_levels_to_print (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2140 Query or set the internal variable that specifies the number of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2141 structure levels to display. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2142 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2143 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2144 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2145 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2146 @seealso{print_struct_array_contents} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2147 @end deftypefn */) |
11474 | 2148 { |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
2149 return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, -1, |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
2150 std::numeric_limits<int>::max ()); |
11474 | 2151 } |
2152 | |
2153 DEFUN (print_struct_array_contents, args, nargout, | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2154 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2155 @deftypefn {} {@var{val} =} print_struct_array_contents () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2156 @deftypefnx {} {@var{old_val} =} print_struct_array_contents (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2157 @deftypefnx {} {} print_struct_array_contents (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2158 Query or set the internal variable that specifies whether to print struct |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2159 array contents. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2160 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2161 If true, values of struct array elements are printed. This variable does |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2162 not affect scalar structures whose elements are always printed. In both |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2163 cases, however, printing will be limited to the number of levels specified |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2164 by @var{struct_levels_to_print}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2165 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2166 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2167 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2168 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2169 @seealso{struct_levels_to_print} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21943
diff
changeset
|
2170 @end deftypefn */) |
11474 | 2171 { |
2172 return SET_INTERNAL_VARIABLE (print_struct_array_contents); | |
2173 } |