ROSE  0.9.9.139
Public Types | Public Member Functions | List of all members
Map< Key, T, Compare, Alloc > Class Template Reference

Description

template<class Key, class T, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
class Map< Key, T, Compare, Alloc >

Extends std::map with methods that return optional values.

Definition at line 10 of file Map.h.

#include <Map.h>

Inheritance diagram for Map< Key, T, Compare, Alloc >:
Inheritance graph
[legend]
Collaboration diagram for Map< Key, T, Compare, Alloc >:
Collaboration graph
[legend]

Public Types

typedef std::map< Key, T, Compare, Alloc > map_type
 

Public Member Functions

 Map (const Compare &comp, const Alloc &alloc=Alloc())
 
template<class InputIterator >
 Map (InputIterator first, InputIterator last, const Compare &comp=Compare(), const Alloc &alloc=Alloc())
 
 Map (const Map &other)
 
boost::optional< T > get (const Key &key) const
 Lookup and return a value or nothing. More...
 
bool exists (const Key &key) const
 Convenience for determining if a key exists in this map. More...
 
const T & get_one (const Key &key) const
 Look up one value or throw an exception. More...
 
T & get_one (const Key &key)
 Look up one value or throw an exception. More...
 
const T & get_value_or (const Key &key, const T &dflt) const
 Convenience for getting a value from an Option. More...
 
T & get_value_or (const Key &key, T &dflt)
 Convenience for getting a value from an Option. More...
 

Member Function Documentation

template<class Key, class T, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
boost::optional<T> Map< Key, T, Compare, Alloc >::get ( const Key &  key) const
inline

Lookup and return a value or nothing.

This is similar to the operator[] defined for std::map, but does not add a new pair to the map when the key does not exist. It returns a copy of the value that was found (if found). Here's an example of the usual way to use this:

...
std::string filename = "foo.txt";
FileInfo info = files.get(filename).get_value_or(FileInfo());

Definition at line 49 of file Map.h.

template<class Key, class T, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
const T& Map< Key, T, Compare, Alloc >::get_one ( const Key &  key) const
inline

Look up one value or throw an exception.

This is like get() except it can't handle the case where the map does not contain the requested key. It is unlike operator[] in that it doesn't add a new default-constructed value. The return value is a reference to the value stored in the map.

Definition at line 58 of file Map.h.

Referenced by Rose::BinaryAnalysis::ControlFlow::explode_blocks(), and Rose::BinaryAnalysis::ControlFlow::fixup_fcall_fret().

template<class Key, class T, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
T& Map< Key, T, Compare, Alloc >::get_one ( const Key &  key)
inline

Look up one value or throw an exception.

This is like get() except it can't handle the case where the map does not contain the requested key. It is unlike operator[] in that it doesn't add a new default-constructed value. The return value is a reference to the value stored in the map.

Definition at line 64 of file Map.h.

template<class Key, class T, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
const T& Map< Key, T, Compare, Alloc >::get_value_or ( const Key &  key,
const T &  dflt 
) const
inline

Convenience for getting a value from an Option.

Since the "map.get(key).get_value_or(dflt)" idiom is so frequenct, a get_value_or() method is defined directly on the map, combining both arguments into a single method call.

Definition at line 75 of file Map.h.

Referenced by Rose::BinaryAnalysis::ControlFlow::build_block_cfg_from_ast(), and Rose::BinaryAnalysis::ControlFlow::fixup_fcall_fret().

template<class Key, class T, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
T& Map< Key, T, Compare, Alloc >::get_value_or ( const Key &  key,
T &  dflt 
)
inline

Convenience for getting a value from an Option.

Since the "map.get(key).get_value_or(dflt)" idiom is so frequenct, a get_value_or() method is defined directly on the map, combining both arguments into a single method call.

Definition at line 79 of file Map.h.

template<class Key, class T, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
bool Map< Key, T, Compare, Alloc >::exists ( const Key &  key) const
inline

Convenience for determining if a key exists in this map.

The STL map requires one to do a find() and compare the result to end(). Although that can be more efficient when the value for that key will be used (because one just dereferences the already-obtained iterator rather than searching again), it requires more code when all one wants to do is check for existence.

Definition at line 89 of file Map.h.


The documentation for this class was generated from the following file: