#include <map2.h>
Public Types | |
typedef __Kty_container | _Kty_container |
typedef __Ty_container | _Ty_container |
typedef map2< __Kty, __Ty, _Kty_container, _Ty_container, __Pr, __Alloc > | _Myt |
typedef map< __Kty, __Ty, __Pr, __Alloc > | _Mybase |
typedef pair< const __Kty, __Ty > | _Element |
typedef __Kty | _Kty |
typedef __Ty | _Ty |
typedef check_fun_t< _Myt, _Element > | _Element_check_fun_t |
typedef check_fun_t < _Kty_container, __Kty > | _Kty_check_fun_t |
typedef check_fun_t < _Ty_container, __Ty > | _Ty_check_fun_t |
Public Member Functions | |
_Ty & | operator[] (const _Kty &key) |
_Kty_container | keys () const |
_Kty_container | keys (_Kty_check_fun_t check) const |
_Ty_container | values () const |
_Ty_container | values (_Ty_check_fun_t check) const |
pair< iterator, bool > | insert_elem (const _Kty &key, const _Ty &val) |
_Myt | select (_Element_check_fun_t check) const |
bool | contains_key (const _Kty &key) const |
const _Kty & | first_key (const _Kty &if_empty) const |
_Ty & | first_elem (_Ty &if_empty) |
const _Ty & | first_elem (const _Ty &if_empty) const |
The template map2 is derived from std::map and uses list2, vector2 or deque2 as key and value containers with vector2 being the default since that should normally result in faster applications.
The main advantage of this specialisation is that you are able to retrieve a container for all or selected keys and/or values. The container type used for this task is determined by the container types used when constructing a class from this template.
This specialisation supports:
_Kty | key type | |
_Ty | value type | |
_Kty_container | container for keys (vector2, list2, deque2) | |
_Ty_container | container for values (vector2, list2, deque2) | |
_Pr | less prediction | |
_Alloc | element allocator |
Definition at line 149 of file map2.h.
typedef __Kty_container std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Kty_container |
typedef __Ty_container std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Ty_container |
typedef map2<__Kty, __Ty, _Kty_container, _Ty_container, __Pr, __Alloc> std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Myt |
typedef map<__Kty, __Ty, __Pr, __Alloc> std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Mybase |
typedef pair<const __Kty, __Ty> std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Element |
typedef check_fun_t<_Myt,_Element> std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Element_check_fun_t |
typedef check_fun_t<_Kty_container,__Kty> std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Kty_check_fun_t |
typedef check_fun_t<_Ty_container,__Ty> std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::_Ty_check_fun_t |
_Ty& std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::operator[] | ( | const _Kty & | key | ) | [inline] |
Definition at line 166 of file map2.h.
00167 { 00168 iterator it = insert_elem(key, _Ty()).first; 00169 return (*it).second; 00170 }
_Kty_container std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::keys | ( | ) | const [inline] |
Returns std::deque, std::list or std::vector of all keys stored in this map.
This is dependent on the template parameter _Kty_containter that defaults to deque2.
Definition at line 187 of file map2.h.
00188 { 00189 _Kty_container __container; 00190 for (const_iterator it=begin(); it!=end(); ++it) 00191 { 00192 __container.push_back(it->first); 00193 } 00194 return __container; 00195 }
_Kty_container std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::keys | ( | _Kty_check_fun_t | check | ) | const [inline] |
Returns std::deque, std::list or std::vector of selected keys stored in this map.
This is dependent on the template parameter _Kty_containter that defaults to std::deque2.
With this specialized version you are able to decide which keys of the map should make it in the returned container.
For example this makes it easy to build a list of keys that conform to to a certain condition. such like returning all keys that start with the same string when using strings as keys.
check | key selection helper function |
Definition at line 216 of file map2.h.
00217 { 00218 _Kty_container container; 00219 for (const_iterator it=begin(); it!=end(); ++it) 00220 { 00221 if (check(container, it->first)) 00222 { 00223 container.push_back(it->first); 00224 } 00225 } 00226 return container; 00227 }
_Ty_container std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::values | ( | ) | const [inline] |
Returns std::deque, std::list or std::vector of all elements stored in this map.
This is dependent on the template parameter _Ty_containter that defaults to std::deque2.
Definition at line 244 of file map2.h.
00245 { 00246 _Ty_container container; 00247 for (const_iterator it=begin(); it!=end(); ++it) 00248 { 00249 container.push_back(it->second); 00250 } 00251 return container; 00252 }
_Ty_container std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::values | ( | _Ty_check_fun_t | check | ) | const [inline] |
Returns std::deque, std::list, std::vector of selected elements stored in this map.
This is dependent on the template parameter _Ty_containter that defaults to std::deque2.
With this specialized version you are able to decide which elements of the map should make it in the returned container.
For example this makes building a container of unique elements easy when the container is deque2, list2 or vector2.
std::map2<int, char*, std::deque2<int>, std::deque2<char*> > v; std::deque2<char*> unique = v.values(std::check_fun(std::deque2<char*>::contains_no));
In the above example the check_fun helper adapter is used to turn the function std::deque2::contains_no into the required test function. This way every element of v
is passed to unique.contains_no()
.
check | element selection helper function |
Definition at line 281 of file map2.h.
00282 { 00283 _Ty_container container; 00284 for (const_iterator it=begin(); it!=end(); ++it) 00285 { 00286 if (check(container, it->second)) 00287 { 00288 container.push_back(it->second); 00289 } 00290 } 00291 return container; 00292 }
pair<iterator, bool> std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::insert_elem | ( | const _Kty & | key, | |
const _Ty & | val | |||
) | [inline] |
Insert a pair constructed from explicit key and val parameters. This is different from operator[] since it uses insert and does therefor not change an existing pair. There exists a template mem function insert what means that all insert functions are non virtual and therefore we cannot name this function insert.
key | Key of element to insert | |
val | Value of element to insert |
Definition at line 307 of file map2.h.
_Myt std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::select | ( | _Element_check_fun_t | check | ) | const [inline] |
Selectively copy key/value pairs to a new map of the same type.
check | element selection helper function |
Definition at line 318 of file map2.h.
00319 { 00320 _Myt container; 00321 for (const_iterator it=begin(); it!=end(); ++it) 00322 { 00323 if (check(container, *it)) 00324 { 00325 container.insert(*it); 00326 } 00327 } 00328 return container; 00329 }
bool std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::contains_key | ( | const _Kty & | key | ) | const [inline] |
Check whether or not the map contains a specific key.
key | Key of element to search for |
Definition at line 335 of file map2.h.
Referenced by mbo::StrToColor().
const _Kty& std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::first_key | ( | const _Kty & | if_empty | ) | const [inline] |
Retrieves the first key or a default one if the map is empty.
if_empty | Key to use when map is empty. |
const T x = y.first_key(T());
. Definition at line 349 of file map2.h.
00350 { 00351 if (size()) 00352 { 00353 return begin()->first; 00354 } 00355 else 00356 { 00357 return if_empty; 00358 } 00359 }
_Ty& std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::first_elem | ( | _Ty & | if_empty | ) | [inline] |
Retrieves the first value or a default one if the map is empty.
if_empty | Value to use when map is empty. |
T x = y.first_elem(T());
. Definition at line 370 of file map2.h.
00371 { 00372 if (size()) 00373 { 00374 return begin()->second; 00375 } 00376 else 00377 { 00378 return if_empty; 00379 } 00380 }
const _Ty& std::map2< __Kty, __Ty, __Kty_container, __Ty_container, __Pr, __Alloc >::first_elem | ( | const _Ty & | if_empty | ) | const [inline] |
Retrieves the first value or a default one if the map is empty (const).
if_empty | Value to use when map is empty. |
const T x = y.first_elem(T());
. Definition at line 391 of file map2.h.
00392 { 00393 if (size()) 00394 { 00395 return begin()->second; 00396 } 00397 else 00398 { 00399 return if_empty; 00400 } 00401 }
Hosted on code.google.com | © Marcus Börger | Generated on Fri Jan 18 21:21:15 2008 for MBO-lib by 1.5.4 |