annotate src/oct-map.h @ 4817:6430596f2238

[project @ 2004-03-04 21:13:33 by jwe]
author jwe
date Thu, 04 Mar 2004 21:13:33 +0000
parents d3bd9c04147f
children c638c144d4da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
1 /*
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
2
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2369
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
4
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
6
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
10 later version.
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
11
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
15 for more details.
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
16
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1297
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
20
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
21 */
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
22
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
23 #if !defined (octave_oct_map_h)
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
24 #define octave_oct_map_h 1
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
25
4192
5719210fff4c [project @ 2002-11-20 16:56:47 by jwe]
jwe
parents: 4066
diff changeset
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
1297
12ecc2ecf0e3 [project @ 1995-05-01 18:39:43 by jwe]
jwe
parents: 1279
diff changeset
27 #pragma interface
12ecc2ecf0e3 [project @ 1995-05-01 18:39:43 by jwe]
jwe
parents: 1279
diff changeset
28 #endif
12ecc2ecf0e3 [project @ 1995-05-01 18:39:43 by jwe]
jwe
parents: 1279
diff changeset
29
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
30 #include <map>
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
31
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
32 #include "Cell.h"
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
33 #include "oct-obj.h"
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
34
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1737
diff changeset
35 class string_vector;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1737
diff changeset
36
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
37 class
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
38 Octave_map
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
39 {
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
40 public:
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
41
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
42 typedef std::map<std::string, Cell>::iterator iterator;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
43 typedef std::map<std::string, Cell>::const_iterator const_iterator;
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
44
4744
7dcb696159ac [project @ 2004-02-06 05:46:22 by jwe]
jwe
parents: 4675
diff changeset
45 // Warning! You should always use at least two dimensions.
7dcb696159ac [project @ 2004-02-06 05:46:22 by jwe]
jwe
parents: 4675
diff changeset
46
7dcb696159ac [project @ 2004-02-06 05:46:22 by jwe]
jwe
parents: 4675
diff changeset
47 Octave_map (const dim_vector& dv = dim_vector (0, 0))
7dcb696159ac [project @ 2004-02-06 05:46:22 by jwe]
jwe
parents: 4675
diff changeset
48 : map (), dimensions (dv) { }
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
49
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
50 Octave_map (const std::string& k, const octave_value& value)
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
51 : map (), dimensions (1, 1)
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
52 { map[k] = value; }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
53
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
54 Octave_map (const std::string& k, const Cell& vals)
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
55 : map (), dimensions (vals.dims ())
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
56 { map[k] = vals; }
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
57
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
58 Octave_map (const std::string& k, const octave_value_list& val_list)
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
59 : map (), dimensions (1, val_list.length ())
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
60 { map[k] = val_list; }
4435
dd7af4fa1942 [project @ 2003-06-23 17:52:36 by jwe]
jwe
parents: 4219
diff changeset
61
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
62 Octave_map (const Octave_map& m) : map (m.map), dimensions (m.dimensions) { }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
63
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
64 Octave_map& operator = (const Octave_map& m)
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
65 {
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
66 if (this != &m)
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
67 {
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
68 map = m.map;
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
69 dimensions = m.dimensions;
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
70 }
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
71
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
72 return *this;
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
73 }
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
74
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
75 ~Octave_map (void) { }
1279
f146197d9d37 [project @ 1995-04-26 17:41:20 by jwe]
jwe
parents: 1009
diff changeset
76
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
77 // This is the number of keys.
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
78 int length (void) const { return map.size (); }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
79
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
80 int empty (void) const { return map.empty (); }
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
81
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
82 void del (const std::string& k)
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
83 {
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
84 iterator p = map.find (k);
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
85 if (p != map.end ())
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
86 map.erase (p);
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
87 }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
88
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
89 iterator begin (void) { return iterator (map.begin ()); }
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
90 const_iterator begin (void) const { return const_iterator (map.begin ()); }
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
91
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
92 iterator end (void) { return iterator (map.end ()); }
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
93 const_iterator end (void) const { return const_iterator (map.end ()); }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
94
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
95 std::string key (const_iterator p) const { return p->first; }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
96
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4587
diff changeset
97 Cell contents (const std::string& k) const;
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
98
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
99 Cell contents (const_iterator p) const
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4587
diff changeset
100 { return contents (key(p)); }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
101
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
102 const_iterator seek (const std::string& k) const { return map.find (k); }
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4200
diff changeset
103
4817
6430596f2238 [project @ 2004-03-04 21:13:33 by jwe]
jwe
parents: 4806
diff changeset
104 bool contains (const std::string& k) const
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
105 { return (seek (k) != map.end ()); }
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
106
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
107 void clear (void) { map.clear (); }
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
108
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
109 string_vector keys (void) const;
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
110
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
111 int rows (void) const { return dimensions(0); }
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
112
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
113 int columns (void) const { return dimensions(1); }
4200
1f04df06e1a6 [project @ 2002-11-22 16:25:49 by jwe]
jwe
parents: 4197
diff changeset
114
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
115 dim_vector dims (void) const { return dimensions; }
4200
1f04df06e1a6 [project @ 2002-11-22 16:25:49 by jwe]
jwe
parents: 4197
diff changeset
116
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4561
diff changeset
117 Octave_map reshape (const dim_vector& new_dims) const;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4561
diff changeset
118
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
119 int numel (void) const;
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
120
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4744
diff changeset
121 int cat (const Octave_map& ra_arg, int dim, int iidx, int move);
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4744
diff changeset
122
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
123 Octave_map& assign (const octave_value_list& idx, const Octave_map& rhs);
4197
40f76ce7a051 [project @ 2002-11-21 18:56:25 by jwe]
jwe
parents: 4192
diff changeset
124
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
125 Octave_map& assign (const octave_value_list& idx, const std::string& k,
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
126 const Cell& rhs);
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
127
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4587
diff changeset
128 Octave_map& assign (const std::string& k, const octave_value& rhs);
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4587
diff changeset
129
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4567
diff changeset
130 Octave_map& assign (const std::string& k, const Cell& rhs);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
131
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
132 Octave_map index (const octave_value_list& idx);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3932
diff changeset
133
3931
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
134 private:
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
135
311981a9726d [project @ 2002-05-07 04:49:53 by jwe]
jwe
parents: 3523
diff changeset
136 // The map of names to values.
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4435
diff changeset
137 std::map<std::string, Cell> map;
3932
2e2e32198722 [project @ 2002-05-07 18:10:44 by jwe]
jwe
parents: 3931
diff changeset
138
4561
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
139 // The current size.
e84592dc70b9 [project @ 2003-10-28 21:07:59 by jwe]
jwe
parents: 4513
diff changeset
140 mutable dim_vector dimensions;
746
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
141 };
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
142
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
143 #endif
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
144
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
145 /*
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
146 ;;; Local Variables: ***
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
147 ;;; mode: C++ ***
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
148 ;;; End: ***
46f6f6a4f5c6 [project @ 1994-09-30 15:05:10 by jwe]
jwe
parents:
diff changeset
149 */