OpenTTD Source: SmallMap< T, U > Struct Template Reference

OpenTTD Source 1.11.0-RC1

Public Types | Public Member Functions | Data Fields
SmallMap< T, U > Struct Template Reference

Implementation of simple mapping class. More...

`#include <smallmap_type.hpp>`

Inheritance diagram for SmallMap< T, U >:

## Public Types
typedef std::pair< T, U > | Pair
typedef Pair * | iterator

## Public Member Functions
| SmallMap ()
| Creates new SmallMap. More...
| ~SmallMap ()
| Data are freed in std::vector destructor.
std::vector< Pair >::const_iterator | Find (const T &key) const
| Finds given key in this map. More...
Pair * | Find (const T &key)
| Finds given key in this map. More...
const Pair * | End () const
Pair * | End ()
bool | Contains (const T &key) const
| Tests whether a key is assigned in this map. More...
bool | Contains (const T &key)
| Tests whether a key is assigned in this map. More...
void | Erase (Pair *pair)
| Removes given pair from this map. More...
bool | Erase (const T &key)
| Removes given key from this map. More...
bool | Insert (const T &key, const U &data)
| Adds new item to this map. More...
U & | operator[] (const T &key)
| Returns data belonging to this key. More...

## Data Fields
const typedef Pair * | const_iterator

## Detailed Description

### template<typename T, typename U>
struct SmallMap< T, U >

Implementation of simple mapping class.

It has inherited accessors from std::vector().

Template Parameters

  T | Key type.
  U | Value type.
  S | Unit of allocation.

See also
  std::vector

Definition at line 26 of file smallmap_type.hpp.

## Constructor & Destructor Documentation

## ◆ SmallMap()

template<typename T , typename U >

SmallMap< T, U >::SmallMap | ( |  | ) |
| inline

Creates new SmallMap.

Data are initialized in std::vector constructor

Definition at line 32 of file smallmap_type.hpp.

## Member Function Documentation

## ◆ Contains() [1/2]

template<typename T , typename U >

bool SmallMap< T, U >::Contains | ( | const T & | key | ) |
| inline

Tests whether a key is assigned in this map.

Parameters

  key | key to test

Returns
  true iff the item is present

Definition at line 89 of file smallmap_type.hpp.

## ◆ Contains() [2/2]

template<typename T , typename U >

bool SmallMap< T, U >::Contains | ( | const T & | key | ) | const
| inline

Tests whether a key is assigned in this map.

Parameters

  key | key to test

Returns
  true iff the item is present

Definition at line 79 of file smallmap_type.hpp.

Referenced by ScriptInfo::AddLabels(), GRFParameterInfo::Finalize(), and NetworkAddress::Resolve().

## ◆ Erase() [1/2]

template<typename T , typename U >

bool SmallMap< T, U >::Erase | ( | const T & | key | ) |
| inline

Removes given key from this map.

Parameters

  key | key to remove

Returns
  true iff the key was found

Note
  last item is moved to its place, so don't increase your iterator if true is returned!

Definition at line 112 of file smallmap_type.hpp.

## ◆ Erase() [2/2]

template<typename T , typename U >

void SmallMap< T, U >::Erase | ( | Pair * | pair | ) |
| inline

Removes given pair from this map.

Parameters

  pair | pair to remove

Note
  it has to be pointer to pair in this map. It is overwritten by the last item.

Definition at line 99 of file smallmap_type.hpp.

## ◆ Find() [1/2]

template<typename T , typename U >

Pair* SmallMap< T, U >::Find | ( | const T & | key | ) |
| inline

Finds given key in this map.

Parameters

  key | key to find

Returns
  &Pair(key, data) if found, this->End() if not

Definition at line 55 of file smallmap_type.hpp.

## ◆ Find() [2/2]

template<typename T , typename U >

std::vector<Pair>::const_iterator SmallMap< T, U >::Find | ( | const T & | key | ) | const
| inline

Finds given key in this map.

Parameters

  key | key to find

Returns
  &Pair(key, data) if found, this->End() if not

Definition at line 41 of file smallmap_type.hpp.

Referenced by ChangeGRFParamValueNames(), Vehicle::GetConsistFreeCapacities(), Layouter::GetFont(), TrueTypeFontCache::GetFontTable(), and Window::GetQueryString().

## ◆ Insert()

template<typename T , typename U >

bool SmallMap< T, U >::Insert | ( | const T & | key,
|  | const U & | data
| ) |  |
| inline

Adds new item to this map.

Parameters

  key | key
  data | data

Returns
  true iff the key wasn't already present

Definition at line 127 of file smallmap_type.hpp.

Referenced by ScriptInfo::AddLabels(), and TrueTypeFontCache::GetFontTable().

## ◆ operator[]()

template<typename T , typename U >

U& SmallMap< T, U >::operator[] | ( | const T & | key | ) |
| inline

Returns data belonging to this key.

Parameters

  key | key

Returns
  data belonging to this key

Note
  if this key wasn't present, new entry is created

Definition at line 140 of file smallmap_type.hpp.

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

- src/core/smallmap_type.hpp