Loading...
Searching...
No Matches
stringHashMap.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: stringHashMap.h,v 1.25 2004/05/06 21:39:37 oliver Exp $
//
#ifndef BALL_DATATYPE_STRINGHASHMAP_H
#define BALL_DATATYPE_STRINGHASHMAP_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_COMMON_HASH_H
# include <BALL/COMMON/hash.h>
#endif
#ifndef BALL_CONCEPT_VISITOR_H
# include <BALL/CONCEPT/visitor.h>
#endif
#ifndef BALL_CONCEPT_PROCESSOR_H
# include <BALL/CONCEPT/processor.h>
#endif
#ifndef BALL_DATATYPE_HASHMAP_H
# include <BALL/DATATYPE/hashMap.h>
#endif
#include <algorithm>
namespace BALL
{
template <typename Value>
class StringHashMap
: public HashMap<String, Value>
{
public:
BALL_CREATE(StringHashMap)
typedef typename HashMap<String, Value>::Iterator Iterator;
typedef typename HashMap<String, Value>::ConstIterator ConstIterator;
typedef typename HashMap<String, Value>::ValueType ValueType;
StringHashMap()
: HashMap<String, Value>()
{
}
StringHashMap(const StringHashMap& map)
: HashMap<String, Value>(map)
{
}
virtual ~StringHashMap()
{
}
void destroy()
{
HashMap<String, Value>::clear();
}
void set(const StringHashMap& hash_map)
{
HashMap<String, Value>::clear();
ConstIterator it = hash_map.begin();
for ( ; it != hash_map.end(); ++it)
{
insert(*it);
}
}
const StringHashMap& operator = (const StringHashMap& hash_map)
{
set(hash_map);
return *this;
}
void get(StringHashMap& hash_map) const
{
hash_map.set(*this);
}
void swap(StringHashMap& hash_map)
{
std::swap(*this, hash_map);
}
std::pair<Iterator, bool> insert(const ValueType& obj)
{
return HashMap<String, Value>::insert(obj);
}
::std::pair<Iterator, bool> insert(const String& key, const Value& value)
{
return HashMap<String, Value>::insert(::std::pair<String, Value>(key, value));
}
bool remove(const String& key)
{
// search the key
Iterator it = HashMap<String, Value>::find(key);
if (it == HashMap<String, Value>::end())
{
// we didn't find it..
return false;
}
// found it: delete it
HashMap<String, Value>::erase(it);
return true;
}
Size getSize() const
{
return HashMap<String, Value>::size();
}
bool operator == (const StringHashMap<Value>& hash_map) const
{
return HashMap<String, Value>::operator == (hash_map);
}
bool operator != (const StringHashMap<Value>& hash_map) const
{
return !(HashMap<String, Value>::operator == (hash_map));
}
bool has(const String& key) const
{
return !(HashMap<String, Value>::find(key) == HashMap<String, Value>::end());
}
bool isEmpty() const
{
return (HashMap<String, Value>::size() == 0);
}
void host(Visitor<StringHashMap<Value> >& visitor)
{
visitor.visit(*this);
}
};
// required for visual studio
#ifdef BALL_COMPILER_MSVC
template class BALL_EXPORT StringHashMap<String>;
#endif
}// namespace BALL
#endif // BALL_DATATYPE_HASHMAP_H
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::HashMap
HashMap class based on the STL map (containing serveral convenience functions).
Definition hashMap.h:74
BALL::HashMap::size
Size size() const
Definition hashMap.h:122
BALL::HashMap::operator==
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
BALL::StringHashMap::~StringHashMap
virtual ~StringHashMap()
Definition stringHashMap.h:87
BALL::StringHashMap::StringHashMap
StringHashMap(const StringHashMap &map)
Definition stringHashMap.h:79
BALL::StringHashMap::Iterator
HashMap< String, Value >::Iterator Iterator
Definition stringHashMap.h:53
BALL::StringHashMap::ConstIterator
HashMap< String, Value >::ConstIterator ConstIterator
Definition stringHashMap.h:57
BALL::StringHashMap::remove
bool remove(const String &key)
Definition stringHashMap.h:164
BALL::StringHashMap::operator=
const StringHashMap & operator=(const StringHashMap &hash_map)
Assign a hash map from another.
Definition stringHashMap.h:120
BALL::StringHashMap::host
void host(Visitor< StringHashMap< Value > > &visitor)
Definition stringHashMap.h:229
BALL::StringHashMap::set
void set(const StringHashMap &hash_map)
Definition stringHashMap.h:108
BALL::StringHashMap::has
bool has(const String &key) const
Definition stringHashMap.h:208
BALL::StringHashMap::get
void get(StringHashMap &hash_map) const
Assigns the content of a hash map to another.
Definition stringHashMap.h:127
BALL::StringHashMap::destroy
void destroy()
Definition stringHashMap.h:94
BALL::StringHashMap::ValueType
HashMap< String, Value >::ValueType ValueType
Definition stringHashMap.h:61
BALL::StringHashMap::getSize
Size getSize() const
Definition stringHashMap.h:182
BALL::StringHashMap::StringHashMap
StringHashMap()
Definition stringHashMap.h:70
BALL::StringHashMap::operator!=
bool operator!=(const StringHashMap< Value > &hash_map) const
Definition stringHashMap.h:201
BALL::StringHashMap::swap
void swap(StringHashMap &hash_map)
Swaps the contents of two hash maps.
Definition stringHashMap.h:133
BALL::StringHashMap::insert
std::pair< Iterator, bool > insert(const ValueType &obj)
Definition stringHashMap.h:145
BALL::StringHashMap::operator==
bool operator==(const StringHashMap< Value > &hash_map) const
Definition stringHashMap.h:194
BALL::StringHashMap::isEmpty
bool isEmpty() const
Definition stringHashMap.h:216
BALL::String
Definition string.h:57
BALL::Visitor
Definition visitor.h:23
common.h
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
hashMap.h
hash.h
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
processor.h
visitor.h