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