source: trunk/lib/utility.h @ 84

Last change on this file since 84 was 84, checked in by Jari Häkkinen, 17 years ago

Added copyright statement. Bumped version number to pre0.3. Cleaned up code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1// $Id: utility.h 84 2006-03-13 22:04:34Z jari $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svnstat is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#ifndef _theplu_svnstat_utility_
25#define _theplu_svnstat_utility_
26
27#include <algorithm>
28#include <functional>
29#include <map>
30#include <string>
31#include <utility>
32#include <vector>
33
34namespace theplu{
35namespace svnstat{
36
37  ///
38  /// @return 0 if ok
39  ///
40  int blame(const std::string&);
41
42  ///
43  /// Extracts information from 'svn info <node>'
44  ///
45  /// @note <node> must be in subversion control.
46  ///
47  std::map<std::string, std::string> info(const std::string&);
48
49//  int log(const std::string&);
50
51  ///
52  /// Calculating sum of two vectors.
53  ///
54  /// @return resulting vector
55  ///
56  template <typename T >
57  struct VectorPlus : 
58    public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> >
59  {
60    std::vector<T> operator()(const std::vector<T>& u,
61                              const std::vector<T>& v) const 
62    {
63      if ( u.size() > v.size() ){
64        std::vector<T> res(u.size());
65        transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>());
66        copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
67        return res;
68      }
69 
70      std::vector<T> res(v.size());
71      transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());
72      if ( v.size() > u.size() )
73        copy(v.begin()+u.size(), v.end(), res.begin()+u.size());
74      return res;
75    }
76
77  };
78
79  ///
80  /// @return resulting vector
81  ///
82  template <typename Key, typename T>
83  struct PairValuePlus :
84    public std::binary_function<std::vector<T>,
85                                std::pair<const Key, std::vector<T> >, 
86                                std::vector<T> >
87  {
88    std::vector<T> operator()(const std::vector<T>& sum, 
89                              const std::pair<const Key,std::vector<T> >& p)
90    {
91      return VectorPlus<T>()(sum, p.second);
92    }
93  };
94
95  ///
96  /// Jari, is this obsolete? And thus erasable?
97  ///
98  struct CodingMore :
99    public std::binary_function<std::pair<std::string,std::vector<u_int> >,
100                                std::pair<std::string,std::vector<u_int> >,
101                                bool >
102  {
103    inline bool operator()
104      (const std::pair<std::string,std::vector<u_int> >& a, 
105       const std::pair<std::string,std::vector<u_int> >& b)
106    {
107      if (a.second.back() > b.second.back())
108        return true;
109      else if (a.second.back() < b.second.back())
110        return false;
111      return a.first < b.first;
112    }
113  };
114
115}}
116
117// end of namespace svnstat end of namespace theplu
118#endif
Note: See TracBrowser for help on using the repository browser.