45 template<
class K,
class V>
46 inline std::list<K>
uUniqueKeys(
const std::multimap<K, V> & mm)
49 typename std::list<K>::reverse_iterator lastValue;
50 for(
typename std::multimap<K, V>::const_iterator iter = mm.begin(); iter!=mm.end(); ++iter)
52 if(iter == mm.begin() || (iter != mm.begin() && *lastValue != iter->first))
54 l.push_back(iter->first);
55 lastValue = l.rbegin();
66 template<
class K,
class V>
67 inline std::vector<K>
uKeys(
const std::multimap<K, V> & mm)
69 std::vector<K> v(mm.size());
71 for(
typename std::multimap<K, V>::const_iterator iter = mm.begin(); iter!=mm.end(); ++iter)
83 template<
class K,
class V>
84 inline std::list<K>
uKeysList(
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->first);
99 template<
class K,
class V>
100 inline std::vector<V>
uValues(
const std::multimap<K, V> & mm)
102 std::vector<V> v(mm.size());
104 for(
typename std::multimap<K, V>::const_iterator iter = mm.begin(); iter!=mm.end(); ++iter)
106 v[i++] = iter->second;
116 template<
class K,
class V>
120 for(
typename std::multimap<K, V>::const_iterator iter = mm.begin(); iter!=mm.end(); ++iter)
122 l.push_back(iter->second);
133 template<
class K,
class V>
134 inline std::list<V>
uValues(
const std::multimap<K, V> & mm,
const K & key)
137 std::pair<typename std::multimap<K, V>::const_iterator,
typename std::multimap<K, V>::const_iterator> range;
138 range = mm.equal_range(key);
139 for(
typename std::multimap<K, V>::const_iterator iter = range.first; iter!=range.second; ++iter)
141 l.push_back(iter->second);
151 template<
class K,
class V>
152 inline std::vector<K>
uKeys(
const std::map<K, V> & m)
154 std::vector<K> v(m.size());
156 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
169 template<
class K,
class V>
173 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
175 l.push_back(iter->first);
185 template<
class K,
class V>
186 inline std::set<K>
uKeysSet(
const std::map<K, V> & m)
190 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
192 s.insert(s.end(), iter->first);
203 template<
class K,
class V>
204 inline std::vector<V>
uValues(
const std::map<K, V> & m)
206 std::vector<V> v(m.size());
208 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
221 template<
class K,
class V>
225 for(
typename std::map<K, V>::const_iterator iter = m.begin(); iter!=m.end(); ++iter)
227 l.push_back(iter->second);
239 template<
class K,
class V>
240 inline V
uValue(
const std::map<K, V> & m,
const K & key,
const V & defaultValue = V())
243 typename std::map<K, V>::const_iterator i = m.find(key);
259 template<
class K,
class V>
260 inline V
uTake(std::map<K, V> & m,
const K & key,
const V & defaultValue = V())
263 typename std::map<K, V>::iterator i = m.find(key);
284 inline typename std::list<V>::iterator
uIteratorAt(std::list<V> & list,
const unsigned int & pos)
286 typename std::list<V>::iterator iter = list.begin();
287 for(
unsigned int i = 0; i<pos && iter != list.end(); ++i )
302 inline typename std::list<V>::const_iterator
uIteratorAt(
const std::list<V> & list,
const unsigned int & pos)
304 typename std::list<V>::const_iterator iter = list.begin();
305 for(
unsigned int i = 0; i<pos && iter != list.end(); ++i )
320 inline typename std::set<V>::iterator
uIteratorAt(std::set<V> &
set,
const unsigned int & pos)
322 typename std::set<V>::iterator iter =
set.begin();
323 for(
unsigned int i = 0; i<pos && iter !=
set.end(); ++i )
338 inline typename std::set<V>::const_iterator
uIteratorAt(
const std::set<V> &
set,
const unsigned int & pos)
340 typename std::set<V>::const_iterator iter =
set.begin();
341 for(
unsigned int i = 0; i<pos && iter !=
set.end(); ++i )
356 inline typename std::vector<V>::iterator
uIteratorAt(std::vector<V> & v,
const unsigned int & pos)
358 return v.begin() + pos;
369 inline typename std::vector<V>::const_iterator
uIteratorAt(
const std::vector<V> & v,
const unsigned int & pos)
371 return v.begin() + pos;
382 inline V &
uValueAt(std::list<V> & list,
const unsigned int & pos)
384 typename std::list<V>::iterator iter =
uIteratorAt(list, pos);
396 inline const V &
uValueAt(
const std::list<V> & list,
const unsigned int & pos)
398 typename std::list<V>::const_iterator iter =
uIteratorAt(list, pos);
409 inline bool uContains(
const std::list<V> & list,
const V & value)
411 return std::find(list.begin(), list.end(), value) != list.end();
420 template<
class K,
class V>
421 inline bool uContains(
const std::map<K, V> & map,
const K & key)
423 return map.find(key) != map.end();
432 template<
class K,
class V>
433 inline bool uContains(
const std::multimap<K, V> & map,
const K & key)
435 return map.find(key) != map.end();
442 template<
class K,
class V>
443 inline void uInsert(std::map<K, V> & map,
const std::pair<K, V> & pair)
445 std::pair<typename std::map<K, V>::iterator,
bool> inserted = map.insert(pair);
446 if(inserted.second ==
false)
448 inserted.first->second = pair.second;
456 template<
class K,
class V>
457 inline void uInsert(std::map<K, V> & map,
const std::map<K, V> & items)
459 for(
typename std::map<K, V>::const_iterator iter=items.begin(); iter!=items.end(); ++iter)
461 std::pair<typename std::map<K, V>::iterator,
bool> inserted = map.insert(*iter);
462 if(inserted.second ==
false)
464 inserted.first->second = iter->second;
477 return std::vector<V>(list.begin(), list.end());
488 return std::list<V>(v.begin(), v.end());
495 template<
class K,
class V>
498 return std::map<K, V>(m.begin(), m.end());
504 template<
class K,
class V>
507 std::map<K, V> mapOut;
509 for(
typename std::list<K>::const_iterator iter = uniqueKeys.begin(); iter!=uniqueKeys.end(); ++iter)
511 if(m.count(*iter) == 1)
513 typename std::multimap<K, V>::const_iterator jter=m.find(*iter);
514 mapOut.insert(mapOut.end(), std::pair<K,V>(jter->first, jter->second));
526 inline void uAppend(std::list<V> & list,
const std::list<V> & newItems)
528 list.insert(list.end(), newItems.begin(), newItems.end());
539 inline int uIndexOf(
const std::vector<V> & list,
const V & value)
543 for(
typename std::vector<V>::const_iterator iter = list.begin(); iter!=list.end(); ++iter)
566 inline std::list<std::string>
uSplit(
const std::string & str,
char separator =
' ')
568 std::list<std::string> v;
570 for(
unsigned int i=0; i<str.size(); ++i)
572 if(str[i] != separator)
603 inline std::string
uJoin(
const std::list<std::string> & strings,
const std::string & separator =
"")
606 for(std::list<std::string>::const_iterator iter = strings.begin(); iter!=strings.end(); ++iter)
608 if(iter!=strings.begin() && !separator.empty())
624 return c >=
'0' && c <=
'9';
632 inline bool uIsInteger(
const std::string & str,
bool checkForSign =
true)
634 bool isInteger = str.size()!=0;
635 for(
unsigned int i=0; i<str.size() && isInteger; ++i)
637 isInteger = (checkForSign && i==0 && str[i]==
'-') ||
uIsDigit(str[i]);
649 std::list<std::string> list =
uSplit(str,
'.');
654 else if(list.size() == 2)
674 std::list<std::string> list;
677 for(
unsigned int i=0; i<str.size(); ++i)
681 if(!num && buf.size())
719 inline int uStrNumCmp(
const std::string & a,
const std::string & b)
721 std::vector<std::string> listA;
722 std::vector<std::string> listB;
729 for(i=0; i<listA.size() && i<listB.size(); ++i)
734 if(listA[i].at(0) ==
'0' && listB[i].size() < listA[i].size())
736 while(listB[i].size() < listA[i].size())
741 else if(listB[i].at(0) ==
'0' && listA[i].size() < listB[i].size())
743 while(listA[i].size() < listB[i].size())
749 if(listB[i].size() < listA[i].size())
753 else if(listB[i].size() > listA[i].size())
759 result = listA[i].compare(listB[i]);
772 result = listA[i].compare(listB[i]);
787 inline bool uStrContains(
const std::string &
string,
const std::string & substring)
789 return string.find(substring) != std::string::npos;
792 inline int uCompareVersion(
const std::string & version,
int major,
int minor=-1,
int patch=-1)
797 int vMajor = atoi(v[0].c_str());
798 int vMinor = atoi(v[1].c_str());
799 int vPatch = atoi(v[2].c_str());
801 (vMajor == major && minor!=-1 && vMinor > minor) ||
802 (vMajor == major && minor!=-1 && vMinor == minor && patch!=-1 && vPatch > patch))
806 else if(vMajor == major && (minor == -1 || (vMinor == minor && (patch == -1 || vPatch == patch))))
bool uIsInteger(const std::string &str, bool checkForSign=true)
std::list< K > uUniqueKeys(const std::multimap< K, V > &mm)
std::map< K, V > uMultimapToMapUnique(const std::multimap< K, V > &m)
std::vector< K > uKeys(const std::multimap< K, V > &mm)
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)
std::list< V > uValuesList(const std::multimap< K, V > &mm)
V uTake(std::map< K, V > &m, const K &key, const V &defaultValue=V())
bool uStrContains(const std::string &string, const std::string &substring)
std::list< std::string > uSplit(const std::string &str, char separator=' ')
std::string uJoin(const std::list< std::string > &strings, const std::string &separator="")
int uCompareVersion(const std::string &version, int major, int minor=-1, int patch=-1)
std::map< K, V > uMultimapToMap(const std::multimap< K, V > &m)
std::list< V > uVectorToList(const std::vector< V > &v)
std::list< std::string > uSplitNumChar(const std::string &str)
bool uIsNumber(const std::string &str)
bool uContains(const std::list< V > &list, const V &value)
std::vector< V > uListToVector(const std::list< V > &list)
std::vector< V > uValues(const std::multimap< K, V > &mm)
std::list< V >::iterator uIteratorAt(std::list< V > &list, const unsigned int &pos)
std::list< K > uKeysList(const std::multimap< K, V > &mm)
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)