source: trunk/lib/utility.h @ 71

Last change on this file since 71 was 71, checked in by Peter Johansson, 18 years ago

class goes to typename, hi hi

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1//$Id: utility.h 71 2006-02-23 09:25:41Z peter $
2
3#ifndef _theplu_svnstat_utility_
4#define _theplu_svnstat_utility_
5
6#include <algorithm>
7#include <functional>
8#include <map>
9#include <string>
10#include <utility>
11#include <vector>
12
13namespace theplu{
14namespace svnstat{
15
16  ///
17  /// @return 0 if ok
18  ///
19  int blame(const std::string&);
20
21  ///
22  /// Extracts information from 'svn info <node>'
23  ///
24  /// @note <node> must be in subversion control.
25  ///
26  std::map<std::string, std::string> info(const std::string&);
27
28//  int log(const std::string&);
29
30  ///
31  /// Calculating sum of two vectors.
32  ///
33  /// @return resulting vector
34  ///
35  template <typename T >
36  struct VectorPlus : 
37    public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> >
38  {
39    std::vector<T> operator()(const std::vector<T>& u,
40                              const std::vector<T>& v) const 
41    {
42      if ( u.size() > v.size() ){
43        std::vector<T> res(u.size());
44        transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>());
45        copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
46        return res;
47      }
48 
49      std::vector<T> res(v.size());
50      transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());
51      if ( v.size() > u.size() )
52        copy(v.begin()+u.size(), v.end(), res.begin()+u.size());
53      return res;
54    }
55
56  };
57
58  ///
59  /// @return resulting vector
60  ///
61  template <typename Key, typename T>
62  struct PairValuePlus :
63    public std::binary_function<std::vector<T>,
64                                std::pair<const Key, std::vector<T> >, 
65                                std::vector<T> >
66  {
67    std::vector<T> operator()(const std::vector<T>& sum, 
68                              const std::pair<const Key,std::vector<T> >& p)
69    {
70      return VectorPlus<T>()(sum, p.second);
71    }
72  };
73
74  ///
75  /// Jari, is this obsolete? And thus erasable?
76  ///
77  struct CodingMore :
78    public std::binary_function<std::pair<std::string,std::vector<u_int> >,
79                                std::pair<std::string,std::vector<u_int> >,
80                                bool >
81  {
82    inline bool operator()
83      (const std::pair<std::string,std::vector<u_int> >& a, 
84       const std::pair<std::string,std::vector<u_int> >& b)
85    {
86      if (a.second.back() > b.second.back())
87        return true;
88      else if (a.second.back() < b.second.back())
89        return false;
90      return a.first < b.first;
91    }
92  };
93
94}}
95
96// end of namespace svnstat end of namespace theplu
97#endif
Note: See TracBrowser for help on using the repository browser.