name_value_map.h

00001 #ifndef _DHT_NAME_VALUE_MAP_H_
00002 #define _DHT_NAME_VALUE_MAP_H_
00003 
00004 #include <map>
00005 #include <string>
00006 #include "exception.h"
00007 
00008 namespace dht {
00021     class name_value_map {
00022     public:
00023         typedef std::map<std::string, std::string>            container_type;
00024         typedef container_type::iterator       iterator;
00025         typedef container_type::const_iterator const_iterator;
00026                 
00027     private:
00028         container_type _str_map;
00029     public:
00030         name_value_map();
00031         
00038         virtual ~name_value_map();
00039 
00048         const std::string &get(const std::string &key) const;
00049 
00057         const std::string &get(const std::string &key, const std::string &def) const;
00058 
00066         void        set(const std::string &key, const std::string &value, 
00067                         bool error_if_set = false);
00068 
00073         inline bool exists(const std::string &key) const;
00074         
00078         inline iterator       begin();
00082         inline const_iterator begin() const;
00086         inline iterator       end();
00090         inline const_iterator end() const;
00091     };  
00092 
00093     inline bool
00094     name_value_map::exists(const std::string &key) const {
00095         return _str_map.find(key) != _str_map.end() ? true : false;
00096     }
00097     
00098     inline name_value_map::iterator 
00099     name_value_map::begin() { return _str_map.begin(); }
00100     
00101     inline name_value_map::const_iterator 
00102     name_value_map::begin() const { return _str_map.begin(); }
00103 
00104     inline name_value_map::iterator 
00105     name_value_map::end() { return _str_map.end(); }
00106 
00107     inline name_value_map::const_iterator 
00108     name_value_map::end() const { return _str_map.end(); }  
00109 } // namespace dht
00110 
00111 #endif //_DHT_NAME_VALUE_MAP_H_

Generated on Thu Mar 1 16:18:47 2007 for libdht by  doxygen 1.5.1