OpenTTD Source: MultiMap< Tkey, Tvalue, Tcompare > Class Template Reference

OpenTTD Source 15.0-RC2

Public Types | Public Member Functions
MultiMap< Tkey, Tvalue, Tcompare > Class Template Reference

Hand-rolled multimap as map of lists. More...

`#include <multimap.hpp>`

Inheritance diagram for MultiMap< Tkey, Tvalue, Tcompare >:

## Public Types
typedef std::list< Tvalue > | List
typedef List::iterator | ListIterator
typedef List::const_iterator | ConstListIterator
typedef std::map< Tkey, List, Tcompare > | Map
typedef Map::iterator | MapIterator
typedef Map::const_iterator | ConstMapIterator
typedef MultiMapIterator< MapIterator, ListIterator, Tkey, Tvalue, Tcompare > | iterator
typedef MultiMapIterator< ConstMapIterator, ConstListIterator, Tkey, const Tvalue, Tcompare > | const_iterator

## Public Member Functions
iterator | erase (iterator it)
| Erase the value pointed to by an iterator.
void | Insert (const Tkey &key, const Tvalue &val)
| Insert a value at the end of the range with the specified key.
size_t | size () const
| Count all items in this MultiMap.
size_t | MapSize () const
| Count the number of ranges with equal keys in this MultiMap.
std::pair< iterator, iterator > | equal_range (const Tkey &key)
| Get a pair of iterators specifying a range of items with equal keys.
std::pair< const_iterator, const_iterator > | equal_range (const Tkey &key) const
| Get a pair of constant iterators specifying a range of items with equal keys.

## Detailed Description

template<typename Tkey, typename Tvalue, typename Tcompare = std::less<Tkey>>
class MultiMap< Tkey, Tvalue, Tcompare >

Hand-rolled multimap as map of lists.

Behaves mostly like a list, but is sorted by Tkey so that you can easily look up ranges of equal keys. Those ranges are internally ordered in a deterministic way (contrary to STL multimap). All STL-compatible members are named in STL style, all others are named in OpenTTD style.

Definition at line 225 of file multimap.hpp.

## Member Typedef Documentation

## ◆ const_iterator

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef MultiMapIterator<ConstMapIterator, ConstListIterator, Tkey, const Tvalue, Tcompare> MultiMap< Tkey, Tvalue, Tcompare >::const_iterator

Definition at line 236 of file multimap.hpp.

## ◆ ConstListIterator

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef List::const_iterator MultiMap< Tkey, Tvalue, Tcompare >::ConstListIterator

Definition at line 229 of file multimap.hpp.

## ◆ ConstMapIterator

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef Map::const_iterator MultiMap< Tkey, Tvalue, Tcompare >::ConstMapIterator

Definition at line 233 of file multimap.hpp.

## ◆ iterator

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef MultiMapIterator<MapIterator, ListIterator, Tkey, Tvalue, Tcompare> MultiMap< Tkey, Tvalue, Tcompare >::iterator

Definition at line 235 of file multimap.hpp.

## ◆ List

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef std::list<Tvalue> MultiMap< Tkey, Tvalue, Tcompare >::List

Definition at line 227 of file multimap.hpp.

## ◆ ListIterator

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef List::iterator MultiMap< Tkey, Tvalue, Tcompare >::ListIterator

Definition at line 228 of file multimap.hpp.

## ◆ Map

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef std::map<Tkey, List, Tcompare > MultiMap< Tkey, Tvalue, Tcompare >::Map

Definition at line 231 of file multimap.hpp.

## ◆ MapIterator

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

typedef Map::iterator MultiMap< Tkey, Tvalue, Tcompare >::MapIterator

Definition at line 232 of file multimap.hpp.

## Member Function Documentation

## ◆ equal_range() [1/2]

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

std::pair< iterator, iterator > MultiMap< Tkey, Tvalue, Tcompare >::equal_range | ( | const Tkey & | key | ) |
| inline

Get a pair of iterators specifying a range of items with equal keys.

Parameters

  key | Key to look for.

Returns
  Range of items with given key.

Definition at line 301 of file multimap.hpp.

Referenced by StationCargoList::ShiftCargo().

## ◆ equal_range() [2/2]

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

std::pair< const_iterator, const_iterator > MultiMap< Tkey, Tvalue, Tcompare >::equal_range | ( | const Tkey & | key | ) | const
| inline

Get a pair of constant iterators specifying a range of items with equal keys.

Parameters

  key | Key to look for.

Returns
  Constant range of items with given key.

Definition at line 316 of file multimap.hpp.

## ◆ erase()

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

iterator MultiMap< Tkey, Tvalue, Tcompare >::erase | ( | iterator | it | ) |
| inline

Erase the value pointed to by an iterator.

The iterator may be invalid afterwards.

Parameters

  it | Iterator pointing at some value.

Returns
  Iterator to the element after the deleted one (or invalid).

Definition at line 243 of file multimap.hpp.

References MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::list_iter, MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::list_valid, and MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::map_iter.

Referenced by StationCargoList::ShiftCargo(), and StationCargoList::Truncate().

## ◆ Insert()

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

void MultiMap< Tkey, Tvalue, Tcompare >::Insert | ( | const Tkey & | key,
|  | const Tvalue & | val
| ) |  |
| inline

Insert a value at the end of the range with the specified key.

Parameters

  key | Key to be inserted at.
  val | Value to be inserted.

Definition at line 267 of file multimap.hpp.

## ◆ MapSize()

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

size_t MultiMap< Tkey, Tvalue, Tcompare >::MapSize | ( |  | ) | const
| inline

Count the number of ranges with equal keys in this MultiMap.

Returns
  Number of ranges with equal keys.

Definition at line 291 of file multimap.hpp.

References Map::size.

Referenced by UpdateStationRating().

## ◆ size()

template<typename Tkey , typename Tvalue , typename Tcompare = std::less<Tkey>>

size_t MultiMap< Tkey, Tvalue, Tcompare >::size | ( |  | ) | const
| inline

Count all items in this MultiMap.

This involves iterating over the map.

Returns
  Number of items in the MultiMap.

Definition at line 278 of file multimap.hpp.

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

- src/core/multimap.hpp