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

rtmap.h

Go to the documentation of this file.
00001 /*
00002  * rtmap.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may be distributed and/or modified under the terms of the 
00008  * GNU General Public License version 2 as published by the Free Software 
00009  * Foundation. 
00010  * 
00011  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013  * 
00014  */
00015 
00022 #ifndef __LRT_MAP__
00023 #define __LRT_MAP__
00024 
00025 #include "rtiterator.h"
00026 #include "rtlist.h"
00027 #include "rtstring.h"
00028 
00029 namespace lrt {
00030 
00031 // fwd declare
00032 template<class K, class V> class Map;
00033 
00035 template<class K, class V> class Pair {
00036 public:
00039         Pair() : key(), value() {}
00041         Pair(const K& k, const V& v) : key(k), value(v) {}
00043         inline const K& getKey() const          { return key; }
00045         inline const V& getValue() const        { return value; }
00047         inline K& getKey()                                      { return key; }
00049         inline V& getValue()                            { return value; }
00050 private:
00051         friend class Map<K,V>;
00052         K key;
00053         V value;
00054 };
00055 
00056 
00063 template<class K, class V> class Map {
00064 public:
00065         
00069         typedef Iterator<Pair<K,V> > Iterator;
00070 
00073         Map();
00076         Map(int (*compareFun)(const K&, const K&));
00078         Map(const Map &);
00079         virtual ~Map() {}
00081         const Map& operator=(const Map &);
00082 
00084         bool isSet(const K&) const;
00087         const V& get(const K&) const;
00091         V& get(const K&);
00095         Pair<K,V>& put(const K&, const V&);
00098         void putAll(const Map<K,V>&);
00102         bool remove(const K&);
00105         void remove(Iterator& iter);
00107         void clear();
00108         //Pair& insert(const Pair&);
00109 
00112         inline const V& operator[](const K&) const;
00116         inline V& operator[](const K&);
00117         
00119         int length() const;
00123         Iterator begin() const;
00127         Iterator end() const;
00131         Iterator begin();
00135         Iterator end();
00136 
00138         static Pair<K,V> noValue;
00139 
00140 protected:
00142         int (*compareFun)(const K&, const K&);
00143 
00144 private:
00145         List< Pair<K,V> > data;
00146 
00147 };
00148 
00153 template<class V> class StringMap : public Map<String,V>
00154 {
00155 public:
00157         StringMap() : Map<String,V>(&String::compare) {}
00159         StringMap(bool caseSensitive) : 
00160                 Map<String,V>(&String::compare)
00161         {
00162                 if(!caseSensitive) compareFun = &String::compareIgnoreCase;             
00163         }
00165         StringMap(const StringMap& sm) : Map<String,V>(sm) {}
00166         virtual ~StringMap() {}
00168         const StringMap& operator=(const StringMap& sm)
00169         { Map<String,V>::operator=(sm); return *this; }
00170 
00171 };
00172 
00173 } // namespace
00174 
00175 #include "rtmap.templ.cpp"
00176 
00177 #endif

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer