Mercurial > octave
annotate libinterp/corefcn/oct-map.h @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | adda9f3ac61f |
children | aac27ad79be6 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29922
diff
changeset
|
3 // Copyright (C) 1994-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
746 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
26 #if ! defined (octave_oct_map_h) |
746 | 27 #define octave_oct_map_h 1 |
28 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
30 |
6059 | 31 #include <algorithm> |
4219 | 32 #include <map> |
746 | 33 |
23721
b2d55b52ee51
new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents:
23678
diff
changeset
|
34 #include "oct-refcount.h" |
b2d55b52ee51
new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents:
23678
diff
changeset
|
35 |
4513 | 36 #include "Cell.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
37 #include "ovl.h" |
746 | 38 |
1755 | 39 class string_vector; |
40 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
41 // A class holding a map field->index. Supports reference-counting. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
42 class OCTINTERP_API |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
43 octave_fields |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
44 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
45 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
|
46 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
47 public: |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
48 fields_rep (void) : std::map<std::string, octave_idx_type> (), m_count (1) { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
49 fields_rep (const fields_rep& other) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
50 : std::map<std::string, octave_idx_type> (other), m_count (1) { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
51 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
52 octave::refcount<octave_idx_type> m_count; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
53 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
54 private: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
55 fields_rep& operator = (const fields_rep&); // no assignment! |
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 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
58 fields_rep *m_rep; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
59 |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
60 static fields_rep *nil_rep (void); |
10742
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 public: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
63 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
64 octave_fields (void) : m_rep (nil_rep ()) { m_rep->m_count++; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
65 octave_fields (const string_vector&); |
10766
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
66 octave_fields (const char * const *); |
10742
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 ~octave_fields (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
70 if (--m_rep->m_count == 0) |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
71 delete m_rep; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
73 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
74 void make_unique (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
76 if (m_rep->m_count > 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
78 fields_rep *r = new fields_rep (*m_rep); |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12155
diff
changeset
|
79 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
80 if (--m_rep->m_count == 0) |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
81 delete m_rep; |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12155
diff
changeset
|
82 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
83 m_rep = r; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
85 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
86 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
87 octave_fields (const octave_fields& o) : m_rep (o.m_rep) { m_rep->m_count++; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
88 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 octave_fields& |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
90 operator = (const octave_fields& o) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
91 { |
26391
3774259dd114
oct-map.h: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
92 if (&o != this) |
3774259dd114
oct-map.h: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
93 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
94 o.m_rep->m_count++; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
95 if (--m_rep->m_count == 0) |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
96 delete m_rep; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
97 m_rep = o.m_rep; |
26391
3774259dd114
oct-map.h: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
98 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
99 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 return *this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
101 } |
10742
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 // constant iteration support. non-const iteration intentionally unsupported. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
104 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
105 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
|
106 typedef const_iterator iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
107 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
108 const_iterator begin (void) const { return m_rep->begin (); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
109 const_iterator end (void) const { return m_rep->end (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
110 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
111 const_iterator cbegin (void) const { return m_rep->cbegin (); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
112 const_iterator cend (void) const { return m_rep->cend (); } |
25343
4d7790d9793f
use cbegin, crbegin, cend, and crend and auto decls where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
113 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
114 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
|
115 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
|
116 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
117 const_iterator seek (const std::string& k) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
118 { return m_rep->find (k); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
119 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
120 // high-level methods. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
121 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
122 // number of fields. |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
123 octave_idx_type nfields (void) const { return m_rep->size (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
124 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
125 // check whether a field exists. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
126 bool isfield (const std::string& name) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
127 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
128 // get index of field. return -1 if not exist |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
129 octave_idx_type getfield (const std::string& name) const; |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
130 // get index of field. add if not exist |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
131 octave_idx_type getfield (const std::string& name); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
132 // 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
|
133 octave_idx_type rmfield (const std::string& name); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
134 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
135 // order the fields of this map. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
136 // creates a permutation used to order the fields. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
137 void orderfields (Array<octave_idx_type>& perm); |
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 // 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
|
140 // 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
|
141 // into the order of *this*. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
142 bool equal_up_to_order (const octave_fields& other, |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
143 octave_idx_type *perm) const; |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
144 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
145 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
|
146 Array<octave_idx_type>& perm) const; |
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 bool is_same (const octave_fields& other) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
149 { return m_rep == other.m_rep; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
150 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
151 // Returns the fields as a vector of strings. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
152 string_vector fieldnames (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
153 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
154 void clear (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
155 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 *this = octave_fields (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
157 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
158 }; |
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 class OCTINTERP_API |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
161 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
162 { |
10766
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
163 public: |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
164 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
165 octave_scalar_map (const octave_fields& k) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
166 : m_keys (k), m_vals (k.nfields ()) { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
167 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
168 octave_scalar_map (void) : m_keys (), m_vals () { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
169 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
170 octave_scalar_map (const string_vector& k) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
171 : m_keys (k), m_vals (k.numel ()) { } |
10742
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 octave_scalar_map (const octave_scalar_map& m) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
174 : m_keys (m.m_keys), m_vals (m.m_vals) { } |
23678
dcba41788495
new struct/map constructors
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
175 |
dcba41788495
new struct/map constructors
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
176 octave_scalar_map (const std::map<std::string, octave_value>& m); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
177 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
178 octave_scalar_map& operator = (const octave_scalar_map& m) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
179 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
180 m_keys = m.m_keys; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
181 m_vals = m.m_vals; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
182 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
183 return *this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
184 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
185 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
186 // iteration support. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
187 // note that both const and non-const iterators are the same. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
188 // The const/non-const distinction is made by the key & contents method. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
189 typedef octave_fields::const_iterator const_iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
190 typedef const_iterator iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
191 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
192 const_iterator begin (void) const { return m_keys.begin (); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
193 const_iterator end (void) const { return m_keys.end (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
194 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
195 const_iterator cbegin (void) const { return m_keys.cbegin (); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
196 const_iterator cend (void) const { return m_keys.cend (); } |
25343
4d7790d9793f
use cbegin, crbegin, cend, and crend and auto decls where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
197 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
198 const_iterator seek (const std::string& k) const { return m_keys.seek (k); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
199 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
200 std::string key (const_iterator p) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
201 { return m_keys.key (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
202 octave_idx_type index (const_iterator p) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
203 { return m_keys.index (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
204 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
205 const octave_value& contents (const_iterator p) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
206 { return m_vals[m_keys.index (p)]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
207 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
208 octave_value& contents (iterator p) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
209 { return m_vals[m_keys.index (p)]; } |
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 const octave_value& contents (octave_idx_type i) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
212 { return m_vals[i]; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
213 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
214 octave_value& contents (octave_idx_type i) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
215 { return m_vals[i]; } |
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 // number of fields. |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
218 octave_idx_type nfields (void) const { return m_keys.nfields (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
219 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
220 // check whether a field exists. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
221 bool isfield (const std::string& name) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
222 { return m_keys.isfield (name); } |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
223 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
224 bool contains (const std::string& name) const |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
225 { return isfield (name); } |
10742
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 string_vector fieldnames (void) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
228 { return m_keys.fieldnames (); } |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
229 |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
230 string_vector keys (void) const |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
231 { return fieldnames (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
232 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
233 // get contents of a given field. empty value if not exist. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
234 octave_value getfield (const std::string& key) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
235 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
236 // set contents of a given field. add if not exist. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
237 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
|
238 void assign (const std::string& k, const octave_value& val) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
239 { setfield (k, val); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
240 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
241 // remove a given field. do nothing if not exist. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
242 void rmfield (const std::string& key); |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
243 void del (const std::string& k) { rmfield (k); } |
10742
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 // 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
|
246 octave_scalar_map orderfields (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
247 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
|
248 octave_scalar_map orderfields (const octave_scalar_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
249 Array<octave_idx_type>& perm) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
250 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
251 // aka getfield/setfield, but the latter returns a reference. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
252 octave_value contents (const std::string& k) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
253 octave_value& contents (const std::string& k); |
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 void clear (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
256 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
257 m_keys.clear (); |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
258 m_vals.clear (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
259 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
260 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
261 friend class octave_map; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
262 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
263 private: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
264 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
265 octave_fields m_keys; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
266 std::vector<octave_value> m_vals; |
10742
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 }; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
269 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
270 template <> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
271 inline octave_scalar_map |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
272 octave_value_extract<octave_scalar_map> (const octave_value& v) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
273 { return v.scalar_map_value (); } |
10757
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
274 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
275 class OCTINTERP_API |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
276 octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
277 { |
10766
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
278 public: |
f0304c545588
make map constructors from octave_fields public
Jaroslav Hajek <highegg@gmail.com>
parents:
10764
diff
changeset
|
279 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
280 octave_map (const octave_fields& k) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
281 : m_keys (k), m_vals (k.nfields ()), m_dimensions () { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
282 |
10753
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10749
diff
changeset
|
283 octave_map (const dim_vector& dv, const octave_fields& k) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
284 : m_keys (k), m_vals (k.nfields (), Cell (dv)), m_dimensions (dv) { } |
10753
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10749
diff
changeset
|
285 |
10756
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
286 typedef octave_scalar_map element_type; |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10755
diff
changeset
|
287 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
288 octave_map (void) : m_keys (), m_vals (), m_dimensions () { } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
289 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
290 octave_map (const dim_vector& dv) : m_keys (), m_vals (), m_dimensions (dv) { } |
10742
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 octave_map (const string_vector& k) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
293 : m_keys (k), m_vals (k.numel (), Cell (1, 1)), m_dimensions (1, 1) { } |
10742
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 octave_map (const dim_vector& dv, const string_vector& k) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
296 : m_keys (k), m_vals (k.numel (), Cell (dv)), m_dimensions (dv) { } |
10742
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 octave_map (const octave_map& m) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
299 : m_keys (m.m_keys), m_vals (m.m_vals), m_dimensions (m.m_dimensions) { } |
10742
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 octave_map (const octave_scalar_map& m); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
302 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
303 octave_map& operator = (const octave_map& m) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
304 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
305 m_keys = m.m_keys; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
306 m_vals = m.m_vals; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
307 m_dimensions = m.m_dimensions; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
308 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
309 return *this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
310 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
311 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
312 // iteration support. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
313 // note that both const and non-const iterators are the same. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
314 // The const/non-const distinction is made by the key & contents method. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
315 typedef octave_fields::const_iterator const_iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
316 typedef const_iterator iterator; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
317 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
318 const_iterator begin (void) const { return m_keys.begin (); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
319 const_iterator end (void) const { return m_keys.end (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
320 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
321 const_iterator cbegin (void) const { return m_keys.cbegin (); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
322 const_iterator cend (void) const { return m_keys.cend (); } |
25343
4d7790d9793f
use cbegin, crbegin, cend, and crend and auto decls where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
323 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
324 const_iterator seek (const std::string& k) const { return m_keys.seek (k); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
325 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
326 std::string key (const_iterator p) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
327 { return m_keys.key (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
328 octave_idx_type index (const_iterator p) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
329 { return m_keys.index (p); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
330 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
331 const Cell& contents (const_iterator p) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
332 { return m_vals[m_keys.index (p)]; } |
10742
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 Cell& contents (iterator p) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
335 { return m_vals[m_keys.index (p)]; } |
10742
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 const Cell& contents (octave_idx_type i) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
338 { return m_vals[i]; } |
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 Cell& contents (octave_idx_type i) |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
341 { return m_vals[i]; } |
10742
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 // number of fields. |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
344 octave_idx_type nfields (void) const { return m_keys.nfields (); } |
10742
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 // check whether a field exists. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
347 bool isfield (const std::string& name) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
348 { return m_keys.isfield (name); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
349 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
350 bool contains (const std::string& name) const |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
351 { return isfield (name); } |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
352 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
353 string_vector fieldnames (void) const |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
354 { return m_keys.fieldnames (); } |
10746
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
355 |
93422177b697
more octave_map compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
10744
diff
changeset
|
356 string_vector keys (void) const |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
357 { return fieldnames (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
358 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
359 // get contents of a given field. empty value if not exist. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
360 Cell getfield (const std::string& key) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
361 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
362 // set contents of a given field. add if not exist. checks for |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
363 // correct m_dimensions. |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
364 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
|
365 void assign (const std::string& k, const Cell& val) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
366 { setfield (k, val); } |
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 // remove a given field. do nothing if not exist. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
369 void rmfield (const std::string& key); |
10744
4716e2e17118
fix octave_map::extract_scalar
Jaroslav Hajek <highegg@gmail.com>
parents:
10743
diff
changeset
|
370 void del (const std::string& k) { rmfield (k); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
371 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
372 // 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
|
373 octave_map orderfields (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
374 octave_map orderfields (Array<octave_idx_type>& perm) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
375 octave_map orderfields (const octave_map& other, |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
376 Array<octave_idx_type>& perm) const; |
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 // aka getfield/setfield, but the latter returns a reference. |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
379 Cell contents (const std::string& k) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
380 Cell& contents (const std::string& k); |
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 void clear (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
383 { |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
384 m_keys.clear (); |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
385 m_vals.clear (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
386 } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
387 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
388 // The Array-like methods. |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
389 octave_idx_type numel (void) const { return m_dimensions.numel (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
390 octave_idx_type length (void) const { return numel (); } |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
391 bool isempty (void) const { return m_dimensions.any_zero (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
392 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
393 octave_idx_type rows (void) const { return m_dimensions(0); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
394 octave_idx_type cols (void) const { return m_dimensions(1); } |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
395 octave_idx_type columns (void) const { return m_dimensions(1); } |
10742
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 // Extract a scalar substructure. |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
398 // FIXME: actually check something. |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
399 octave_scalar_map checkelem (octave_idx_type n) const |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
400 { return elem (n); } |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
401 |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
402 // FIXME: actually check something. |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
403 octave_scalar_map checkelem (octave_idx_type i, octave_idx_type j) const |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
404 { return elem (i, j); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
405 |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
406 // FIXME: actually check something. |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
407 octave_scalar_map checkelem (const Array<octave_idx_type>& ra_idx) const |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
408 { return elem (ra_idx); } |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
409 |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
410 octave_scalar_map elem (octave_idx_type n) const; |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
411 |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
412 octave_scalar_map elem (octave_idx_type i, octave_idx_type j) const; |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
413 |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
414 octave_scalar_map elem (const Array<octave_idx_type>& ra_idx) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
415 |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
416 octave_scalar_map operator () (octave_idx_type n) const |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
417 { return elem (n); } |
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
418 |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
419 octave_scalar_map operator () (octave_idx_type i, octave_idx_type j) const |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
420 { return elem (i, j); } |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
421 |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
422 octave_scalar_map |
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
423 operator () (const Array<octave_idx_type>& ra_idx) const |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
424 { return elem (ra_idx); } |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
425 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
426 octave_map squeeze (void) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
427 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
428 octave_map permute (const Array<int>& vec, bool inv = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
429 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
430 dim_vector dims (void) const { return m_dimensions; } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
431 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
432 int ndims (void) const { return m_dimensions.ndims (); } |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
433 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
434 octave_map transpose (void) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
435 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
436 octave_map reshape (const dim_vector& dv) const; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
437 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
438 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
|
439 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
440 static octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
441 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
|
442 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
443 static octave_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
444 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
|
445 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
446 octave_map index (const octave::idx_vector& i, bool resize_ok = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
447 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
448 octave_map index (const octave::idx_vector& i, const octave::idx_vector& j, |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
449 bool resize_ok = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
450 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
451 octave_map index (const Array<octave::idx_vector>& ia, |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
452 bool resize_ok = false) const; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
453 |
10743
cb3ed842bd30
make the new interface more backward compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
454 octave_map index (const octave_value_list&, bool resize_ok = false) const; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
455 |
10755
6ba7937a6fa4
more array-like methods in octave_map
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
456 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
|
457 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
|
458 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
459 void assign (const octave::idx_vector& i, const octave_map& rhs); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
460 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
461 void assign (const octave::idx_vector& i, const octave::idx_vector& j, |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
462 const octave_map& rhs); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
463 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
464 void assign (const Array<octave::idx_vector>& ia, const octave_map& rhs); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
465 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
466 void assign (const octave_value_list&, const octave_map& rhs); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
467 |
10749
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10747
diff
changeset
|
468 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
|
469 const Cell& rhs); |
df1a3e0ebbff
important fixes for struct rewrite(1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10747
diff
changeset
|
470 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
471 void delete_elements (const octave::idx_vector& i); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
472 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
473 void delete_elements (int dim, const octave::idx_vector& i); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
474 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
475 void delete_elements (const Array<octave::idx_vector>& ia); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
476 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
477 void delete_elements (const octave_value_list&); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
478 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 octave_map concat (const octave_map& rb, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
480 const Array<octave_idx_type>& ra_idx); |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
481 |
10760
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
482 // like checkelem, but no check. |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
483 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
|
484 |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
485 // element assignment, no bounds check |
76079e505f9d
optimize cellfun with uniform struct output
Jaroslav Hajek <highegg@gmail.com>
parents:
10757
diff
changeset
|
486 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
|
487 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
488 private: |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
489 |
29922
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
490 octave_fields m_keys; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
491 std::vector<Cell> m_vals; |
adda9f3ac61f
use m_ prefix for data members in octave_map classes
John W. Eaton <jwe@octave.org>
parents:
29569
diff
changeset
|
492 dim_vector m_dimensions; |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
493 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
494 void optimize_dimensions (void); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
495 void extract_scalar (octave_scalar_map& dest, |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
496 octave_idx_type index) const; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
497 static void do_cat (int dim, octave_idx_type n, |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
498 const octave_scalar_map *map_list, octave_map& retval); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
499 static void do_cat (int dim, octave_idx_type n, |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
500 const octave_map *map_list, octave_map& retval); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
501 }; |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10333
diff
changeset
|
502 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20940
diff
changeset
|
503 template <> |
10757
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
504 inline octave_map octave_value_extract<octave_map> (const octave_value& v) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
505 { return v.map_value (); } |
10757
1cc44f3ec814
templated extractors for maps and cells
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
506 |
746 | 507 #endif |