source: trunk/lib/utility.h @ 115

Last change on this file since 115 was 115, checked in by Peter Johansson, 15 years ago

added pwd function

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1// $Id: utility.h 115 2006-06-30 11:19:30Z peter $
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 <fstream>
29#include <functional>
30#include <map>
31#include <string>
32#include <utility>
33#include <vector>
34
35namespace theplu{
36namespace svnstat{
37
38  ///
39  /// @return 0 if ok
40  ///
41  int blame(const std::string&);
42 
43  ///
44  /// Create directory \a dir. The call can fail in many ways, cf. 'man
45  /// mkdir'. If the \a dir exists, setting \a force to true will
46  /// trigger a recursive removal of the target \a dir.
47  ///
48  int createdir(const std::string& dir, bool force=false);
49
50  ///
51  /// @return everything after last '/'
52  ///
53  std::string file_name(const std::string&);
54
55  ///
56  /// Extracts information from 'svn info <node>'
57  ///
58  /// @note <node> must be in subversion control.
59  ///
60  std::map<std::string, std::string> info(const std::string&);
61
62  ///
63  /// @return the current working directory.
64  ///
65  std::string pwd(void);
66
67  ///
68  /// @printing cascading style sheet to stream @a s.
69  ///
70  void print_css(std::ostream& s);
71
72  ///
73  /// Calculating sum of two vectors.
74  ///
75  /// @return resulting vector
76  ///
77  template <typename T >
78  struct VectorPlus : 
79    public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> >
80  {
81    std::vector<T> operator()(const std::vector<T>& u,
82                              const std::vector<T>& v) const 
83    {
84      if ( u.size() > v.size() ){
85        std::vector<T> res(u.size());
86        transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>());
87        copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
88        return res;
89      }
90 
91      std::vector<T> res(v.size());
92      transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());
93      if ( v.size() > u.size() )
94        copy(v.begin()+u.size(), v.end(), res.begin()+u.size());
95      return res;
96    }
97
98  };
99
100  ///
101  /// @return resulting vector
102  ///
103  template <typename Key, typename T>
104  struct PairValuePlus :
105    public std::binary_function<std::vector<T>,
106                                std::pair<const Key, std::vector<T> >, 
107                                std::vector<T> >
108  {
109    std::vector<T> operator()(const std::vector<T>& sum, 
110                              const std::pair<const Key,std::vector<T> >& p)
111    {
112      return VectorPlus<T>()(sum, p.second);
113    }
114  };
115
116  ///
117  /// Jari, is this obsolete? And thus erasable?
118  ///
119  struct CodingMore :
120    public std::binary_function<std::pair<std::string,std::vector<u_int> >,
121                                std::pair<std::string,std::vector<u_int> >,
122                                bool >
123  {
124    inline bool operator()
125      (const std::pair<std::string,std::vector<u_int> >& a, 
126       const std::pair<std::string,std::vector<u_int> >& b)
127    {
128      if (a.second.back() > b.second.back())
129        return true;
130      else if (a.second.back() < b.second.back())
131        return false;
132      return a.first < b.first;
133    }
134  };
135
136}}
137
138// end of namespace svnstat end of namespace theplu
139#endif
Note: See TracBrowser for help on using the repository browser.