Public Types | Public Member Functions | Static Public Member Functions

SmallMap< T, U, S > Struct Template Reference

Implementation of simple mapping class. More...

#include <smallmap_type.hpp>

Inheritance diagram for SmallMap< T, U, S >:
SmallVector< SmallPair< T, U >, S >

Public Types

typedef ::SmallPair< T, U > Pair
typedef Pairiterator
typedef const Pairconst_iterator

Public Member Functions

 SmallMap ()
 Creates new SmallMap.
 ~SmallMap ()
 Data are freed in SmallVector destructor.
PairFind (const T &key)
 Finds given key in this map.
bool Contains (const T &key)
 Tests whether a key is assigned in this map.
void Erase (Pair *pair)
 Removes given pair from this map.
bool Erase (const T &key)
 Removes given key from this map.
bool Insert (const T &key, const U &data)
 Adds new item to this map.
U & operator[] (const T &key)
 Returns data belonging to this key.
void SortByKey ()

Static Public Member Functions

static int CDECL KeySorter (const Pair *a, const Pair *b)

Detailed Description

template<typename T, typename U, uint S = 16>
struct SmallMap< T, U, S >

Implementation of simple mapping class.

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

Template Parameters:
T Key type.
U Value type.
S Unit of allocation.
See also:
SmallVector

Definition at line 42 of file smallmap_type.hpp.


Constructor & Destructor Documentation

template<typename T, typename U, uint S = 16>
SmallMap< T, U, S >::SmallMap (  )  [inline]

Creates new SmallMap.

Data are initialized in SmallVector constructor

Definition at line 48 of file smallmap_type.hpp.


Member Function Documentation

template<typename T, typename U, uint S = 16>
bool SmallMap< T, U, S >::Contains ( const T &  key  )  [inline]
template<typename T, typename U, uint S = 16>
bool SmallMap< T, U, S >::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 92 of file smallmap_type.hpp.

template<typename T, typename U, uint S = 16>
void SmallMap< T, U, S >::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 80 of file smallmap_type.hpp.

Referenced by GamelogPrint().

template<typename T, typename U, uint S = 16>
Pair* SmallMap< T, U, S >::Find ( const T &  key  )  [inline]
template<typename T, typename U, uint S = 16>
bool SmallMap< T, U, S >::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 109 of file smallmap_type.hpp.

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

template<typename T, typename U, uint S = 16>
U& SmallMap< T, U, S >::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 124 of file smallmap_type.hpp.


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