UtiLite  0.3.1
A lite utilities library
Functions
include/utilite/UStl.h File Reference

Wrappers of STL for convenient functions. More...

#include <list>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>

Go to the source code of this file.

Functions

template<class K , class V >
std::list< K > uUniqueKeys (const std::multimap< K, V > &mm)
template<class K , class V >
std::vector< K > uKeys (const std::multimap< K, V > &mm)
template<class K , class V >
std::list< K > uKeysList (const std::multimap< K, V > &mm)
template<class K , class V >
std::vector< V > uValues (const std::multimap< K, V > &mm)
template<class K , class V >
std::list< V > uValuesList (const std::multimap< K, V > &mm)
template<class K , class V >
std::list< V > uValues (const std::multimap< K, V > &mm, const K &key)
template<class K , class V >
std::vector< K > uKeys (const std::map< K, V > &m)
template<class K , class V >
std::list< K > uKeysList (const std::map< K, V > &m)
template<class K , class V >
std::set< K > uKeysSet (const std::map< K, V > &m)
template<class K , class V >
std::vector< V > uValues (const std::map< K, V > &m)
template<class K , class V >
std::list< V > uValuesList (const std::map< K, V > &m)
template<class K , class V >
uValue (const std::map< K, V > &m, const K &key, const V &defaultValue=V())
template<class K , class V >
uTake (std::map< K, V > &m, const K &key, const V &defaultValue=V())
template<class V >
std::list< V >::iterator uIteratorAt (std::list< V > &list, const unsigned int &pos)
template<class V >
std::list< V >::const_iterator uIteratorAt (const std::list< V > &list, const unsigned int &pos)
template<class V >
std::vector< V >::iterator uIteratorAt (std::vector< V > &v, const unsigned int &pos)
template<class V >
V & uValueAt (std::list< V > &list, const unsigned int &pos)
template<class V >
const V & uValueAt (const std::list< V > &list, const unsigned int &pos)
template<class V >
bool uContains (const std::list< V > &list, const V &value)
template<class K , class V >
bool uContains (const std::map< K, V > &map, const K &key)
template<class K , class V >
bool uContains (const std::multimap< K, V > &map, const K &key)
template<class K , class V >
void uInsert (std::map< K, V > &map, const std::pair< K, V > &pair)
template<class V >
std::vector< V > uListToVector (const std::list< V > &list)
template<class V >
std::list< V > uVectorToList (const std::vector< V > &v)
template<class V >
void uAppend (std::list< V > &list, const std::list< V > &newItems)
template<class V >
int uIndexOf (const std::vector< V > &list, const V &value)
std::list< std::string > uSplit (const std::string &str, char separator= ' ')
bool uIsDigit (const char c)
std::list< std::string > uSplitNumChar (const std::string &str)
int uStrNumCmp (const std::string &a, const std::string &b)

Detailed Description

Wrappers of STL for convenient functions.

All functions you will find here are here for the use of STL in a more convenient way.


Function Documentation

template<class V >
void uAppend ( std::list< V > &  list,
const std::list< V > &  newItems 
) [inline]

Append a list to another list.

Parameters:
listthe list on which the other list will be appended
newItemsthe list of items to be appended
template<class V >
bool uContains ( const std::list< V > &  list,
const V &  value 
) [inline]

Check if the list contains the specified value.

Parameters:
listthe list
valuethe value
Returns:
true if the value is found in the list, otherwise false
template<class K , class V >
bool uContains ( const std::map< K, V > &  map,
const K &  key 
) [inline]

Check if the map contains the specified key.

Parameters:
mapthe map
keythe key
Returns:
true if the value is found in the map, otherwise false
template<class K , class V >
bool uContains ( const std::multimap< K, V > &  map,
const K &  key 
) [inline]

Check if the multimap contains the specified key.

Parameters:
mapthe map
keythe key
Returns:
true if the value is found in the map, otherwise false
template<class V >
int uIndexOf ( const std::vector< V > &  list,
const V &  value 
) [inline]

Get the index in the list of the specified value. S negative index is returned if the value is not found.

Parameters:
listthe list
valuethe value
Returns:
the index of the value in the list
template<class K , class V >
void uInsert ( std::map< K, V > &  map,
const std::pair< K, V > &  pair 
) [inline]

Insert an item in the map. Contrary to the insert in the STL, if the key already exists, the value will be replaced by the new one.

bool uIsDigit ( const char  c) [inline]

Check if a character is a digit.

Parameters:
cthe character
Returns:
if the character is a digit (if c >= '0' && c <= '9')
template<class V >
std::list<V>::iterator uIteratorAt ( std::list< V > &  list,
const unsigned int &  pos 
) [inline]

Get the iterator at a specified position in a std::list. If the position is out of range, the result is the end iterator of the list.

Parameters:
listthe list
posthe index position in the list
Returns:
the iterator at the specified index
template<class V >
std::list<V>::const_iterator uIteratorAt ( const std::list< V > &  list,
const unsigned int &  pos 
) [inline]

Get the iterator at a specified position in a std::list. If the position is out of range, the result is the end iterator of the list.

Parameters:
listthe list
posthe index position in the list
Returns:
the iterator at the specified index
template<class V >
std::vector<V>::iterator uIteratorAt ( std::vector< V > &  v,
const unsigned int &  pos 
) [inline]

Get the iterator at a specified position in a std::vector. If the position is out of range, the result is the end iterator of the vector.

Parameters:
vthe vector
posthe index position in the vector
Returns:
the iterator at the specified index
template<class K , class V >
std::vector<K> uKeys ( const std::multimap< K, V > &  mm) [inline]

Get all keys from a std::multimap.

Parameters:
mmthe multimap
Returns:
the vector which contains all keys (may contains duplicated keys)
template<class K , class V >
std::vector<K> uKeys ( const std::map< K, V > &  m) [inline]

Get all keys from a std::map.

Parameters:
mthe map
Returns:
the vector of keys
template<class K , class V >
std::list<K> uKeysList ( const std::multimap< K, V > &  mm) [inline]

Get all keys from a std::multimap.

Parameters:
mmthe multimap
Returns:
the list which contains all keys (may contains duplicated keys)
template<class K , class V >
std::list<K> uKeysList ( const std::map< K, V > &  m) [inline]

Get all keys from a std::map.

Parameters:
mthe map
Returns:
the list of keys
template<class K , class V >
std::set<K> uKeysSet ( const std::map< K, V > &  m) [inline]

Get all keys from a std::map.

Parameters:
mthe map
Returns:
the set of keys
template<class V >
std::vector<V> uListToVector ( const std::list< V > &  list) [inline]

Convert a std::list to a std::vector.

Parameters:
listthe list
Returns:
the vector
std::list<std::string> uSplit ( const std::string &  str,
char  separator = ' ' 
) [inline]

Split a string into multiple string around the specified separator. Example:

                std::list<std::string> v = split("Hello the world!", ' ');

The list v will contain {"Hello", "the", "world!"}

Parameters:
strthe string
separatorthe separator character
Returns:
the list of strings
std::list<std::string> uSplitNumChar ( const std::string &  str) [inline]

Split a string into number and character strings. Example:

                std::list<std::string> v = uSplit("Hello 03 my 65 world!");

The list v will contain {"Hello ", "03", " my ", "65", " world!"}

Parameters:
strthe string
Returns:
the list of strings
int uStrNumCmp ( const std::string &  a,
const std::string &  b 
) [inline]

Compare two alphanumeric strings. Useful to sort filenames (human-like sorting). Example:

        std::string a = "Image9.jpg";
        std::string b = "Image10.jpg";
        int r = uStrNumCmp(a, b); // r returns -1 (a is smaller than b). In contrast, std::strcmp(a, b) would return 1.
Parameters:
athe first string
bthe second string
Returns:
-1 if a<b, 0 if a=b and 1 if a>b
template<class K , class V >
V uTake ( std::map< K, V > &  m,
const K &  key,
const V &  defaultValue = V() 
) [inline]

Get the value of a specified key from a std::map. This will remove the value from the map;

Parameters:
mthe map
keythe key
defaultValuethe default value used if the key is not found
Returns:
the value
template<class K , class V >
std::list<K> uUniqueKeys ( const std::multimap< K, V > &  mm) [inline]

Get unique keys from a std::multimap.

Parameters:
mmthe multimap
Returns:
the list which contains unique keys
template<class K , class V >
V uValue ( const std::map< K, V > &  m,
const K &  key,
const V &  defaultValue = V() 
) [inline]

Get the value of a specified key from a std::map.

Parameters:
mthe map
keythe key
defaultValuethe default value used if the key is not found
Returns:
the value
template<class V >
V& uValueAt ( std::list< V > &  list,
const unsigned int &  pos 
) [inline]

Get the value at a specified position in a std::list. If the position is out of range, the result is undefined.

Parameters:
listthe list
posthe index position in the list
Returns:
the value at the specified index
template<class V >
const V& uValueAt ( const std::list< V > &  list,
const unsigned int &  pos 
) [inline]

Get the value at a specified position in a std::list. If the position is out of range, the result is undefined.

Parameters:
listthe list
posthe index position in the list
Returns:
the value at the specified index
template<class K , class V >
std::vector<V> uValues ( const std::multimap< K, V > &  mm) [inline]

Get all values from a std::multimap.

Parameters:
mmthe multimap
Returns:
the vector which contains all values (contains values from duplicated keys)
template<class K , class V >
std::list<V> uValues ( const std::multimap< K, V > &  mm,
const K &  key 
) [inline]

Get values for a specified key from a std::multimap.

Parameters:
mmthe multimap
keythe key
Returns:
the list which contains the values of the key
template<class K , class V >
std::vector<V> uValues ( const std::map< K, V > &  m) [inline]

Get all values from a std::map.

Parameters:
mthe map
Returns:
the vector of values
template<class K , class V >
std::list<V> uValuesList ( const std::multimap< K, V > &  mm) [inline]

Get all values from a std::multimap.

Parameters:
mmthe multimap
Returns:
the list which contains all values (contains values from duplicated keys)
template<class K , class V >
std::list<V> uValuesList ( const std::map< K, V > &  m) [inline]

Get all values from a std::map.

Parameters:
mthe map
Returns:
the list of values
template<class V >
std::list<V> uVectorToList ( const std::vector< V > &  v) [inline]

Convert a std::vector to a std::list.

Parameters:
vthe vector
Returns:
the list
 All Classes Files Functions Variables Enumerations Friends Defines