33 #ifndef __KLEOPATRA_MODELS_PREDICATES_H__
34 #define __KLEOPATRA_MODELS_PREDICATES_H__
36 #include <kleo/stl_util.h>
40 #include <gpgme++/key.h>
43 #include <boost/bind.hpp>
53 inline int mystrcmp(
const char * s1,
const char * s2 ) {
55 return s1 ? s2 ? strcmp( s1, s2 ) : 1 : s2 ? -1 : 0 ;
58 #define make_comparator_str_impl( Name, expr, cmp ) \
59 template <template <typename U> class Op> \
61 typedef bool result_type; \
63 bool operator()( const char * lhs, const char * rhs ) const { \
64 return Op<int>()( cmp, 0 ); \
67 bool operator()( const std::string & lhs, const std::string & rhs ) const { \
68 return operator()( lhs.c_str(), rhs.c_str() ); \
70 bool operator()( const char * lhs, const std::string & rhs ) const { \
71 return operator()( lhs, rhs.c_str() ); \
73 bool operator()( const std::string & lhs, const char * rhs ) const { \
74 return operator()( lhs.c_str(), rhs ); \
77 template <typename T> \
78 bool operator()( const T & lhs, const T & rhs ) const { \
79 return operator()( (lhs expr), (rhs expr) ); \
81 template <typename T> \
82 bool operator()( const T & lhs, const char * rhs ) const { \
83 return operator()( (lhs expr), rhs ); \
85 template <typename T> \
86 bool operator()( const char * lhs, const T & rhs ) const { \
87 return operator()( lhs, (rhs expr) ); \
89 template <typename T> \
90 bool operator()( const T & lhs, const std::string & rhs ) const { \
91 return operator()( (lhs expr), rhs ); \
93 template <typename T> \
94 bool operator()( const std::string & lhs, const T & rhs ) const { \
95 return operator()( lhs, (rhs expr) ); \
99 #define make_comparator_str_fast( Name, expr ) \
100 make_comparator_str_impl( Name, expr, _detail::mystrcmp( lhs, rhs ) )
101 #define make_comparator_str( Name, expr ) \
102 make_comparator_str_impl( Name, expr, qstricmp( lhs, rhs ) )
109 template <
typename T>
111 std::sort( t.begin(), t.end(), ByFingerprint<std::less>() );
114 template <
typename T>
116 t.erase( std::unique( t.begin(), t.end(), ByFingerprint<std::equal_to>() ), t.end() );
119 template <
typename T>
122 result.reserve( t1.size() + t2.size() );
123 std::set_union( t1.begin(), t1.end(),
124 t2.begin(), t2.end(),
125 std::back_inserter( result ),
126 ByFingerprint<std::less>() );
130 template <
typename T>
138 template <
typename T>
140 t.erase( std::remove_if( t.begin(), t.end(), boost::bind( &GpgME::Key::protocol, _1 ) != proto ), t.end() );
143 template <
typename T>
145 return kdtools::any( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
148 template <
typename T>
150 return kdtools::all( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
153 template <
typename T>
155 return kdtools::none_of( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
158 template <
typename T>
160 t.erase( std::remove_if( t.begin(), t.end(), boost::mem_fn( &GpgME::Key::hasSecret ) ), t.end() );
163 template <
typename T>
165 return kdtools::any( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
168 template <
typename T>
170 return kdtools::all( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
173 template <
typename T>
175 return kdtools::none_of( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
179 template <
typename T>
181 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)