dht::name_value_map Class Reference

Contains name/value pairs of strings. More...

#include <dht/name_value_map.h>

List of all members.

Public Types

typedef std::map< std::string,
std::string > 
container_type
typedef container_type::iterator iterator
typedef container_type::const_iterator const_iterator

Public Member Functions

virtual ~name_value_map ()
 Destructor.
const std::string & get (const std::string &key) const
 Obtains a reference to a stored value.
const std::string & get (const std::string &key, const std::string &def) const
 Obtains a reference to a stored value.
void set (const std::string &key, const std::string &value, bool error_if_set=false)
 Sets the value.
bool exists (const std::string &key) const
 Checks if the key exists.
iterator begin ()
 stl style iterator accessors
const_iterator begin () const
 stl style iterator accessors
iterator end ()
 stl style iterator accessors
const_iterator end () const
 stl style iterator accessors


Detailed Description

Contains name/value pairs of strings.

A simple class wrapping a number of name/value pairs of strings to an easily accessable interface. Name is an unique identifier for a value: for each name only one value exists.

Stl style iterator is provided for going through all the name/value pairs contained within.


Constructor & Destructor Documentation

virtual dht::name_value_map::~name_value_map (  )  [virtual]

Destructor.

Frees all data contained in the object. References to the data obtained with get() or iterators are invalid.


Member Function Documentation

const std::string& dht::name_value_map::get ( const std::string &  key  )  const

Obtains a reference to a stored value.

Parameters:
key A string specifying the key
If there is no value for the key, throws an exception.

Returns:
a reference to the value.

const std::string& dht::name_value_map::get ( const std::string &  key,
const std::string &  def 
) const

Obtains a reference to a stored value.

Parameters:
key A string specifying the key
def If no value is found for the key, returns the string specified here.
Returns:
a reference to the value.

void dht::name_value_map::set ( const std::string &  key,
const std::string &  value,
bool  error_if_set = false 
)

Sets the value.

Parameters:
key A string specifying the key
value A string specifying the value
error_if_set If true and there already exists a value for the key, throws an exception

bool dht::name_value_map::exists ( const std::string &  key  )  const [inline]

Checks if the key exists.

Returns:
true if a value for the given key exists

name_value_map::iterator dht::name_value_map::begin (  )  [inline]

stl style iterator accessors

name_value_map::const_iterator dht::name_value_map::begin (  )  const [inline]

stl style iterator accessors

name_value_map::iterator dht::name_value_map::end (  )  [inline]

stl style iterator accessors

name_value_map::const_iterator dht::name_value_map::end (  )  const [inline]

stl style iterator accessors


The documentation for this class was generated from the following file:
Generated on Thu Mar 1 16:18:47 2007 for libdht by  doxygen 1.5.1