33 #ifndef __KLEOPATRA_MODELS_PREDICATES_H__
34 #define __KLEOPATRA_MODELS_PREDICATES_H__
36 #include <kleo/stl_util.h>
41 #include <gpgme++/key.h>
43 #include <boost/bind.hpp>
52 inline int mystrcmp(
const char * s1,
const char * s2 ) {
54 return s1 ? s2 ? strcmp( s1, s2 ) : 1 : s2 ? -1 : 0 ;
57 #define make_comparator_str_impl( Name, expr, cmp ) \
58 template <template <typename U> class Op> \
60 typedef bool result_type; \
62 bool operator()( const char * lhs, const char * rhs ) const { \
63 return Op<int>()( cmp, 0 ); \
66 bool operator()( const std::string & lhs, const std::string & rhs ) const { \
67 return operator()( lhs.c_str(), rhs.c_str() ); \
69 bool operator()( const char * lhs, const std::string & rhs ) const { \
70 return operator()( lhs, rhs.c_str() ); \
72 bool operator()( const std::string & lhs, const char * rhs ) const { \
73 return operator()( lhs.c_str(), rhs ); \
76 template <typename T> \
77 bool operator()( const T & lhs, const T & rhs ) const { \
78 return operator()( (lhs expr), (rhs expr) ); \
80 template <typename T> \
81 bool operator()( const T & lhs, const char * rhs ) const { \
82 return operator()( (lhs expr), rhs ); \
84 template <typename T> \
85 bool operator()( const char * lhs, const T & rhs ) const { \
86 return operator()( lhs, (rhs expr) ); \
88 template <typename T> \
89 bool operator()( const T & lhs, const std::string & rhs ) const { \
90 return operator()( (lhs expr), rhs ); \
92 template <typename T> \
93 bool operator()( const std::string & lhs, const T & rhs ) const { \
94 return operator()( lhs, (rhs expr) ); \
98 #define make_comparator_str_fast( Name, expr ) \
99 make_comparator_str_impl( Name, expr, _detail::mystrcmp( lhs, rhs ) )
100 #define make_comparator_str( Name, expr ) \
101 make_comparator_str_impl( Name, expr, qstricmp( lhs, rhs ) )
108 template <
typename T>
110 std::sort( t.begin(), t.end(), ByFingerprint<std::less>() );
113 template <
typename T>
115 t.erase( std::unique( t.begin(), t.end(), ByFingerprint<std::equal_to>() ), t.end() );
118 template <
typename T>
121 result.reserve( t1.size() + t2.size() );
122 std::set_union( t1.begin(), t1.end(),
123 t2.begin(), t2.end(),
124 std::back_inserter( result ),
125 ByFingerprint<std::less>() );
129 template <
typename T>
137 template <
typename T>
139 t.erase( std::remove_if( t.begin(), t.end(), boost::bind( &GpgME::Key::protocol, _1 ) != proto ), t.end() );
142 template <
typename T>
144 return kdtools::any( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
147 template <
typename T>
149 return kdtools::all( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
152 template <
typename T>
154 return kdtools::none_of( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
157 template <
typename T>
159 t.erase( std::remove_if( t.begin(), t.end(), boost::mem_fn( &GpgME::Key::hasSecret ) ), t.end() );
162 template <
typename T>
164 return kdtools::any( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
167 template <
typename T>
169 return kdtools::all( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
172 template <
typename T>
174 return kdtools::none_of( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
178 template <
typename T>
180 t.erase( std::remove_if( t.begin(), t.end(), !boost::bind( &GpgME::Key::canEncrypt, _1 ) ), t.end() );
bool any_protocol(const T &t, GpgME::Protocol proto)
void grep_can_encrypt(T &t)
make_comparator_str_fast(ByFingerprint,.primaryFingerprint())
bool any_secret(const T &t)
T union_by_fpr(const T &t1, const T &t2)
void grep_protocol(T &t, GpgME::Protocol proto)
bool all_secret(const T &t)
bool all_protocol(const T &t, GpgME::Protocol proto)
bool none_of_secret(const T &t)
bool none_of_protocol(const T &t, GpgME::Protocol proto)
void remove_duplicates_by_fpr(T &t)
T union_by_fpr_dirty(const T &t1, const T &t2)
int mystrcmp(const char *s1, const char *s2)