1 | //$Id: utility.h 39 2006-01-13 15:02:31Z jari $ |
---|
2 | |
---|
3 | #ifndef _theplu_svnstat_utility_ |
---|
4 | #define _theplu_svnstat_utility_ |
---|
5 | |
---|
6 | #include <algorithm> |
---|
7 | #include <functional> |
---|
8 | #include <string> |
---|
9 | #include <utility> |
---|
10 | #include <vector> |
---|
11 | |
---|
12 | namespace theplu{ |
---|
13 | namespace svnstat{ |
---|
14 | |
---|
15 | /// |
---|
16 | /// Calculating sum of two vectors. |
---|
17 | /// |
---|
18 | /// @return resulting vector |
---|
19 | /// |
---|
20 | template <class T > |
---|
21 | struct VectorPlus : |
---|
22 | public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> > |
---|
23 | { |
---|
24 | std::vector<T> operator()(const std::vector<T>& u, |
---|
25 | const std::vector<T>& v) const |
---|
26 | { |
---|
27 | if ( u.size() > v.size() ){ |
---|
28 | std::vector<T> res(u.size()); |
---|
29 | transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>()); |
---|
30 | copy(u.begin()+v.size(), u.end(), res.begin()+v.size()); |
---|
31 | return res; |
---|
32 | } |
---|
33 | |
---|
34 | std::vector<T> res(v.size()); |
---|
35 | transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>()); |
---|
36 | if ( v.size() > u.size() ) |
---|
37 | copy(v.begin()+u.size(), v.end(), res.begin()+u.size()); |
---|
38 | return res; |
---|
39 | } |
---|
40 | |
---|
41 | }; |
---|
42 | |
---|
43 | /// |
---|
44 | /// @return resulting vector |
---|
45 | /// |
---|
46 | template <class Key, class T> |
---|
47 | struct PairValuePlus : |
---|
48 | public std::binary_function<std::vector<T>, |
---|
49 | std::pair<const Key, std::vector<T> >, |
---|
50 | std::vector<T> > |
---|
51 | { |
---|
52 | std::vector<T> operator()(const std::vector<T>& sum, |
---|
53 | const std::pair<const Key,std::vector<T> >& p) |
---|
54 | { |
---|
55 | return VectorPlus<T>()(sum, p.second); |
---|
56 | } |
---|
57 | }; |
---|
58 | |
---|
59 | /// |
---|
60 | /// Jari, is this obsolete? And thus erasable? |
---|
61 | /// |
---|
62 | struct CodingMore : |
---|
63 | public std::binary_function<std::pair<std::string,std::vector<u_int> >, |
---|
64 | std::pair<std::string,std::vector<u_int> >, |
---|
65 | bool > |
---|
66 | { |
---|
67 | inline bool operator() |
---|
68 | (const std::pair<std::string,std::vector<u_int> >& a, |
---|
69 | const std::pair<std::string,std::vector<u_int> >& b) |
---|
70 | { |
---|
71 | if (a.second.back() > b.second.back()) |
---|
72 | return true; |
---|
73 | else if (a.second.back() < b.second.back()) |
---|
74 | return false; |
---|
75 | return a.first < b.first; |
---|
76 | } |
---|
77 | }; |
---|
78 | |
---|
79 | }} |
---|
80 | |
---|
81 | // end of namespace svnstat end of namespace theplu |
---|
82 | #endif |
---|