Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

multimapwdef.h

00001 #ifndef MULTIMAPWDEF
00002 #define MULTIMAPWDEF
00003 
00004 #include <map>
00005 
00006 using namespace std;
00007 
00008 // multmap that still lets you use [] to reference FIRST
00009 // entry of a key if multiples exist
00010 template <class Key, class T, class Compare>
00011 class multimapwithdefault : public multimap<Key, T, Compare> {
00012 public:
00013         typedef pair<const Key, T> value_type;
00014         T& operator[](const Key& k) {
00015                 if (find(k) == end()) {
00016                         insert(value_type(k, T()));
00017                 }
00018                 return (*(find(k))).second;
00019         }
00020         bool has(const Key& k, const T &val) const {
00021                 typename multimap<Key, T, Compare>::const_iterator start = lower_bound(k);
00022                 typename multimap<Key, T, Compare>::const_iterator end = upper_bound(k);
00023                 for (; start!=end; start++) {
00024                         if (start->second == val)
00025                                 return true;
00026                 }
00027                 return false;
00028         }
00029 };
00030 
00031 #endif

Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by doxygen1.2.15