OpenTTD Source: MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare > Class Template Reference

OpenTTD Source 15.3

Public Member Functions | Protected Types | Protected Attributes | Friends
MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare > Class Template Reference

STL-style iterator for MultiMap. More...

`#include <multimap.hpp>`

## Public Member Functions
| MultiMapIterator ()
| Simple, dangerous constructor to allow later assignment with operator=.
template<class Tnon_const >
| MultiMapIterator (Tnon_const mi)
| Constructor to allow possibly const iterators to be assigned from possibly non-const map iterators.
| MultiMapIterator (Tmap_iter mi, Tlist_iter li)
| Constructor to allow specifying an exact position in map and list.
template<class Tnon_const >
Self & | operator= (Tnon_const mi)
| Assignment iterator like constructor with the same signature.
Tvalue & | operator* () const
| Dereference operator.
Tvalue * | operator-> () const
| Same as operator*(), but returns a pointer.
const Tmap_iter & | GetMapIter () const
const Tlist_iter & | GetListIter () const
bool | ListValid () const
const Tkey & | GetKey () const
Self & | operator++ ()
| Prefix increment operator.
Self | operator++ (int)
| Postfix increment operator.
Self & | operator-- ()
| Prefix decrement operator.
Self | operator-- (int)
| Postfix decrement operator.
template<class Tmap_iter_other , class Tlist_iter_other , class Tvalue_other >
bool | operator== (const MultiMapIterator< Tmap_iter_other, Tlist_iter_other, Tkey, Tvalue_other, Tcompare > &other) const
| Compare two MultiMap iterators.
template<class Titer >
bool | operator== (const Titer &iter) const
| Check if a MultiMap iterator is at the begin of a list pointed to by the given map iterator.

## Protected Types
typedef MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare > | Self

## Protected Attributes
Tlist_iter | list_iter
| Iterator pointing to current position in the current list of items with equal keys.
Tmap_iter | map_iter
| Iterator pointing to the position of the current list of items with equal keys in the map.
bool | list_valid
| Flag to show that the iterator has just "walked" a step in the map.

## Friends
class | MultiMap< Tkey, Tvalue, Tcompare >

## Detailed Description

template<class Tmap_iter, class Tlist_iter, class Tkey, class Tvalue, class Tcompare>
class MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >

STL-style iterator for MultiMap.

Template Parameters

  Tmap_iter | Iterator type for the map in the MultiMap.
  Tlist_iter | Iterator type for the lists in the MultiMap.
  Tkey | Key type of the MultiMap.
  Tvalue | Value type of the MultMap.
  Tcompare | Comparator type for keys of the MultiMap.

Definition at line 25 of file multimap.hpp.

## Member Typedef Documentation

## ◆ Self

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

typedef MultiMapIterator<Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare> MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::Self
| protected

Definition at line 28 of file multimap.hpp.

## Constructor & Destructor Documentation

## ◆ MultiMapIterator() [1/3]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::MultiMapIterator | ( |  | ) |
| inline

Simple, dangerous constructor to allow later assignment with operator=.

Definition at line 48 of file multimap.hpp.

## ◆ MultiMapIterator() [2/3]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >
template<class Tnon_const >

MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::MultiMapIterator | ( | Tnon_const | mi | ) |
| inline

Constructor to allow possibly const iterators to be assigned from possibly non-const map iterators.

You can assign end() like this.

Template Parameters

  Tnon_const | Iterator type assignable to Tmap_iter (which might be const).

Parameters

  mi | One such iterator.

Definition at line 57 of file multimap.hpp.

## ◆ MultiMapIterator() [3/3]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::MultiMapIterator | ( | Tmap_iter | mi,
|  | Tlist_iter | li
| ) |  |
| inline

Constructor to allow specifying an exact position in map and list.

You cannot construct end() like this as the constructor will actually check li and mi->second for list_valid.

Parameters

  mi | Iterator in the map.
  li | Iterator in the list.

Definition at line 66 of file multimap.hpp.

## Member Function Documentation

## ◆ GetKey()

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

const Tkey & MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::GetKey | ( |  | ) | const
| inline

Definition at line 114 of file multimap.hpp.

## ◆ GetListIter()

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

const Tlist_iter & MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::GetListIter | ( |  | ) | const
| inline

Definition at line 111 of file multimap.hpp.

## ◆ GetMapIter()

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

const Tmap_iter & MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::GetMapIter | ( |  | ) | const
| inline

Definition at line 110 of file multimap.hpp.

## ◆ ListValid()

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

bool MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::ListValid | ( |  | ) | const
| inline

Definition at line 112 of file multimap.hpp.

## ◆ operator*()

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Tvalue & MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator* | ( |  | ) | const
| inline

Dereference operator.

Works just like usual STL operator*() on various containers. Doesn't do a lot of checks for sanity, just like STL.

Returns
  The value associated with the item this iterator points to.

Definition at line 90 of file multimap.hpp.

## ◆ operator++() [1/2]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Self & MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator++ | ( |  | ) |
| inline

Prefix increment operator.

Increment the iterator and set it to the next item in the MultiMap. This either increments the list iterator or the map iterator and sets list_valid accordingly.

Returns
  This iterator after incrementing.

Definition at line 122 of file multimap.hpp.

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

Referenced by MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator++().

## ◆ operator++() [2/2]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Self MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator++ | ( | int |  | ) |
| inline

Postfix increment operator.

Same as prefix increment, but return the previous state.

Parameters

  dummy | param to mark postfix.

Returns
  This iterator before incrementing.

Definition at line 147 of file multimap.hpp.

References MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator++().

## ◆ operator--() [1/2]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Self & MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator-- | ( |  | ) |
| inline

Prefix decrement operator.

Decrement the iterator and set it to the previous item in the MultiMap.

Returns
  This iterator after decrementing.

Definition at line 159 of file multimap.hpp.

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

Referenced by MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator--().

## ◆ operator--() [2/2]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Self MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator-- | ( | int |  | ) |
| inline

Postfix decrement operator.

Same as prefix decrement, but return the previous state.

Parameters

  dummy | param to mark postfix.

Returns
  This iterator before decrementing.

Definition at line 178 of file multimap.hpp.

References MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator--().

## ◆ operator->()

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Tvalue * MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator-> | ( |  | ) | const
| inline

Same as operator*(), but returns a pointer.

Returns
  Pointer to the value this iterator points to.

Definition at line 102 of file multimap.hpp.

## ◆ operator=()

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >
template<class Tnon_const >

Self & MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator= | ( | Tnon_const | mi | ) |
| inline

Assignment iterator like constructor with the same signature.

Template Parameters

  Tnon_const | Iterator type assignable to Tmap_iter (which might be const).

Parameters

  mi | One such iterator.

Returns
  This iterator.

Definition at line 78 of file multimap.hpp.

## ◆ operator==() [1/2]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >
template<class Tmap_iter_other , class Tlist_iter_other , class Tvalue_other >

bool MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator== | ( | const MultiMapIterator< Tmap_iter_other, Tlist_iter_other, Tkey, Tvalue_other, Tcompare > & | other | ) | const
| inline

Compare two MultiMap iterators.

Iterators are equal if

1. Their map iterators are equal.
2. They agree about list_valid.
3. If list_valid they agree about list_iter. Lots of template parameters to make all possible const and non-const types of MultiMap iterators (on maps with const and non-const values) comparable to each other.
   Parameters

     other | Other iterator to compare to.

   Returns
     If other is equal to this.

Definition at line 195 of file multimap.hpp.

## ◆ operator==() [2/2]

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >
template<class Titer >

bool MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator== | ( | const Titer & | iter | ) | const
| inline

Check if a MultiMap iterator is at the begin of a list pointed to by the given map iterator.

Lots of template parameters to make all possible const and non-const types of MultiMap iterators (on maps with const and non-const values) comparable to all possible types of map iterators.

Parameters

  iter | Map iterator.

Returns
  If this points to the begin of the list pointed to by iter.

Definition at line 211 of file multimap.hpp.

## Friends And Related Symbol Documentation

## ◆ MultiMap< Tkey, Tvalue, Tcompare >

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

friend class MultiMap< Tkey, Tvalue, Tcompare >
| friend

Definition at line 1 of file multimap.hpp.

## Field Documentation

## ◆ list_iter

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Tlist_iter MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::list_iter
| protected

Iterator pointing to current position in the current list of items with equal keys.

Definition at line 30 of file multimap.hpp.

Referenced by MultiMap< Tkey, Tvalue, Tcompare >::erase().

## ◆ list_valid

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

bool MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::list_valid
| protected

Flag to show that the iterator has just "walked" a step in the map.

We cannot check the current list for that as we might have reached end() of the map. In that case we'd need to set list_iter to some sort of "invalid" state, but that's impossible as operator== yields undefined behaviour if the iterators don't belong to the same list and there is no list at end(). So if we created a static empty list and an "invalid" iterator in that we could not determine if the iterator is invalid while it's valid. We can also not determine if the map iterator is valid while we don't have the map; so in the end it's easiest to just introduce an extra flag.

Definition at line 42 of file multimap.hpp.

Referenced by MultiMap< Tkey, Tvalue, Tcompare >::erase().

## ◆ map_iter

template<class Tmap_iter , class Tlist_iter , class Tkey , class Tvalue , class Tcompare >

Tmap_iter MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::map_iter
| protected

Iterator pointing to the position of the current list of items with equal keys in the map.

Definition at line 31 of file multimap.hpp.

Referenced by MultiMap< Tkey, Tvalue, Tcompare >::erase(), MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator++(), and MultiMapIterator< Tmap_iter, Tlist_iter, Tkey, Tvalue, Tcompare >::operator--().

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

- src/core/multimap.hpp