1 | //$Id: utility.h 7 2005-12-30 06:41:11Z jari $ |
---|

2 | |
---|

3 | #ifndef _theplu_svnstat_utility_ |
---|

4 | #define _theplu_svnstat_utility_ |
---|

5 | |
---|

6 | #include <algorithm> |
---|

7 | #include <functional> |
---|

8 | #include <utility> |
---|

9 | #include <vector> |
---|

10 | |
---|

11 | namespace theplu{ |
---|

12 | namespace svnstat{ |
---|

13 | |
---|

14 | /// |
---|

15 | /// A resulting vector is calculated as sum of the value of arg |
---|

16 | /// and vector sum_so_far. Each element in value of arg is added to the |
---|

17 | /// corresponded element in sum_so_far. The size of resulting vector is |
---|

18 | /// equal to size of sum_so_far. For elements not having a corresponding |
---|

19 | /// element in vector arg, the element in resulting vector is taken to |
---|

20 | /// be equal to element in sum_so_far. |
---|

21 | /// |
---|

22 | /// @return resulting vector |
---|

23 | /// @note if size of arg.second is larger than size of sum_so_far, the |
---|

24 | /// result is undefined. |
---|

25 | /// |
---|

26 | template <class Key, class T > |
---|

27 | struct VectorPlus : |
---|

28 | public std::binary_function< std::pair<const Key,std::vector<T> >, |
---|

29 | std::vector<T>, std::vector<T> > |
---|

30 | { |
---|

31 | std::vector<T> operator() |
---|

32 | (std::vector<T>& sum_so_far, |
---|

33 | const std::pair<const Key, std::vector<T> >& arg) const |
---|

34 | { |
---|

35 | std::vector<T> res(sum_so_far.size()); |
---|

36 | transform(arg.second.begin(),arg.second.end(),sum_so_far.begin(), |
---|

37 | res.begin(), std::plus<T>()); |
---|

38 | if (sum_so_far.size() > arg.second.size()) |
---|

39 | copy(sum_so_far.begin()+arg.second.size(),sum_so_far.end(), |
---|

40 | res.begin()+arg.second.size()); |
---|

41 | return res; |
---|

42 | } |
---|

43 | |
---|

44 | }; |
---|

45 | }} |
---|

46 | |
---|

47 | #endif // end of namespace svnstat end of namespace theplu |
---|