annotate src/oct-map.cc @ 11068:b0eec300d3fc

avoid SID in octave_fields
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 30 Sep 2010 21:50:35 +0200
parents b721e12140cc
children fd0a3ac60b0e
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
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8682
diff changeset
3 Copyright (C) 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2006, 2007,
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8682
diff changeset
4 2008, 2009 John W. Eaton
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
5 Copyright (C) 2010 VZLU Prague
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
6
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
8
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
12 option) any later version.
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
13
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
17 for more details.
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
18
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
19 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
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
21 <http://www.gnu.org/licenses/>.
1278
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 */
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
24
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
25 #ifdef HAVE_CONFIG_H
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
26 #include <config.h>
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
27 #endif
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
28
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
29 #include "error.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
30 #include "str-vec.h"
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
31
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
32 #include "oct-map.h"
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
33 #include "utils.h"
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
34
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
35 octave_fields::octave_fields (const string_vector& fields)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
36 : rep (new fields_rep)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
37 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
38 octave_idx_type n = fields.numel ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
39 for (octave_idx_type i = 0; i < n; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
40 (*rep)[fields(i)] = i;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
41 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
42
10766
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
43 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
44 : rep (new fields_rep)
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
45 {
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
46 octave_idx_type n = 0;
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
47 while (*fields)
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
48 (*rep)[std::string (*fields++)] = n++;
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
49 }
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
50
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
51 bool
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
52 octave_fields::isfield (const std::string& field) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
53 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
54 return rep->find (field) != rep->end ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
55 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
56
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
57 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
58 octave_fields::getfield (const std::string& field) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
59 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
60 fields_rep::iterator p = rep->find (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
61 return (p != rep->end ()) ? p->second : -1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
62 }
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 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
65 octave_fields::getfield (const std::string& field)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
66 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
67 fields_rep::iterator p = rep->find (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
68 if (p != rep->end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
69 return p->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
70 else
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 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
73 octave_idx_type n = rep->size ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
74 return (*rep)[field] = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
75 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
76 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
77
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
78 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
79 octave_fields::rmfield (const std::string& field)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
80 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
81 fields_rep::iterator p = rep->find (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
82 if (p == rep->end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
83 return -1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
84 else
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 n = p->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
87 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
88 rep->erase (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
89 for (fields_rep::iterator q = rep->begin (); q != rep->end (); q++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
90 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
91 if (q->second >= n)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
92 q->second--;
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
95 return n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
96 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
97 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
98
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
99 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
100 octave_fields::orderfields (Array<octave_idx_type>& perm)
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 octave_idx_type n = rep->size ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
103 perm.clear (n, 1);
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 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
106 octave_idx_type i = 0;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
107 for (fields_rep::iterator q = rep->begin (); q != rep->end (); q++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
108 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
109 octave_idx_type j = q->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
110 q->second = i;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
111 perm(i++) = j;
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 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
114
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
115 bool
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
116 octave_fields::equal_up_to_order (const octave_fields& other,
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
117 octave_idx_type* perm) const
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
118 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
119 bool retval = true;
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 iterator p = begin (), q = other.begin ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
122 for (; p != end () && q != other.end (); p++, q++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
123 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
124 if (p->first == q->first)
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
125 perm[p->second] = q->second;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
126 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
127 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
128 retval = false;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
129 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
130 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
131 }
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 retval = (p == end () && q == other.end ());
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
134
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
135 return retval;
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
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
138 bool
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
139 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
140 Array<octave_idx_type>& perm) const
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
141 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
142 octave_idx_type n = nfields ();
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
143 if (perm.length () != n)
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
144 perm.clear (1, n);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
145
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
146 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
147 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
148
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
149 string_vector
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
150 octave_fields::fieldnames (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
151 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
152 octave_idx_type n = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
153 string_vector retval(n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
154
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
155 for (iterator p = begin (); p != end (); p++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
156 retval.xelem(p->second) = p->first;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
157
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
158 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
159 }
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_value
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
162 octave_scalar_map::getfield (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
163 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
164 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
165 return (idx >= 0) ? xvals[idx] : octave_value ();
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
168 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
169 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
170 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
171 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
172 if (idx < static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
173 xvals[idx] = val;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
174 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
175 xvals.push_back (val);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
176 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
177
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
178 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
179 octave_scalar_map::rmfield (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
180 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
181 octave_idx_type idx = xkeys.rmfield (k);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
182 if (idx >= 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
183 xvals.erase (xvals.begin () + idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
184 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
185
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
186 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
187 octave_scalar_map::orderfields (void) const
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 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
190 return orderfields (perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
191 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
192
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
193 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
194 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
195 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
196 octave_scalar_map retval (xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
197 retval.xkeys.orderfields (perm);
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 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
200 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
201 retval.xvals[i] = xvals[perm.xelem(i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
202
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
203 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
204 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
205
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
206 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
207 octave_scalar_map::orderfields (const octave_scalar_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
208 Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
209 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
210 if (xkeys.is_same (other.xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
211 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
212 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
213 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
214 octave_scalar_map retval (other.xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
215 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
216 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
217 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
218 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
219 retval.xvals[i] = xvals[perm.xelem(i)];
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 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
222 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
223
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
224 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
225 }
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_value
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
229 octave_scalar_map::contents (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
230 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
231 return getfield (k);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
232 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
233
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
234 octave_value&
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
235 octave_scalar_map::contents (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
236 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
237 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
238 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
239 xvals.resize (idx+1);
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
240 return xvals[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
241 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
242
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
243 octave_map::octave_map (const octave_scalar_map& m)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
244 : xkeys (m.xkeys), xvals (), dimensions (1, 1)
10742
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 octave_idx_type nf = m.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
247 xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
248 for (octave_idx_type i = 0; i < nf; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
249 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
250 xvals.push_back (Cell (dimensions));
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
251 xvals[i].xelem(0) = m.xvals[i];
10742
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 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
254
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
255 octave_map::octave_map (const Octave_map& m)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
256 : xkeys (m.keys ()), xvals (m.nfields ()), dimensions (m.dims ())
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
257 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
258 for (iterator p = begin (); p != end (); p++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
259 contents(p) = m.contents (key (p));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
260
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
261 optimize_dimensions ();
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
264 Cell
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
265 octave_map::getfield (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
266 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
267 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
268 return (idx >= 0) ? xvals[idx] : Cell ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
269 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
270
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
271 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
272 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
273 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
274 if (nfields () == 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
275 dimensions = val.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
276
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
277 if (val.dims () == dimensions)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
278 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
279 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
280 if (idx < static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
281 xvals[idx] = val;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
282 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
283 xvals.push_back (val);
10742
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 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
286 error ("octave_map::setfield: internal error");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
287 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
288
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
289 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
290 octave_map::rmfield (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
291 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
292 octave_idx_type idx = xkeys.rmfield (k);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
293 if (idx >= 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
294 xvals.erase (xvals.begin () + idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
295 }
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 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
298 octave_map::orderfields (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
299 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
300 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
301 return orderfields (perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
302 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
303
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
304 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
305 octave_map::orderfields (Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
306 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
307 octave_map retval (xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
308 retval.xkeys.orderfields (perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
309
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
310 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
311 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
312 retval.xvals[i] = xvals[perm.xelem(i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
313
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
314 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
315 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
316
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
317 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
318 octave_map::orderfields (const octave_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
319 Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
320 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
321 if (xkeys.is_same (other.xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
322 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
323 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
324 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
325 octave_map retval (other.xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
326 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
327 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
328 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
329 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
330 retval.xvals[i] = xvals[perm.xelem(i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
331 }
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 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
334
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
335 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
336 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
337 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
338
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
339 Cell
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
340 octave_map::contents (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
341 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
342 return getfield (k);
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 Cell&
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
346 octave_map::contents (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
347 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
348 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
349 if (idx >= static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
350 xvals.push_back (Cell (dimensions)); // auto-set correct dims.
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
351 return xvals[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
352 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
353
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
354 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
355 octave_map::extract_scalar (octave_scalar_map& dest,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
356 octave_idx_type idx) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
357 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
358 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
359 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
360 dest.xvals[i] = xvals[i](idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
361 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
362
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
363 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
364 octave_map::checkelem (octave_idx_type n) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
365 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
366 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
367
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
368 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
369 extract_scalar (retval, compute_index (n, dimensions));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
370
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
371 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
372 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
373
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
374 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
375 octave_map::checkelem (octave_idx_type i, octave_idx_type j) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
376 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
377 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
378
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
379 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
380 extract_scalar (retval, compute_index (i, j, dimensions));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
381
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
382 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
383 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
384
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
385 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
386 octave_map::checkelem (const Array<octave_idx_type>& ra_idx) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
387 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
388 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
389
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
390 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
391 extract_scalar (retval, compute_index (ra_idx, dimensions));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
392
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
393 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
394 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
395
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
396 octave_scalar_map
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
397 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
398 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
399 octave_scalar_map retval (xkeys);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
400
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
401 extract_scalar (retval, n);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
402
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
403 return retval;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
404 }
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 bool
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
407 octave_map::fast_elem_insert (octave_idx_type n,
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
408 const octave_scalar_map& rhs)
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 bool retval = false;
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 octave_idx_type nf = nfields ();
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
413 if (rhs.xkeys.is_same (xkeys))
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
414 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
415 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
416 xvals[i](n) = rhs.xvals[i];
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
417
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
418 retval = true;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
419 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
420 else
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 OCTAVE_LOCAL_BUFFER (octave_idx_type, perm, nf);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
423 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
424 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
425 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
426 xvals[i](n) = rhs.xvals[perm[i]];
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
427
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
428 retval = true;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
429 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
430 }
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 return retval;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
433 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
434
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
435 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
436 octave_map::squeeze (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
437 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
438 octave_map retval (*this);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
439 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
440
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
441 retval.dimensions = dimensions.squeeze ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
442
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
443 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
444 retval.xvals[i] = xvals[i].squeeze ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
445
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
446 retval.optimize_dimensions ();
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
449 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
450
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
451 /*
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
452 %!# test preservation of xkeys by squeeze
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
453 %!test
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
454 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
455 %! assert (fieldnames (squeeze (x)), {"d"; "a"; "f"});
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 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
459 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
460 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
461 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
462 octave_idx_type nf = nfields ();
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 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
465 retval.xvals[i] = xvals[i].permute (vec, inv);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
466
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
467 // FIXME:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
468 // There is no dim_vector::permute for technical reasons.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
469 // We pick the dim vector from results if possible, otherwise use a dummy
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
470 // array to get it. Need (?) a better solution to this problem.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
471 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
472 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
473 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
474 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
475 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
476 dummy = dummy.permute (vec, inv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
477 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
478 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
479
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
480 retval.optimize_dimensions ();
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
483 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
484
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 %!# test preservation of key order by permute
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
487 %!test
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
488 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
489 %! assert (fieldnames (permute (x, [3, 4, 1, 2])), {"d"; "a"; "f"});
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 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
493 octave_map::transpose (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
494 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
495 assert (ndims () == 2);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
496
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
497 octave_map retval (xkeys);
10742
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 retval.dimensions = dim_vector (dimensions (1), dimensions (0));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
500
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
501 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
502 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
503 retval.xvals[i] = xvals[i].transpose ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
504
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
505 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
506
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
507 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
508 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
509
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
510 /*
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
511 %!# test preservation of key order by transpose
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
512 %!test
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
513 %! x(1,1).d = 10; x(3,5).a = "b"; x(2,4).f = 27;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
514 %! assert (fieldnames (transpose (x)), {"d"; "a"; "f"});
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
515 %! assert (fieldnames (x'), {"d"; "a"; "f"});
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
516 %! assert (fieldnames (x.'), {"d"; "a"; "f"});
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
517 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
518
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
519 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
520 octave_map::reshape (const dim_vector& dv) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
521 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
522 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
523 retval.dimensions = dv;
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 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
526 if (nf > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
527 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
528 retval.xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
529 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
530 retval.xvals[i] = xvals[i].reshape (dv);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
531 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
532 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
533 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
534 // 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
535 // Need (?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
536 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
537 dummy.reshape (dv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
538 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
539
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
540 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
541
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
542 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
543 }
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 /*
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
546 %!# test preservation of key order by reshape
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
547 %!test
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
548 %! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
549 %! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"});
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
552 void
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
553 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
554 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
555 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
556 if (nf > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
557 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
558 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
559 {
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
560 if (fill)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
561 xvals[i].resize (dv, Cell::resize_fill_value ());
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
562 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
563 xvals[i].resize (dv);
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
564 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
565 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
566 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
567 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
568 // 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
569 // Need (?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
570 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
571 dummy.resize (dv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
572 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
573
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
574 dimensions = dv;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
575 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
576 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
577
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
578 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
579 octave_map::do_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
580 octave_map& retval)
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 octave_idx_type nf = retval.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
583 retval.xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
584
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
585 dim_vector& rd = retval.dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
586 rd.resize (dim+1, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
587 rd(0) = rd(1) = 1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
588 rd(dim) = n;
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 for (octave_idx_type j = 0; j < nf; j++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
591 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
592 retval.xvals.push_back (Cell (rd));
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
593 assert (retval.xvals[j].numel () == n);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
594 for (octave_idx_type i = 0; i < n; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
595 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
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
599 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
600 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
601 octave_map& retval)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
602 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
603 octave_idx_type nf = retval.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
604 retval.xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
605
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
606 OCTAVE_LOCAL_BUFFER (Array<octave_value>, field_list, n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
607
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
608 for (octave_idx_type j = 0; j < nf; j++)
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 for (octave_idx_type i = 0; i < n; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
611 field_list[i] = map_list[i].xvals[j];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
612
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
613 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
614 if (j == 0)
e141bcb1befd implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents: 10763
diff changeset
615 retval.dimensions = retval.xvals[j].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
616 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
617 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
618
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
619 // This is just a wrapper.
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
620 void permute_to_correct_order1 (const octave_scalar_map& ref, const octave_scalar_map& src,
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
621 octave_scalar_map& dest, Array<octave_idx_type>& perm)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
622 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
623 dest = src.orderfields (ref, perm);
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
624 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
625
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
626 // 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
627 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
628 octave_map& dest, Array<octave_idx_type>& perm)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
629 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
630 if (src.nfields () == 0 && src.is_empty ())
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
631 dest = octave_map (src.dims (), ref.keys ());
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
632 else
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
633 dest = src.orderfields (ref, perm);
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
634 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
635
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
636 template <class map>
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
637 static void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
638 permute_to_correct_order (octave_idx_type n, octave_idx_type nf,
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
639 octave_idx_type idx, const map *map_list,
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
640 map *new_map_list)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
641 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
642 new_map_list[idx] = map_list[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
643
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
644 Array<octave_idx_type> perm (1, nf);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
645
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
646 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
647 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
648 if (i == idx)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
649 continue;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
650
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
651 permute_to_correct_order1 (map_list[idx], map_list[i], new_map_list[i], perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
652
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
653 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
654 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
655 // Use liboctave exception to be consistent.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
656 (*current_liboctave_error_handler)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
657 ("cat: field names mismatch in concatenating structs");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
658 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
659 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
660 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
661 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
662
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
663
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
664 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
665 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
666 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
667 octave_map retval;
10763
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
668 // 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
669 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
670 dim = -dim - 1;
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
671 else if (dim < 0)
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
672 (*current_liboctave_error_handler)
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
673 ("cat: invalid dimension");
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
674
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
675 if (n > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
676 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
677 octave_idx_type idx, nf = 0;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
678 for (idx = 0; idx < n; idx++)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
679 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
680 nf = map_list[idx].nfields ();
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
681 if (nf > 0)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
682 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
683 retval.xkeys = map_list[idx].xkeys;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
684 break;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
685 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
686 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
687
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
688 if (nf > 0)
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 // Try the fast case.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
691 bool all_same = true;
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
692 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
693 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
694 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
695 if (! all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
696 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
697 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
698
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
699 if (all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
700 do_cat (dim, n, map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
701 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
702 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
703 // permute all structures to common order.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
704 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
705
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
706 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
707
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
708 do_cat (dim, n, new_map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
709 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
710
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
711 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
712 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
713 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
714 dim_vector& rd = retval.dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
715 rd.resize (dim+1, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
716 rd(0) = rd(1) = 1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
717 rd(dim) = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
718 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
719
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
720 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
721 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
722
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
723 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
724 }
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 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
727 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
728 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
729 octave_map retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
730 if (n > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
731 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
732 octave_idx_type idx, nf = 0;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
733 for (idx = 0; idx < n; idx++)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
734 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
735 nf = map_list[idx].nfields ();
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
736 if (nf > 0)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
737 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
738 retval.xkeys = map_list[idx].xkeys;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
739 break;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
740 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
741 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
743 // Try the fast case.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
744 bool all_same = true;
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
745 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
746 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
747 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
748 if (! all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
749 break;
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
752 if (all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
753 do_cat (dim, n, map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
754 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
755 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
756 // permute all structures to correct order.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
757 OCTAVE_LOCAL_BUFFER (octave_map, new_map_list, n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
758
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
759 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
760
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
761 if (nf > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
762 do_cat (dim, n, new_map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
763 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
764 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
765 // Use dummy arrays. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
766 OCTAVE_LOCAL_BUFFER (Array<char>, dummy, n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
767 for (octave_idx_type i = 0; i < n; i++)
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
768 dummy[i].clear (map_list[i].dimensions);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
769 Array<char>::cat (dim, n, dummy);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
770 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
771 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
772
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
773 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
774 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
775
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
776 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
777 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
778
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
779 /*
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
780 %!# test preservation of key order by concatenation
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
781 %!test
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
782 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
783 %! y(1, 6).f = 11; y(1, 6).a = "c"; y(1, 6).d = 33;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
784 %! assert (fieldnames ([x; y]), {"d"; "a"; "f"});
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
785 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
786
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
787 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
788 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
789 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
790 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
791 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
792
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
793 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
794 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
795
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
796 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
797 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
798 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
799 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
800 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
801 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
802 dummy = dummy.index (i, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
803 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
804 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
805
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
806 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
807
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
808 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
809 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
810
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
811 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
812 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
813 bool resize_ok) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
814 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
815 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
816 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
817
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
818 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
819 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
820
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
821 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
822 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
823 else
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 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
826 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
827 dummy = dummy.index (i, j, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
828 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
829 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
830
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
831 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
832
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
833 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
834 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
835
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
836 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
837 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
838 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
839 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
840 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
841
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
842 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
843 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
844
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
845 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
846 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
847 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
848 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
849 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
850 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
851 dummy = dummy.index (ia, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
852 retval.dimensions = dummy.dims ();
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
855 retval.optimize_dimensions ();
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
858 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
859
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
860 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
861 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
862 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
863 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
864 octave_map retval;
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 switch (n_idx)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
867 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
868 case 1:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
869 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
870 idx_vector i = idx(0).index_vector ();
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 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
873 retval = index (i, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
874 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
875 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
876
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
877 case 2:
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 idx_vector i = idx(0).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
880
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
881 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
882 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
883 idx_vector j = idx(1).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
884
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
885 retval = index (i, j, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
886 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
887 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
888 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
889
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
890 default:
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 Array<idx_vector> ia (n_idx, 1);
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 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
895 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
896 ia(i) = idx(i).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
897
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
898 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
899 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
900 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
901
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
902 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
903 retval = index (ia, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
904 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
905 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
906 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
907
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
908 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
909 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
910
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
911 // Perhaps one day these will be optimized. Right now, they just call index.
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
912 octave_map
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
913 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
914 {
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
915 return index (idx_vector::colon, k);
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
916 }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
917
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
918 octave_map
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
919 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
920 {
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
921 static Array<idx_vector> ia (3, 1, idx_vector::colon);
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
922
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
923 ia(2) = k;
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
924 return index (ia);
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
925 }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
926
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
927 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
928 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
929 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
930 if (rhs.xkeys.is_same (xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
931 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
932 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
933
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
934 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
935 xvals[k].assign (i, rhs.xvals[k]);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
936
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
937 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
938 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
939 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
940 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
941 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
942 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
943 dummy.assign (i, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
944 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
945 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
946
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
947 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
948 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
949 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
950 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
951 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
952 tmp.assign (i, rhs);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
953 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
954 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
955 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
956 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
957 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
958 octave_map rhs1 = rhs.orderfields (*this, perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
959 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
960 {
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
961 assert (rhs1.xkeys.is_same (xkeys));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
962 assign (i, rhs1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
963 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
964 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
965 error ("incompatible fields in struct assignment");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
966 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
967 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
968
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
969 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
970 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
971 const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
972 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
973 if (rhs.xkeys.is_same (xkeys))
10742
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 octave_idx_type nf = nfields ();
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 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
978 xvals[k].assign (i, j, rhs.xvals[k]);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
979
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
980 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
981 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
982 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
983 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
984 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
985 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
986 dummy.assign (i, j, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
987 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
988 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
989
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
990 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
991 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
992 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
993 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
994 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
995 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
996 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
997 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
998 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
999 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1000 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1001 octave_map rhs1 = rhs.orderfields (*this, perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1002 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1003 {
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1004 assert (rhs1.xkeys.is_same (xkeys));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1005 assign (i, j, rhs1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1006 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1007 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1008 error ("incompatible fields in struct assignment");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1009 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1010 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1011
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1012 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1013 octave_map::assign (const Array<idx_vector>& ia,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1014 const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1015 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1016 if (rhs.xkeys.is_same (xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1017 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1018 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1019
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1020 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1021 xvals[k].assign (ia, rhs.xvals[k]);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1022
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1023 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1024 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1025 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1026 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1027 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1028 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1029 dummy.assign (ia, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1030 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1031 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1032
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1033 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1034 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1035 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1036 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1037 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
1038 tmp.assign (ia, rhs);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1039 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1040 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1041 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1042 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1043 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1044 octave_map rhs1 = rhs.orderfields (*this, perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1045 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1046 {
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1047 assert (rhs1.xkeys.is_same (xkeys));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1048 assign (ia, rhs1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1049 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1050 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1051 error ("incompatible fields in struct assignment");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1052 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1053 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1054
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1055 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1056 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
1057 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1058 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1059
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1060 switch (n_idx)
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 case 1:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1063 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1064 idx_vector i = idx(0).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1065
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1066 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1067 assign (i, rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1068 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1069 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1070
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1071 case 2:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1072 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1073 idx_vector i = idx(0).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1074
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1075 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1076 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1077 idx_vector j = idx(1).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1078
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1079 assign (i, j, rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1080 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1081 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1082 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1083
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1084 default:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1085 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1086 Array<idx_vector> ia (n_idx, 1);
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 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
1089 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1090 ia(i) = idx(i).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1091
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1092 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1093 break;
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1096 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1097 assign (ia, rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1098 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1099 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1100 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1101 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1102
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1103 void
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1104 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
1105 const Cell& rhs)
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1106 {
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1107 Cell tmp;
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1108 iterator p = seek (k);
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1109 Cell& ref = p != end () ? contents (p) : tmp;
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1110
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1111 if (&ref == &tmp)
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1112 ref = Cell (dimensions);
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1113
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1114 ref.assign (idx, rhs);
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1115
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1116 if (! error_state && ref.dims () != dimensions)
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1117 {
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1118 dimensions = ref.dims ();
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1119
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1120 octave_idx_type nf = nfields ();
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1121 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
1122 {
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1123 if (&xvals[i] != &ref)
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1124 xvals[i].resize (dimensions, Cell::resize_fill_value ());
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1125 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1126
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1127 optimize_dimensions ();
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1128 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1129
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1130 if (! error_state && &ref == &tmp)
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1131 setfield (k, tmp);
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1132 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1133
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1134 void
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1135 octave_map::delete_elements (const idx_vector& i)
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 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1138 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1139 xvals[k].delete_elements (i);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1140
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1141 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1142 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1143 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1144 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1145 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1146 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1147 dummy.delete_elements (i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1148 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1149 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1150
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1151 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1152 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1153
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1154 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1155 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
1156 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1157 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1158 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1159 xvals[k].delete_elements (dim, i);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1160
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1161 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1162 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1163 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1164 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1165 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1166 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1167 dummy.delete_elements (dim, i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1168 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1169 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1170
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1171 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1172 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1173
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1174 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1175 octave_map::delete_elements (const Array<idx_vector>& ia)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1176 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1177 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1178 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1179 xvals[k].delete_elements (ia);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1180
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1181 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1182 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1183 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1184 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1185 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1186 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1187 dummy.delete_elements (ia);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1188 dimensions = dummy.dims ();
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 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1192 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1193
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1194 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1195 octave_map::delete_elements (const octave_value_list& idx)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1196 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1197 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1198
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1199 Array<idx_vector> ia (n_idx, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1200
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1201 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
1202 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1203 ia(i) = idx(i).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1204
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1205 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1206 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1207 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1208
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1209 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1210 delete_elements (ia);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1211 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1212
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1213 /*
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1214 %!# test preservation of key order by indexing
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1215 %!test
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1216 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1217 %! assert (fieldnames (x([1, 2], [2:5])), {"d"; "a"; "f"});
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1218 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1219
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1220 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1221 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
1222 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1223 if (nfields () == rb.nfields ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1224 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1225 for (const_iterator pa = begin (); pa != end (); pa++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1226 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1227 const_iterator pb = rb.seek (key(pa));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1228
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1229 if (pb == rb.end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1230 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1231 error ("field name mismatch in structure concatenation");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1232 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1233 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1234
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1235 contents(pa).insert (rb.contents(pb), ra_idx);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1236 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1237 }
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 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1240 dim_vector dv = dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1241
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1242 if (dv.all_zero ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1243 *this = rb;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1244 else if (! rb.dims ().all_zero ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1245 error ("invalid structure concatenation");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1246 }
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 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1249 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1250
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1251 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1252 octave_map::optimize_dimensions (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1253 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1254 octave_idx_type nf = nfields ();
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 for (octave_idx_type i = 0; i < nf; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1257 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1258 if (! xvals[i].optimize_dimensions (dimensions))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1259 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1260 error ("internal error: dimension mismatch across fields in struct");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1261 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1262 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1263 }
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
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6946
diff changeset
1267 Octave_map::Octave_map (const dim_vector& dv, const Cell& key_vals)
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1268 : map (), key_list (), dimensions (dv)
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1269 {
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1270 Cell c (dv);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1271
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6946
diff changeset
1272 if (key_vals.is_cellstr ())
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1273 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6946
diff changeset
1274 for (octave_idx_type i = 0; i < key_vals.numel (); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1275 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1276 std::string k = key_vals(i).string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1277 map[k] = c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1278 key_list.push_back (k);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1279 }
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1280 }
6946
10c7a803b409 [project @ 2007-10-03 14:38:48 by jwe]
jwe
parents: 6639
diff changeset
1281 else
10c7a803b409 [project @ 2007-10-03 14:38:48 by jwe]
jwe
parents: 6639
diff changeset
1282 error ("Octave_map: expecting keys to be cellstr");
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1283 }
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1284
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1285 Octave_map::Octave_map (const octave_map& m)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1286 : map (), key_list (), dimensions (m.dims ())
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 for (octave_map::const_iterator p = m.begin (); p != m.end (); p++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1289 map[m.key (p)] = m.contents (p);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1290 const string_vector mkeys = m.fieldnames ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1291 for (octave_idx_type i = 0; i < mkeys.numel (); i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1292 key_list.push_back (mkeys(i));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1293 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1294
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1295 Octave_map
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1296 Octave_map::squeeze (void) const
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1297 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1298 Octave_map retval (dims ().squeeze ());
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1299
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1300 for (const_iterator pa = begin (); pa != end (); pa++)
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1301 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1302 Cell tmp = contents (pa).squeeze ();
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1303
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1304 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1305 break;
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1306
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1307 retval.assign (key (pa), tmp);
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1308 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1309
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1310 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1311 retval.key_list = key_list;
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1312
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1313 return retval;
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1314 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1315
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1316 Octave_map
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1317 Octave_map::permute (const Array<int>& vec, bool inv) const
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1318 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1319 Octave_map retval (dims ());
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1320
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1321 for (const_iterator pa = begin (); pa != end (); pa++)
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1322 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1323 Cell tmp = contents (pa).permute (vec, inv);
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1324
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1325 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1326 break;
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1327
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1328 retval.assign (key (pa), tmp);
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1329 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1330
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1331 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1332 retval.key_list = key_list;
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1333
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1334 return retval;
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1335 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1336
5328
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1337 Cell&
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1338 Octave_map::contents (const std::string& k)
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1339 {
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1340 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1341
5328
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1342 return map[k];
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1343 }
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1344
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4219
diff changeset
1345 Cell
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1346 Octave_map::contents (const std::string& k) const
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1347 {
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1348 const_iterator p = seek (k);
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1349
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4219
diff changeset
1350 return p != end () ? p->second : Cell ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1351 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1352
5156
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1353 int
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1354 Octave_map::intfield (const std::string& k, int def_val) const
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1355 {
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1356 int retval = def_val;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1357
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1358 Cell c = contents (k);
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1359
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1360 if (! c.is_empty ())
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1361 retval = c(0).int_value ();
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1362
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1363 return retval;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1364 }
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1365
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1366 std::string
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1367 Octave_map::stringfield (const std::string& k,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1368 const std::string& def_val) const
5156
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1369 {
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1370 std::string retval = def_val;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1371
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1372 Cell c = contents (k);
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1373
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1374 if (! c.is_empty ())
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1375 retval = c(0).string_value ();
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1376
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1377 return retval;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1378 }
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1379
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
1380 string_vector
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1381 Octave_map::keys (void) const
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1382 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1383 assert (nfields () == key_list.size ());
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1384
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1385 return string_vector (key_list);
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1386 }
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1387
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1388 Octave_map
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1389 Octave_map::transpose (void) const
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1390 {
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1391 assert (ndims () == 2);
5593
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1392
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1393 dim_vector dv = dims ();
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1394
5593
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1395 octave_idx_type nr = dv(0);
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1396 octave_idx_type nc = dv(1);
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1397
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1398 dim_vector new_dims (nc, nr);
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1399
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1400 Octave_map retval (new_dims);
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1401
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1402 for (const_iterator p = begin (); p != end (); p++)
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1403 retval.assign (key(p), Cell (contents(p).transpose ()));
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1404
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1405 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1406 retval.key_list = key_list;
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1407
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1408 return retval;
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1409 }
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1410
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1411 Octave_map
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1412 Octave_map::reshape (const dim_vector& new_dims) const
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1413 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1414 Octave_map retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1415
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1416 if (new_dims != dims ())
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1417 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1418 for (const_iterator p = begin (); p != end (); p++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1419 retval.assign (key(p), contents(p).reshape (new_dims));
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1420
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1421 retval.dimensions = new_dims;
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1422
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1423 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1424 retval.key_list = key_list;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1425 }
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1426 else
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1427 retval = *this;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1428
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1429 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1430 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1431
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1432 void
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1433 Octave_map::resize (const dim_vector& dv, bool fill)
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1434 {
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1435 if (dv != dims ())
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1436 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1437 if (nfields () == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1438 dimensions = dv;
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1439 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1440 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1441 for (const_iterator p = begin (); p != end (); p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1442 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1443 Cell tmp = contents(p);
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1444
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1445 if (fill)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1446 tmp.resize (dv, Cell::resize_fill_value ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1447 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1448 tmp.resize (dv);
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1449
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1450 dimensions = dv;
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1451
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1452 assign (key(p), tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1453 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1454 }
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1455 }
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1456 }
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1457
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
1458 Octave_map
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5156
diff changeset
1459 Octave_map::concat (const Octave_map& rb, const Array<octave_idx_type>& ra_idx)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4730
diff changeset
1460 {
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1461 Octave_map retval;
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1462
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1463 if (nfields () == rb.nfields ())
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1464 {
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1465 for (const_iterator pa = begin (); pa != end (); pa++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1466 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1467 const_iterator pb = rb.seek (key(pa));
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1468
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1469 if (pb == rb.end ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1470 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1471 error ("field name mismatch in structure concatenation");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1472 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1473 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1474
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1475 retval.assign (key(pa),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1476 contents(pa).insert (rb.contents(pb), ra_idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1477 }
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1478
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1479 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1480 retval.key_list = key_list;
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1481 }
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1482 else
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1483 {
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1484 dim_vector dv = dims ();
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1485
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1486 if (dv.all_zero ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1487 retval = rb;
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1488 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1489 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1490 dv = rb.dims ();
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1491
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1492 if (dv.all_zero ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1493 retval = *this;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1494 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1495 error ("invalid structure concatenation");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1496 }
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1497 }
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1498
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
1499 return retval;
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4730
diff changeset
1500 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4730
diff changeset
1501
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1502 static bool
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1503 keys_ok (const Octave_map& a, const Octave_map& b, string_vector& keys)
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1504 {
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1505 bool retval = false;
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1506
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1507 keys = string_vector ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1508
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1509 if (a.nfields () == 0)
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1510 {
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1511 keys = b.keys ();
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1512 retval = true;
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1513 }
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1514 else
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1515 {
8503
8ba2ee57c594 remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents: 8294
diff changeset
1516 string_vector a_keys = a.keys().sort ();
8ba2ee57c594 remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents: 8294
diff changeset
1517 string_vector b_keys = b.keys().sort ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1518
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1519 octave_idx_type a_len = a_keys.length ();
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1520 octave_idx_type b_len = b_keys.length ();
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1521
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1522 if (a_len == b_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1523 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1524 for (octave_idx_type i = 0; i < a_len; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1525 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1526 if (a_keys[i] != b_keys[i])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1527 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1528 }
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1529
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1530 keys = a_keys;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1531 retval = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1532 }
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1533 }
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1534
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1535 done:
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1536 return retval;
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1537 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1538
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1539 Octave_map&
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1540 Octave_map::maybe_delete_elements (const octave_value_list& idx)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1541 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1542 string_vector t_keys = keys();
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1543 octave_idx_type len = t_keys.length ();
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1544
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1545 if (len > 0)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1546 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1547 for (octave_idx_type i = 0; i < len; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1548 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1549 std::string k = t_keys[i];
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1550
10649
64472dd48517 cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
1551 contents(k).delete_elements (idx);
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1552
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1553 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1554 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1555 }
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1556
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1557 if (!error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1558 dimensions = contents(t_keys[0]).dims();
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1559 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1560
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1561 return *this;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1562 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1563
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1564 Octave_map&
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4219
diff changeset
1565 Octave_map::assign (const octave_value_list& idx, const Octave_map& rhs)
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1566 {
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1567 string_vector t_keys;
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1568
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1569 if (keys_ok (*this, rhs, t_keys))
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1570 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5156
diff changeset
1571 octave_idx_type len = t_keys.length ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1572
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1573 if (len == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1574 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1575 Cell tmp_lhs (dims ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1576 Cell tmp_rhs (rhs.dims ());
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1577
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1578 tmp_lhs.assign (idx, tmp_rhs, Matrix ());
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1579
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1580 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1581 resize (tmp_lhs.dims ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1582 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1583 error ("size mismatch in structure assignment");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1584 }
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1585 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1586 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1587 for (octave_idx_type i = 0; i < len; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1588 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1589 std::string k = t_keys[i];
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1590
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1591 Cell t_rhs = rhs.contents (k);
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1592
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1593 assign (idx, k, t_rhs);
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1594
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1595 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1596 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1597 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1598 }
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1599 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1600 else
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1601 error ("field name mismatch in structure assignment");
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1602
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1603 return *this;
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1604 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1605
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1606 Octave_map&
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1607 Octave_map::assign (const octave_value_list& idx, const std::string& k,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1608 const Cell& rhs)
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1609 {
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1610 Cell tmp;
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1611
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1612 if (contains (k))
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1613 tmp = map[k];
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1614 else
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1615 tmp = Cell (dimensions);
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1616
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1617 tmp.assign (idx, rhs);
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1618
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1619 if (! error_state)
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1620 {
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1621 dim_vector tmp_dims = tmp.dims ();
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1622
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1623 if (tmp_dims != dimensions)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1624 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1625 for (iterator p = begin (); p != end (); p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1626 contents(p).resize (tmp_dims, Cell::resize_fill_value ());
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1627
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1628 dimensions = tmp_dims;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1629 }
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1630
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1631 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1632
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1633 map[k] = tmp;
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1634 }
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1635
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1636 return *this;
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1637 }
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1638
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1639 Octave_map&
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1640 Octave_map::assign (const std::string& k, const octave_value& rhs)
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1641 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1642 if (nfields () == 0)
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1643 {
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1644 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1645
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1646 map[k] = Cell (rhs);
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1647
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1648 dimensions = dim_vector (1, 1);
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1649 }
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1650 else
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1651 {
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1652 dim_vector dv = dims ();
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1653
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1654 if (dv.all_ones ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1655 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1656 maybe_add_to_key_list (k);
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1657
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1658 map[k] = Cell (rhs);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1659 }
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1660 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1661 error ("invalid structure assignment");
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1662 }
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1663
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1664 return *this;
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1665 }
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1666
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1667 Octave_map&
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1668 Octave_map::assign (const std::string& k, const Cell& rhs)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1669 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1670 if (nfields () == 0)
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4562
diff changeset
1671 {
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1672 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1673
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1674 map[k] = rhs;
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4562
diff changeset
1675
4730
c88afb778c41 [project @ 2004-02-02 18:31:09 by jwe]
jwe
parents: 4675
diff changeset
1676 dimensions = rhs.dims ();
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4562
diff changeset
1677 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1678 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1679 {
4562
4699bdb4c362 [project @ 2003-10-28 21:14:07 by jwe]
jwe
parents: 4561
diff changeset
1680 if (dims () == rhs.dims ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1681 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1682 maybe_add_to_key_list (k);
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1683
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1684 map[k] = rhs;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1685 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1686 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1687 error ("invalid structure assignment");
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1688 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1689
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1690 return *this;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1691 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1692
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1693 Octave_map
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1694 Octave_map::index (const octave_value_list& idx, bool resize_ok) const
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1695 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1696 Octave_map retval;
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1697
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1698 octave_idx_type n_idx = idx.length ();
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1699
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1700 if (n_idx > 0)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1701 {
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1702 Array<idx_vector> ra_idx (n_idx, 1);
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1703
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1704 for (octave_idx_type i = 0; i < n_idx; i++)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1705 {
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1706 ra_idx(i) = idx(i).index_vector ();
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1707 if (error_state)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1708 break;
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1709 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1710
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1711 if (! error_state)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1712 {
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1713 for (const_iterator p = begin (); p != end (); p++)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1714 {
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1715 Cell tmp = contents (p);
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1716
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9392
diff changeset
1717 tmp = tmp.Array<octave_value>::index (ra_idx, resize_ok);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1718
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1719 if (error_state)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1720 break;
8294
b2a6309b2d87 oct-map.cc: copy key_list in indexing functions
John W. Eaton <jwe@octave.org>
parents: 8175
diff changeset
1721
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1722 retval.assign (key(p), tmp);
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1723 }
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1724
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1725 // Preserve order of keys.
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1726 retval.key_list = key_list;
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1727 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1728 }
5435
66ad03c58880 [project @ 2005-08-31 20:41:47 by jwe]
jwe
parents: 5329
diff changeset
1729 else
5539
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5435
diff changeset
1730 retval = *this;
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1731
5539
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5435
diff changeset
1732 return retval;
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1733 }