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

Public Member Functions

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

Static Public Member Functions

static int CDECL KeySorter (const void *a, const void *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().

See also:
SmallVector

Definition at line 25 of file smallmap_type.hpp.


Constructor & Destructor Documentation

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

Creates new SmallMap.

Data are initialized in SmallVector constructor

Definition at line 30 of file smallmap_type.hpp.


Member Function Documentation

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

References SmallVector< SmallPair< T, U >, S >::data, SmallVector< SmallPair< T, U >, S >::End(), and SmallVector< SmallPair< T, U >, S >::items.

Referenced by SmallMap< T, U, S >::Insert().

template<typename T, typename U, uint S = 16>
FORCEINLINE 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 50 of file smallmap_type.hpp.

References SmallVector< SmallPair< T, U >, S >::Begin(), SmallVector< SmallPair< T, U >, S >::data, SmallVector< SmallPair< T, U >, S >::End(), and SmallVector< SmallPair< T, U >, S >::items.

template<typename T, typename U, uint S = 16>
FORCEINLINE 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 61 of file smallmap_type.hpp.

References SmallVector< SmallPair< T, U >, S >::data, and SmallVector< SmallPair< T, U >, S >::items.

template<typename T, typename U, uint S = 16>
FORCEINLINE 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 77 of file smallmap_type.hpp.

References SmallVector< SmallPair< T, U >, S >::Append(), SmallVector< SmallPair< T, U >, S >::End(), and SmallMap< T, U, S >::Find().

template<typename T, typename U, uint S = 16>
FORCEINLINE 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 89 of file smallmap_type.hpp.

References SmallVector< SmallPair< T, U >, S >::Append(), SmallVector< SmallPair< T, U >, S >::data, SmallPair< T, U >::first, SmallVector< SmallPair< T, U >, S >::items, and SmallPair< T, U >::second.


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

Generated on Sun Nov 15 15:40:40 2009 for OpenTTD by  doxygen 1.5.6