465 |
24 Aug 07 |
peter |
1 |
#ifndef _theplu_svndigest_functor_ |
465 |
24 Aug 07 |
peter |
2 |
#define _theplu_svndigest_functor_ |
165 |
24 Aug 06 |
jari |
3 |
|
84 |
13 Mar 06 |
jari |
// $Id$ |
4 |
29 Dec 05 |
peter |
5 |
|
84 |
13 Mar 06 |
jari |
6 |
/* |
847 |
17 Nov 09 |
peter |
Copyright (C) 2005 Peter Johansson |
978 |
12 Dec 09 |
peter |
Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
1515 |
26 Sep 12 |
peter |
Copyright (C) 2010, 2011, 2012 Peter Johansson |
84 |
13 Mar 06 |
jari |
10 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
84 |
13 Mar 06 |
jari |
12 |
|
149 |
12 Aug 06 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
84 |
13 Mar 06 |
jari |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
84 |
13 Mar 06 |
jari |
(at your option) any later version. |
84 |
13 Mar 06 |
jari |
17 |
|
149 |
12 Aug 06 |
jari |
svndigest is distributed in the hope that it will be useful, but |
84 |
13 Mar 06 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
126 |
01 Aug 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
84 |
13 Mar 06 |
jari |
General Public License for more details. |
84 |
13 Mar 06 |
jari |
22 |
|
84 |
13 Mar 06 |
jari |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
84 |
13 Mar 06 |
jari |
25 |
*/ |
84 |
13 Mar 06 |
jari |
26 |
|
727 |
11 Dec 08 |
jari |
27 |
#include <algorithm> |
4 |
29 Dec 05 |
peter |
28 |
#include <functional> |
23 |
02 Jan 06 |
peter |
29 |
#include <string> |
4 |
29 Dec 05 |
peter |
30 |
#include <utility> |
4 |
29 Dec 05 |
peter |
31 |
#include <vector> |
4 |
29 Dec 05 |
peter |
32 |
|
126 |
01 Aug 06 |
jari |
33 |
#include <sys/stat.h> |
126 |
01 Aug 06 |
jari |
34 |
|
4 |
29 Dec 05 |
peter |
35 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
36 |
namespace svndigest{ |
4 |
29 Dec 05 |
peter |
37 |
|
308 |
12 May 07 |
peter |
38 |
struct AlNum |
308 |
12 May 07 |
peter |
39 |
{ |
1513 |
23 Sep 12 |
peter |
40 |
inline bool operator()(std::string::const_iterator i) const |
308 |
12 May 07 |
peter |
41 |
{ return isalnum(*i); } |
308 |
12 May 07 |
peter |
42 |
}; |
308 |
12 May 07 |
peter |
43 |
|
308 |
12 May 07 |
peter |
44 |
|
289 |
08 May 07 |
peter |
45 |
struct Digit |
289 |
08 May 07 |
peter |
46 |
{ |
1513 |
23 Sep 12 |
peter |
47 |
inline bool operator()(std::string::const_iterator i) const |
294 |
08 May 07 |
peter |
48 |
{ return isdigit(*i); } |
289 |
08 May 07 |
peter |
49 |
}; |
289 |
08 May 07 |
peter |
50 |
|
308 |
12 May 07 |
peter |
51 |
|
289 |
08 May 07 |
peter |
52 |
class notChar |
289 |
08 May 07 |
peter |
53 |
{ |
289 |
08 May 07 |
peter |
54 |
public: |
289 |
08 May 07 |
peter |
55 |
notChar(char); |
1513 |
23 Sep 12 |
peter |
56 |
inline bool operator()(std::string::const_iterator i) const |
294 |
08 May 07 |
peter |
57 |
{ return *i!=char_; } |
289 |
08 May 07 |
peter |
58 |
private: |
289 |
08 May 07 |
peter |
59 |
char char_; |
289 |
08 May 07 |
peter |
60 |
}; |
289 |
08 May 07 |
peter |
61 |
|
371 |
19 Jun 07 |
peter |
62 |
|
289 |
08 May 07 |
peter |
63 |
class not2Char |
289 |
08 May 07 |
peter |
64 |
{ |
289 |
08 May 07 |
peter |
65 |
public: |
289 |
08 May 07 |
peter |
66 |
not2Char(char, char); |
1513 |
23 Sep 12 |
peter |
67 |
inline bool operator()(std::string::const_iterator i) const |
294 |
08 May 07 |
peter |
68 |
{ return *i!=char1_ && *i!=char2_; } |
289 |
08 May 07 |
peter |
69 |
private: |
289 |
08 May 07 |
peter |
70 |
const char char1_; |
289 |
08 May 07 |
peter |
71 |
const char char2_; |
289 |
08 May 07 |
peter |
72 |
}; |
289 |
08 May 07 |
peter |
73 |
|
294 |
08 May 07 |
peter |
74 |
class not2Str |
294 |
08 May 07 |
peter |
75 |
{ |
294 |
08 May 07 |
peter |
76 |
public: |
294 |
08 May 07 |
peter |
77 |
not2Str(std::string, std::string); |
1513 |
23 Sep 12 |
peter |
78 |
inline bool operator()(std::string::const_iterator i) const |
1513 |
23 Sep 12 |
peter |
79 |
{ |
294 |
08 May 07 |
peter |
80 |
return !(std::equal(str1_.begin(), str1_.end(), i) || |
294 |
08 May 07 |
peter |
81 |
std::equal(str2_.begin(), str2_.end(), i)); |
1513 |
23 Sep 12 |
peter |
82 |
} |
294 |
08 May 07 |
peter |
83 |
|
294 |
08 May 07 |
peter |
84 |
private: |
294 |
08 May 07 |
peter |
85 |
const std::string str1_; |
294 |
08 May 07 |
peter |
86 |
const std::string str2_; |
294 |
08 May 07 |
peter |
87 |
}; |
294 |
08 May 07 |
peter |
88 |
|
226 |
11 Mar 07 |
peter |
89 |
/// |
371 |
19 Jun 07 |
peter |
/// Functor to be used on contaioners and works as standard less, |
371 |
19 Jun 07 |
peter |
/// but on the reversed container. |
371 |
19 Jun 07 |
peter |
92 |
/// |
371 |
19 Jun 07 |
peter |
/// Requirements on T is that has rend and rbegin. T::value_type |
371 |
19 Jun 07 |
peter |
/// must be comparable (i.e. have operator<) |
1513 |
23 Sep 12 |
peter |
95 |
/// |
371 |
19 Jun 07 |
peter |
96 |
template <typename T> |
371 |
19 Jun 07 |
peter |
97 |
struct LessReversed |
371 |
19 Jun 07 |
peter |
98 |
{ |
371 |
19 Jun 07 |
peter |
99 |
/// |
371 |
19 Jun 07 |
peter |
/// using std::lexicographical_compare on the reversed container |
371 |
19 Jun 07 |
peter |
101 |
/// |
371 |
19 Jun 07 |
peter |
102 |
inline bool operator()(const T& x, const T& y) const |
371 |
19 Jun 07 |
peter |
103 |
{ return std::lexicographical_compare(x.rbegin(),x.rend(), |
371 |
19 Jun 07 |
peter |
104 |
y.rbegin(),y.rend()); } |
371 |
19 Jun 07 |
peter |
105 |
}; |
371 |
19 Jun 07 |
peter |
106 |
|
371 |
19 Jun 07 |
peter |
107 |
|
371 |
19 Jun 07 |
peter |
108 |
/// |
234 |
09 Apr 07 |
peter |
/// @brief Functor comparing pairs using second. |
234 |
09 Apr 07 |
peter |
110 |
/// |
234 |
09 Apr 07 |
peter |
/// STL provides operator< for the pair.first element, but none for |
234 |
09 Apr 07 |
peter |
/// pair.second. This template provides this and can be used as the |
234 |
09 Apr 07 |
peter |
/// comparison object in generic functions such as the STL sort. |
234 |
09 Apr 07 |
peter |
114 |
/// |
371 |
19 Jun 07 |
peter |
115 |
template <typename T1, typename T2> |
234 |
09 Apr 07 |
peter |
116 |
struct pair_value_compare |
234 |
09 Apr 07 |
peter |
117 |
{ |
234 |
09 Apr 07 |
peter |
118 |
/// |
234 |
09 Apr 07 |
peter |
/// @return true if x.second<y.second or (x.second==y.second and |
234 |
09 Apr 07 |
peter |
/// x.first<y.first) |
234 |
09 Apr 07 |
peter |
121 |
/// |
234 |
09 Apr 07 |
peter |
122 |
inline bool operator()(const std::pair<T1,T2>& x, |
234 |
09 Apr 07 |
peter |
123 |
const std::pair<T1,T2>& y) { |
234 |
09 Apr 07 |
peter |
124 |
return ((x.second<y.second) || |
1513 |
23 Sep 12 |
peter |
125 |
(!(y.second<x.second) && (x.first<y.first))); |
234 |
09 Apr 07 |
peter |
126 |
} |
234 |
09 Apr 07 |
peter |
127 |
}; |
234 |
09 Apr 07 |
peter |
128 |
|
1513 |
23 Sep 12 |
peter |
129 |
|
371 |
19 Jun 07 |
peter |
130 |
/// |
371 |
19 Jun 07 |
peter |
/// Functor working on pair.second, using a user passed functor. |
371 |
19 Jun 07 |
peter |
132 |
/// |
371 |
19 Jun 07 |
peter |
133 |
template <typename T1, typename T2, typename T3> |
303 |
11 May 07 |
peter |
134 |
struct PairSecondCompare |
303 |
11 May 07 |
peter |
135 |
{ |
303 |
11 May 07 |
peter |
136 |
|
303 |
11 May 07 |
peter |
137 |
/// |
303 |
11 May 07 |
peter |
/// @brief Constructor |
303 |
11 May 07 |
peter |
139 |
/// |
303 |
11 May 07 |
peter |
140 |
explicit PairSecondCompare(const T3& comp) |
303 |
11 May 07 |
peter |
141 |
: compare_(comp) {} |
303 |
11 May 07 |
peter |
142 |
|
303 |
11 May 07 |
peter |
143 |
/// |
371 |
19 Jun 07 |
peter |
/// @return compare(x.second, y.second) where compare is a |
371 |
19 Jun 07 |
peter |
/// internal comparison functor. |
303 |
11 May 07 |
peter |
146 |
/// |
303 |
11 May 07 |
peter |
147 |
inline bool operator()(const std::pair<T1,T2>& x, |
303 |
11 May 07 |
peter |
148 |
const std::pair<T1,T2>& y) const |
303 |
11 May 07 |
peter |
149 |
{ return compare_(x.second,y.second); } |
303 |
11 May 07 |
peter |
150 |
|
303 |
11 May 07 |
peter |
151 |
private: |
303 |
11 May 07 |
peter |
152 |
T3 compare_; |
303 |
11 May 07 |
peter |
153 |
|
303 |
11 May 07 |
peter |
154 |
}; |
1513 |
23 Sep 12 |
peter |
155 |
|
1204 |
05 Oct 10 |
peter |
156 |
/** |
1204 |
05 Oct 10 |
peter |
Functor perfoming plus assignment on first argument using second argument |
4 |
29 Dec 05 |
peter |
158 |
|
1204 |
05 Oct 10 |
peter |
arg1 += arg2.second |
1204 |
05 Oct 10 |
peter |
160 |
*/ |
126 |
01 Aug 06 |
jari |
161 |
template <typename Key, typename T> |
1652 |
14 Jun 23 |
peter |
162 |
struct PairValuePlusAssign |
1203 |
05 Oct 10 |
peter |
163 |
{ |
1495 |
27 Aug 12 |
peter |
164 |
void operator()(T& x, const std::pair<const Key, T>& p) const |
1203 |
05 Oct 10 |
peter |
165 |
{ |
1203 |
05 Oct 10 |
peter |
166 |
x += p.second; |
1203 |
05 Oct 10 |
peter |
167 |
} |
1203 |
05 Oct 10 |
peter |
168 |
}; |
1203 |
05 Oct 10 |
peter |
169 |
|
1203 |
05 Oct 10 |
peter |
170 |
|
1203 |
05 Oct 10 |
peter |
171 |
/** |
1203 |
05 Oct 10 |
peter |
T1 must be mutable |
1203 |
05 Oct 10 |
peter |
173 |
*/ |
1203 |
05 Oct 10 |
peter |
174 |
template<typename T1, typename T2> |
1652 |
14 Jun 23 |
peter |
175 |
struct PlusAssign |
1203 |
05 Oct 10 |
peter |
176 |
{ |
1203 |
05 Oct 10 |
peter |
177 |
void operator()(T1 t1, T2 t2) const |
1203 |
05 Oct 10 |
peter |
178 |
{ t1+=t2; } |
1203 |
05 Oct 10 |
peter |
179 |
}; |
1203 |
05 Oct 10 |
peter |
180 |
|
149 |
12 Aug 06 |
jari |
181 |
}} // end of namespace svndigest end of namespace theplu |
4 |
29 Dec 05 |
peter |
182 |
|
1513 |
23 Sep 12 |
peter |
183 |
#endif |