Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes

threadsafe_map< K, T > Class Template Reference
[Threadsafe Collection API]

threadsafe map object More...

#include <threadsafe_map.h>

Collaboration diagram for threadsafe_map< K, T >:
Collaboration graph
[legend]

List of all members.

Classes

struct  iterator_t
struct  real_iter_t

Public Member Functions

int size (void) const throw ()
 how many elements in the map
void insert (const K &key, const T &t)
 insert the given object at the given key value (map, not multimap!)
bool lookup (const K &key, T &t) const throw ()
 retrieve value at key--true if there is a value there
bool remove (const K &key)
 remove (erase) the element at key, if there is one
void clear (void)
 clear out (erase) the entire map
void getIterator (iterator_t &i) const throw ()
 get an iterator (points to the first element in the map)
bool getNextElement (iterator_t &i, K &k, T &t) const
 get next element in map and increment iterator

Static Public Member Functions

static int getRealIteratorSize (void) throw ()
 for debugging/validation only

Private Types

typedef std::map< K, T > base_map_t
typedef std::map< K, T >::iterator base_iterator_t
typedef threadsafe_map< K, T > map_t

Private Member Functions

map_tgetNonConst (void) const throw ()

Static Private Member Functions

static real_iter_tgetRealIterator (iterator_t &i) throw ()

Private Attributes

smart_mutex m_mutex
dword_t m_rvn

Detailed Description

template<class K, class T>
class threadsafe_map< K, T >

threadsafe map object

A very simple map object that is safe for multiple threads to use at the same time. There is a single mutex protecting the entire map.

You can iterate using getIterator()/getNextElement(). However, that is not guaranteed iteration. Your iterator will be invalidated (and getNextElement() will return false) if another thread has since updated the map.

Definition at line 59 of file threadsafe_map.h.


Member Typedef Documentation

template<class K, class T>
typedef std::map<K,T> threadsafe_map< K, T >::base_map_t [private]

Definition at line 62 of file threadsafe_map.h.

template<class K, class T>
typedef std::map<K,T>::iterator threadsafe_map< K, T >::base_iterator_t [private]

Definition at line 63 of file threadsafe_map.h.

template<class K, class T>
typedef threadsafe_map<K, T> threadsafe_map< K, T >::map_t [private]

Definition at line 64 of file threadsafe_map.h.


Member Function Documentation

template<class K, class T>
int threadsafe_map< K, T >::size ( void   )  const throw () [inline]

how many elements in the map

Definition at line 81 of file threadsafe_map.h.

template<class K, class T>
void threadsafe_map< K, T >::insert ( const K &  key,
const T &  t 
) [inline]

insert the given object at the given key value (map, not multimap!)

Definition at line 88 of file threadsafe_map.h.

template<class K, class T>
bool threadsafe_map< K, T >::lookup ( const K &  key,
T &  t 
) const throw () [inline]

retrieve value at key--true if there is a value there

Definition at line 95 of file threadsafe_map.h.

template<class K, class T>
bool threadsafe_map< K, T >::remove ( const K &  key  )  [inline]

remove (erase) the element at key, if there is one

Definition at line 107 of file threadsafe_map.h.

template<class K, class T>
void threadsafe_map< K, T >::clear ( void   )  [inline]

clear out (erase) the entire map

Definition at line 119 of file threadsafe_map.h.

template<class K, class T>
void threadsafe_map< K, T >::getIterator ( iterator_t i  )  const throw () [inline]

get an iterator (points to the first element in the map)

Definition at line 126 of file threadsafe_map.h.

template<class K, class T>
bool threadsafe_map< K, T >::getNextElement ( iterator_t i,
K &  k,
T &  t 
) const [inline]

get next element in map and increment iterator

Definition at line 135 of file threadsafe_map.h.

template<class K, class T>
static int threadsafe_map< K, T >::getRealIteratorSize ( void   )  throw () [inline, static]

for debugging/validation only

Definition at line 152 of file threadsafe_map.h.

template<class K, class T>
static real_iter_t* threadsafe_map< K, T >::getRealIterator ( iterator_t i  )  throw () [inline, static, private]

Definition at line 158 of file threadsafe_map.h.

template<class K, class T>
map_t* threadsafe_map< K, T >::getNonConst ( void   )  const throw () [inline, private]

Definition at line 164 of file threadsafe_map.h.


Member Data Documentation

template<class K, class T>
smart_mutex threadsafe_map< K, T >::m_mutex [private]

Definition at line 169 of file threadsafe_map.h.

template<class K, class T>
dword_t threadsafe_map< K, T >::m_rvn [private]

Definition at line 170 of file threadsafe_map.h.


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