annotate src/oct-map.h @ 10761:12dfe91e9fab

more bkw compatibility for octave_map
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 01 Jul 2010 09:31:54 +0200
parents 76079e505f9d
children e141bcb1befd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
1 /*
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 2000, 2002, 2003, 2004, 2005,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8785
diff changeset
4 2006, 2007, 2009 John W. Eaton
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
5 Copyright (C) 2010 VZLU Prague
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
6
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
8
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
12 option) any later version.
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
13
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
17 for more details.
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
18
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6959
diff changeset
21 <http://www.gnu.org/licenses/>.
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
22
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
23 */
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
24
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
25 #if !defined (octave_oct_map_h)
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
26 #define octave_oct_map_h 1
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
27
6059
8fd77759707c [project @ 2006-10-18 02:21:22 by jwe]
jwe
parents: 5925
diff changeset
28 #include <algorithm>
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
29 #include <map>
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
30
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
31 #include "Cell.h"
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
32 #include "oct-obj.h"
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
33
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1737
diff changeset
34 class string_vector;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1737
diff changeset
35
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
36 // A class holding a map field->index. Supports reference-counting.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
37 class OCTINTERP_API
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
38 octave_fields
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
39 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
40 class fields_rep : public std::map<std::string, octave_idx_type>
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
41 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
42 public:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
43 fields_rep (void) : std::map<std::string, octave_idx_type> (), count (1) { }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
44 fields_rep (const fields_rep& other)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
45 : std::map<std::string, octave_idx_type> (other), count (1) { }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
46
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
47 int count;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
48
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
49 private:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
50 fields_rep& operator = (const fields_rep&); // no assignment!
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
51 };
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
52
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
53 fields_rep *rep;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
54
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
55 static fields_rep nil_rep;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
56
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
57 public:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
58
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
59 octave_fields (void) : rep (&nil_rep) { rep->count++; }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
60 octave_fields (const string_vector&);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
61
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
62 ~octave_fields (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
63 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
64 if (--rep->count == 0)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
65 delete rep;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
66 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
67
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
68 void make_unique (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
69 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
70 if (rep->count > 1)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
71 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
72 --rep->count;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
73 rep = new fields_rep (*rep);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
74 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
75 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
76
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
77 octave_fields (const octave_fields& o) : rep (o.rep) { rep->count++; }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
78
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
79 octave_fields&
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
80 operator = (const octave_fields& o)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
81 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
82 o.rep->count++;
10747
58c1b5402588 fix a showstopping bug in octave_fields reference counting
Jaroslav Hajek <highegg@gmail.com>
parents: 10746
diff changeset
83 if (--rep->count == 0)
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
84 delete rep;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
85 rep = o.rep;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
86
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
87 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
88 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
89
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
90 // constant iteration support. non-const iteration intentionally unsupported.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
91
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
92 typedef std::map<std::string, octave_idx_type>::const_iterator const_iterator;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
93 typedef const_iterator iterator;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
94
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
95 const_iterator begin (void) const { return rep->begin (); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
96 const_iterator end (void) const { return rep->end (); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
97
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
98 std::string key (const_iterator p) const { return p->first; }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
99 octave_idx_type index (const_iterator p) const { return p->second; }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
100
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
101 const_iterator seek (const std::string& k) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
102 { return rep->find (k); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
103
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
104 // high-level methods.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
105
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
106 // number of fields.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
107 octave_idx_type nfields (void) const { return rep->size (); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
108
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
109 // check whether a field exists.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
110 bool isfield (const std::string& name) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
111
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
112 // get index of field. return -1 if not exist
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
113 octave_idx_type getfield (const std::string& name) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
114 // get index of field. add if not exist
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
115 octave_idx_type getfield (const std::string& name);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
116 // remove field and return the index. -1 if didn't exist.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
117 octave_idx_type rmfield (const std::string& name);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
118
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
119 // order the fields of this map. creates a permutation
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
120 // used to order the fields.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
121 void orderfields (Array<octave_idx_type>& perm);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
122
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
123 // compares two instances for equality up to order of fields.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
124 // returns a permutation needed to bring the fields of *other*
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
125 // into the order of *this*.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
126 bool equal_up_to_order (const octave_fields& other,
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
127 octave_idx_type* perm) const;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
128
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
129 bool equal_up_to_order (const octave_fields& other,
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
130 Array<octave_idx_type>& perm) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
131
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
132 bool is_same (const octave_fields& other) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
133 { return rep == other.rep; }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
134
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
135 // Returns the fields as a vector of strings.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
136 string_vector fieldnames (void) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
137
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
138 void clear (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
139 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
140 *this = octave_fields ();
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
141 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
142 };
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
143
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
144
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
145 class OCTINTERP_API
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
146 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
147 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
148 octave_scalar_map (const octave_fields& k)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
149 : xkeys (k), xvals (k.nfields ()) { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
150
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
151 public:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
152
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
153 octave_scalar_map (void) : xkeys (), xvals () { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
154
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
155 octave_scalar_map (const string_vector& k)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
156 : xkeys (k), xvals (k.length ()) { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
157
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
158 octave_scalar_map (const octave_scalar_map& m)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
159 : xkeys (m.xkeys), xvals(m.xvals) { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
160
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
161 octave_scalar_map& operator = (const octave_scalar_map& m)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
162 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
163 xkeys = m.xkeys;
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
164 xvals = m.xvals;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
165
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
166 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
167 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
168
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
169 // iteration support. note that both const and non-const iterators are the
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
170 // same. The const/non-const distinction is made by the key & contents method.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
171 typedef octave_fields::const_iterator const_iterator;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
172 typedef const_iterator iterator;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
173
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
174 const_iterator begin (void) const { return xkeys.begin (); }
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
175 const_iterator end (void) const { return xkeys.end (); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
176
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
177 const_iterator seek (const std::string& k) const { return xkeys.seek (k); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
178
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
179 std::string key (const_iterator p) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
180 { return xkeys.key (p); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
181 octave_idx_type index (const_iterator p) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
182 { return xkeys.index (p); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
183
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
184 const octave_value& contents (const_iterator p) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
185 { return xvals[xkeys.index (p)]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
186
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
187 octave_value& contents (iterator p)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
188 { return xvals[xkeys.index (p)]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
189
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
190 const octave_value& contents (octave_idx_type i) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
191 { return xvals[i]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
192
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
193 octave_value& contents (octave_idx_type i)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
194 { return xvals[i]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
195
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
196 // number of fields.
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
197 octave_idx_type nfields (void) const { return xkeys.nfields (); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
198
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
199 // check whether a field exists.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
200 bool isfield (const std::string& name) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
201 { return xkeys.isfield (name); }
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
202
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
203 bool contains (const std::string& name) const
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
204 { return isfield (name); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
205
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
206 string_vector fieldnames (void) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
207 { return xkeys.fieldnames (); }
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
208
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
209 string_vector keys (void) const
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
210 { return fieldnames (); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
211
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
212 // get contents of a given field. empty value if not exist.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
213 octave_value getfield (const std::string& key) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
214
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
215 // set contents of a given field. add if not exist.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
216 void setfield (const std::string& key, const octave_value& val);
10761
12dfe91e9fab more bkw compatibility for octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
217 void assign (const std::string& k, const octave_value& val)
12dfe91e9fab more bkw compatibility for octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
218 { setfield (k, val); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
219
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
220 // remove a given field. do nothing if not exist.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
221 void rmfield (const std::string& key);
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
222 void del (const std::string& k) { rmfield (k); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
223
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
224 // return a copy with fields ordered, optionally along with permutation.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
225 octave_scalar_map orderfields (void) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
226 octave_scalar_map orderfields (Array<octave_idx_type>& perm) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
227 octave_scalar_map orderfields (const octave_scalar_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
228 Array<octave_idx_type>& perm) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
229
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
230 // aka getfield/setfield, but the latter returns a reference.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
231 octave_value contents (const std::string& k) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
232 octave_value& contents (const std::string& k);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
233
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
234 void clear (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
235 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
236 xkeys.clear ();
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
237 xvals.clear ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
238 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
239
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
240 friend class octave_map;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
241
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
242 private:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
243
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
244 octave_fields xkeys;
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
245 std::vector<octave_value> xvals;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
246
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
247 };
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
248
10757
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
249 template<>
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
250 inline octave_scalar_map octave_value_extract<octave_scalar_map> (const octave_value& v)
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
251 { return v.scalar_map_value (); }
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
252
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
253 class OCTINTERP_API
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
254 octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
255 {
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
256 octave_map (const octave_fields& k)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
257 : xkeys (k), xvals (k.nfields ()), dimensions () { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
258
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
259 octave_map (const dim_vector& dv, const octave_fields& k)
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
260 : xkeys (k), xvals (k.nfields (), Cell (dv)), dimensions (dv) { }
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
261
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
262 public:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
263
10756
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
264 typedef octave_scalar_map element_type;
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10755
diff changeset
265
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
266 octave_map (void) : xkeys (), xvals (), dimensions () { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
267
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
268 octave_map (const dim_vector& dv) : xkeys (), xvals (), dimensions (dv) { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
269
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
270 octave_map (const string_vector& k)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
271 : xkeys (k), xvals (k.length ()), dimensions (1, 1) { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
272
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
273 octave_map (const dim_vector& dv, const string_vector& k)
10753
bee1b1a2e29a yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents: 10749
diff changeset
274 : xkeys (k), xvals (k.length (), Cell (dv)), dimensions (dv) { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
275
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
276 octave_map (const octave_map& m)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
277 : xkeys (m.xkeys), xvals (m.xvals), dimensions (m.dimensions) { }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
278
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
279 octave_map (const octave_scalar_map& m);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
280
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
281 octave_map (const Octave_map& m);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
282
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
283 octave_map& operator = (const octave_map& m)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
284 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
285 xkeys = m.xkeys;
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
286 xvals = m.xvals;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
287 dimensions = m.dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
288
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
289 return *this;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
290 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
291
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
292 // iteration support. note that both const and non-const iterators are the
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
293 // same. The const/non-const distinction is made by the key & contents method.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
294 typedef octave_fields::const_iterator const_iterator;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
295 typedef const_iterator iterator;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
296
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
297 const_iterator begin (void) const { return xkeys.begin (); }
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
298 const_iterator end (void) const { return xkeys.end (); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
299
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
300 const_iterator seek (const std::string& k) const { return xkeys.seek (k); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
301
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
302 std::string key (const_iterator p) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
303 { return xkeys.key (p); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
304 octave_idx_type index (const_iterator p) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
305 { return xkeys.index (p); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
306
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
307 const Cell& contents (const_iterator p) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
308 { return xvals[xkeys.index (p)]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
309
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
310 Cell& contents (iterator p)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
311 { return xvals[xkeys.index (p)]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
312
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
313 const Cell& contents (octave_idx_type i) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
314 { return xvals[i]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
315
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
316 Cell& contents (octave_idx_type i)
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
317 { return xvals[i]; }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
318
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
319 // number of fields.
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
320 octave_idx_type nfields (void) const { return xkeys.nfields (); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
321
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
322 // check whether a field exists.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
323 bool isfield (const std::string& name) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
324 { return xkeys.isfield (name); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
325
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
326 bool contains (const std::string& name) const
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
327 { return isfield (name); }
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
328
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
329 string_vector fieldnames (void) const
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
330 { return xkeys.fieldnames (); }
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
331
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
332 string_vector keys (void) const
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
333 { return fieldnames (); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
334
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
335 // get contents of a given field. empty value if not exist.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
336 Cell getfield (const std::string& key) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
337
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
338 // set contents of a given field. add if not exist. checks for
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
339 // correct dimensions.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
340 void setfield (const std::string& key, const Cell& val);
10761
12dfe91e9fab more bkw compatibility for octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
341 void assign (const std::string& k, const Cell& val)
12dfe91e9fab more bkw compatibility for octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10760
diff changeset
342 { setfield (k, val); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
343
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
344 // remove a given field. do nothing if not exist.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
345 void rmfield (const std::string& key);
10744
4716e2e17118 fix octave_map::extract_scalar
Jaroslav Hajek <highegg@gmail.com>
parents: 10743
diff changeset
346 void del (const std::string& k) { rmfield (k); }
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
347
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
348 // return a copy with fields ordered, optionally along with permutation.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
349 octave_map orderfields (void) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
350 octave_map orderfields (Array<octave_idx_type>& perm) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
351 octave_map orderfields (const octave_map& other,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
352 Array<octave_idx_type>& perm) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
353
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
354 // aka getfield/setfield, but the latter returns a reference.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
355 Cell contents (const std::string& k) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
356 Cell& contents (const std::string& k);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
357
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
358 void clear (void)
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
359 {
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
360 xkeys.clear ();
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
361 xvals.clear ();
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
362 }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
363
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
364 // The Array-like methods.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
365 octave_idx_type numel (void) const { return dimensions.numel (); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
366 octave_idx_type length (void) const { return numel (); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
367
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
368 octave_idx_type rows (void) const { return dimensions(0); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
369 octave_idx_type cols (void) const { return dimensions(1); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
370 octave_idx_type columns (void) const { return dimensions(1); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
371
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
372 // Extract a scalar substructure.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
373 octave_scalar_map checkelem (octave_idx_type n) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
374 octave_scalar_map checkelem (octave_idx_type i, octave_idx_type j) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
375
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
376 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
377 checkelem (const Array<octave_idx_type>& ra_idx) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
378
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
379 octave_scalar_map operator () (octave_idx_type n) const
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
380 { return checkelem (n); }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
381 octave_scalar_map operator () (octave_idx_type i, octave_idx_type j) const
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
382 { return checkelem (i, j); }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
383
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
384 octave_scalar_map
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
385 operator () (const Array<octave_idx_type>& ra_idx) const
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
386 { return checkelem (ra_idx); }
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
387
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
388 octave_map squeeze (void) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
389
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
390 octave_map permute (const Array<int>& vec, bool inv = false) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
391
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
392 dim_vector dims (void) const { return dimensions; }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
393
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
394 int ndims (void) const { return dimensions.length (); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
395
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
396 octave_map transpose (void) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
397
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
398 octave_map reshape (const dim_vector& dv) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
399
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
400 void resize (const dim_vector& dv, bool fill = false);
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
401
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
402 static octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
403 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: 10333
diff changeset
404
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
405 static octave_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
406 cat (int dim, octave_idx_type n, const octave_map *map_list);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
407
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
408 octave_map index (const idx_vector& i, bool resize_ok = false) const;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
409
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
410 octave_map index (const idx_vector& i, const idx_vector& j,
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
411 bool resize_ok = false) const;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
412
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
413 octave_map index (const Array<idx_vector>& ia,
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
414 bool resize_ok = false) const;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
415
10743
cb3ed842bd30 make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
416 octave_map index (const octave_value_list&, bool resize_ok = false) const;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
417
10755
6ba7937a6fa4 more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 10753
diff changeset
418 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
419 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
420
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
421 void assign (const idx_vector& i, const octave_map& rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
422
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
423 void assign (const idx_vector& i, const idx_vector& j, const octave_map& rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
424
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
425 void assign (const Array<idx_vector>& ia, const octave_map& rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
426
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
427 void assign (const octave_value_list&, const octave_map& rhs);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
428
10749
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10747
diff changeset
429 void assign (const octave_value_list& idx, const std::string& k,
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10747
diff changeset
430 const Cell& rhs);
df1a3e0ebbff important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10747
diff changeset
431
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
432 void delete_elements (const idx_vector& i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
433
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
434 void delete_elements (int dim, const idx_vector& i);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
435
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
436 void delete_elements (const Array<idx_vector>& ia);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
437
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
438 void delete_elements (const octave_value_list&);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
439
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
440 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: 10333
diff changeset
441
10760
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
442 // like checkelem, but no check.
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
443 octave_scalar_map fast_elem_extract (octave_idx_type n) const;
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
444
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
445 // element assignment, no bounds check
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
446 bool fast_elem_insert (octave_idx_type n, const octave_scalar_map& rhs);
76079e505f9d optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents: 10757
diff changeset
447
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
448 private:
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
449
10746
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
450 octave_fields xkeys;
93422177b697 more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 10744
diff changeset
451 std::vector<Cell> xvals;
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
452 dim_vector dimensions;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
453
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
454 void optimize_dimensions (void);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
455 void extract_scalar (octave_scalar_map& dest,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
456 octave_idx_type index) const;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
457 static void do_cat (int dim, octave_idx_type n,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
458 const octave_scalar_map *map_list, octave_map& retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
459 static void do_cat (int dim, octave_idx_type n,
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
460 const octave_map *map_list, octave_map& retval);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
461 };
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
462
10757
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
463 template<>
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
464 inline octave_map octave_value_extract<octave_map> (const octave_value& v)
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
465 { return v.map_value (); }
1cc44f3ec814 templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
466
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
467 // The original Octave_map object. Octave_map and octave_map are convertible to
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
468 // each other.
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
469
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
470 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 6059
diff changeset
471 OCTINTERP_API
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
472 Octave_map
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
473 {
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
474 public:
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
475
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
476 typedef std::map<std::string, Cell>::iterator iterator;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
477 typedef std::map<std::string, Cell>::const_iterator const_iterator;
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
478
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
479 typedef std::list<std::string>::iterator key_list_iterator;
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
480 typedef std::list<std::string>::const_iterator const_key_list_iterator;
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
481
4744
7dcb696159ac [project @ 2004-02-06 05:46:22 by jwe]
jwe
parents: 4675
diff changeset
482 // Warning! You should always use at least two dimensions.
7dcb696159ac [project @ 2004-02-06 05:46:22 by jwe]
jwe
parents: 4675
diff changeset
483
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
484 Octave_map (const dim_vector& dv = dim_vector (0, 0),
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
485 const Cell& key_vals = Cell ());
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
486
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
487 Octave_map (const std::string& k, const octave_value& value)
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
488 : map (), key_list (), dimensions (1, 1)
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
489 {
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
490 map[k] = value;
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
491 key_list.push_back (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
492 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
493
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10313
diff changeset
494 Octave_map (const string_vector& sv,
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10313
diff changeset
495 const dim_vector& dv = dim_vector (0, 0))
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10313
diff changeset
496 : map (), key_list (), dimensions (dv)
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
497 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
498 for (octave_idx_type i = 0; i < sv.length (); i++)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
499 {
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
500 std::string k = sv[i];
10333
0c42b6b7da24 imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents: 10313
diff changeset
501 map[k] = Cell (dv);
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
502 key_list.push_back (k);
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
503 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
504 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
505
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
506 Octave_map (const std::string& k, const Cell& vals)
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
507 : map (), key_list (), dimensions (vals.dims ())
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
508 {
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
509 map[k] = vals;
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
510 key_list.push_back (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
511 }
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
512
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
513 Octave_map (const std::string& k, const octave_value_list& val_list)
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
514 : map (), key_list (), dimensions (1, val_list.length ())
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
515 {
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
516 map[k] = val_list;
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
517 key_list.push_back (k);
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
518 }
4435
dd7af4fa1942 [project @ 2003-06-23 17:52:36 by jwe]
jwe
parents: 4219
diff changeset
519
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
520 Octave_map (const Octave_map& m)
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
521 : map (m.map), key_list (m.key_list), dimensions (m.dimensions) { }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
522
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
523 Octave_map (const octave_map& m);
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10333
diff changeset
524
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
525 Octave_map& operator = (const Octave_map& m)
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
526 {
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
527 if (this != &m)
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
528 {
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
529 map = m.map;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
530 key_list = m.key_list;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
531 dimensions = m.dimensions;
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
532 }
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
533
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
534 return *this;
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
535 }
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
536
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
537 ~Octave_map (void) { }
1279
f146197d9d37 [project @ 1995-04-26 17:41:20 by jwe]
jwe
parents: 1009
diff changeset
538
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
539 Octave_map squeeze (void) const;
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
540
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
541 Octave_map permute (const Array<int>& vec, bool inv = false) const;
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
542
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
543 // This is the number of keys.
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6109
diff changeset
544 octave_idx_type nfields (void) const { return map.size (); }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
545
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
546 void del (const std::string& k)
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
547 {
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
548 iterator p = map.find (k);
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
549
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
550 if (p != map.end ())
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
551 {
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
552 map.erase (p);
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
553
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
554 key_list_iterator q
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
555 = std::find (key_list.begin (), key_list.end (), k);
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
556
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
557 assert (q != key_list.end ());
5881
70b3f8f1a793 [project @ 2006-07-08 03:54:17 by jwe]
jwe
parents: 5880
diff changeset
558
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
559 key_list.erase (q);
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
560 }
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
561 }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
562
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
563 iterator begin (void) { return iterator (map.begin ()); }
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
564 const_iterator begin (void) const { return const_iterator (map.begin ()); }
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
565
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
566 iterator end (void) { return iterator (map.end ()); }
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
567 const_iterator end (void) const { return const_iterator (map.end ()); }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
568
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
569 std::string key (const_iterator p) const { return p->first; }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
570
5328
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
571 Cell& contents (const std::string& k);
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4587
diff changeset
572 Cell contents (const std::string& k) const;
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
573
9129
17a3df1d992b avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
574 Cell& contents (iterator p)
17a3df1d992b avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
575 { return p->second; }
5328
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
576
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
577 Cell contents (const_iterator p) const
9129
17a3df1d992b avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
578 { return p->second; }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
579
5156
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
580 int intfield (const std::string& k, int def_val = 0) const;
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
581
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
582 std::string stringfield (const std::string& k,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
583 const std::string& def_val = std::string ()) const;
5156
7c3b22bafedc [project @ 2005-02-22 17:42:15 by jwe]
jwe
parents: 5105
diff changeset
584
5328
322ab0da00f8 [project @ 2005-05-02 10:48:43 by jwe]
jwe
parents: 5307
diff changeset
585 iterator seek (const std::string& k) { return map.find (k); }
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
586 const_iterator seek (const std::string& k) const { return map.find (k); }
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
587
4817
6430596f2238 [project @ 2004-03-04 21:13:33 by jwe]
jwe
parents: 4806
diff changeset
588 bool contains (const std::string& k) const
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
589 { return (seek (k) != map.end ()); }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
590
5925
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
591 void clear (void)
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
592 {
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
593 map.clear ();
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
594 key_list.clear ();
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
595 }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
596
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
597 string_vector keys (void) const;
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
598
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5156
diff changeset
599 octave_idx_type rows (void) const { return dimensions(0); }
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
600
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5156
diff changeset
601 octave_idx_type columns (void) const { return dimensions(1); }
4200
1f04df06e1a6 [project @ 2002-11-22 16:25:49 by jwe]
jwe
parents: 4197
diff changeset
602
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
603 dim_vector dims (void) const { return dimensions; }
4200
1f04df06e1a6 [project @ 2002-11-22 16:25:49 by jwe]
jwe
parents: 4197
diff changeset
604
5435
66ad03c58880 [project @ 2005-08-31 20:41:47 by jwe]
jwe
parents: 5328
diff changeset
605 int ndims (void) const { return dimensions.length (); }
66ad03c58880 [project @ 2005-08-31 20:41:47 by jwe]
jwe
parents: 5328
diff changeset
606
5571
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5435
diff changeset
607 Octave_map transpose (void) const;
9fc532d861d4 [project @ 2005-12-12 20:45:16 by jwe]
jwe
parents: 5435
diff changeset
608
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4561
diff changeset
609 Octave_map reshape (const dim_vector& new_dims) const;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4561
diff changeset
610
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5731
diff changeset
611 void resize (const dim_vector& dv, bool fill = false);
4936
e63617efbd3f [project @ 2004-08-06 16:18:17 by jwe]
jwe
parents: 4915
diff changeset
612
6639
ed74670db09b [project @ 2007-05-21 19:47:22 by jwe]
jwe
parents: 6109
diff changeset
613 octave_idx_type numel (void) const { return dimensions.numel (); }
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
614
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5156
diff changeset
615 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: 4744
diff changeset
616
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5571
diff changeset
617 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
618
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
619 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
620
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
621 Octave_map& assign (const octave_value_list& idx, const std::string& k,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
622 const Cell& rhs);
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
623
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4587
diff changeset
624 Octave_map& assign (const std::string& k, const octave_value& rhs);
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4587
diff changeset
625
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
626 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
627
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
628 Octave_map index (const octave_value_list& idx,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
629 bool resize_ok = false) const;
7046
fbf8576cf399 [project @ 2007-10-22 12:12:20 by dbateman]
dbateman
parents: 7017
diff changeset
630
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
631 private:
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
632
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
633 // The map of names to values.
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
634 std::map<std::string, Cell> map;
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
635
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
636 // An extra list of keys, so we can keep track of the order the keys
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
637 // are added for compatibility with you know what.
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
638 std::list<std::string> key_list;
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
639
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
640 // The current size.
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
641 mutable dim_vector dimensions;
5880
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
642
84ca47e311b3 [project @ 2006-07-06 22:34:48 by jwe]
jwe
parents: 5781
diff changeset
643 void maybe_add_to_key_list (const std::string& k)
5925
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
644 {
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
645 if (! contains (k))
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
646 key_list.push_back (k);
5925
fe5cedbf3806 [project @ 2006-08-14 19:08:36 by jwe]
jwe
parents: 5882
diff changeset
647 }
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
648 };
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
649
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
650 #endif