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)
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;
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)
189 for(
typename std::map<K, V>::const_iterator
iter =
m.begin();
iter!=
m.end(); ++
iter)
191 s.insert(
s.end(),
iter->first);
201 template<
class K,
class V>
202 inline std::vector<V>
uValues(
const std::map<K, V> & m)
204 std::vector<V>
v(
m.size());
206 for(
typename std::map<K, V>::const_iterator
iter =
m.begin();
iter!=
m.end(); ++
iter)
219 template<
class K,
class V>
223 for(
typename std::map<K, V>::const_iterator
iter =
m.begin();
iter!=
m.end(); ++
iter)
225 l.push_back(
iter->second);
237 template<
class K,
class V>
238 inline V uValue(
const std::map<K, V> & m,
const K & key,
const V & defaultValue =
V())
241 typename std::map<K, V>::const_iterator
i =
m.find(
key);
257 template<
class K,
class V>
258 inline V uTake(std::map<K, V> & m,
const K & key,
const V & defaultValue =
V())
261 typename std::map<K, V>::iterator
i =
m.find(
key);
300 inline typename std::list<V>::const_iterator
uIteratorAt(
const std::list<V> &
list,
const unsigned int &
pos)
320 typename std::set<V>::iterator
iter =
set.begin();
336 inline typename std::set<V>::const_iterator
uIteratorAt(
const std::set<V> &
set,
const unsigned int &
pos)
338 typename std::set<V>::const_iterator
iter =
set.begin();
354 inline typename std::vector<V>::iterator
uIteratorAt(std::vector<V> & v,
const unsigned int &
pos)
356 return v.begin() +
pos;
367 inline typename std::vector<V>::const_iterator
uIteratorAt(
const std::vector<V> & v,
const unsigned int &
pos)
369 return v.begin() +
pos;
418 template<
class K,
class V>
419 inline bool uContains(
const std::map<K, V> & map,
const K & key)
421 return map.find(
key) != map.end();
430 template<
class K,
class V>
431 inline bool uContains(
const std::multimap<K, V> & map,
const K & key)
433 return map.find(
key) != map.end();
440 template<
class K,
class V>
441 inline void uInsert(std::map<K, V> & map,
const std::pair<K, V> & pair)
443 std::pair<typename std::map<K, V>::iterator,
bool> inserted = map.insert(pair);
444 if(inserted.second ==
false)
446 inserted.first->second = pair.second;
454 template<
class K,
class V>
455 inline void uInsert(std::map<K, V> & map,
const std::map<K, V> & items)
457 for(
typename std::map<K, V>::const_iterator
iter=items.begin();
iter!=items.end(); ++
iter)
459 std::pair<typename std::map<K, V>::iterator,
bool> inserted = map.insert(*
iter);
460 if(inserted.second ==
false)
462 inserted.first->second =
iter->second;
486 return std::list<V>(
v.begin(),
v.end());
493 template<
class K,
class V>
496 return std::map<K, V>(
m.begin(),
m.end());
502 template<
class K,
class V>
505 std::map<K, V> mapOut;
507 for(
typename std::list<K>::const_iterator
iter = uniqueKeys.begin();
iter!=uniqueKeys.end(); ++
iter)
509 if(
m.count(*
iter) == 1)
511 typename std::multimap<K, V>::const_iterator jter=
m.find(*
iter);
512 mapOut.insert(mapOut.end(), std::pair<K,V>(jter->first, jter->second));
524 inline void uAppend(std::list<V> &
list,
const std::list<V> & newItems)
564 inline std::list<std::string>
uSplit(
const std::string &
str,
char separator =
' ')
566 std::list<std::string>
v;
568 for(
unsigned int i=0;
i<
str.size(); ++
i)
570 if(
str[
i] != separator)
601 inline std::string
uJoin(
const std::list<std::string> & strings,
const std::string & separator =
"")
604 for(std::list<std::string>::const_iterator
iter = strings.begin();
iter!=strings.end(); ++
iter)
606 if(
iter!=strings.begin() && !separator.empty())
622 return c >=
'0' &&
c <=
'9';
632 bool isInteger =
str.size()!=0;
633 for(
unsigned int i=0;
i<
str.size() && isInteger; ++
i)
672 std::list<std::string>
list;
675 for(
unsigned int i=0;
i<
str.size(); ++
i)
679 if(!num && buf.size())
717 inline int uStrNumCmp(
const std::string & a,
const std::string & b)
719 std::vector<std::string> listA;
720 std::vector<std::string> listB;
727 for(
i=0;
i<listA.size() &&
i<listB.size(); ++
i)
732 if(listA[
i].at(0) ==
'0' && listB[
i].
size() < listA[
i].
size())
739 else if(listB[
i].at(0) ==
'0' && listA[
i].
size() < listB[
i].
size())
757 result = listA[
i].compare(listB[
i]);
770 result = listA[
i].compare(listB[
i]);
785 inline bool uStrContains(
const std::string &
string,
const std::string & substring)
787 return string.find(substring) != std::string::npos;
790 inline int uCompareVersion(
const std::string & version,
int major,
int minor=-1,
int patch=-1)
795 int vMajor = atoi(
v[0].
c_str());
796 int vMinor = atoi(
v[1].
c_str());
797 int vPatch = atoi(
v[2].
c_str());
799 (vMajor == major && minor!=-1 && vMinor > minor) ||
800 (vMajor == major && minor!=-1 && vMinor == minor && patch!=-1 && vPatch > patch))
804 else if(vMajor == major && (minor == -1 || (vMinor == minor && (patch == -1 || vPatch == patch))))
812 inline std::string
uPad(
const std::string & title,
int padding = 20)
814 int emptySize = padding - (
int)title.size();
817 return title + std::string(emptySize,
' ');