annotate libinterp/corefcn/oct-map.cc @ 25342:416856765a55

be more careful with using auto in place of explicit const iterator decls * dialog.cc, m-editor/file-editor.cc, octave-qt-link.cc, call-stack.cc, debug.cc, genprops.awk, graphics.cc, gtk-manager.cc, gtk-manager.h, load-path.cc, oct-map.cc, oct-stream.cc, regexp.cc, symscope.h, symtab.h, variables.cc, ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-struct.cc, bp-table.cc, jit-ir.cc, jit-typeinfo.cc, pt-jit.cc, lo-regexp.cc: Only replace explicit const iterator decls with auto keyword if corresponding object is const. Otherwise, tag with a fixme comment. * lo-regexp.h (regexp::match_data::named_patterns): Now const.
author John W. Eaton <jwe@octave.org>
date Thu, 03 May 2018 00:39:14 -0400
parents 3ff9192b676e
children 4d7790d9793f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1 /*
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
2
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3 Copyright (C) 1995-2018 John W. Eaton
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
4 Copyright (C) 2010 VZLU Prague
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
5
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
7
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23832
diff changeset
8 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22327
diff changeset
9 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23832
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22327
diff changeset
11 (at your option) any later version.
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
12
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22327
diff changeset
13 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22327
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22327
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22327
diff changeset
16 GNU General Public License for more details.
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
17
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
19 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23832
diff changeset
20 <https://www.gnu.org/licenses/>.
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
21
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
22 */
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
25 # include "config.h"
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
26 #endif
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
27
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18538
diff changeset
28 #include "Array-util.h"
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
29 #include "error.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18538
diff changeset
30 #include "oct-locbuf.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
31 #include "str-vec.h"
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
32
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
33 #include "oct-map.h"
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
34 #include "utils.h"
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
35
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
36 octave_fields::fields_rep *
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
37 octave_fields::nil_rep (void)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
38 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
39 static fields_rep nr;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
40 return &nr;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
41 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
42
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
43 octave_fields::octave_fields (const string_vector& fields)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
44 : rep (new fields_rep)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
45 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
46 octave_idx_type n = fields.numel ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
47 for (octave_idx_type i = 0; i < n; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
48 (*rep)[fields(i)] = i;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
49 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
50
10766
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
51 octave_fields::octave_fields (const char * const *fields)
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
52 : rep (new fields_rep)
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
53 {
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
54 octave_idx_type n = 0;
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
55 while (*fields)
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
56 (*rep)[std::string (*fields++)] = n++;
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
57 }
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
58
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
59 bool
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
60 octave_fields::isfield (const std::string& field) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
61 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
62 return rep->find (field) != rep->end ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
63 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
64
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
65 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
66 octave_fields::getfield (const std::string& field) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
67 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
68 auto p = rep->find (field);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
69 return (p != rep->end ()) ? p->second : -1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
70 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
71
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
72 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
73 octave_fields::getfield (const std::string& field)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
74 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
75 auto p = rep->find (field);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
76 if (p != rep->end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
77 return p->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
78 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
79 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
80 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
81 octave_idx_type n = rep->size ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
82 return (*rep)[field] = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
83 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
84 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
85
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
86 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
87 octave_fields::rmfield (const std::string& field)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
88 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
89 auto p = rep->find (field);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
90 if (p == rep->end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
91 return -1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
92 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
93 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
94 octave_idx_type n = p->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
95 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
96 rep->erase (field);
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
97 for (auto& fld_idx : *rep)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
98 {
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
99 if (fld_idx.second >= n)
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
100 fld_idx.second--;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
101 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
102
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
103 return n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
104 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
105 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
106
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
107 void
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
108 octave_fields::orderfields (Array<octave_idx_type>& perm)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
109 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
110 octave_idx_type n = rep->size ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
111 perm.clear (n, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
112
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
113 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
114 octave_idx_type i = 0;
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
115 for (auto& fld_idx : *rep)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
116 {
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
117 octave_idx_type j = fld_idx.second;
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
118 fld_idx.second = i;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
119 perm(i++) = j;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
120 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
121 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
122
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
123 bool
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
124 octave_fields::equal_up_to_order (const octave_fields& other,
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
125 octave_idx_type *perm) const
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
126 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
127 bool retval = true;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
128
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
129 auto p = begin ();
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
130 auto q = other.begin ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
131 for (; p != end () && q != other.end (); p++, q++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
132 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
133 if (p->first == q->first)
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
134 perm[p->second] = q->second;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
135 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
136 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
137 retval = false;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
138 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
139 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
140 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
141
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
142 retval = (p == end () && q == other.end ());
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
143
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
144 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
145 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
146
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
147 bool
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
148 octave_fields::equal_up_to_order (const octave_fields& other,
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
149 Array<octave_idx_type>& perm) const
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
150 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
151 octave_idx_type n = nfields ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
152 if (perm.numel () != n)
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
153 perm.clear (1, n);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
154
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
155 return equal_up_to_order (other, perm.fortran_vec ());
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
156 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
157
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
158 string_vector
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
159 octave_fields::fieldnames (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
160 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
161 octave_idx_type n = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
162 string_vector retval(n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
163
22862
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
164 for (auto& fld_idx : *this)
e365e87371a3 maint: Use C++ range feature to simplify some for loops in libinterp/corefcn.
Rik <rik@octave.org>
parents: 22755
diff changeset
165 retval.xelem (fld_idx.second) = fld_idx.first;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
166
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
167 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
168 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
169
23678
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
170 octave_scalar_map::octave_scalar_map
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
171 (const std::map<std::string, octave_value>& m)
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
172 {
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
173 size_t sz = m.size ();
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
174 xvals.resize (sz);
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
175 size_t i = 0;
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
176 for (const auto& k_v : m)
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
177 {
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
178 xkeys.getfield (k_v.first);
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
179 xvals[i++] = k_v.second;
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
180 }
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
181 }
dcba41788495 new struct/map constructors
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
182
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
183 octave_value
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
184 octave_scalar_map::getfield (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
185 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
186 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
187 return (idx >= 0) ? xvals[idx] : octave_value ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
188 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
189
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
190 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
191 octave_scalar_map::setfield (const std::string& k, const octave_value& val)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
192 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
193 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
194 if (idx < static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
195 xvals[idx] = val;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
196 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
197 xvals.push_back (val);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
198 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
199
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
200 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
201 octave_scalar_map::rmfield (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
202 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
203 octave_idx_type idx = xkeys.rmfield (k);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
204 if (idx >= 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
205 xvals.erase (xvals.begin () + idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
206 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
207
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
208 octave_scalar_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
209 octave_scalar_map::orderfields (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
210 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
211 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
212 return orderfields (perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
213 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
214
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
215 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
216 octave_scalar_map::orderfields (Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
217 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
218 octave_scalar_map retval (xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
219 retval.xkeys.orderfields (perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
220
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
221 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
222 for (octave_idx_type i = 0; i < nf; i++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
223 retval.xvals[i] = xvals[perm.xelem (i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
224
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
225 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
226 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
227
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
228 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
229 octave_scalar_map::orderfields (const octave_scalar_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
230 Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
231 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
232 if (xkeys.is_same (other.xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
233 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
234 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
235 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
236 octave_scalar_map retval (other.xkeys);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
237 if (! other.xkeys.equal_up_to_order (xkeys, perm))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
238 error ("orderfields: structs must have same fields up to order");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
239
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
240 octave_idx_type nf = nfields ();
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
241 for (octave_idx_type i = 0; i < nf; i++)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
242 retval.xvals[i] = xvals[perm.xelem (i)];
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
243
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
244 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
245 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
246 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
247
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
248 octave_value
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
249 octave_scalar_map::contents (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
250 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
251 return getfield (k);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
252 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
253
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
254 octave_value&
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
255 octave_scalar_map::contents (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
256 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
257 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
258 if (idx >= static_cast<octave_idx_type> (xvals.size ()))
11055
b721e12140cc fix off-by-1 error in octave_scalar_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10937
diff changeset
259 xvals.resize (idx+1);
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
260 return xvals[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
261 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
262
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
263 octave_map::octave_map (const octave_scalar_map& m)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
264 : xkeys (m.xkeys), xvals (), dimensions (1, 1)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
265 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
266 octave_idx_type nf = m.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
267 xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
268 for (octave_idx_type i = 0; i < nf; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
269 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
270 xvals.push_back (Cell (dimensions));
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
271 xvals[i].xelem (0) = m.xvals[i];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
272 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
273 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
274
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
275 Cell
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
276 octave_map::getfield (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
277 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
278 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
279 return (idx >= 0) ? xvals[idx] : Cell ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
280 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
281
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
282 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
283 octave_map::setfield (const std::string& k, const Cell& val)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
284 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
285 if (nfields () == 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
286 dimensions = val.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
287
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
288 if (val.dims () != dimensions)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
289 error ("octave_map::setfield: internal error");
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
290
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
291 octave_idx_type idx = xkeys.getfield (k);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
292 if (idx < static_cast<octave_idx_type> (xvals.size ()))
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
293 xvals[idx] = val;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
294 else
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
295 xvals.push_back (val);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
296 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
297
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
298 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
299 octave_map::rmfield (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
300 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
301 octave_idx_type idx = xkeys.rmfield (k);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
302 if (idx >= 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
303 xvals.erase (xvals.begin () + idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
304 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
305
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
306 octave_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
307 octave_map::orderfields (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
308 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
309 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
310 return orderfields (perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
311 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
312
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
313 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
314 octave_map::orderfields (Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
315 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
316 octave_map retval (xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
317 retval.xkeys.orderfields (perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
318
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
319 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
320 for (octave_idx_type i = 0; i < nf; i++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
321 retval.xvals[i] = xvals[perm.xelem (i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
322
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
323 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
324 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
325
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
326 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
327 octave_map::orderfields (const octave_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
328 Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
329 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
330 if (xkeys.is_same (other.xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
331 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
332 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
333 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
334 octave_map retval (other.xkeys);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
335 if (! other.xkeys.equal_up_to_order (xkeys, perm))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
336 error ("orderfields: structs must have same fields up to order");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
337
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
338 octave_idx_type nf = nfields ();
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
339 for (octave_idx_type i = 0; i < nf; i++)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
340 retval.xvals[i] = xvals[perm.xelem (i)];
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20831
diff changeset
341
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
342 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
343 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
344 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
345
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
346 Cell
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
347 octave_map::contents (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
348 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
349 return getfield (k);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
350 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
351
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
352 Cell&
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
353 octave_map::contents (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
354 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
355 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
356 if (idx >= static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
357 xvals.push_back (Cell (dimensions)); // auto-set correct dims.
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
358 return xvals[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
359 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
360
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
361 void
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
362 octave_map::extract_scalar (octave_scalar_map& dest,
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
363 octave_idx_type idx) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
364 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
365 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
366 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
367 dest.xvals[i] = xvals[i](idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
368 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
369
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
370 octave_scalar_map
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23450
diff changeset
371 octave_map::elem (octave_idx_type n) const
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
372 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
373 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
374
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
375 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
376 extract_scalar (retval, compute_index (n, dimensions));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
377
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
378 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
379 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
380
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
381 octave_scalar_map
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23450
diff changeset
382 octave_map::elem (octave_idx_type i, octave_idx_type j) const
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
383 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
384 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
385
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
386 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
387 extract_scalar (retval, compute_index (i, j, dimensions));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
388
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
389 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
390 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
391
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
392 octave_scalar_map
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23450
diff changeset
393 octave_map::elem (const Array<octave_idx_type>& ra_idx) const
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
394 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
395 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
396
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
397 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
398 extract_scalar (retval, compute_index (ra_idx, dimensions));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
399
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
400 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
401 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
402
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
403 octave_scalar_map
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
404 octave_map::fast_elem_extract (octave_idx_type n) const
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
405 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
406 octave_scalar_map retval (xkeys);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
407
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
408 extract_scalar (retval, n);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
409
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
410 return retval;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
411 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
412
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
413 bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
414 octave_map::fast_elem_insert (octave_idx_type n,
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
415 const octave_scalar_map& rhs)
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
416 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
417 bool retval = false;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
418
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
419 octave_idx_type nf = nfields ();
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
420 if (rhs.xkeys.is_same (xkeys))
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
421 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
422 for (octave_idx_type i = 0; i < nf; i++)
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
423 xvals[i](n) = rhs.xvals[i];
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
424
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
425 retval = true;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
426 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
427 else
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
428 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
429 OCTAVE_LOCAL_BUFFER (octave_idx_type, perm, nf);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
430 if (xkeys.equal_up_to_order (rhs.xkeys, perm))
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
431 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
432 for (octave_idx_type i = 0; i < nf; i++)
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
433 xvals[i](n) = rhs.xvals[perm[i]];
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
434
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
435 retval = true;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
436 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
437 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
438
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
439 return retval;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
440 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
441
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
442 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
443 octave_map::squeeze (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
444 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
445 octave_map retval (*this);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
446 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
447
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
448 retval.dimensions = dimensions.squeeze ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
449
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
450 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
451 retval.xvals[i] = xvals[i].squeeze ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
452
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
453 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
454
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
455 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
456 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
457
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
458 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
459 ## test preservation of xkeys by squeeze
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
460 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
461 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
462 %! assert (fieldnames (squeeze (x)), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
463 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
464
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
465 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
466 octave_map::permute (const Array<int>& vec, bool inv) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
467 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
468 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
469 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
470
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
471 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
472 retval.xvals[i] = xvals[i].permute (vec, inv);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
473
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
474 // FIXME:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
475 // There is no dim_vector::permute for technical reasons.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
476 // We pick the dim vector from results if possible, otherwise use a dummy
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
477 // array to get it. Need (?) a better solution to this problem.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
478 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
479 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
480 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
481 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
482 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
483 dummy = dummy.permute (vec, inv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
484 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
485 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
486
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
487 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
488
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
489 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
490 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
491
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
492 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
493 ## test preservation of key order by permute
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
494 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
495 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
496 %! assert (fieldnames (permute (x, [3, 4, 1, 2])), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
497 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
498
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
499 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
500 octave_map::transpose (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
501 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
502 assert (ndims () == 2);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
503
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
504 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
505
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
506 retval.dimensions = dim_vector (dimensions (1), dimensions (0));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
507
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
508 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
509 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
510 retval.xvals[i] = xvals[i].transpose ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
511
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
512 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
513
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
514 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
515 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
516
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
517 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
518 ## test preservation of key order by transpose
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
519 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
520 %! x(1,1).d = 10; x(3,5).a = "b"; x(2,4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
521 %! assert (fieldnames (transpose (x)), {"d"; "a"; "f"});
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
522 %! assert (fieldnames (x'), {"d"; "a"; "f"});
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
523 %! assert (fieldnames (x.'), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
524 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
525
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
526 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
527 octave_map::reshape (const dim_vector& dv) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
528 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
529 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
530 retval.dimensions = dv;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
531
23832
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
532 // When reshaping xvals the Array constructor chops trailing singletons,
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
533 // hence we need to do the same for the whole map.
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
534 retval.dimensions.chop_trailing_singletons ();
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
535
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
536 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
537 if (nf > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
538 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
539 retval.xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
540 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
541 retval.xvals[i] = xvals[i].reshape (dv);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
542 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
543 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
544 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
545 // FIXME: Do it with a dummy array, to reuse error message.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
546 // Need (?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
547 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
548 dummy.reshape (dv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
549 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
550
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
551 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
552
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
553 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
554 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
555
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
556 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
557 ## test preservation of key order by reshape
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
558 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
559 %! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
560 %! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"});
23832
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
561
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
562 ## test chopping of trailing singletons
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
563 %!test <51634>
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
564 %! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27;
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
565 %! reshape (x, 3, 8, 1, 1);
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
566
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
567 %!test <46385>
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
568 %! M = repmat (struct ('a', ones(100), 'b', true), 1, 2);
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
569 %! M = repmat(M, 1, 2);
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
570 %! assert (size (M), [1, 4]);
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
571
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
572 libinterp/corefcn/oct-map.cc
3544f88a2bb5 Fix reshape of octave_map with trailing singletons (bug #51634, bug #45385, bug #43650).
Piotr Held <pjheld@gmail.com>
parents: 23678
diff changeset
573
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
574 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
575
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
576 void
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
577 octave_map::resize (const dim_vector& dv, bool fill)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
578 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
579 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
580 if (nf > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
581 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
582 for (octave_idx_type i = 0; i < nf; i++)
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
583 {
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
584 if (fill)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14569
diff changeset
585 xvals[i].resize (dv, Matrix ());
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
586 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
587 xvals[i].resize (dv);
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
588 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
589 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
590 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
591 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
592 // FIXME: Do it with a dummy array, to reuse error message.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
593 // Need (?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
594 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
595 dummy.resize (dv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
596 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
597
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
598 dimensions = dv;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
599 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
600 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
601
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
602 void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
603 octave_map::do_cat (int dim, octave_idx_type n,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
604 const octave_scalar_map *map_list,
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
605 octave_map& retval)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
606 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
607 octave_idx_type nf = retval.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
608 retval.xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
609
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
610 dim_vector& rd = retval.dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
611 rd.resize (dim+1, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
612 rd(0) = rd(1) = 1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
613 rd(dim) = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
614
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
615 for (octave_idx_type j = 0; j < nf; j++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
616 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
617 retval.xvals.push_back (Cell (rd));
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
618 assert (retval.xvals[j].numel () == n);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
619 for (octave_idx_type i = 0; i < n; i++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
620 retval.xvals[j].xelem (i) = map_list[i].xvals[j];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
621 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
622 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
623
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
624 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
625 octave_map::do_cat (int dim, octave_idx_type n, const octave_map *map_list,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
626 octave_map& retval)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
627 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
628 octave_idx_type nf = retval.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
629 retval.xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
630
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
631 OCTAVE_LOCAL_BUFFER (Array<octave_value>, field_list, n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
632
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
633 for (octave_idx_type j = 0; j < nf; j++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
634 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
635 for (octave_idx_type i = 0; i < n; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
636 field_list[i] = map_list[i].xvals[j];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
637
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
638 retval.xvals.push_back (Array<octave_value>::cat (dim, n, field_list));
10764
e141bcb1befd implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents: 10763
diff changeset
639 if (j == 0)
e141bcb1befd implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents: 10763
diff changeset
640 retval.dimensions = retval.xvals[j].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
641 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
642 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
643
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
644 // This is just a wrapper.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
645 void permute_to_correct_order1 (const octave_scalar_map& ref,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
646 const octave_scalar_map& src,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
647 octave_scalar_map& dest,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
648 Array<octave_idx_type>& perm)
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
649 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
650 dest = src.orderfields (ref, perm);
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
651 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
652
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
653 // In non-scalar case, we also promote empty structs without fields.
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
654 void permute_to_correct_order1 (const octave_map& ref, const octave_map& src,
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
655 octave_map& dest, Array<octave_idx_type>& perm)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
656 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23487
diff changeset
657 if (src.nfields () == 0 && src.isempty ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
658 dest = octave_map (src.dims (), ref.keys ());
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
659 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
660 dest = src.orderfields (ref, perm);
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
661 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
662
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20982
diff changeset
663 template <typename map>
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
664 static void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
665 permute_to_correct_order (octave_idx_type n, octave_idx_type nf,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
666 octave_idx_type idx, const map *map_list,
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
667 map *new_map_list)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
668 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
669 new_map_list[idx] = map_list[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
670
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
671 Array<octave_idx_type> perm (dim_vector (1, nf));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
672
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
673 try
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
674 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
675 for (octave_idx_type i = 0; i < n; i++)
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
676 {
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
677 if (i == idx)
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
678 continue;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
679
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
680 permute_to_correct_order1 (map_list[idx], map_list[i],
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
681 new_map_list[i], perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
682 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
683 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
684 catch (octave::execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
685 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
686 error (e, "cat: field names mismatch in concatenating structs");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
687 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
688 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
689
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
690 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
691 octave_map::cat (int dim, octave_idx_type n, const octave_scalar_map *map_list)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
692 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
693 octave_map retval;
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
694
10763
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
695 // Allow dim = -1, -2 for compatibility, though it makes no difference here.
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
696 if (dim == -1 || dim == -2)
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
697 dim = -dim - 1;
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
698 else if (dim < 0)
20650
a6a452346c42 use error and error_with_id directly in libinterp code
John W. Eaton <jwe@octave.org>
parents: 20558
diff changeset
699 error ("cat: invalid dimension");
10763
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
700
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
701 if (n == 1)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
702 retval = map_list[0];
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
703 else if (n > 1)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
704 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
705 octave_idx_type idx, nf = 0;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
706 for (idx = 0; idx < n; idx++)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
707 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
708 nf = map_list[idx].nfields ();
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
709 if (nf > 0)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
710 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
711 retval.xkeys = map_list[idx].xkeys;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
712 break;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
713 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
714 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
715
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
716 if (nf > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
717 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
718 // Try the fast case.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
719 bool all_same = true;
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
720 for (octave_idx_type i = 0; i < n; i++)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
721 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
722 all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
723 if (! all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
724 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
725 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
726
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
727 if (all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
728 do_cat (dim, n, map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
729 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
730 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
731 // permute all structures to common order.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
732 OCTAVE_LOCAL_BUFFER (octave_scalar_map, new_map_list, n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
733
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
734 permute_to_correct_order (n, nf, idx, map_list, new_map_list);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
735
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
736 do_cat (dim, n, new_map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
737 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
738
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
739 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
740 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
741 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
742 dim_vector& rd = retval.dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
743 rd.resize (dim+1, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
744 rd(0) = rd(1) = 1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
745 rd(dim) = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
746 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
747
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
748 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
749 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
750
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
751 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
752 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
753
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
754 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
755 octave_map::cat (int dim, octave_idx_type n, const octave_map *map_list)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
756 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
757 octave_map retval;
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
758
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
759 // Allow dim = -1, -2 for compatibility, though it makes no difference here.
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
760 if (dim == -1 || dim == -2)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
761 dim = -dim - 1;
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
762 else if (dim < 0)
20650
a6a452346c42 use error and error_with_id directly in libinterp code
John W. Eaton <jwe@octave.org>
parents: 20558
diff changeset
763 error ("cat: invalid dimension");
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
764
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
765 if (n == 1)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
766 retval = map_list[0];
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
767 else if (n > 1)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
768 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
769 octave_idx_type idx, nf = 0;
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
770
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
771 for (idx = 0; idx < n; idx++)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
772 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
773 nf = map_list[idx].nfields ();
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
774 if (nf > 0)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
775 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
776 retval.xkeys = map_list[idx].xkeys;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
777 break;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
778 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
779 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
780
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
781 // Try the fast case.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
782 bool all_same = true;
13968
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
783
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
784 if (nf > 0)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
785 {
13968
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
786 for (octave_idx_type i = 0; i < n; i++)
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
787 {
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
788 all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys);
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
789
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
790 if (! all_same)
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
791 break;
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
792 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
793 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
794
13968
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
795 if (all_same && nf > 0)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
796 do_cat (dim, n, map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
797 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
798 {
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
799 if (nf > 0)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
800 {
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
801 // permute all structures to correct order.
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
802 OCTAVE_LOCAL_BUFFER (octave_map, new_map_list, n);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
803
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
804 permute_to_correct_order (n, nf, idx, map_list, new_map_list);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
805
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
806 do_cat (dim, n, new_map_list, retval);
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
807 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
808 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
809 {
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
810 dim_vector dv = map_list[0].dimensions;
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
811
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
812 for (octave_idx_type i = 1; i < n; i++)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
813 {
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
814 if (! dv.concat (map_list[i].dimensions, dim))
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
815 error ("dimension mismatch in struct concatenation");
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
816 }
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
817
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
818 retval.dimensions = dv;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
819 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
820 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
821
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
822 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
823 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
824
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
825 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
826 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
827
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
828 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
829 ## test preservation of key order by concatenation
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
830 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
831 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
832 %! y(1, 6).f = 11; y(1, 6).a = "c"; y(1, 6).d = 33;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
833 %! assert (fieldnames ([x; y]), {"d"; "a"; "f"});
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
834
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
835 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
836 %! s = struct ();
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
837 %! sr = [s,s];
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
838 %! sc = [s;s];
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
839 %! sm = [s,s;s,s];
18538
fcd87f68af4f Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents: 18402
diff changeset
840 %! assert (numfields (sr), 0);
fcd87f68af4f Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents: 18402
diff changeset
841 %! assert (numfields (sc), 0);
fcd87f68af4f Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents: 18402
diff changeset
842 %! assert (numfields (sm), 0);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
843 %! assert (size (sr), [1, 2]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
844 %! assert (size (sc), [2, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
845 %! assert (size (sm), [2, 2]);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
846 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
847
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
848 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
849 octave_map::index (const idx_vector& i, bool resize_ok) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
850 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
851 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
852 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
853
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
854 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
855 retval.xvals[k] = xvals[k].index (i, resize_ok);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
856
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
857 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
858 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
859 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
860 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
861 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
862 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
863 dummy = dummy.index (i, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
864 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
865 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
866
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
867 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
868
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
869 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
870 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
871
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
872 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
873 octave_map::index (const idx_vector& i, const idx_vector& j,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
874 bool resize_ok) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
875 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
876 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
877 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
878
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
879 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
880 retval.xvals[k] = xvals[k].index (i, j, resize_ok);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
881
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
882 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
883 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
884 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
885 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
886 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
887 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
888 dummy = dummy.index (i, j, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
889 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
890 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
891
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
892 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
893
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
894 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
895 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
896
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
897 octave_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
898 octave_map::index (const Array<idx_vector>& ia, bool resize_ok) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
899 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
900 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
901 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
902
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
903 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
904 retval.xvals[k] = xvals[k].index (ia, resize_ok);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
905
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
906 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
907 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
908 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
909 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
910 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
911 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
912 dummy = dummy.index (ia, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
913 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
914 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
915
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
916 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
917
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
918 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
919 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
920
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
921 octave_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
922 octave_map::index (const octave_value_list& idx, bool resize_ok) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
923 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
924 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
925 octave_map retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
926
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
927 // If we catch an indexing error in index_vector, we flag an error in
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
928 // index k. Ensure it is the right value befor each idx_vector call.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
929 // Same variable as used in the for loop in the default case.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
930
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
931 octave_idx_type k = 0;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
932
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
933 try
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
934 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
935 switch (n_idx)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
936 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
937 case 1:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
938 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
939 idx_vector i = idx(0).index_vector ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
940
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
941 retval = index (i, resize_ok);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
942 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
943 break;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
944
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
945 case 2:
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
946 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
947 idx_vector i = idx(0).index_vector ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
948
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
949 k = 1;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
950 idx_vector j = idx(1).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
951
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
952 retval = index (i, j, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
953 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
954 break;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
955
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
956 default:
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
957 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
958 Array<idx_vector> ia (dim_vector (n_idx, 1));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
959
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
960 for (k = 0; k < n_idx; k++)
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
961 ia(k) = idx(k).index_vector ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
962
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
963 retval = index (ia, resize_ok);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
964 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
965 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
966 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
967 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
968 catch (octave::index_exception& e)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
969 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
970 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
971 e.set_pos_if_unset (n_idx, k+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
972 throw;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
973 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
974
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
975 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
976 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
977
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
978 // Perhaps one day these will be optimized. Right now, they just call index.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
979 octave_map
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
980 octave_map::column (octave_idx_type k) const
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
981 {
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
982 return index (idx_vector::colon, k);
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
983 }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
984
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
985 octave_map
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
986 octave_map::page (octave_idx_type k) const
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
987 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
988 static Array<idx_vector> ia (dim_vector (3, 1), idx_vector::colon);
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
989
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
990 ia(2) = k;
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
991 return index (ia);
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
992 }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
993
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
994 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
995 octave_map::assign (const idx_vector& i, const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
996 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
997 if (rhs.xkeys.is_same (xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
998 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
999 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1000
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1001 for (octave_idx_type k = 0; k < nf; k++)
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1002 xvals[k].assign (i, rhs.xvals[k], Matrix ());
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1003
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1004 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1005 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1006 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1007 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1008 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1009 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1010 dummy.assign (i, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1011 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1012 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1013
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1014 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1015 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1016 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1017 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1018 octave_map tmp (dimensions, rhs.xkeys);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1019 tmp.assign (i, rhs);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1020 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1021 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1022 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1023 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1024 Array<octave_idx_type> perm;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1025 octave_map rhs1;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1026
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1027 try
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1028 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1029 rhs1 = rhs.orderfields (*this, perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1030 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1031 catch (octave::execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1032 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
1033 error (e, "incompatible fields in struct assignment");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1034 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1035
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1036 assert (rhs1.xkeys.is_same (xkeys));
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1037 assign (i, rhs1);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1038 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1039 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1040
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1041 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1042 octave_map::assign (const idx_vector& i, const idx_vector& j,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1043 const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1044 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1045 if (rhs.xkeys.is_same (xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1046 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1047 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1048
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1049 for (octave_idx_type k = 0; k < nf; k++)
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1050 xvals[k].assign (i, j, rhs.xvals[k], Matrix ());
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1051
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1052 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1053 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1054 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1055 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1056 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1057 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1058 dummy.assign (i, j, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1059 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1060 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1061
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1062 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1063 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1064 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1065 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1066 octave_map tmp (dimensions, rhs.xkeys);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1067 tmp.assign (i, j, rhs);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1068 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1069 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1070 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1071 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1072 Array<octave_idx_type> perm;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1073 octave_map rhs1;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1074
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1075 try
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1076 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1077 rhs1 = rhs.orderfields (*this, perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1078 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1079 catch (octave::execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1080 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
1081 error (e, "incompatible fields in struct assignment");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1082 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1083
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1084 assert (rhs1.xkeys.is_same (xkeys));
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1085 assign (i, j, rhs1);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1086 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1087 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1088
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1089 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1090 octave_map::assign (const Array<idx_vector>& ia,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1091 const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1092 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1093 if (rhs.xkeys.is_same (xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1094 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1095 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1096
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1097 for (octave_idx_type k = 0; k < nf; k++)
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1098 xvals[k].assign (ia, rhs.xvals[k], Matrix ());
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1099
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1100 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1101 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1102 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1103 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1104 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1105 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1106 dummy.assign (ia, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1107 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1108 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1109
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1110 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1111 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1112 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1113 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1114 octave_map tmp (dimensions, rhs.xkeys);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1115 tmp.assign (ia, rhs);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1116 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1117 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1118 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1119 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1120 Array<octave_idx_type> perm;
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1121 octave_map rhs1;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1122
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1123 try
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1124 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1125 rhs1 = rhs.orderfields (*this, perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1126 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1127 catch (octave::execution_exception& e)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1128 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
1129 error (e, "incompatible fields in struct assignment");
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1130 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1131
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1132 assert (rhs1.xkeys.is_same (xkeys));
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20650
diff changeset
1133 assign (ia, rhs1);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1134 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1135 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1136
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1137 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1138 octave_map::assign (const octave_value_list& idx, const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1139 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1140 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1141
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1142 // If we catch an indexing error in index_vector, we flag an error in
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1143 // index k. Ensure it is the right value befor each idx_vector call.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1144 // Same variable as used in the for loop in the default case.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1145
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1146 octave_idx_type k = 0;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1147
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1148 try
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1149 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1150 switch (n_idx)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1151 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1152 case 1:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1153 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1154 idx_vector i = idx(0).index_vector ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1155
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1156 assign (i, rhs);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1157 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1158 break;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1159
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1160 case 2:
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1161 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1162 idx_vector i = idx(0).index_vector ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1163
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1164 k = 1;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1165 idx_vector j = idx(1).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1166
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1167 assign (i, j, rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1168 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1169 break;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1170
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1171 default:
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1172 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1173 Array<idx_vector> ia (dim_vector (n_idx, 1));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1174
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1175 for (k = 0; k < n_idx; k++)
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1176 ia(k) = idx(k).index_vector ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1177
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1178 assign (ia, rhs);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1179 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1180 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1181 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1182 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1183 catch (octave::index_exception& e)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1184 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1185 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1186 e.set_pos_if_unset (n_idx, k+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1187 throw;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1188 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1189 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1190
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1191 void
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1192 octave_map::assign (const octave_value_list& idx, const std::string& k,
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1193 const Cell& rhs)
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1194 {
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1195 Cell tmp;
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
1196 auto p = seek (k);
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1197 Cell& ref = (p != end () ? contents (p) : tmp);
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1198
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1199 if (&ref == &tmp)
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1200 ref = Cell (dimensions);
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1201
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1202 ref.assign (idx, rhs);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
1203
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1204 if (ref.dims () != dimensions)
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1205 {
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1206 dimensions = ref.dims ();
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1207
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1208 octave_idx_type nf = nfields ();
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1209 for (octave_idx_type i = 0; i < nf; i++)
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1210 {
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1211 if (&xvals[i] != &ref)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14569
diff changeset
1212 xvals[i].resize (dimensions, Matrix ());
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1213 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1214
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1215 optimize_dimensions ();
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1216 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1217
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1218 if (&ref == &tmp)
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1219 setfield (k, tmp);
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1220 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1221
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1222 /*
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1223 %!test
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1224 %! rhs.b = 1;
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1225 %! a(3) = rhs;
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21574
diff changeset
1226 %! assert ({a.b}, {[], [], 1});
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1227 */
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1228
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1229 void
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1230 octave_map::delete_elements (const idx_vector& i)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1231 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1232 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1233 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1234 xvals[k].delete_elements (i);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1235
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1236 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1237 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1238 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1239 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1240 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1241 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1242 dummy.delete_elements (i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1243 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1244 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1245
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1246 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1247 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1248
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1249 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1250 octave_map::delete_elements (int dim, const idx_vector& i)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1251 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1252 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1253 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1254 xvals[k].delete_elements (dim, i);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1255
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1256 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1257 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1258 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1259 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1260 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1261 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1262 dummy.delete_elements (dim, i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1263 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1264 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1265
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1266 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1267 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1268
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1269 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1270 octave_map::delete_elements (const Array<idx_vector>& ia)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1271 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1272 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1273 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1274 xvals[k].delete_elements (ia);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1275
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1276 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1277 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1278 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1279 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1280 // Use dummy array. FIXME: Need(?) a better solution.
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1281 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1282 dummy.delete_elements (ia);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1283 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1284 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1285
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1286 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1287 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1288
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1289 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1290 octave_map::delete_elements (const octave_value_list& idx)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1291 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1292 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1293
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1294 Array<idx_vector> ia (dim_vector (n_idx, 1));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1295
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1296 for (octave_idx_type i = 0; i < n_idx; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1297 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1298 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1299 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1300 ia(i) = idx(i).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1301 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1302 catch (octave::index_exception& e)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1303 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1304 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1305 e.set_pos_if_unset (n_idx, i+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1306 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
1307 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1308 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1309
20558
1a0a433c8263 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1310 delete_elements (ia);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1311 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1312
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1313 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1314 ## test preservation of key order by indexing
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1315 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1316 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1317 %! assert (fieldnames (x([1, 2], [2:5])), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1318 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1319
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1320 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1321 octave_map::concat (const octave_map& rb, const Array<octave_idx_type>& ra_idx)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1322 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1323 if (nfields () == rb.nfields ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1324 {
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1325 // FIXME: use cbegin and auto decl here when available.
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1326 for (const_iterator pa = begin (); pa != end (); pa++)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1327 {
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1328 // FIXME: use cbegin and auto decl here when available.
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1329 const_iterator pb = rb.seek (key (pa));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1330
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1331 if (pb == rb.end ())
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1332 error ("field name mismatch in structure concatenation");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
1333
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1334 contents(pa).insert (rb.contents (pb), ra_idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1335 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1336 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1337 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1338 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1339 dim_vector dv = dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1340
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1341 if (dv.all_zero ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1342 *this = rb;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1343 else if (! rb.dims ().all_zero ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1344 error ("invalid structure concatenation");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1345 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1346
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1347 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1348 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1349
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1350 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1351 octave_map::optimize_dimensions (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1352 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1353 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1354
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1355 for (octave_idx_type i = 0; i < nf; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1356 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1357 if (! xvals[i].optimize_dimensions (dimensions))
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1358 error ("internal error: dimension mismatch across fields in struct");
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1359 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1360
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1361 }