annotate src/oct-map.cc @ 14616:13cc11418393

improve handling of default resize fill value for arrays * Array.cc (Array<T>::resize_fill_value): Return T, not const T&. * Array.h (Array<T>::resize_fill_value): Now virtual member function instead of static. (Array<T>::resize1 (octave_idx_type)): New function. (Array<T>::resize1 (octave_idx_type, const T&)): Eliminate default value for second arg. (Array<T>::resize (octave_idx_type, octave_idx_type)): New function. (Array<T>::resize (octave_idx_type, octave_idx_type, const T&)): Eliminate default value for third arg. (Array<T>::resize (const dim_vector&)): New function. (Array<T>::resize (const dim_vector&, const T&)): New function. (Array<T>::resize2 (octave_idx_type, octave_idx_type)): New function. (Array<T>::resize2 (octave_idx_type, octave_idx_type, const T&)): Eliminate default value for third arg. (Array<T>::index (const idx_vector&, bool) const): New function. (Array<T>::index (const idx_vector&, bool, const T&) const): Eliminate default value for third arg. (Array<T>::index (const idx_vector&, const idx_vector&, bool) const): New function. (Array<T>::index (const idx_vector&, const idx_vector&, bool, const T&) const): Eliminate default value for third arg. (Array<T>::index (const Array<idx_vector>&, bool) const): New function. (Array<T>::index (const Array<idx_vector>&, const T&) const): Eliminate default value for third arg. (Array<T>::assign (const idx_vector&, const Array<T>&)): New function. (Array<T>::assign (const idx_vector&, const Array<T>&, const T&)): Eliminate default value for third arg. (Array<T>::assign (const idx_vector&, const idx_vector&, const Array<T>&)): New function. (Array<T>::assign (const idx_vector&, const idx_vector&, const Array<T>&, const T&)): Eliminate default value for third arg. (Array<T>::assign (const Array<idx_vector>&, const Array<T>&)): New function. (Array<T>::assign (const Array<idx_vector>&, const Array<T>&, const T&)): Eliminate default value for third arg. * DiagArray2.h (DiagArray2<T>::resize (octave_idx_type, octave_idx_type)): New function. (DiagArray2<T>::resize (octave_idx_type, octave_idx_type, const T&)): Eliminate default value for third arg. * CColVector.h (ComplexColumnVector::resize): Use Complex (0) as default value instead of Array<Complex>::resize_fill_value (). * CMatrix.h (ComplexMatrix::resize): Use Complex (0) as default value instead of Array<Complex>::resize_fill_value (). (ComplexMatrix::resize_fill_value): Delete. * CNDArray.h (ComplexNDArray::resize_fill_value): Delete. * CRowVector.h (ComplexRowVector::resize): Use Complex (0) as default value instead of Array<Complex>::resize_fill_value (). * boolMatrix.h (boolMatrix::resize): Use false as default value instead of resize_fill_value (). (boolMatrix::resize_fill_value): Delete. * boolNDArray.h (boolNDArray::resize_fill_value): Delete. * chMatrix.h (charMatrix::resize): Use 0 as default value instead of resize_fill_value. (charMatrix::resize_fill_value): Delete. * chNDArray.h (charNDArray::resize_fill_value): Delete. * dColVector.h (ColumnVector::resize): Use 0 as default value instead of Array<double>::resize_fill_value (). * dMatrix.h (Matrix::resize): Use 0 as default value instead of resize_fill_value (). (Matrix::resize_fill_value): Delete. * dNDArray.h (NDArray::resize_fill_value): Delete. * dRowVector.h (RowVector::resize): Use 0 as default value instead of Array<double>::resize_fill_value (). * fCColVector.h (FloatComplexColumnVector::resize): Use FloatComplex (0) as default value instead of Array<FloatComplex>::resize_fill_value (). * fCMatrix.h (FloatComplexMatrix::resize): Use FloatComplex (0) as default value instead of resize_fill_value ()). FloatCmplexMatrix::resize_fill_value): Delete. * fCNDArray.h (FloatComplexNDArray::resize_fill_value): Delete. * fCRowVector.h (FloatComplexRowVector::resize): Use FloatComplex (0) as default value instead of Array<FloatComplex>::resize_fill_value (). * fColVector.h (FloatColumnVector::resize): Use 0 as default value instead of Array<float>::resize_fill_value (). * fMatrix.h (FloatMatrix::resize): Use 0 as default value instead of resize_fill_value (). * fMatrix.h (FloatMatrix::resize_fill_value): Delete. * fNDArray.h (FloatNDArray::resize_fill_value): Delete. * fRowVector.h (FloatRowVector::resize): Use 0 as default value instead of Array<float>::resize_fill_value (). * intNDArray.h (intNDArray<T>::resize_fill_value): Delete. * str-vec.h (string_vector::resize): Use std::string as default value instead of resize_fill_value (). * Cell.cc, Cell.h (Cell::Cell, Cell::assign, Cell::index): Use Matrix () as default value instead of resize_fill_value (). (Cell::resize_fill_value): No longer static. * oct-map.cc (octave_map::resize, octave_map::assign, Octave_map::resize, Octave_map::assign): Use Matrix () as default value instead of Cell::resize_fill_value. * oct-obj.h (octave_value_list::resize): Use octave_value () instead of Array<octave_value>::resize_fill_value (). * ov-complex.cc (octave_complex::resize): Use Complex (0) for fill value instead of ComplexNDArray::resize_fill_value (). * ov-float.cc (octave_float_scalar::resize): Use 0 for fill value instead of NDArray::resize_fill_value (). * ov-flt-complex.cc (octave_float_complex_scalar::resize): Use Complex (0) for fill value instead of ComplexNDArray::resize_fill_value (). * ov-range.cc (octave_range::resize): Use 0 for fill value instead of NDArray::resize_fill_value (). * ov-scalar.cc (octave_scalar::resize): Use 0 for fill value instead of NDArray::resize_fill_value (). * ov-str-mat.cc (octave_char_matrix_str::resize): Use 0 for fill value instead of charNDArray::resize_fill_value ().
author John W. Eaton <jwe@octave.org>
date Thu, 10 May 2012 16:31:02 -0400
parents 3a9a56999ce5
children 954e1a180375
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1 /*
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13968
diff changeset
3 Copyright (C) 1995-2012 John W. Eaton
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
4 Copyright (C) 2010 VZLU Prague
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
5
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
7
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
11 option) any later version.
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
12
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
16 for more details.
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
17
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
20 <http://www.gnu.org/licenses/>.
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
21
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
22 */
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
23
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
26 #endif
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
27
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
28 #include "error.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
29 #include "str-vec.h"
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
30
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
31 #include "oct-map.h"
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
32 #include "utils.h"
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
33
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
34 octave_fields::octave_fields (const string_vector& fields)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
35 : rep (new fields_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_idx_type n = fields.numel ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
38 for (octave_idx_type i = 0; i < n; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
39 (*rep)[fields(i)] = i;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
40 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
41
10766
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
42 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
43 : rep (new fields_rep)
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
44 {
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
45 octave_idx_type n = 0;
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
46 while (*fields)
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
47 (*rep)[std::string (*fields++)] = n++;
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
48 }
f0304c545588 make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents: 10764
diff changeset
49
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
50 bool
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
51 octave_fields::isfield (const std::string& field) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
52 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
53 return rep->find (field) != rep->end ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
54 }
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 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
57 octave_fields::getfield (const std::string& field) const
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 fields_rep::iterator p = rep->find (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
60 return (p != rep->end ()) ? p->second : -1;
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
63 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
64 octave_fields::getfield (const std::string& field)
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 fields_rep::iterator p = rep->find (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
67 if (p != rep->end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
68 return p->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
69 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
70 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
71 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
72 octave_idx_type n = rep->size ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
73 return (*rep)[field] = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
74 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
75 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
76
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
77 octave_idx_type
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
78 octave_fields::rmfield (const std::string& field)
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 fields_rep::iterator p = rep->find (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
81 if (p == rep->end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
82 return -1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
83 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
84 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
85 octave_idx_type n = p->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
86 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
87 rep->erase (field);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
88 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
89 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
90 if (q->second >= n)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
91 q->second--;
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
94 return n;
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
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
98 void
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
99 octave_fields::orderfields (Array<octave_idx_type>& perm)
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 octave_idx_type n = rep->size ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
102 perm.clear (n, 1);
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 make_unique ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
105 octave_idx_type i = 0;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
106 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
107 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
108 octave_idx_type j = q->second;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
109 q->second = i;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
110 perm(i++) = j;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
111 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
112 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
113
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
114 bool
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
115 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
116 octave_idx_type* perm) const
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
117 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
118 bool retval = true;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
119
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
120 iterator p = begin (), q = other.begin ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
121 for (; p != end () && q != other.end (); p++, q++)
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 if (p->first == q->first)
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
124 perm[p->second] = q->second;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
125 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
126 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
127 retval = false;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
128 break;
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 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
131
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
132 retval = (p == end () && q == other.end ());
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
135 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
136
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
137 bool
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
138 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
139 Array<octave_idx_type>& perm) const
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
140 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
141 octave_idx_type n = nfields ();
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
142 if (perm.length () != n)
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
143 perm.clear (1, n);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
144
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
145 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
146 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
147
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
148 string_vector
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
149 octave_fields::fieldnames (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
150 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
151 octave_idx_type n = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
152 string_vector retval(n);
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 for (iterator p = begin (); p != end (); p++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
155 retval.xelem(p->second) = p->first;
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
158 }
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 octave_value
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
161 octave_scalar_map::getfield (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
162 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
163 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
164 return (idx >= 0) ? xvals[idx] : octave_value ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
165 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
166
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
167 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
168 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
169 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
170 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
171 if (idx < static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
172 xvals[idx] = val;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
173 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
174 xvals.push_back (val);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
175 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
176
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
177 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
178 octave_scalar_map::rmfield (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
179 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
180 octave_idx_type idx = xkeys.rmfield (k);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
181 if (idx >= 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
182 xvals.erase (xvals.begin () + idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
183 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
184
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
185 octave_scalar_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
186 octave_scalar_map::orderfields (void) const
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 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
189 return orderfields (perm);
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
192 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
193 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
194 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
195 octave_scalar_map retval (xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
196 retval.xkeys.orderfields (perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
197
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
198 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
199 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
200 retval.xvals[i] = xvals[perm.xelem(i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
201
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
202 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
203 }
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 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
206 octave_scalar_map::orderfields (const octave_scalar_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
207 Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
208 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
209 if (xkeys.is_same (other.xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
210 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
211 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
212 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
213 octave_scalar_map retval (other.xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
214 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
215 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
216 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
217 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
218 retval.xvals[i] = xvals[perm.xelem(i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
219 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
220 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
221 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
222
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
223 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
224 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
225 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
226
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
227 octave_value
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
228 octave_scalar_map::contents (const std::string& k) const
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 return getfield (k);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
231 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
232
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
233 octave_value&
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
234 octave_scalar_map::contents (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
235 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
236 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
237 if (idx >= static_cast<octave_idx_type> (xvals.size ()))
11055
b721e12140cc fix off-by-1 error in octave_scalar_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10937
diff changeset
238 xvals.resize (idx+1);
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
239 return xvals[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
240 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
241
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
242 octave_map::octave_map (const octave_scalar_map& m)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
243 : xkeys (m.xkeys), xvals (), dimensions (1, 1)
10742
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_idx_type nf = m.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
246 xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
247 for (octave_idx_type i = 0; i < nf; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
248 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
249 xvals.push_back (Cell (dimensions));
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
250 xvals[i].xelem(0) = m.xvals[i];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
251 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
252 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
253
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
254 octave_map::octave_map (const Octave_map& m)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
255 : 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
256 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
257 for (iterator p = begin (); p != end (); p++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
258 contents(p) = m.contents (key (p));
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 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
261 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
262
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
263 Cell
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
264 octave_map::getfield (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
265 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
266 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
267 return (idx >= 0) ? xvals[idx] : Cell ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
268 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
269
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
270 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
271 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
272 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
273 if (nfields () == 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
274 dimensions = val.dims ();
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 (val.dims () == dimensions)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
277 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
278 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
279 if (idx < static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
280 xvals[idx] = val;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
281 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
282 xvals.push_back (val);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
283 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
284 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
285 error ("octave_map::setfield: internal error");
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
288 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
289 octave_map::rmfield (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
290 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
291 octave_idx_type idx = xkeys.rmfield (k);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
292 if (idx >= 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
293 xvals.erase (xvals.begin () + idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
294 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
295
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
296 octave_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
297 octave_map::orderfields (void) const
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 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
300 return orderfields (perm);
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
303 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
304 octave_map::orderfields (Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
305 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
306 octave_map retval (xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
307 retval.xkeys.orderfields (perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
308
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
309 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
310 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
311 retval.xvals[i] = xvals[perm.xelem(i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
312
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
313 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
314 }
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 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
317 octave_map::orderfields (const octave_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
318 Array<octave_idx_type>& perm) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
319 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
320 if (xkeys.is_same (other.xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
321 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
322 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
323 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
324 octave_map retval (other.xkeys);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
325 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
326 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
327 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
328 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
329 retval.xvals[i] = xvals[perm.xelem(i)];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
330 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
331 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
332 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
333
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
334 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
335 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
336 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
337
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
338 Cell
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
339 octave_map::contents (const std::string& k) const
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 return getfield (k);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
342 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
343
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
344 Cell&
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
345 octave_map::contents (const std::string& k)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
346 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
347 octave_idx_type idx = xkeys.getfield (k);
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
348 if (idx >= static_cast<octave_idx_type> (xvals.size ()))
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
349 xvals.push_back (Cell (dimensions)); // auto-set correct dims.
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
350 return xvals[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
351 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
352
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
353 void
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
354 octave_map::extract_scalar (octave_scalar_map& dest,
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
355 octave_idx_type idx) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
356 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
357 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
358 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
359 dest.xvals[i] = xvals[i](idx);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
360 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
361
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
362 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
363 octave_map::checkelem (octave_idx_type n) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
364 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
365 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
366
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
367 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
368 extract_scalar (retval, compute_index (n, dimensions));
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
371 }
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 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
374 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
375 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
376 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
377
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
378 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
379 extract_scalar (retval, compute_index (i, j, dimensions));
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
382 }
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 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
385 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
386 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
387 octave_scalar_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
388
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
389 // Optimize this so that there is just one check.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
390 extract_scalar (retval, compute_index (ra_idx, dimensions));
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
393 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
394
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
395 octave_scalar_map
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
396 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
397 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
398 octave_scalar_map retval (xkeys);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
399
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
400 extract_scalar (retval, n);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
401
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
402 return retval;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
403 }
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 bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
406 octave_map::fast_elem_insert (octave_idx_type n,
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
407 const octave_scalar_map& rhs)
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
408 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
409 bool retval = false;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
410
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
411 octave_idx_type nf = nfields ();
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
412 if (rhs.xkeys.is_same (xkeys))
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 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
415 xvals[i](n) = rhs.xvals[i];
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 retval = true;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
418 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
419 else
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
420 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
421 OCTAVE_LOCAL_BUFFER (octave_idx_type, perm, nf);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
422 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
423 {
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
424 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
425 xvals[i](n) = rhs.xvals[perm[i]];
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 retval = true;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
428 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
429 }
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
430
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
431 return retval;
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
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
434 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
435 octave_map::squeeze (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
436 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
437 octave_map retval (*this);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
438 octave_idx_type nf = nfields ();
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 retval.dimensions = dimensions.squeeze ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
441
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
442 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
443 retval.xvals[i] = xvals[i].squeeze ();
10742
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 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
446
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
447 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
448 }
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 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
451 ## test preservation of xkeys by squeeze
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
452 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
453 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
454 %! assert (fieldnames (squeeze (x)), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
455 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
456
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
457 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
458 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
459 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
460 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
461 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
462
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
463 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
464 retval.xvals[i] = xvals[i].permute (vec, inv);
10742
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 // FIXME:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
467 // There is no dim_vector::permute for technical reasons.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
468 // 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
469 // 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
470 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
471 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
472 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
473 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
474 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
475 dummy = dummy.permute (vec, inv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
476 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
477 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
478
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
479 retval.optimize_dimensions ();
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
482 }
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 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
485 ## test preservation of key order by permute
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
486 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
487 %! x(1,1,1,1).d = 10; x(3,5,1,7).a = "b"; x(2,4,1,7).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
488 %! assert (fieldnames (permute (x, [3, 4, 1, 2])), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
489 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
490
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
491 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
492 octave_map::transpose (void) const
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 assert (ndims () == 2);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
495
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
496 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
497
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
498 retval.dimensions = dim_vector (dimensions (1), dimensions (0));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
499
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
500 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
501 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
502 retval.xvals[i] = xvals[i].transpose ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
503
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
504 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
505
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
506 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
507 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
508
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
509 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
510 ## test preservation of key order by transpose
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
511 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
512 %! x(1,1).d = 10; x(3,5).a = "b"; x(2,4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
513 %! assert (fieldnames (transpose (x)), {"d"; "a"; "f"});
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
514 %! assert (fieldnames (x'), {"d"; "a"; "f"});
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
515 %! assert (fieldnames (x.'), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
516 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
517
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
518 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
519 octave_map::reshape (const dim_vector& dv) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
520 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
521 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
522 retval.dimensions = dv;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
523
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
524 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
525 if (nf > 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
526 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
527 retval.xvals.reserve (nf);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
528 for (octave_idx_type i = 0; i < nf; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
529 retval.xvals[i] = xvals[i].reshape (dv);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
530 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
531 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
532 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
533 // 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
534 // Need (?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
535 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
536 dummy.reshape (dv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
537 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
538
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
539 retval.optimize_dimensions ();
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
542 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
543
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
544 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
545 ## test preservation of key order by reshape
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
546 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
547 %! x(1,1).d = 10; x(4,6).a = "b"; x(2,4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
548 %! assert (fieldnames (reshape (x, 3, 8)), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
549 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
550
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
551 void
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
552 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
553 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
554 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
555 if (nf > 0)
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 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
558 {
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
559 if (fill)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14569
diff changeset
560 xvals[i].resize (dv, Matrix ());
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
561 else
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
562 xvals[i].resize (dv);
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
563 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
564 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
565 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
566 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
567 // 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
568 // Need (?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
569 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
570 dummy.resize (dv);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
571 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
572
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
573 dimensions = dv;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
574 optimize_dimensions ();
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
577 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
578 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
579 octave_map& retval)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
580 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
581 octave_idx_type nf = retval.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
582 retval.xvals.reserve (nf);
10742
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 dim_vector& rd = retval.dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
585 rd.resize (dim+1, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
586 rd(0) = rd(1) = 1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
587 rd(dim) = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
588
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
589 for (octave_idx_type j = 0; j < nf; j++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
590 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
591 retval.xvals.push_back (Cell (rd));
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
592 assert (retval.xvals[j].numel () == n);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
593 for (octave_idx_type i = 0; i < n; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
594 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
595 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
596 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
597
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
598 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
599 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
600 octave_map& retval)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
601 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
602 octave_idx_type nf = retval.nfields ();
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
603 retval.xvals.reserve (nf);
10742
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_LOCAL_BUFFER (Array<octave_value>, field_list, n);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
606
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
607 for (octave_idx_type j = 0; j < nf; j++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
608 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
609 for (octave_idx_type i = 0; i < n; i++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
610 field_list[i] = map_list[i].xvals[j];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
611
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
612 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
613 if (j == 0)
e141bcb1befd implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents: 10763
diff changeset
614 retval.dimensions = retval.xvals[j].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
615 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
616 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
617
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
618 // This is just a wrapper.
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
619 void permute_to_correct_order1 (const octave_scalar_map& ref, const octave_scalar_map& src,
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
620 octave_scalar_map& dest, Array<octave_idx_type>& perm)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
621 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
622 dest = src.orderfields (ref, perm);
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
623 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
624
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
625 // In non-scalar case, we also promote empty structs without fields.
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
626 void permute_to_correct_order1 (const octave_map& ref, const octave_map& src,
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
627 octave_map& dest, Array<octave_idx_type>& perm)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
628 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
629 if (src.nfields () == 0 && src.is_empty ())
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
630 dest = octave_map (src.dims (), ref.keys ());
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
631 else
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
632 dest = src.orderfields (ref, perm);
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
633 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
634
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
635 template <class map>
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
636 static void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
637 permute_to_correct_order (octave_idx_type n, octave_idx_type nf,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
638 octave_idx_type idx, const map *map_list,
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
639 map *new_map_list)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
640 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
641 new_map_list[idx] = map_list[idx];
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
642
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
643 Array<octave_idx_type> perm (dim_vector (1, nf));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
644
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
645 for (octave_idx_type i = 0; i < n; i++)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
646 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
647 if (i == idx)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
648 continue;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
649
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
650 permute_to_correct_order1 (map_list[idx], map_list[i], new_map_list[i], perm);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
651
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
652 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
653 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
654 // Use liboctave exception to be consistent.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
655 (*current_liboctave_error_handler)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
656 ("cat: field names mismatch in concatenating structs");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
657 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
658 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
659 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
660 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
661
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
662
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
663 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
664 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
665 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
666 octave_map retval;
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
667
10763
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
668 // Allow dim = -1, -2 for compatibility, though it makes no difference here.
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
669 if (dim == -1 || dim == -2)
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
670 dim = -dim - 1;
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
671 else if (dim < 0)
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
672 (*current_liboctave_error_handler)
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
673 ("cat: invalid dimension");
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
674
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
675 if (n == 1)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
676 retval = map_list[0];
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
677 else if (n > 1)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
678 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
679 octave_idx_type idx, nf = 0;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
680 for (idx = 0; idx < n; idx++)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
681 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
682 nf = map_list[idx].nfields ();
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
683 if (nf > 0)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
684 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
685 retval.xkeys = map_list[idx].xkeys;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
686 break;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
687 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
688 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
689
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
690 if (nf > 0)
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 // Try the fast case.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
693 bool all_same = true;
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
694 for (octave_idx_type i = 0; i < n; i++)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
695 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
696 all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
697 if (! all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
698 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
699 }
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 if (all_same)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
702 do_cat (dim, n, map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
703 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
704 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
705 // permute all structures to common order.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
706 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
707
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
708 permute_to_correct_order (n, nf, idx, map_list, new_map_list);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
709
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
710 do_cat (dim, n, new_map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
711 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
712
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
713 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
714 else
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 dim_vector& rd = retval.dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
717 rd.resize (dim+1, 1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
718 rd(0) = rd(1) = 1;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
719 rd(dim) = n;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
720 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
721
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
722 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
723 }
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 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
726 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
727
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
728 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
729 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
730 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
731 octave_map retval;
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
732
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
733 // Allow dim = -1, -2 for compatibility, though it makes no difference here.
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
734 if (dim == -1 || dim == -2)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
735 dim = -dim - 1;
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
736 else if (dim < 0)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
737 (*current_liboctave_error_handler)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
738 ("cat: invalid dimension");
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
739
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
740 if (n == 1)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
741 retval = map_list[0];
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
742 else if (n > 1)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
743 {
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
744 octave_idx_type idx, nf = 0;
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
745
10937
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
746 for (idx = 0; idx < n; idx++)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
747 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
748 nf = map_list[idx].nfields ();
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
749 if (nf > 0)
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
750 {
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
751 retval.xkeys = map_list[idx].xkeys;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
752 break;
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
753 }
f42e8c6196c3 tweaks in concatenation of empty structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10766
diff changeset
754 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
755
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
756 // Try the fast case.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
757 bool all_same = true;
13968
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
758
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
759 if (nf > 0)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
760 {
13968
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
761 for (octave_idx_type i = 0; i < n; i++)
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
762 {
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
763 all_same = map_list[idx].xkeys.is_same (map_list[i].xkeys);
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
764
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
765 if (! all_same)
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
766 break;
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
767 }
10742
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
13968
241f68fb48c3 octave_map::cat: avoid indexing beyond end of array
John W. Eaton <jwe@octave.org>
parents: 13754
diff changeset
770 if (all_same && nf > 0)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
771 do_cat (dim, n, map_list, retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
772 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
773 {
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
774 if (nf > 0)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
775 {
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
776 // permute all structures to correct order.
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
777 OCTAVE_LOCAL_BUFFER (octave_map, new_map_list, n);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
778
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
779 permute_to_correct_order (n, nf, idx, map_list, new_map_list);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
780
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
781 do_cat (dim, n, new_map_list, retval);
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
782 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
783 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
784 {
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
785 dim_vector dv = map_list[0].dimensions;
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
786
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
787 for (octave_idx_type i = 1; i < n; i++)
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
788 {
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
789 if (! dv.concat (map_list[i].dimensions, dim))
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
790 {
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
791 error ("dimension mismatch in struct concatenation");
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
792 return retval;
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
793 }
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
794 }
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
795
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
796 retval.dimensions = dv;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
797 }
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 retval.optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
801 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
802
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
803 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
804 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
805
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
806 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
807 ## test preservation of key order by concatenation
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
808 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
809 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
810 %! y(1, 6).f = 11; y(1, 6).a = "c"; y(1, 6).d = 33;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
811 %! assert (fieldnames ([x; y]), {"d"; "a"; "f"});
13754
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
812
e652ff4d1522 don't crash when concatenating structs with no fields
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
813 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
814 %! s = struct ();
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
815 %! sr = [s,s];
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
816 %! sc = [s;s];
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
817 %! sm = [s,s;s,s];
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
818 %! assert (nfields (sr), 0);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
819 %! assert (nfields (sc), 0);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
820 %! assert (nfields (sm), 0);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
821 %! assert (size (sr), [1, 2]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
822 %! assert (size (sc), [2, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
823 %! assert (size (sm), [2, 2]);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
824 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
825
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
826 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
827 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
828 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
829 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
830 octave_idx_type nf = nfields ();
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 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
833 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
834
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
835 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
836 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
837 else
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 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
840 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
841 dummy = dummy.index (i, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
842 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
843 }
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 retval.optimize_dimensions ();
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 return retval;
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
850 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
851 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
852 bool resize_ok) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
853 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
854 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
855 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
856
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
857 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
858 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
859
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
860 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
861 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
862 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
863 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
864 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
865 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
866 dummy = dummy.index (i, j, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
867 retval.dimensions = dummy.dims ();
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
870 retval.optimize_dimensions ();
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
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
875 octave_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
876 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
877 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
878 octave_map retval (xkeys);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
879 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
880
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
881 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
882 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
883
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
884 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
885 retval.dimensions = retval.xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
886 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
887 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
888 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
889 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
890 dummy = dummy.index (ia, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
891 retval.dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
892 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
893
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
894 retval.optimize_dimensions ();
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 return retval;
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
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
899 octave_map
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
900 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
901 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
902 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
903 octave_map retval;
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 switch (n_idx)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
906 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
907 case 1:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
908 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
909 idx_vector i = idx(0).index_vector ();
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 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
912 retval = index (i, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
913 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
914 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
915
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
916 case 2:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
917 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
918 idx_vector i = idx(0).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
919
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
920 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
921 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
922 idx_vector j = idx(1).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
923
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
924 retval = index (i, j, resize_ok);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
925 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
926 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
927 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
928
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
929 default:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
930 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
931 Array<idx_vector> ia (dim_vector (n_idx, 1));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
932
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
933 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
934 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
935 ia(i) = idx(i).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
936
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
937 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
938 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
939 }
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 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
942 retval = index (ia, resize_ok);
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 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
945 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
946
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
947 return retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
948 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
949
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
950 // Perhaps one day these will be optimized. Right now, they just call index.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
951 octave_map
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
952 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
953 {
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
954 return index (idx_vector::colon, k);
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
955 }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
956
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
957 octave_map
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
958 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
959 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
960 static Array<idx_vector> ia (dim_vector (3, 1), idx_vector::colon);
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
961
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
962 ia(2) = k;
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
963 return index (ia);
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
964 }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
965
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
966 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
967 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
968 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
969 if (rhs.xkeys.is_same (xkeys))
10742
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 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
972
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
973 for (octave_idx_type k = 0; k < nf; k++)
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
974 xvals[k].assign (i, rhs.xvals[k], Matrix ());
10742
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 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
977 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
978 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
979 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
980 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
981 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
982 dummy.assign (i, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
983 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
984 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
985
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
986 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
987 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
988 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
989 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
990 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
991 tmp.assign (i, rhs);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
992 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
993 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
994 else
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 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
997 octave_map rhs1 = rhs.orderfields (*this, perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
998 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
999 {
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1000 assert (rhs1.xkeys.is_same (xkeys));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1001 assign (i, rhs1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1002 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1003 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1004 error ("incompatible fields in struct assignment");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1005 }
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1008 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1009 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
1010 const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1011 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1012 if (rhs.xkeys.is_same (xkeys))
10742
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 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1015
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1016 for (octave_idx_type k = 0; k < nf; k++)
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1017 xvals[k].assign (i, j, rhs.xvals[k], Matrix ());
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1018
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1019 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1020 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1021 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1022 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1023 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1024 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1025 dummy.assign (i, j, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1026 dimensions = dummy.dims ();
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1029 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1030 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1031 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1032 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1033 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
1034 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
1035 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1036 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1037 else
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 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1040 octave_map rhs1 = rhs.orderfields (*this, perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1041 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1042 {
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1043 assert (rhs1.xkeys.is_same (xkeys));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1044 assign (i, j, rhs1);
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 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1047 error ("incompatible fields in struct assignment");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1048 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1049 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1050
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1051 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1052 octave_map::assign (const Array<idx_vector>& ia,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1053 const octave_map& rhs)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1054 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1055 if (rhs.xkeys.is_same (xkeys))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1056 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1057 octave_idx_type nf = nfields ();
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 for (octave_idx_type k = 0; k < nf; k++)
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1060 xvals[k].assign (ia, rhs.xvals[k], Matrix ());
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1061
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1062 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1063 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1064 else
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 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1067 Array<char> dummy (dimensions), rhs_dummy (rhs.dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1068 dummy.assign (ia, rhs_dummy);;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1069 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1070 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1071
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1072 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1073 }
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1074 else if (nfields () == 0)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1075 {
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1076 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
1077 tmp.assign (ia, rhs);
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1078 *this = tmp;
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10750
diff changeset
1079 }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1080 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1081 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1082 Array<octave_idx_type> perm;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1083 octave_map rhs1 = rhs.orderfields (*this, perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1084 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1085 {
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1086 assert (rhs1.xkeys.is_same (xkeys));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1087 assign (ia, rhs1);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1088 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1089 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1090 error ("incompatible fields in struct assignment");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1091 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1092 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1093
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1094 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1095 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
1096 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1097 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1098
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1099 switch (n_idx)
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 case 1:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1102 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1103 idx_vector i = idx(0).index_vector ();
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 (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1106 assign (i, rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1107 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1108 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1109
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1110 case 2:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1111 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1112 idx_vector i = idx(0).index_vector ();
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 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1115 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1116 idx_vector j = idx(1).index_vector ();
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 assign (i, j, rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1119 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1120 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1121 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1122
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1123 default:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1124 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1125 Array<idx_vector> ia (dim_vector (n_idx, 1));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1126
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1127 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
1128 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1129 ia(i) = idx(i).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1130
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1131 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1132 break;
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 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1136 assign (ia, rhs);
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 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1139 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1140 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1141
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1142 void
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1143 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
1144 const Cell& rhs)
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1145 {
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1146 Cell tmp;
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1147 iterator p = seek (k);
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1148 Cell& ref = p != end () ? contents (p) : tmp;
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1149
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1150 if (&ref == &tmp)
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1151 ref = Cell (dimensions);
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1152
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1153 ref.assign (idx, rhs);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
1154
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1155 if (! error_state && ref.dims () != dimensions)
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1156 {
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1157 dimensions = ref.dims ();
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1158
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1159 octave_idx_type nf = nfields ();
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1160 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
1161 {
10750
f75e827649a5 struct rewrite: 4 failures remaining
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
1162 if (&xvals[i] != &ref)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14569
diff changeset
1163 xvals[i].resize (dimensions, Matrix ());
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1164 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1165
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1166 optimize_dimensions ();
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1167 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1168
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1169 if (! error_state && &ref == &tmp)
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1170 setfield (k, tmp);
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1171 }
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1172
14568
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1173 /*
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1174 %!test
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1175 %! rhs.b = 1;
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1176 %! a(3) = rhs;
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1177 %! assert ({a.b}, {[], [], 1})
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1178 */
82449d607d20 correctly fill struct arrays for assignments that cause resizing (bug #33178)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1179
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
1180 void
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1181 octave_map::delete_elements (const idx_vector& i)
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 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1184 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1185 xvals[k].delete_elements (i);
10742
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 (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1188 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1189 else
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 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1192 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1193 dummy.delete_elements (i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1194 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1195 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1196
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1197 optimize_dimensions ();
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1200 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1201 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
1202 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1203 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1204 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1205 xvals[k].delete_elements (dim, i);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1206
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1207 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1208 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1209 else
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 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1212 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1213 dummy.delete_elements (dim, i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1214 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1215 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1216
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1217 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1218 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1219
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1220 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1221 octave_map::delete_elements (const Array<idx_vector>& ia)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1222 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1223 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1224 for (octave_idx_type k = 0; k < nf; k++)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1225 xvals[k].delete_elements (ia);
10742
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 if (nf > 0)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1228 dimensions = xvals[0].dims ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1229 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1230 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1231 // Use dummy array. FIXME: Need(?) a better solution.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1232 Array<char> dummy (dimensions);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1233 dummy.delete_elements (ia);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1234 dimensions = dummy.dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1235 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1236
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1237 optimize_dimensions ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1238 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1239
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1240 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1241 octave_map::delete_elements (const octave_value_list& idx)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1242 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1243 octave_idx_type n_idx = idx.length ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1244
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1245 Array<idx_vector> ia (dim_vector (n_idx, 1));
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1246
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1247 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
1248 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1249 ia(i) = idx(i).index_vector ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1250
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1251 if (error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1252 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1253 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1254
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1255 if (! error_state)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1256 delete_elements (ia);
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
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1259 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1260 ## test preservation of key order by indexing
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1261 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1262 %! x(1, 1).d = 10; x(4, 6).a = "b"; x(2, 4).f = 27;
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1263 %! assert (fieldnames (x([1, 2], [2:5])), {"d"; "a"; "f"});
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1264 */
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1265
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1266 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1267 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
1268 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1269 if (nfields () == rb.nfields ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1270 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1271 for (const_iterator pa = begin (); pa != end (); pa++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1272 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1273 const_iterator pb = rb.seek (key(pa));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1274
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1275 if (pb == rb.end ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1276 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1277 error ("field name mismatch in structure concatenation");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1278 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1279 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
1280
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1281 contents(pa).insert (rb.contents(pb), ra_idx);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1282 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1283 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1284 else
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1285 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1286 dim_vector dv = dims ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1287
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1288 if (dv.all_zero ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1289 *this = rb;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1290 else if (! rb.dims ().all_zero ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1291 error ("invalid structure concatenation");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1292 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1293
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1294 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1295 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1296
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1297 void
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1298 octave_map::optimize_dimensions (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1299 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1300 octave_idx_type nf = nfields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1301
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1302 for (octave_idx_type i = 0; i < nf; i++)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1303 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
1304 if (! xvals[i].optimize_dimensions (dimensions))
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1305 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1306 error ("internal error: dimension mismatch across fields in struct");
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1307 break;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1308 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1309 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1310
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1311 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1312
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6946
diff changeset
1313 Octave_map::Octave_map (const dim_vector& dv, const Cell& key_vals)
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1314 : map (), key_list (), dimensions (dv)
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1315 {
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1316 Cell c (dv);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1317
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6946
diff changeset
1318 if (key_vals.is_cellstr ())
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1319 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6946
diff changeset
1320 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
1321 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1322 std::string k = key_vals(i).string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1323 map[k] = c;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1324 key_list.push_back (k);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1325 }
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1326 }
6946
10c7a803b409 [project @ 2007-10-03 14:38:48 by jwe]
jwe
parents: 6639
diff changeset
1327 else
10c7a803b409 [project @ 2007-10-03 14:38:48 by jwe]
jwe
parents: 6639
diff changeset
1328 error ("Octave_map: expecting keys to be cellstr");
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1329 }
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1330
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1331 Octave_map::Octave_map (const octave_map& m)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1332 : map (), key_list (), dimensions (m.dims ())
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1333 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1334 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
1335 map[m.key (p)] = m.contents (p);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1336 const string_vector mkeys = m.fieldnames ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1337 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
1338 key_list.push_back (mkeys(i));
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1339 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10649
diff changeset
1340
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1341 Octave_map
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1342 Octave_map::squeeze (void) const
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1343 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1344 Octave_map retval (dims ().squeeze ());
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1345
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1346 for (const_iterator pa = begin (); pa != end (); pa++)
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1347 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1348 Cell tmp = contents (pa).squeeze ();
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1349
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1350 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1351 break;
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1352
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1353 retval.assign (key (pa), tmp);
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1354 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1355
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1356 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1357 retval.key_list = key_list;
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1358
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1359 return retval;
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1360 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1361
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1362 Octave_map
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1363 Octave_map::permute (const Array<int>& vec, bool inv) const
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1364 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1365 Octave_map retval (dims ());
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1366
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1367 for (const_iterator pa = begin (); pa != end (); pa++)
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1368 {
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1369 Cell tmp = contents (pa).permute (vec, inv);
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1370
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1371 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1372 break;
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1373
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1374 retval.assign (key (pa), tmp);
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1375 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1376
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1377 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1378 retval.key_list = key_list;
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1379
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1380 return retval;
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1381 }
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1382
5328
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1383 Cell&
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1384 Octave_map::contents (const std::string& k)
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1385 {
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1386 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1387
5328
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1388 return map[k];
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1389 }
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
1390
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4219
diff changeset
1391 Cell
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1392 Octave_map::contents (const std::string& k) const
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1393 {
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1394 const_iterator p = seek (k);
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1395
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4219
diff changeset
1396 return p != end () ? p->second : Cell ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1397 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1398
5156
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1399 int
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1400 Octave_map::intfield (const std::string& k, int def_val) const
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1401 {
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1402 int retval = def_val;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1403
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1404 Cell c = contents (k);
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1405
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1406 if (! c.is_empty ())
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1407 retval = c(0).int_value ();
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1408
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1409 return retval;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1410 }
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1411
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1412 std::string
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1413 Octave_map::stringfield (const std::string& k,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1414 const std::string& def_val) const
5156
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1415 {
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1416 std::string retval = def_val;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1417
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1418 Cell c = contents (k);
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1419
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1420 if (! c.is_empty ())
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1421 retval = c(0).string_value ();
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1422
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1423 return retval;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1424 }
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
1425
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
1426 string_vector
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1427 Octave_map::keys (void) const
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1428 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1429 assert (nfields () == key_list.size ());
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1430
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1431 return string_vector (key_list);
1278
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1432 }
606361d34c74 [project @ 1995-04-26 17:40:24 by jwe]
jwe
parents:
diff changeset
1433
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1434 Octave_map
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1435 Octave_map::transpose (void) const
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1436 {
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1437 assert (ndims () == 2);
5593
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1438
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1439 dim_vector dv = dims ();
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1440
5593
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1441 octave_idx_type nr = dv(0);
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1442 octave_idx_type nc = dv(1);
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1443
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1444 dim_vector new_dims (nc, nr);
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1445
edaf21425386 [project @ 2006-01-12 20:57:27 by jwe]
jwe
parents: 5592
diff changeset
1446 Octave_map retval (new_dims);
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1447
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1448 for (const_iterator p = begin (); p != end (); p++)
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1449 retval.assign (key(p), Cell (contents(p).transpose ()));
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1450
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1451 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1452 retval.key_list = key_list;
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1453
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1454 return retval;
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1455 }
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1456
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5539
diff changeset
1457 Octave_map
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1458 Octave_map::reshape (const dim_vector& new_dims) const
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1459 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1460 Octave_map retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1461
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1462 if (new_dims != dims ())
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1463 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1464 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
1465 retval.assign (key(p), contents(p).reshape (new_dims));
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1466
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1467 retval.dimensions = new_dims;
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1468
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1469 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1470 retval.key_list = key_list;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1471 }
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1472 else
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1473 retval = *this;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1474
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1475 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1476 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4563
diff changeset
1477
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1478 void
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1479 Octave_map::resize (const dim_vector& dv, bool fill)
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1480 {
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1481 if (dv != dims ())
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1482 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1483 if (nfields () == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1484 dimensions = dv;
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1485 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1486 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1487 for (const_iterator p = begin (); p != end (); p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1488 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1489 Cell tmp = contents(p);
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1490
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1491 if (fill)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14569
diff changeset
1492 tmp.resize (dv, Matrix ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1493 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1494 tmp.resize (dv);
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1495
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1496 dimensions = dv;
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
1497
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1498 assign (key(p), tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1499 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1500 }
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1501 }
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1502 }
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1503
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
1504 Octave_map
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5156
diff changeset
1505 Octave_map::concat (const Octave_map& rb, const Array<octave_idx_type>& ra_idx)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4730
diff changeset
1506 {
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1507 Octave_map retval;
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1508
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1509 if (nfields () == rb.nfields ())
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1510 {
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1511 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
1512 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1513 const_iterator pb = rb.seek (key(pa));
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1514
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1515 if (pb == rb.end ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1516 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1517 error ("field name mismatch in structure concatenation");
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 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
1520
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1521 retval.assign (key(pa),
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1522 contents(pa).insert (rb.contents(pb), ra_idx));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1523 }
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1524
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1525 // Preserve order of keys.
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1526 retval.key_list = key_list;
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
1527 }
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1528 else
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1529 {
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1530 dim_vector dv = dims ();
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1531
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1532 if (dv.all_zero ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1533 retval = rb;
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1534 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1535 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1536 dv = rb.dims ();
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1537
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1538 if (dv.all_zero ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1539 retval = *this;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1540 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1541 error ("invalid structure concatenation");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1542 }
7959
a73b80cd1f10 allow empty matrix by cell (or struct) concatentation
John W. Eaton <jwe@octave.org>
parents: 7046
diff changeset
1543 }
4937
4cf211c83158 [project @ 2004-08-06 16:21:20 by jwe]
jwe
parents: 4936
diff changeset
1544
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
1545 return retval;
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4730
diff changeset
1546 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4730
diff changeset
1547
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1548 static bool
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1549 keys_ok (const Octave_map& a, const Octave_map& b, string_vector& keys)
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1550 {
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1551 bool retval = false;
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1552
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1553 keys = string_vector ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1554
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1555 if (a.nfields () == 0)
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1556 {
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1557 keys = b.keys ();
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1558 retval = true;
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1559 }
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1560 else
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1561 {
8503
8ba2ee57c594 remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents: 8294
diff changeset
1562 string_vector a_keys = a.keys().sort ();
8ba2ee57c594 remove qsort in favor of sort
Jaroslav Hajek <highegg@gmail.com>
parents: 8294
diff changeset
1563 string_vector b_keys = b.keys().sort ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1564
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1565 octave_idx_type a_len = a_keys.length ();
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1566 octave_idx_type b_len = b_keys.length ();
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1567
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1568 if (a_len == b_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1569 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1570 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
1571 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1572 if (a_keys[i] != b_keys[i])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1573 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1574 }
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1575
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1576 keys = a_keys;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1577 retval = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1578 }
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1579 }
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1580
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1581 done:
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1582 return retval;
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1583 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1584
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1585 Octave_map&
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1586 Octave_map::maybe_delete_elements (const octave_value_list& idx)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1587 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1588 string_vector t_keys = keys();
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1589 octave_idx_type len = t_keys.length ();
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1590
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1591 if (len > 0)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1592 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1593 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
1594 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1595 std::string k = t_keys[i];
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1596
10649
64472dd48517 cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
1597 contents(k).delete_elements (idx);
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1598
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1599 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1600 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1601 }
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1602
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1603 if (!error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1604 dimensions = contents(t_keys[0]).dims();
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1605 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1606
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1607 return *this;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1608 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1609
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
1610 Octave_map&
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4219
diff changeset
1611 Octave_map::assign (const octave_value_list& idx, const Octave_map& rhs)
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1612 {
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1613 string_vector t_keys;
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1614
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1615 if (keys_ok (*this, rhs, t_keys))
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1616 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5156
diff changeset
1617 octave_idx_type len = t_keys.length ();
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1618
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1619 if (len == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1620 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1621 Cell tmp_lhs (dims ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1622 Cell tmp_rhs (rhs.dims ());
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1623
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1624 tmp_lhs.assign (idx, tmp_rhs, Matrix ());
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1625
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1626 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1627 resize (tmp_lhs.dims ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1628 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1629 error ("size mismatch in structure assignment");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1630 }
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1631 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1632 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1633 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
1634 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1635 std::string k = t_keys[i];
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1636
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1637 Cell t_rhs = rhs.contents (k);
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 5900
diff changeset
1638
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1639 assign (idx, k, t_rhs);
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1640
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1641 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1642 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1643 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1644 }
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1645 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1646 else
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1647 error ("field name mismatch in structure assignment");
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1648
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1649 return *this;
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1650 }
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
1651
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1652 Octave_map&
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1653 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
1654 const Cell& rhs)
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1655 {
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1656 Cell tmp;
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1657
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1658 if (contains (k))
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
1659 tmp = map[k];
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1660 else
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1661 tmp = Cell (dimensions);
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1662
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1663 tmp.assign (idx, rhs);
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1664
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1665 if (! error_state)
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1666 {
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1667 dim_vector tmp_dims = tmp.dims ();
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1668
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1669 if (tmp_dims != dimensions)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1670 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1671 for (iterator p = begin (); p != end (); p++)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14569
diff changeset
1672 contents(p).resize (tmp_dims, Matrix ());
9127
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1673
5ec4dc52c131 fix empty struct indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
1674 dimensions = tmp_dims;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1675 }
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1676
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1677 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1678
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1679 map[k] = tmp;
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1680 }
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1681
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1682 return *this;
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1683 }
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
1684
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1685 Octave_map&
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1686 Octave_map::assign (const std::string& k, const octave_value& rhs)
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1687 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1688 if (nfields () == 0)
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1689 {
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1690 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1691
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1692 map[k] = Cell (rhs);
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1693
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1694 dimensions = dim_vector (1, 1);
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1695 }
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1696 else
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1697 {
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1698 dim_vector dv = dims ();
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1699
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1700 if (dv.all_ones ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1701 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1702 maybe_add_to_key_list (k);
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1703
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1704 map[k] = Cell (rhs);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1705 }
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1706 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1707 error ("invalid structure assignment");
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1708 }
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1709
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1710 return *this;
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1711 }
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1712
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4625
diff changeset
1713 Octave_map&
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1714 Octave_map::assign (const std::string& k, const Cell& rhs)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1715 {
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6609
diff changeset
1716 if (nfields () == 0)
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4562
diff changeset
1717 {
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1718 maybe_add_to_key_list (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1719
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
1720 map[k] = rhs;
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4562
diff changeset
1721
4730
c88afb778c41 [project @ 2004-02-02 18:31:09 by jwe]
jwe
parents: 4675
diff changeset
1722 dimensions = rhs.dims ();
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4562
diff changeset
1723 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1724 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1725 {
4562
4699bdb4c362 [project @ 2003-10-28 21:14:07 by jwe]
jwe
parents: 4561
diff changeset
1726 if (dims () == rhs.dims ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1727 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1728 maybe_add_to_key_list (k);
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
1729
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1730 map[k] = rhs;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1731 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1732 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1733 error ("invalid structure assignment");
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1734 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1735
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1736 return *this;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1737 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1738
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1739 Octave_map
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
1740 Octave_map::index (const octave_value_list& idx, bool resize_ok) const
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1741 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1742 Octave_map retval;
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1743
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1744 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
1745
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1746 if (n_idx > 0)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1747 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1748 Array<idx_vector> ra_idx (dim_vector (n_idx, 1));
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1749
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1750 for (octave_idx_type i = 0; i < n_idx; i++)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1751 {
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1752 ra_idx(i) = idx(i).index_vector ();
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1753 if (error_state)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1754 break;
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1755 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1756
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1757 if (! error_state)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1758 {
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1759 for (const_iterator p = begin (); p != end (); p++)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1760 {
9379
d77fa87c47d8 oct-map.cc: preserve key order
John W. Eaton <jwe@octave.org>
parents: 9127
diff changeset
1761 Cell tmp = contents (p);
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1762
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9392
diff changeset
1763 tmp = tmp.Array<octave_value>::index (ra_idx, resize_ok);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1764
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1765 if (error_state)
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1766 break;
8294
b2a6309b2d87 oct-map.cc: copy key_list in indexing functions
John W. Eaton <jwe@octave.org>
parents: 8175
diff changeset
1767
8682
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1768 retval.assign (key(p), tmp);
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1769 }
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1770
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1771 // Preserve order of keys.
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1772 retval.key_list = key_list;
38968f09f7ca optimize Octave_map::index
Jaroslav Hajek <highegg@gmail.com>
parents: 8679
diff changeset
1773 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1774 }
5435
66ad03c58880 [project @ 2005-08-31 20:41:47 by jwe]
jwe
parents: 5329
diff changeset
1775 else
5539
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5435
diff changeset
1776 retval = *this;
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1777
5539
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5435
diff changeset
1778 return retval;
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
1779 }