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 |
746
|
30 #include "Map.h" |
|
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: |
3932
|
40 Octave_map (void) : map (octave_value_list ()), array_len (0) { } |
746
|
41 |
3523
|
42 Octave_map (const std::string& key, const octave_value& value) |
3932
|
43 : map (octave_value_list ()), array_len (1) |
746
|
44 { |
3931
|
45 map[key] = octave_value_list (value); |
746
|
46 } |
|
47 |
3932
|
48 Octave_map (const Octave_map& m) |
|
49 : map (m.map), array_len (m.array_len) { } |
3931
|
50 |
|
51 Octave_map& operator = (const Octave_map& m) |
|
52 { |
|
53 if (this != &m) |
3932
|
54 { |
|
55 map = m.map; |
|
56 array_len = m.array_len; |
|
57 } |
3931
|
58 return *this; |
|
59 } |
746
|
60 |
|
61 ~Octave_map (void) { } |
1279
|
62 |
3932
|
63 // This is the number of keys. |
3931
|
64 int length (void) const { return map.length (); } |
|
65 |
|
66 int empty (void) const { return map.empty (); } |
|
67 |
3932
|
68 octave_value_list& operator [] (const std::string& key) { return map[key]; } |
3931
|
69 |
4197
|
70 octave_value_list operator [] (const std::string& key) const; |
|
71 |
3931
|
72 void del (const std::string& key) { map.del (key); } |
|
73 |
|
74 Pix first (void) const { return map.first (); } |
|
75 void next (Pix& i) const { map.next (i); } |
|
76 |
|
77 std::string key (Pix p) const { return map.key (p); } |
|
78 |
3932
|
79 octave_value_list& contents (Pix p) const { return map.contents (p); } |
3931
|
80 |
|
81 Pix seek (const std::string& key) const { return map.seek (key); } |
|
82 |
|
83 int contains (const std::string& key) const { return map.contains (key); } |
|
84 |
|
85 void clear (void) { map.clear (); } |
|
86 |
3933
|
87 string_vector keys (void) const; |
3931
|
88 |
4200
|
89 int rows (void) const { return 1; } |
|
90 |
|
91 int columns (void) const { return array_length (); } |
|
92 |
|
93 int array_length (void) const; |
3932
|
94 |
4197
|
95 Octave_map& assign (const idx_vector& idx, const Octave_map& rhs); |
|
96 |
3932
|
97 Octave_map& assign (const idx_vector& idx, const std::string& key, |
|
98 const octave_value_list& rhs); |
|
99 |
3933
|
100 Octave_map& assign (const std::string& key, const octave_value_list& rhs); |
|
101 |
|
102 Octave_map index (idx_vector& idx); |
|
103 |
3931
|
104 private: |
|
105 |
|
106 // The map of names to values. |
|
107 CHMap<octave_value_list> map; |
3932
|
108 |
|
109 // The current size of this struct array; |
|
110 mutable int array_len; |
746
|
111 }; |
|
112 |
|
113 #endif |
|
114 |
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C++ *** |
|
118 ;;; End: *** |
|
119 */ |