ROSE 0.11.145.192
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 13 of file util/Map.h.

#include <util/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.
 
bool exists (const Key &key) const
 Convenience for determining if a key exists in this map.
 
const T & get_one (const Key &key) const
 Look up one value or throw an exception.
 
T & get_one (const Key &key)
 Look up one value or throw an exception.
 
const T & get_value_or (const Key &key, const T &dflt) const
 Convenience for getting a value from an Option.
 
T & get_value_or (const Key &key, T &dflt)
 Convenience for getting a value from an Option.
 

Member Typedef Documentation

◆ map_type

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

Definition at line 15 of file util/Map.h.

Constructor & Destructor Documentation

◆ Map() [1/4]

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

Definition at line 29 of file util/Map.h.

◆ Map() [2/4]

template<class Key , class T , class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
Map< Key, T, Compare, Alloc >::Map ( const Compare &  comp,
const Alloc &  alloc = Alloc() 
)
inlineexplicit

Definition at line 31 of file util/Map.h.

◆ Map() [3/4]

template<class Key , class T , class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T> >>
template<class InputIterator >
Map< Key, T, Compare, Alloc >::Map ( InputIterator  first,
InputIterator  last,
const Compare &  comp = Compare(),
const Alloc &  alloc = Alloc() 
)
inline

Definition at line 35 of file util/Map.h.

◆ Map() [4/4]

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

Definition at line 38 of file util/Map.h.

Member Function Documentation

◆ get()

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());
Extends std::map with methods that return optional values.
Definition util/Map.h:13
boost::optional< T > get(const Key &key) const
Lookup and return a value or nothing.
Definition util/Map.h:52

Definition at line 52 of file util/Map.h.

◆ get_one() [1/2]

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 61 of file util/Map.h.

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

◆ get_one() [2/2]

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 67 of file util/Map.h.

◆ get_value_or() [1/2]

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 78 of file util/Map.h.

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

◆ get_value_or() [2/2]

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 82 of file util/Map.h.

◆ exists()

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 92 of file util/Map.h.


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