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 |
|
45 Octave_map (void) : map (), array_len (0) { } |
746
|
46 |
3523
|
47 Octave_map (const std::string& key, const octave_value& value) |
4219
|
48 : map (), array_len (1) |
746
|
49 { |
4513
|
50 map[key] = Cell (value); |
|
51 } |
|
52 |
|
53 Octave_map (const std::string& key, const Cell& vals) |
|
54 : map (), array_len (vals.length ()) |
|
55 { |
|
56 map[key] = vals; |
746
|
57 } |
|
58 |
4435
|
59 Octave_map (const std::string& key, const octave_value_list& val_list) |
|
60 : map (), array_len (val_list.length ()) |
|
61 { |
|
62 map[key] = val_list; |
|
63 } |
|
64 |
3932
|
65 Octave_map (const Octave_map& m) |
|
66 : map (m.map), array_len (m.array_len) { } |
3931
|
67 |
|
68 Octave_map& operator = (const Octave_map& m) |
|
69 { |
|
70 if (this != &m) |
3932
|
71 { |
|
72 map = m.map; |
|
73 array_len = m.array_len; |
|
74 } |
3931
|
75 return *this; |
|
76 } |
746
|
77 |
|
78 ~Octave_map (void) { } |
1279
|
79 |
3932
|
80 // This is the number of keys. |
4219
|
81 int length (void) const { return map.size (); } |
3931
|
82 |
|
83 int empty (void) const { return map.empty (); } |
|
84 |
4513
|
85 Cell& operator [] (const std::string& key) { return map[key]; } |
3931
|
86 |
4513
|
87 Cell operator [] (const std::string& key) const; |
4197
|
88 |
4219
|
89 void del (const std::string& key) |
|
90 { |
|
91 iterator p = map.find (key); |
|
92 if (p != map.end ()) |
|
93 map.erase (p); |
|
94 } |
3931
|
95 |
4219
|
96 iterator begin (void) { return iterator (map.begin ()); } |
|
97 const_iterator begin (void) const { return const_iterator (map.begin ()); } |
|
98 |
|
99 iterator end (void) { return iterator (map.end ()); } |
|
100 const_iterator end (void) const { return const_iterator (map.end ()); } |
3931
|
101 |
4219
|
102 std::string key (const_iterator p) const { return p->first; } |
3931
|
103 |
4513
|
104 Cell& contents (const_iterator p) |
4219
|
105 { return operator [] (key(p)); } |
3931
|
106 |
4513
|
107 Cell contents (const_iterator p) const |
4219
|
108 { return operator [] (key(p)); } |
3931
|
109 |
4219
|
110 const_iterator seek (const std::string& key) const { return map.find (key); } |
|
111 |
|
112 int contains (const std::string& key) const |
|
113 { return (seek (key) != map.end ()); } |
3931
|
114 |
|
115 void clear (void) { map.clear (); } |
|
116 |
3933
|
117 string_vector keys (void) const; |
3931
|
118 |
4200
|
119 int rows (void) const { return 1; } |
|
120 |
|
121 int columns (void) const { return array_length (); } |
|
122 |
|
123 int array_length (void) const; |
3932
|
124 |
4513
|
125 Octave_map& assign (const octave_value_list& idx, const Octave_map& rhs); |
4197
|
126 |
4513
|
127 Octave_map& assign (const octave_value_list& idx, const std::string& key, |
|
128 const Cell& rhs); |
3932
|
129 |
4513
|
130 Octave_map& assign (const std::string& key, 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 |
|
139 // The current size of this struct array; |
|
140 mutable int array_len; |
746
|
141 }; |
|
142 |
|
143 #endif |
|
144 |
|
145 /* |
|
146 ;;; Local Variables: *** |
|
147 ;;; mode: C++ *** |
|
148 ;;; End: *** |
|
149 */ |