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 |
3931
|
32 #include "oct-obj.h" |
746
|
33 |
1755
|
34 class string_vector; |
|
35 |
746
|
36 class |
3931
|
37 Octave_map |
746
|
38 { |
|
39 public: |
4219
|
40 |
|
41 typedef std::map<std::string, octave_value_list>::iterator iterator; |
|
42 typedef std::map<std::string, octave_value_list>::const_iterator const_iterator; |
|
43 |
|
44 Octave_map (void) : map (), array_len (0) { } |
746
|
45 |
3523
|
46 Octave_map (const std::string& key, const octave_value& value) |
4219
|
47 : map (), array_len (1) |
746
|
48 { |
3931
|
49 map[key] = octave_value_list (value); |
746
|
50 } |
|
51 |
4435
|
52 Octave_map (const std::string& key, const octave_value_list& val_list) |
|
53 : map (), array_len (val_list.length ()) |
|
54 { |
|
55 map[key] = val_list; |
|
56 } |
|
57 |
3932
|
58 Octave_map (const Octave_map& m) |
|
59 : map (m.map), array_len (m.array_len) { } |
3931
|
60 |
|
61 Octave_map& operator = (const Octave_map& m) |
|
62 { |
|
63 if (this != &m) |
3932
|
64 { |
|
65 map = m.map; |
|
66 array_len = m.array_len; |
|
67 } |
3931
|
68 return *this; |
|
69 } |
746
|
70 |
|
71 ~Octave_map (void) { } |
1279
|
72 |
3932
|
73 // This is the number of keys. |
4219
|
74 int length (void) const { return map.size (); } |
3931
|
75 |
|
76 int empty (void) const { return map.empty (); } |
|
77 |
3932
|
78 octave_value_list& operator [] (const std::string& key) { return map[key]; } |
3931
|
79 |
4197
|
80 octave_value_list operator [] (const std::string& key) const; |
|
81 |
4219
|
82 void del (const std::string& key) |
|
83 { |
|
84 iterator p = map.find (key); |
|
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 |
4219
|
97 octave_value_list& contents (const_iterator p) |
|
98 { return operator [] (key(p)); } |
3931
|
99 |
4219
|
100 octave_value_list contents (const_iterator p) const |
|
101 { return operator [] (key(p)); } |
3931
|
102 |
4219
|
103 const_iterator seek (const std::string& key) const { return map.find (key); } |
|
104 |
|
105 int contains (const std::string& key) const |
|
106 { return (seek (key) != map.end ()); } |
3931
|
107 |
|
108 void clear (void) { map.clear (); } |
|
109 |
3933
|
110 string_vector keys (void) const; |
3931
|
111 |
4200
|
112 int rows (void) const { return 1; } |
|
113 |
|
114 int columns (void) const { return array_length (); } |
|
115 |
|
116 int array_length (void) const; |
3932
|
117 |
4197
|
118 Octave_map& assign (const idx_vector& idx, const Octave_map& rhs); |
|
119 |
3932
|
120 Octave_map& assign (const idx_vector& idx, const std::string& key, |
|
121 const octave_value_list& rhs); |
|
122 |
3933
|
123 Octave_map& assign (const std::string& key, const octave_value_list& rhs); |
|
124 |
|
125 Octave_map index (idx_vector& idx); |
|
126 |
3931
|
127 private: |
|
128 |
|
129 // The map of names to values. |
4219
|
130 std::map<std::string, octave_value_list> map; |
3932
|
131 |
|
132 // The current size of this struct array; |
|
133 mutable int array_len; |
746
|
134 }; |
|
135 |
|
136 #endif |
|
137 |
|
138 /* |
|
139 ;;; Local Variables: *** |
|
140 ;;; mode: C++ *** |
|
141 ;;; End: *** |
|
142 */ |