Mercurial > hg > octave-jordi
annotate src/oct-map.h @ 11298:cb94bdc74670
defaults.cc (FEXEC_PATH): only call set_exec_path if nargin is greater than zero
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 26 Nov 2010 02:44:24 -0500 |
parents | 8a3b7e8fcbbc |
children | fd0a3ac60b0e |
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 |
11068
b0eec300d3fc
avoid SID in octave_fields
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
55 static fields_rep *nil_rep (void) |
b0eec300d3fc
avoid SID in octave_fields
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
56 { |
b0eec300d3fc
avoid SID in octave_fields
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
57 static fields_rep *nr = new fields_rep (); |
b0eec300d3fc
avoid SID in octave_fields
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
58 return nr; |
b0eec300d3fc
avoid SID in octave_fields
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
59 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
60 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
61 public: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
62 |
11068
b0eec300d3fc
avoid SID in octave_fields
Jaroslav Hajek <highegg@gmail.com>
parents:
10766
diff
changeset
|
63 octave_fields (void) : rep (nil_rep ()) { rep->count++; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
64 octave_fields (const string_vector&); |
10766
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
65 octave_fields (const char * const *); |
10742
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 ~octave_fields (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
68 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
69 if (--rep->count == 0) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
70 delete rep; |
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 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
73 void make_unique (void) |
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 if (rep->count > 1) |
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 --rep->count; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
78 rep = new fields_rep (*rep); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
79 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
80 } |
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 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
|
83 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
84 octave_fields& |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
85 operator = (const octave_fields& o) |
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 o.rep->count++; |
10747
58c1b5402588
fix a showstopping bug in octave_fields reference counting
Jaroslav Hajek <highegg@gmail.com>
parents:
10746
diff
changeset
|
88 if (--rep->count == 0) |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
89 delete rep; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
90 rep = o.rep; |
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 return *this; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
93 } |
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 // constant iteration support. non-const iteration intentionally unsupported. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
96 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
97 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
|
98 typedef const_iterator iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
99 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
100 const_iterator begin (void) const { return rep->begin (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
101 const_iterator end (void) const { return rep->end (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
102 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
103 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
|
104 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
|
105 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
106 const_iterator seek (const std::string& k) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
107 { return rep->find (k); } |
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 // high-level methods. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
110 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
111 // number of fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
112 octave_idx_type nfields (void) const { return rep->size (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
113 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
114 // check whether a field exists. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
115 bool isfield (const std::string& name) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
116 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
117 // get index of field. return -1 if not exist |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
118 octave_idx_type getfield (const std::string& name) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
119 // get index of field. add if not exist |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
120 octave_idx_type getfield (const std::string& name); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
121 // 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
|
122 octave_idx_type rmfield (const std::string& name); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
123 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
124 // order the fields of this map. creates a permutation |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
125 // used to order the fields. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
126 void orderfields (Array<octave_idx_type>& perm); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
127 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
128 // 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
|
129 // 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
|
130 // into the order of *this*. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
131 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
|
132 octave_idx_type* perm) const; |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
133 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
134 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
|
135 Array<octave_idx_type>& perm) const; |
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 bool is_same (const octave_fields& other) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
138 { return rep == other.rep; } |
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 // Returns the fields as a vector of strings. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
141 string_vector fieldnames (void) const; |
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 void clear (void) |
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 *this = octave_fields (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
146 } |
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 |
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 class OCTINTERP_API |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
151 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
152 { |
10766
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
153 public: |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
154 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
155 octave_scalar_map (const octave_fields& k) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
156 : xkeys (k), xvals (k.nfields ()) { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
157 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
158 octave_scalar_map (void) : xkeys (), xvals () { } |
10742
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 octave_scalar_map (const string_vector& k) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
161 : xkeys (k), xvals (k.length ()) { } |
10742
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 octave_scalar_map (const octave_scalar_map& m) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
164 : xkeys (m.xkeys), 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 octave_scalar_map& operator = (const octave_scalar_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
167 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
168 xkeys = m.xkeys; |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
169 xvals = m.xvals; |
10742
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 return *this; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
172 } |
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 // 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
|
175 // 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
|
176 typedef octave_fields::const_iterator const_iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
177 typedef const_iterator iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
178 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
179 const_iterator begin (void) const { return xkeys.begin (); } |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
180 const_iterator end (void) const { return xkeys.end (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
181 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
182 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
|
183 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
184 std::string key (const_iterator p) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
185 { return xkeys.key (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
186 octave_idx_type index (const_iterator p) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
187 { return xkeys.index (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
188 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
189 const octave_value& contents (const_iterator p) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
190 { return xvals[xkeys.index (p)]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
191 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
192 octave_value& contents (iterator p) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
193 { return xvals[xkeys.index (p)]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
194 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
195 const octave_value& contents (octave_idx_type i) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
196 { return xvals[i]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
197 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
198 octave_value& contents (octave_idx_type i) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
199 { return xvals[i]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
200 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
201 // number of fields. |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
202 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
|
203 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
204 // check whether a field exists. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
205 bool isfield (const std::string& name) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
206 { return xkeys.isfield (name); } |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
207 |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
208 bool contains (const std::string& name) const |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
209 { return isfield (name); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
210 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
211 string_vector fieldnames (void) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
212 { return xkeys.fieldnames (); } |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
213 |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
214 string_vector keys (void) const |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
215 { return fieldnames (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
216 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
217 // 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
|
218 octave_value getfield (const std::string& key) const; |
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 // 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
|
221 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
|
222 void assign (const std::string& k, const octave_value& val) |
11074
8a3b7e8fcbbc
graphics.cc, graphics.h.in, genprops.awk: use octave_map and octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11068
diff
changeset
|
223 { setfield (k, val); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
224 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
225 // remove a given field. do nothing if not exist. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
226 void rmfield (const std::string& key); |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
227 void del (const std::string& k) { rmfield (k); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
228 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
229 // 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
|
230 octave_scalar_map orderfields (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
231 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
|
232 octave_scalar_map orderfields (const octave_scalar_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
233 Array<octave_idx_type>& perm) const; |
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 // aka getfield/setfield, but the latter returns a reference. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
236 octave_value contents (const std::string& k) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
237 octave_value& contents (const std::string& k); |
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 void clear (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
240 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
241 xkeys.clear (); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
242 xvals.clear (); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
243 } |
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 friend class octave_map; |
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 private: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
248 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
249 octave_fields xkeys; |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
250 std::vector<octave_value> xvals; |
10742
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 }; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
253 |
10757
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
254 template<> |
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
255 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
|
256 { return v.scalar_map_value (); } |
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
257 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
258 class OCTINTERP_API |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
259 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
260 { |
10766
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
261 public: |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
262 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
263 octave_map (const octave_fields& k) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
264 : xkeys (k), xvals (k.nfields ()), dimensions () { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
265 |
10753
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10749
diff
changeset
|
266 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
|
267 : 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
|
268 |
10756
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
269 typedef octave_scalar_map element_type; |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
270 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
271 octave_map (void) : xkeys (), xvals (), dimensions () { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
272 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
273 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
|
274 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
275 octave_map (const string_vector& k) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
276 : xkeys (k), xvals (k.length ()), dimensions (1, 1) { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
277 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
278 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
|
279 : 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
|
280 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
281 octave_map (const octave_map& m) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
282 : 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
|
283 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
284 octave_map (const octave_scalar_map& m); |
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 octave_map (const Octave_map& m); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
287 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
288 octave_map& operator = (const octave_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
289 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
290 xkeys = m.xkeys; |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
291 xvals = m.xvals; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
292 dimensions = m.dimensions; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
293 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
294 return *this; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
295 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
296 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
297 // 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
|
298 // 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
|
299 typedef octave_fields::const_iterator const_iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
300 typedef const_iterator iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
301 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
302 const_iterator begin (void) const { return xkeys.begin (); } |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
303 const_iterator end (void) const { return xkeys.end (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
304 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
305 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
|
306 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
307 std::string key (const_iterator p) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
308 { return xkeys.key (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
309 octave_idx_type index (const_iterator p) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
310 { return xkeys.index (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
311 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
312 const Cell& contents (const_iterator p) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
313 { return xvals[xkeys.index (p)]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
314 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
315 Cell& contents (iterator p) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
316 { return xvals[xkeys.index (p)]; } |
10742
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 const Cell& contents (octave_idx_type i) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
319 { return xvals[i]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
320 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
321 Cell& contents (octave_idx_type i) |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
322 { return xvals[i]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
323 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
324 // number of fields. |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
325 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
|
326 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
327 // check whether a field exists. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
328 bool isfield (const std::string& name) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
329 { return xkeys.isfield (name); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
330 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
331 bool contains (const std::string& name) const |
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
332 { return isfield (name); } |
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
333 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
334 string_vector fieldnames (void) const |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
335 { return xkeys.fieldnames (); } |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
336 |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
337 string_vector keys (void) const |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
338 { return fieldnames (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
339 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
340 // 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
|
341 Cell getfield (const std::string& key) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
342 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
343 // 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
|
344 // correct dimensions. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
345 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
|
346 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
|
347 { setfield (k, val); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
348 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
349 // remove a given field. do nothing if not exist. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
350 void rmfield (const std::string& key); |
10744
4716e2e17118
fix octave_map::extract_scalar
Jaroslav Hajek <highegg@gmail.com>
parents:
10743
diff
changeset
|
351 void del (const std::string& k) { rmfield (k); } |
10742
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 // 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
|
354 octave_map orderfields (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
355 octave_map orderfields (Array<octave_idx_type>& perm) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
356 octave_map orderfields (const octave_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
357 Array<octave_idx_type>& perm) const; |
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 // aka getfield/setfield, but the latter returns a reference. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
360 Cell contents (const std::string& k) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
361 Cell& contents (const std::string& k); |
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 void clear (void) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
364 { |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
365 xkeys.clear (); |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
366 xvals.clear (); |
10742
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 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
369 // The Array-like methods. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
370 octave_idx_type numel (void) const { return dimensions.numel (); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
371 octave_idx_type length (void) const { return numel (); } |
10764
e141bcb1befd
implement map concat optimizations for [] operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10761
diff
changeset
|
372 bool is_empty (void) const { return dimensions.any_zero (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
373 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
374 octave_idx_type rows (void) const { return dimensions(0); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
375 octave_idx_type cols (void) const { return dimensions(1); } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
376 octave_idx_type columns (void) const { return dimensions(1); } |
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 // Extract a scalar substructure. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
379 octave_scalar_map checkelem (octave_idx_type n) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
380 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
|
381 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
382 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
383 checkelem (const Array<octave_idx_type>& ra_idx) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
384 |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
385 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
|
386 { return checkelem (n); } |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
387 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
|
388 { return checkelem (i, j); } |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
389 |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
390 octave_scalar_map |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
391 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
|
392 { return checkelem (ra_idx); } |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
393 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
394 octave_map squeeze (void) const; |
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 permute (const Array<int>& vec, bool inv = false) 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 dim_vector dims (void) const { return dimensions; } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
399 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
400 int ndims (void) const { return dimensions.length (); } |
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 octave_map transpose (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
403 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
404 octave_map reshape (const dim_vector& dv) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
405 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
406 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
|
407 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
408 static octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
409 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
|
410 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
411 static octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
412 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
|
413 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
414 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
|
415 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
416 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
|
417 bool resize_ok = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
418 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
419 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
|
420 bool resize_ok = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
421 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
422 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
|
423 |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
424 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
|
425 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
|
426 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
427 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
|
428 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
429 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
|
430 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
431 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
|
432 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
433 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
|
434 |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10747
diff
changeset
|
435 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
|
436 const Cell& rhs); |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10747
diff
changeset
|
437 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
438 void delete_elements (const idx_vector& i); |
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 void delete_elements (int dim, const idx_vector& i); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
441 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
442 void delete_elements (const Array<idx_vector>& ia); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
443 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
444 void delete_elements (const octave_value_list&); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
445 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
446 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
|
447 |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
448 // like checkelem, but no check. |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
449 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
|
450 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
451 // element assignment, no bounds check |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
452 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
|
453 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
454 private: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
455 |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
456 octave_fields xkeys; |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
457 std::vector<Cell> xvals; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
458 dim_vector dimensions; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
459 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
460 void optimize_dimensions (void); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
461 void extract_scalar (octave_scalar_map& dest, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
462 octave_idx_type index) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
463 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
|
464 const octave_scalar_map *map_list, octave_map& retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
465 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
|
466 const octave_map *map_list, octave_map& retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
467 }; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
468 |
10757
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
469 template<> |
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
470 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
|
471 { return v.map_value (); } |
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
472 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
473 // 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
|
474 // each other. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
475 |
746 | 476 class |
6109 | 477 OCTINTERP_API |
3931 | 478 Octave_map |
746 | 479 { |
480 public: | |
4219 | 481 |
4513 | 482 typedef std::map<std::string, Cell>::iterator iterator; |
483 typedef std::map<std::string, Cell>::const_iterator const_iterator; | |
4219 | 484 |
5880 | 485 typedef std::list<std::string>::iterator key_list_iterator; |
486 typedef std::list<std::string>::const_iterator const_key_list_iterator; | |
487 | |
4744 | 488 // Warning! You should always use at least two dimensions. |
489 | |
5880 | 490 Octave_map (const dim_vector& dv = dim_vector (0, 0), |
10313 | 491 const Cell& key_vals = Cell ()); |
746 | 492 |
4587 | 493 Octave_map (const std::string& k, const octave_value& value) |
5880 | 494 : map (), key_list (), dimensions (1, 1) |
495 { | |
496 map[k] = value; | |
497 key_list.push_back (k); | |
498 } | |
4513 | 499 |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10313
diff
changeset
|
500 Octave_map (const string_vector& sv, |
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10313
diff
changeset
|
501 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
|
502 : 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
|
503 { |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8679
diff
changeset
|
504 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
|
505 { |
10313 | 506 std::string k = sv[i]; |
10333
0c42b6b7da24
imfinfo: support image files with multiple frames
Søren Hauberg <soren@hauberg.org>
parents:
10313
diff
changeset
|
507 map[k] = Cell (dv); |
10313 | 508 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
|
509 } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8679
diff
changeset
|
510 } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8679
diff
changeset
|
511 |
4587 | 512 Octave_map (const std::string& k, const Cell& vals) |
5880 | 513 : map (), key_list (), dimensions (vals.dims ()) |
514 { | |
515 map[k] = vals; | |
516 key_list.push_back (k); | |
517 } | |
746 | 518 |
4587 | 519 Octave_map (const std::string& k, const octave_value_list& val_list) |
5880 | 520 : map (), key_list (), dimensions (1, val_list.length ()) |
521 { | |
522 map[k] = val_list; | |
523 key_list.push_back (k); | |
524 } | |
4435 | 525 |
5880 | 526 Octave_map (const Octave_map& m) |
527 : map (m.map), key_list (m.key_list), dimensions (m.dimensions) { } | |
3931 | 528 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
529 Octave_map (const octave_map& m); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
530 |
3931 | 531 Octave_map& operator = (const Octave_map& m) |
532 { | |
533 if (this != &m) | |
10313 | 534 { |
535 map = m.map; | |
536 key_list = m.key_list; | |
537 dimensions = m.dimensions; | |
538 } | |
4561 | 539 |
3931 | 540 return *this; |
541 } | |
746 | 542 |
543 ~Octave_map (void) { } | |
1279 | 544 |
7046 | 545 Octave_map squeeze (void) const; |
546 | |
547 Octave_map permute (const Array<int>& vec, bool inv = false) const; | |
548 | |
3932 | 549 // This is the number of keys. |
6639 | 550 octave_idx_type nfields (void) const { return map.size (); } |
3931 | 551 |
4587 | 552 void del (const std::string& k) |
4219 | 553 { |
4587 | 554 iterator p = map.find (k); |
5881 | 555 |
4219 | 556 if (p != map.end ()) |
10313 | 557 { |
558 map.erase (p); | |
5880 | 559 |
10313 | 560 key_list_iterator q |
561 = std::find (key_list.begin (), key_list.end (), k); | |
5881 | 562 |
10313 | 563 assert (q != key_list.end ()); |
5881 | 564 |
10313 | 565 key_list.erase (q); |
566 } | |
4219 | 567 } |
3931 | 568 |
4219 | 569 iterator begin (void) { return iterator (map.begin ()); } |
570 const_iterator begin (void) const { return const_iterator (map.begin ()); } | |
571 | |
572 iterator end (void) { return iterator (map.end ()); } | |
573 const_iterator end (void) const { return const_iterator (map.end ()); } | |
3931 | 574 |
4219 | 575 std::string key (const_iterator p) const { return p->first; } |
3931 | 576 |
5328 | 577 Cell& contents (const std::string& k); |
4675 | 578 Cell contents (const std::string& k) const; |
3931 | 579 |
9129
17a3df1d992b
avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
580 Cell& contents (iterator p) |
17a3df1d992b
avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
581 { return p->second; } |
5328 | 582 |
4513 | 583 Cell contents (const_iterator p) const |
9129
17a3df1d992b
avoid double lookups when iterating Octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
584 { return p->second; } |
3931 | 585 |
5156 | 586 int intfield (const std::string& k, int def_val = 0) const; |
587 | |
588 std::string stringfield (const std::string& k, | |
10313 | 589 const std::string& def_val = std::string ()) const; |
5156 | 590 |
5328 | 591 iterator seek (const std::string& k) { return map.find (k); } |
4587 | 592 const_iterator seek (const std::string& k) const { return map.find (k); } |
4219 | 593 |
4817 | 594 bool contains (const std::string& k) const |
4587 | 595 { return (seek (k) != map.end ()); } |
3931 | 596 |
5925 | 597 void clear (void) |
598 { | |
599 map.clear (); | |
600 key_list.clear (); | |
601 } | |
3931 | 602 |
3933 | 603 string_vector keys (void) const; |
3931 | 604 |
5275 | 605 octave_idx_type rows (void) const { return dimensions(0); } |
4561 | 606 |
5275 | 607 octave_idx_type columns (void) const { return dimensions(1); } |
4200 | 608 |
4561 | 609 dim_vector dims (void) const { return dimensions; } |
4200 | 610 |
5435 | 611 int ndims (void) const { return dimensions.length (); } |
612 | |
5571 | 613 Octave_map transpose (void) const; |
614 | |
4567 | 615 Octave_map reshape (const dim_vector& new_dims) const; |
616 | |
5781 | 617 void resize (const dim_vector& dv, bool fill = false); |
4936 | 618 |
6639 | 619 octave_idx_type numel (void) const { return dimensions.numel (); } |
3932 | 620 |
5275 | 621 Octave_map concat (const Octave_map& rb, const Array<octave_idx_type>& ra_idx); |
4806 | 622 |
5592 | 623 Octave_map& maybe_delete_elements (const octave_value_list& idx); |
624 | |
4513 | 625 Octave_map& assign (const octave_value_list& idx, const Octave_map& rhs); |
4197 | 626 |
4587 | 627 Octave_map& assign (const octave_value_list& idx, const std::string& k, |
10313 | 628 const Cell& rhs); |
3932 | 629 |
4675 | 630 Octave_map& assign (const std::string& k, const octave_value& rhs); |
631 | |
4587 | 632 Octave_map& assign (const std::string& k, const Cell& rhs); |
3933 | 633 |
7046 | 634 Octave_map index (const octave_value_list& idx, |
10313 | 635 bool resize_ok = false) const; |
7046 | 636 |
3931 | 637 private: |
638 | |
639 // The map of names to values. | |
4513 | 640 std::map<std::string, Cell> map; |
3932 | 641 |
5880 | 642 // An extra list of keys, so we can keep track of the order the keys |
643 // are added for compatibility with you know what. | |
644 std::list<std::string> key_list; | |
645 | |
4561 | 646 // The current size. |
647 mutable dim_vector dimensions; | |
5880 | 648 |
649 void maybe_add_to_key_list (const std::string& k) | |
5925 | 650 { |
651 if (! contains (k)) | |
10313 | 652 key_list.push_back (k); |
5925 | 653 } |
746 | 654 }; |
655 | |
656 #endif |