46 template<
class K,
class V>
47 inline std::list<K>
uUniqueKeys(
const std::multimap<K, V> & mm)
50 typename std::list<K>::reverse_iterator lastValue;
51 for(
typename std::multimap<K, V>::const_iterator iter = mm.begin(); iter!=mm.end(); ++iter)
53 if(iter == mm.begin() || (iter != mm.begin() && *lastValue != iter->first))
55 l.push_back(iter->first);
56 lastValue = l.rbegin();
67 template<
class K,
class V>
68 inline std::list<K>
uKeys(
const std::multimap<K, V> & mm)
71 for(
typename std::multimap<K, V>::const_iterator iter = mm.begin(); iter!=mm.end(); ++iter)
73 l.push_back(iter->first);
83 template<
class K,
class V>
84 inline std::list<V>
uValues(
const std::multimap<K, V> & mm)
87 for(
typename std::multimap<K, V>::const_iterator iter = mm.begin(); iter!=mm.end(); ++iter)
89 l.push_back(iter->second);
100 template<
class K,
class V>
101 inline std::list<V>
uValues(
const std::multimap<K, V> & mm,
const K & key)
104 std::pair<typename std::multimap<K, V>::const_iterator,
typename std::multimap<K, V>::const_iterator> range;
105 range = mm.equal_range(key);
106 for(
typename std::multimap<K, V>::const_iterator iter = range.first; iter!=range.second; ++iter)
108 l.push_back(iter->second);
118 template<
class K,
class V>
119 inline std::vector<K>
uKeys(
const std::map<K, V> & m)
121 std::vector<K> v(m.size());
123 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
136 template<
class K,
class V>
140 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
142 l.push_back(iter->first);
152 template<
class K,
class V>
153 inline std::set<K>
uKeysSet(
const std::map<K, V> & m)
157 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
159 s.insert(s.end(), iter->first);
170 template<
class K,
class V>
171 inline std::vector<V>
uValues(
const std::map<K, V> & m)
173 std::vector<V> v(m.size());
175 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
188 template<
class K,
class V>
192 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
194 l.push_back(iter->second);
206 template<
class K,
class V>
207 inline V
uValue(
const std::map<K, V> & m,
const K & key,
const V & defaultValue = V())
210 typename std::map<K, V>::const_iterator i = m.find(key);
226 template<
class K,
class V>
227 inline V
uTake(std::map<K, V> & m,
const K & key,
const V & defaultValue = V())
230 typename std::map<K, V>::iterator i = m.find(key);
251 inline typename std::list<V>::iterator
uIteratorAt(std::list<V> & list,
const unsigned int & pos)
253 typename std::list<V>::iterator iter = list.begin();
254 for(
unsigned int i = 0; i<pos && iter != list.end(); ++i )
269 inline typename std::list<V>::const_iterator
uIteratorAt(
const std::list<V> & list,
const unsigned int & pos)
271 typename std::list<V>::const_iterator iter = list.begin();
272 for(
unsigned int i = 0; i<pos && iter != list.end(); ++i )
287 inline typename std::vector<V>::iterator
uIteratorAt(std::vector<V> & v,
const unsigned int & pos)
289 return v.begin() + pos;
300 inline V &
uValueAt(std::list<V> & list,
const unsigned int & pos)
302 typename std::list<V>::iterator iter =
uIteratorAt(list, pos);
314 inline const V &
uValueAt(
const std::list<V> & list,
const unsigned int & pos)
316 typename std::list<V>::const_iterator iter =
uIteratorAt(list, pos);
327 inline bool uContains(
const std::list<V> & list,
const V & value)
329 return std::find(list.begin(), list.end(), value) != list.end();
338 template<
class K,
class V>
339 inline bool uContains(
const std::map<K, V> & map,
const K & key)
341 return map.find(key) != map.end();
350 template<
class K,
class V>
351 inline bool uContains(
const std::multimap<K, V> & map,
const K & key)
353 return map.find(key) != map.end();
360 template<
class K,
class V>
361 inline void uInsert(std::map<K, V> & map,
const std::pair<K, V> & pair)
363 std::pair<typename std::map<K, V>::iterator,
bool> inserted = map.insert(pair);
364 if(inserted.second ==
false)
366 inserted.first->second = pair.second;
378 return std::vector<V>(list.begin(), list.end());
389 return std::list<V>(v.begin(), v.end());
398 inline void uAppend(std::list<V> & list,
const std::list<V> & newItems)
400 list.insert(list.end(), newItems.begin(), newItems.end());
411 inline int uIndexOf(
const std::vector<V> & list,
const V & value)
415 for(
typename std::vector<V>::const_iterator iter = list.begin(); iter!=list.end(); ++iter)
438 inline std::list<std::string>
uSplit(
const std::string & str,
char separator =
' ')
440 std::list<std::string> v;
442 for(
unsigned int i=0; i<str.size(); ++i)
444 if(str[i] != separator)
468 return c >=
'0' && c <=
'9';
483 std::list<std::string> list;
486 for(
unsigned int i=0; i<str.size(); ++i)
490 if(!num && buf.size())
528 inline int uStrNumCmp(
const std::string & a,
const std::string & b)
530 std::vector<std::string> listA;
531 std::vector<std::string> listB;
538 for(i=0; i<listA.size() && i<listB.size(); ++i)
543 if(listA[i].at(0) ==
'0' && listB[i].size() < listA[i].size())
545 while(listB[i].size() < listA[i].size())
550 else if(listB[i].at(0) ==
'0' && listA[i].size() < listB[i].size())
552 while(listA[i].size() < listB[i].size())
558 if(listB[i].size() < listA[i].size())
562 else if(listB[i].size() > listA[i].size())
568 result = listA[i].compare(listB[i]);
581 result = listA[i].compare(listB[i]);
std::list< K > uUniqueKeys(const std::multimap< K, V > &mm)
std::list< K > uKeysList(const std::map< K, V > &m)
bool uIsDigit(const char c)
V & uValueAt(std::list< V > &list, const unsigned int &pos)
int uStrNumCmp(const std::string &a, const std::string &b)
std::set< K > uKeysSet(const std::map< K, V > &m)
V uTake(std::map< K, V > &m, const K &key, const V &defaultValue=V())
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
std::list< V > uVectorToList(const std::vector< V > &v)
std::list< std::string > uSplitNumChar(const std::string &str)
std::list< V > uValues(const std::multimap< K, V > &mm)
bool uContains(const std::list< V > &list, const V &value)
std::vector< V > uListToVector(const std::list< V > &list)
std::list< V >::iterator uIteratorAt(std::list< V > &list, const unsigned int &pos)
std::list< K > uKeys(const std::multimap< K, V > &mm)
std::list< V > uValuesList(const std::map< K, V > &m)
void uAppend(std::list< V > &list, const std::list< V > &newItems)
int uIndexOf(const std::vector< V > &list, const V &value)
V uValue(const std::map< K, V > &m, const K &key, const V &defaultValue=V())
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)