OpenTTD
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 ::SmallPair< T, U > Pair
 
typedef Pairiterator
 
typedef const Pairconst_iterator
 

Public Member Functions

 SmallMap ()
 Creates new SmallMap. More...
 
 ~SmallMap ()
 Data are freed in SmallVector 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...
 

Detailed Description

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

Implementation of simple mapping class.

Both types have to be POD ("Plain Old Data")! It has inherited accessors from SmallVector().

Template Parameters
TKey type.
UValue type.
SUnit of allocation.
See also
SmallVector

Definition at line 40 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 SmallVector constructor

Definition at line 46 of file smallmap_type.hpp.

Member Function Documentation

◆ Contains() [1/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 93 of file smallmap_type.hpp.

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

◆ Contains() [2/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 103 of file smallmap_type.hpp.

◆ Erase() [1/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 113 of file smallmap_type.hpp.

◆ Erase() [2/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 126 of file smallmap_type.hpp.

◆ Find() [1/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 55 of file smallmap_type.hpp.

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

◆ Find() [2/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 69 of file smallmap_type.hpp.

◆ 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 141 of file smallmap_type.hpp.

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

◆ 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 154 of file smallmap_type.hpp.


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