Mercurial > hg > octave-jordi
annotate src/oct-map.h @ 10743:cb3ed842bd30
make the new interface more backward compatible
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 23 Jun 2010 12:21:49 +0200 |
parents | 604e13a89c7f |
children | 4716e2e17118 |
rev | line source |
---|---|
746 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 2000, 2002, 2003, 2004, 2005, |
8920 | 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 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
746 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
746 | 22 |
23 */ | |
24 | |
25 #if !defined (octave_oct_map_h) | |
26 #define octave_oct_map_h 1 | |
27 | |
6059 | 28 #include <algorithm> |
4219 | 29 #include <map> |
746 | 30 |
4513 | 31 #include "Cell.h" |
3931 | 32 #include "oct-obj.h" |
746 | 33 |
1755 | 34 class string_vector; |
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++; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
83 if (--rep->count) |
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, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
127 Array<octave_idx_type>& perm) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
128 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
129 bool is_same (const octave_fields& other) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
130 { return rep == other.rep; } |
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 // Returns the fields as a vector of strings. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
133 string_vector fieldnames (void) const; |
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 void clear (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
136 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
137 *this = octave_fields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
138 } |
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 |
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 class OCTINTERP_API |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
143 octave_scalar_map |
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 octave_scalar_map (const octave_fields& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
146 : keys (k), vals (k.nfields ()) { } |
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 public: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
149 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
150 octave_scalar_map (void) : keys (), vals () { } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
151 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
152 octave_scalar_map (const string_vector& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
153 : keys (k), vals (k.length ()) { } |
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 octave_scalar_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
156 : keys (m.keys), vals(m.vals) { } |
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& operator = (const octave_scalar_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
159 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
160 keys = m.keys; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
161 vals = m.vals; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
162 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
163 return *this; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
164 } |
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 // 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
|
167 // 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
|
168 typedef octave_fields::const_iterator const_iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
169 typedef const_iterator iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
170 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
171 const_iterator begin (void) const { return keys.begin (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
172 const_iterator end (void) const { return keys.end (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
173 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
174 const_iterator seek (const std::string& k) const { return keys.seek (k); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
175 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
176 std::string key (const_iterator p) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
177 { return keys.key (p); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
178 octave_idx_type index (const_iterator p) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
179 { return keys.index (p); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
180 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
181 const octave_value& contents (const_iterator p) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
182 { return vals[keys.index (p)]; } |
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 octave_value& contents (iterator p) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
185 { return vals[keys.index (p)]; } |
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 const octave_value& contents (octave_idx_type i) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
188 { return vals[i]; } |
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 octave_value& contents (octave_idx_type i) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
191 { return vals[i]; } |
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 // number of fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
194 octave_idx_type nfields (void) const { return keys.nfields (); } |
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 // check whether a field exists. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
197 bool isfield (const std::string& name) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
198 { return keys.isfield (name); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
199 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
200 string_vector fieldnames (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
201 { return keys.fieldnames (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
202 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
203 // 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
|
204 octave_value getfield (const std::string& key) const; |
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 // 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
|
207 void setfield (const std::string& key, const octave_value& val); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
208 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
209 // remove a given field. do nothing if not exist. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
210 void rmfield (const std::string& key); |
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 // 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
|
213 octave_scalar_map orderfields (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
214 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
|
215 octave_scalar_map orderfields (const octave_scalar_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
216 Array<octave_idx_type>& perm) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
217 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
218 // aka getfield/setfield, but the latter returns a reference. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
219 octave_value contents (const std::string& k) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
220 octave_value& contents (const std::string& k); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
221 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
222 void clear (void) |
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 keys.clear (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
225 vals.clear (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
226 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
227 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
228 friend class octave_map; |
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 private: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
231 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
232 octave_fields keys; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
233 std::vector<octave_value> vals; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
234 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
235 }; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
236 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
237 class OCTINTERP_API |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
238 octave_map |
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 octave_map (const octave_fields& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
241 : keys (k), vals (k.nfields ()), dimensions () { } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
242 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
243 public: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
244 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
245 octave_map (void) : keys (), vals (), dimensions () { } |
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 octave_map (const dim_vector& dv) : keys (), vals (), dimensions (dv) { } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
248 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
249 octave_map (const string_vector& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
250 : keys (k), vals (k.length ()), dimensions (1, 1) { } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
251 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
252 octave_map (const dim_vector& dv, const string_vector& k) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
253 : keys (k), vals (k.length ()), dimensions (dv) { } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
254 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
255 octave_map (const octave_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
256 : keys (m.keys), vals (m.vals), dimensions (m.dimensions) { } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
257 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
258 octave_map (const octave_scalar_map& m); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
259 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
260 octave_map (const Octave_map& m); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
261 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
262 octave_map& operator = (const octave_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
263 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
264 keys = m.keys; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
265 vals = m.vals; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
266 dimensions = m.dimensions; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
267 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
268 return *this; |
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 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
271 // 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
|
272 // 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
|
273 typedef octave_fields::const_iterator const_iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
274 typedef const_iterator iterator; |
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 const_iterator begin (void) const { return keys.begin (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
277 const_iterator end (void) const { return keys.end (); } |
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 const_iterator seek (const std::string& k) const { return keys.seek (k); } |
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 std::string key (const_iterator p) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
282 { return keys.key (p); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
283 octave_idx_type index (const_iterator p) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
284 { return keys.index (p); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
285 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
286 const Cell& contents (const_iterator p) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
287 { return vals[keys.index (p)]; } |
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 Cell& contents (iterator p) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
290 { return vals[keys.index (p)]; } |
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 const Cell& contents (octave_idx_type i) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
293 { return vals[i]; } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
294 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
295 Cell& contents (octave_idx_type i) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
296 { return vals[i]; } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
297 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
298 // number of fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
299 octave_idx_type nfields (void) const { return keys.nfields (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
300 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
301 // check whether a field exists. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
302 bool isfield (const std::string& name) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
303 { return keys.isfield (name); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
304 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
305 bool contains (const std::string& name) const |
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
306 { return isfield (name); } |
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
307 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
308 string_vector fieldnames (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
309 { return keys.fieldnames (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
310 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
311 // 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
|
312 Cell getfield (const std::string& key) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
313 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
314 // 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
|
315 // correct dimensions. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
316 void setfield (const std::string& key, const Cell& val); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
317 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
318 // remove a given field. do nothing if not exist. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
319 void rmfield (const std::string& key); |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
320 void del (const std::string& key) { rmfield (key); } |
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 // 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
|
323 octave_map orderfields (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
324 octave_map orderfields (Array<octave_idx_type>& perm) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
325 octave_map orderfields (const octave_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
326 Array<octave_idx_type>& perm) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
327 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
328 // aka getfield/setfield, but the latter returns a reference. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
329 Cell contents (const std::string& k) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
330 Cell& contents (const std::string& k); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
331 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
332 void clear (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
333 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
334 keys.clear (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
335 vals.clear (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
336 } |
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 // The Array-like methods. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
339 octave_idx_type numel (void) const { return dimensions.numel (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
340 octave_idx_type length (void) const { return numel (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
341 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
342 octave_idx_type rows (void) const { return dimensions(0); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
343 octave_idx_type cols (void) const { return dimensions(1); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
344 octave_idx_type columns (void) const { return dimensions(1); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
345 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
346 // Extract a scalar substructure. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
347 octave_scalar_map checkelem (octave_idx_type n) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
348 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
|
349 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
350 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
351 checkelem (const Array<octave_idx_type>& ra_idx) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
352 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
353 octave_map squeeze (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
354 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
355 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
|
356 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
357 dim_vector dims (void) const { return dimensions; } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
358 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
359 int ndims (void) const { return dimensions.length (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
360 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
361 octave_map transpose (void) const; |
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 octave_map reshape (const dim_vector& dv) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
364 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
365 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
|
366 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
367 static octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
368 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
|
369 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
370 static octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
371 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
|
372 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
373 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
|
374 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
375 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
|
376 bool resize_ok = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
377 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
378 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
|
379 bool resize_ok = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
380 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
381 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
|
382 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
383 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
|
384 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
385 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
|
386 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
387 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
|
388 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
389 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
|
390 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
391 void delete_elements (const idx_vector& i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
392 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
393 void delete_elements (int dim, const idx_vector& i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
394 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
395 void delete_elements (const Array<idx_vector>& ia); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
396 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
397 void delete_elements (const octave_value_list&); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
398 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
399 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
|
400 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
401 private: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
402 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
403 octave_fields keys; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
404 std::vector<Cell> vals; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
405 dim_vector dimensions; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
406 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
407 void optimize_dimensions (void); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
408 void extract_scalar (octave_scalar_map& dest, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
409 octave_idx_type index) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
410 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
|
411 const octave_scalar_map *map_list, octave_map& retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
412 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
|
413 const octave_map *map_list, octave_map& retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
414 }; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
415 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
416 // 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
|
417 // each other. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
418 |
746 | 419 class |
6109 | 420 OCTINTERP_API |
3931 | 421 Octave_map |
746 | 422 { |
423 public: | |
4219 | 424 |
4513 | 425 typedef std::map<std::string, Cell>::iterator iterator; |
426 typedef std::map<std::string, Cell>::const_iterator const_iterator; | |
4219 | 427 |
5880 | 428 typedef std::list<std::string>::iterator key_list_iterator; |
429 typedef std::list<std::string>::const_iterator const_key_list_iterator; | |
430 | |
4744 | 431 // Warning! You should always use at least two dimensions. |
432 | |
5880 | 433 Octave_map (const dim_vector& dv = dim_vector (0, 0), |
10313 | 434 const Cell& key_vals = Cell ()); |
746 | 435 |
4587 | 436 Octave_map (const std::string& k, const octave_value& value) |
5880 | 437 : map (), key_list (), dimensions (1, 1) |
438 { | |
439 map[k] = value; | |
440 key_list.push_back (k); | |
441 } | |
4513 | 442 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10313
diff
changeset
|
443 Octave_map (const string_vector& sv, |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10313
diff
changeset
|
444 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
|
445 : 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
|
446 { |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8679
diff
changeset
|
447 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
|
448 { |
10313 | 449 std::string k = sv[i]; |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10313
diff
changeset
|
450 map[k] = Cell (dv); |
10313 | 451 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
|
452 } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8679
diff
changeset
|
453 } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8679
diff
changeset
|
454 |
4587 | 455 Octave_map (const std::string& k, const Cell& vals) |
5880 | 456 : map (), key_list (), dimensions (vals.dims ()) |
457 { | |
458 map[k] = vals; | |
459 key_list.push_back (k); | |
460 } | |
746 | 461 |
4587 | 462 Octave_map (const std::string& k, const octave_value_list& val_list) |
5880 | 463 : map (), key_list (), dimensions (1, val_list.length ()) |
464 { | |
465 map[k] = val_list; | |
466 key_list.push_back (k); | |
467 } | |
4435 | 468 |
5880 | 469 Octave_map (const Octave_map& m) |
470 : map (m.map), key_list (m.key_list), dimensions (m.dimensions) { } | |
3931 | 471 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
472 Octave_map (const octave_map& m); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
473 |
3931 | 474 Octave_map& operator = (const Octave_map& m) |
475 { | |
476 if (this != &m) | |
10313 | 477 { |
478 map = m.map; | |
479 key_list = m.key_list; | |
480 dimensions = m.dimensions; | |
481 } | |
4561 | 482 |
3931 | 483 return *this; |
484 } | |
746 | 485 |
486 ~Octave_map (void) { } | |
1279 | 487 |
7046 | 488 Octave_map squeeze (void) const; |
489 | |
490 Octave_map permute (const Array<int>& vec, bool inv = false) const; | |
491 | |
3932 | 492 // This is the number of keys. |
6639 | 493 octave_idx_type nfields (void) const { return map.size (); } |
3931 | 494 |
4587 | 495 void del (const std::string& k) |
4219 | 496 { |
4587 | 497 iterator p = map.find (k); |
5881 | 498 |
4219 | 499 if (p != map.end ()) |
10313 | 500 { |
501 map.erase (p); | |
5880 | 502 |
10313 | 503 key_list_iterator q |
504 = std::find (key_list.begin (), key_list.end (), k); | |
5881 | 505 |
10313 | 506 assert (q != key_list.end ()); |
5881 | 507 |
10313 | 508 key_list.erase (q); |
509 } | |
4219 | 510 } |
3931 | 511 |
4219 | 512 iterator begin (void) { return iterator (map.begin ()); } |
513 const_iterator begin (void) const { return const_iterator (map.begin ()); } | |
514 | |
515 iterator end (void) { return iterator (map.end ()); } | |
516 const_iterator end (void) const { return const_iterator (map.end ()); } | |
3931 | 517 |
4219 | 518 std::string key (const_iterator p) const { return p->first; } |
3931 | 519 |
5328 | 520 Cell& contents (const std::string& k); |
4675 | 521 Cell contents (const std::string& k) const; |
3931 | 522 |
9129
17a3df1d992b
avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
523 Cell& contents (iterator p) |
17a3df1d992b
avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
524 { return p->second; } |
5328 | 525 |
4513 | 526 Cell contents (const_iterator p) const |
9129
17a3df1d992b
avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
527 { return p->second; } |
3931 | 528 |
5156 | 529 int intfield (const std::string& k, int def_val = 0) const; |
530 | |
531 std::string stringfield (const std::string& k, | |
10313 | 532 const std::string& def_val = std::string ()) const; |
5156 | 533 |
5328 | 534 iterator seek (const std::string& k) { return map.find (k); } |
4587 | 535 const_iterator seek (const std::string& k) const { return map.find (k); } |
4219 | 536 |
4817 | 537 bool contains (const std::string& k) const |
4587 | 538 { return (seek (k) != map.end ()); } |
3931 | 539 |
5925 | 540 void clear (void) |
541 { | |
542 map.clear (); | |
543 key_list.clear (); | |
544 } | |
3931 | 545 |
3933 | 546 string_vector keys (void) const; |
3931 | 547 |
5275 | 548 octave_idx_type rows (void) const { return dimensions(0); } |
4561 | 549 |
5275 | 550 octave_idx_type columns (void) const { return dimensions(1); } |
4200 | 551 |
4561 | 552 dim_vector dims (void) const { return dimensions; } |
4200 | 553 |
5435 | 554 int ndims (void) const { return dimensions.length (); } |
555 | |
5571 | 556 Octave_map transpose (void) const; |
557 | |
4567 | 558 Octave_map reshape (const dim_vector& new_dims) const; |
559 | |
5781 | 560 void resize (const dim_vector& dv, bool fill = false); |
4936 | 561 |
6639 | 562 octave_idx_type numel (void) const { return dimensions.numel (); } |
3932 | 563 |
5275 | 564 Octave_map concat (const Octave_map& rb, const Array<octave_idx_type>& ra_idx); |
4806 | 565 |
5592 | 566 Octave_map& maybe_delete_elements (const octave_value_list& idx); |
567 | |
4513 | 568 Octave_map& assign (const octave_value_list& idx, const Octave_map& rhs); |
4197 | 569 |
4587 | 570 Octave_map& assign (const octave_value_list& idx, const std::string& k, |
10313 | 571 const Cell& rhs); |
3932 | 572 |
4675 | 573 Octave_map& assign (const std::string& k, const octave_value& rhs); |
574 | |
4587 | 575 Octave_map& assign (const std::string& k, const Cell& rhs); |
3933 | 576 |
7046 | 577 Octave_map index (const octave_value_list& idx, |
10313 | 578 bool resize_ok = false) const; |
7046 | 579 |
3931 | 580 private: |
581 | |
582 // The map of names to values. | |
4513 | 583 std::map<std::string, Cell> map; |
3932 | 584 |
5880 | 585 // An extra list of keys, so we can keep track of the order the keys |
586 // are added for compatibility with you know what. | |
587 std::list<std::string> key_list; | |
588 | |
4561 | 589 // The current size. |
590 mutable dim_vector dimensions; | |
5880 | 591 |
592 void maybe_add_to_key_list (const std::string& k) | |
5925 | 593 { |
594 if (! contains (k)) | |
10313 | 595 key_list.push_back (k); |
5925 | 596 } |
746 | 597 }; |
598 | |
599 #endif |