BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
stringHashMap.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: stringHashMap.h,v 1.25 2004/05/06 21:39:37 oliver Exp $
5 //
6 
7 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
8 #define BALL_DATATYPE_STRINGHASHMAP_H
9 
10 #ifndef BALL_COMMON_H
11 # include <BALL/common.h>
12 #endif
13 
14 #ifndef BALL_COMMON_HASH_H
15 # include <BALL/COMMON/hash.h>
16 #endif
17 
18 #ifndef BALL_CONCEPT_VISITOR_H
19 # include <BALL/CONCEPT/visitor.h>
20 #endif
21 
22 #ifndef BALL_CONCEPT_PROCESSOR_H
23 # include <BALL/CONCEPT/processor.h>
24 #endif
25 
26 #ifndef BALL_DATATYPE_HASHMAP_H
27 # include <BALL/DATATYPE/hashMap.h>
28 #endif
29 
30 #include <algorithm>
31 
32 namespace BALL
33 {
34 
35 
39  template <typename Value>
41  : public HashMap<String, Value>
42  {
43  public:
44 
46 
47 
50 
53  typedef typename HashMap<String, Value>::Iterator Iterator;
54 
57  typedef typename HashMap<String, Value>::ConstIterator ConstIterator;
58 
61  typedef typename HashMap<String, Value>::ValueType ValueType;
63 
66 
71  : HashMap<String, Value>()
72  {
73  }
74 
80  : HashMap<String, Value>(map)
81  {
82  }
83 
87  virtual ~StringHashMap()
88  {
89  }
90 
94  void destroy()
95  {
97  }
98 
100 
103 
108  void set(const StringHashMap& hash_map)
109  {
111 
112  ConstIterator it = hash_map.begin();
113  for ( ; it != hash_map.end(); ++it)
114  {
115  insert(*it);
116  }
117  }
118 
120  const StringHashMap& operator = (const StringHashMap& hash_map)
121  {
122  set(hash_map);
123  return *this;
124  }
125 
127  void get(StringHashMap& hash_map) const
128  {
129  hash_map.set(*this);
130  }
131 
133  void swap(StringHashMap& hash_map)
134  {
135  std::swap(*this, hash_map);
136  }
137 
139 
142 
145  std::pair<Iterator, bool> insert(const ValueType& obj)
146  {
147  return HashMap<String, Value>::insert(obj);
148  }
149 
154  ::std::pair<Iterator, bool> insert(const String& key, const Value& value)
155  {
156  return HashMap<String, Value>::insert(::std::pair<String, Value>(key, value));
157  }
158 
159 
164  bool remove(const String& key)
165  {
166  // search the key
168  if (it == HashMap<String, Value>::end())
169  {
170  // we didn't find it..
171  return false;
172  }
173 
174  // found it: delete it
176 
177  return true;
178  }
179 
182  Size getSize() const
183  {
185  }
186 
188 
191 
194  bool operator == (const StringHashMap<Value>& hash_map) const
195  {
196  return HashMap<String, Value>::operator == (hash_map);
197  }
198 
201  bool operator != (const StringHashMap<Value>& hash_map) const
202  {
203  return !(HashMap<String, Value>::operator == (hash_map));
204  }
205 
208  bool has(const String& key) const
209  {
211  }
212 
216  bool isEmpty() const
217  {
218  return (HashMap<String, Value>::size() == 0);
219  }
221 
224 
230  {
231  visitor.visit(*this);
232  }
234 
235  };
236 
237 // required for visual studio
238 #ifdef BALL_COMPILER_MSVC
239 template class BALL_EXPORT StringHashMap<String>;
240 #endif
241 
242 }// namespace BALL
243 
244 #endif // BALL_DATATYPE_HASHMAP_H
#define BALL_CREATE(name)
Definition: create.h:62
Base::const_iterator ConstIterator
Definition: hashMap.h:98
const StringHashMap & operator=(const StringHashMap &hash_map)
Assign a hash map from another.
bool operator==(const HashMap< Key, T > &rhs) const
Equality operator. Check whether two two hashmaps contain the same elements. O(n) runtime...
Definition: hashMap.h:144
::std::pair< Iterator, bool > insert(const String &key, const Value &value)
virtual ~StringHashMap()
Definition: stringHashMap.h:87
Size getSize() const
Base::iterator Iterator
Definition: hashMap.h:97
void swap(StringHashMap &hash_map)
Swaps the contents of two hash maps.
bool operator!=(const StringHashMap< Value > &hash_map) const
Size size() const
Definition: hashMap.h:122
bool has(const String &key) const
StringHashMap(const StringHashMap &map)
Definition: stringHashMap.h:79
bool operator==(const StringHashMap< Value > &hash_map) const
void set(const StringHashMap &hash_map)
Base::value_type ValueType
Definition: hashMap.h:94
void host(Visitor< StringHashMap< Value > > &visitor)
bool isEmpty() const
std::pair< Iterator, bool > insert(const ValueType &obj)
HashMap class based on the STL map (containing serveral convenience functions)
Definition: hashMap.h:73
#define BALL_EXPORT
Definition: COMMON/global.h:50