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