OpenTTD Source  1.11.2
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 Pairiterator
 

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...
 
PairFind (const T &key)
 Finds given key in this map. More...
 
const PairEnd () const
 
PairEnd ()
 
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 Pairconst_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
TKey type.
UValue type.
SUnit 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
keykey 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
keykey 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
keykey 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
pairpair 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
keykey 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
keykey 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
keykey
datadata
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
keykey
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: