Main MRPT website > C++ reference
MRPT logo
Public Types | Public Member Functions | Private Attributes
mrpt::utils::bimap Class Reference

Detailed Description

A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std::map's, one for keys and another for values.

To use this class, insert new pairs KEY<->VALUE with bimap::insert. Then, you can access the KEY->VALUE map with bimap::direct(), and the VALUE->KEY map with bimap::inverse(). The consistency of the two internal maps is assured at any time.

Note:
This class can be accessed through iterators to the map KEY->VALUE only.
Both typenames KEY and VALUE must be suitable for being employed as keys in a std::map, i.e. they must be comparable through a "< operator".

#include <mrpt/utils/bimap.h>

Inheritance diagram for mrpt::utils::bimap:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::map< KEY, VALUE >
::const_iterator 
const_iterator
typedef std::map< KEY, VALUE >
::iterator 
iterator
typedef std::map< VALUE, KEY >
::const_iterator 
const_iterator_inverse
typedef std::map< VALUE, KEY >
::iterator 
iterator_inverse

Public Member Functions

 bimap ()
 Default constructor - does nothing.
const_iterator begin () const
iterator begin ()
const_iterator end () const
iterator end ()
const_iterator_inverse inverse_begin () const
iterator_inverse inverse_begin ()
const_iterator_inverse inverse_end () const
iterator_inverse inverse_end ()
size_t size () const
bool empty () const
const std::map< KEY, VALUE > & getDirectMap () const
 Return a read-only reference to the internal map KEY->VALUES.
const std::map< VALUE, KEY > & getInverseMap () const
 Return a read-only reference to the internal map KEY->VALUES.
void clear ()
void insert (const KEY &k, const VALUE &v)
 Insert a new pair KEY<->VALUE in the bi-map.
bool direct (const KEY &k, VALUE &out_v) const
 Get the value associated the given key, KEY->VALUE, returning false if not present.
bool hasKey (const KEY &k) const
 Return true if the given key 'k' is in the bi-map.
bool hasValue (const VALUE &v) const
 Return true if the given value 'v' is in the bi-map.
VALUE direct (const KEY &k) const
 Get the value associated the given key, KEY->VALUE, raising an exception if not present.
bool inverse (const VALUE &v, KEY &out_k) const
 Get the key associated the given value, VALUE->KEY, returning false if not present.
KEY inverse (const VALUE &v) const
 Get the key associated the given value, VALUE->KEY, raising an exception if not present.
const_iterator find_key (const KEY &k) const
iterator find_key (const KEY &k)
const_iterator_inverse find_value (const VALUE &v) const
iterator_inverse find_value (const VALUE &v)

Private Attributes

std::map< KEY, VALUE > m_k2v
std::map< VALUE, KEY > m_v2k

Member Typedef Documentation

Definition at line 55 of file bimap.h.

Definition at line 58 of file bimap.h.

Definition at line 56 of file bimap.h.

Definition at line 59 of file bimap.h.


Constructor & Destructor Documentation

mrpt::utils::bimap::bimap ( ) [inline]

Default constructor - does nothing.

Definition at line 62 of file bimap.h.


Member Function Documentation

const_iterator mrpt::utils::bimap::begin ( ) const [inline]

Definition at line 64 of file bimap.h.

iterator mrpt::utils::bimap::begin ( ) [inline]

Definition at line 65 of file bimap.h.

void mrpt::utils::bimap::clear ( void  ) [inline]

Definition at line 82 of file bimap.h.

bool mrpt::utils::bimap::direct ( const KEY &  k,
VALUE &  out_v 
) const [inline]

Get the value associated the given key, KEY->VALUE, returning false if not present.

See also:
inverse, hasKey, hasValue
Returns:
false on key not found.

Definition at line 99 of file bimap.h.

VALUE mrpt::utils::bimap::direct ( const KEY &  k) const [inline]

Get the value associated the given key, KEY->VALUE, raising an exception if not present.

See also:
inverse, hasKey, hasValue
Exceptions:
std::exceptionOn key not present in the bi-map.

Definition at line 120 of file bimap.h.

bool mrpt::utils::bimap::empty ( ) const [inline]

Definition at line 75 of file bimap.h.

const_iterator mrpt::utils::bimap::end ( ) const [inline]

Definition at line 66 of file bimap.h.

iterator mrpt::utils::bimap::end ( ) [inline]

Definition at line 67 of file bimap.h.

const_iterator mrpt::utils::bimap::find_key ( const KEY &  k) const [inline]

Definition at line 151 of file bimap.h.

iterator mrpt::utils::bimap::find_key ( const KEY &  k) [inline]

Definition at line 152 of file bimap.h.

const_iterator_inverse mrpt::utils::bimap::find_value ( const VALUE &  v) const [inline]

Definition at line 154 of file bimap.h.

iterator_inverse mrpt::utils::bimap::find_value ( const VALUE &  v) [inline]

Definition at line 155 of file bimap.h.

const std::map<KEY,VALUE>& mrpt::utils::bimap::getDirectMap ( ) const [inline]

Return a read-only reference to the internal map KEY->VALUES.

Definition at line 78 of file bimap.h.

const std::map<VALUE,KEY>& mrpt::utils::bimap::getInverseMap ( ) const [inline]

Return a read-only reference to the internal map KEY->VALUES.

Definition at line 80 of file bimap.h.

bool mrpt::utils::bimap::hasKey ( const KEY &  k) const [inline]

Return true if the given key 'k' is in the bi-map.

See also:
hasValue, direct, inverse

Definition at line 108 of file bimap.h.

bool mrpt::utils::bimap::hasValue ( const VALUE &  v) const [inline]

Return true if the given value 'v' is in the bi-map.

See also:
hasKey, direct, inverse

Definition at line 112 of file bimap.h.

void mrpt::utils::bimap::insert ( const KEY &  k,
const VALUE &  v 
) [inline]
bool mrpt::utils::bimap::inverse ( const VALUE &  v,
KEY &  out_k 
) const [inline]

Get the key associated the given value, VALUE->KEY, returning false if not present.

See also:
direct, hasKey, hasValue
Returns:
false on value not found.

Definition at line 131 of file bimap.h.

KEY mrpt::utils::bimap::inverse ( const VALUE &  v) const [inline]

Get the key associated the given value, VALUE->KEY, raising an exception if not present.

See also:
direct, hasKey, hasValue
Returns:
false on value not found.

Definition at line 143 of file bimap.h.

const_iterator_inverse mrpt::utils::bimap::inverse_begin ( ) const [inline]

Definition at line 69 of file bimap.h.

iterator_inverse mrpt::utils::bimap::inverse_begin ( ) [inline]

Definition at line 70 of file bimap.h.

const_iterator_inverse mrpt::utils::bimap::inverse_end ( ) const [inline]

Definition at line 71 of file bimap.h.

iterator_inverse mrpt::utils::bimap::inverse_end ( ) [inline]

Definition at line 72 of file bimap.h.

size_t mrpt::utils::bimap::size ( ) const [inline]

Definition at line 74 of file bimap.h.


Member Data Documentation

std::map<KEY,VALUE> mrpt::utils::bimap::m_k2v [private]
std::map<VALUE,KEY> mrpt::utils::bimap::m_v2k [private]



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011