source: trunk/lib/utility.h @ 34

Last change on this file since 34 was 23, checked in by Peter Johansson, 17 years ago

added print functionality

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1//$Id: utility.h 23 2006-01-02 08:14:57Z peter $
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
12namespace theplu{
13namespace 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  struct CodingMore :
61    public std::binary_function<std::pair<std::string,std::vector<u_int> >,
62                                std::pair<std::string,std::vector<u_int> >,
63                                bool >
64  {
65    inline bool operator()
66      (const std::pair<std::string,std::vector<u_int> >& a, 
67       const std::pair<std::string,std::vector<u_int> >& b)
68    {
69      if (a.second.back() > b.second.back())
70        return true;
71      else if (a.second.back() < b.second.back())
72        return false;
73      return a.first < b.first;
74    }
75  };
76
77}}
78
79// end of namespace svnstat end of namespace theplu
80#endif
Note: See TracBrowser for help on using the repository browser.