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