aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Heinecke <[email protected]>2016-04-11 15:02:04 +0000
committerAndre Heinecke <[email protected]>2016-04-11 15:06:14 +0000
commit1bb162a54ba480413c4da07f2578efe6860494c0 (patch)
treeeccf5fe6a26088f8e510480c47cf993991cd247a
parentCpp: Remove last usages of boost (diff)
downloadgpgme-1bb162a54ba480413c4da07f2578efe6860494c0.tar.gz
gpgme-1bb162a54ba480413c4da07f2578efe6860494c0.zip
Cpp: Add string comparators for keys
* lang/cpp/src/global.h (GPGMEPP_MAKE_STRCMP): New. (_gpgmepp_strcmp): NULL save wrapper around std::strcmp. * lang/cpp/src/key.h: Add comparators for various attributes. -- This was taken from libkleo predicates.h. Appears generally useful.
-rw-r--r--lang/cpp/src/global.h51
-rw-r--r--lang/cpp/src/key.h5
2 files changed, 56 insertions, 0 deletions
diff --git a/lang/cpp/src/global.h b/lang/cpp/src/global.h
index b48ec074..9be5202c 100644
--- a/lang/cpp/src/global.h
+++ b/lang/cpp/src/global.h
@@ -28,6 +28,7 @@
#include "gpgmepp_export.h"
#include <iosfwd>
+#include <cstring>
namespace GpgME
{
@@ -152,4 +153,54 @@ GPGMEPP_EXPORT bool hasFeature(unsigned long feature, unsigned long feature2);
operator unspecified_bool_type() const { return ( Cond ) ? &__safe_bool_dummy__::nonnull : 0 ; }
# endif
+inline int _gpgmepp_strcmp(const char *s1, const char *s2)
+{
+ return s1 ? s2 ? std::strcmp(s1, s2) : 1 : s2 ? -1 : 0;
+}
+
+#define _GPGMEPP_MAKE_STRCMP( Name, expr, cmp ) \
+ template <template <typename U> class Op> \
+ struct Name { \
+ typedef bool result_type; \
+ \
+ bool operator()( const char * lhs, const char * rhs ) const { \
+ return Op<int>()( cmp, 0 ); \
+ } \
+ \
+ bool operator()( const std::string & lhs, const std::string & rhs ) const { \
+ return operator()( lhs.c_str(), rhs.c_str() ); \
+ } \
+ bool operator()( const char * lhs, const std::string & rhs ) const { \
+ return operator()( lhs, rhs.c_str() ); \
+ } \
+ bool operator()( const std::string & lhs, const char * rhs ) const { \
+ return operator()( lhs.c_str(), rhs ); \
+ } \
+ \
+ template <typename T> \
+ bool operator()( const T & lhs, const T & rhs ) const { \
+ return operator()( (lhs expr), (rhs expr) ); \
+ } \
+ template <typename T> \
+ bool operator()( const T & lhs, const char * rhs ) const { \
+ return operator()( (lhs expr), rhs ); \
+ } \
+ template <typename T> \
+ bool operator()( const char * lhs, const T & rhs ) const { \
+ return operator()( lhs, (rhs expr) ); \
+ } \
+ template <typename T> \
+ bool operator()( const T & lhs, const std::string & rhs ) const { \
+ return operator()( (lhs expr), rhs ); \
+ } \
+ template <typename T> \
+ bool operator()( const std::string & lhs, const T & rhs ) const { \
+ return operator()( lhs, (rhs expr) ); \
+ } \
+ }
+
+#define GPGMEPP_MAKE_STRCMP( Name, expr ) \
+ _GPGMEPP_MAKE_STRCMP( Name, expr, _gpgmepp_strcmp( lhs, rhs ) )
+
+
#endif // __GPGMEPP_GLOBAL_H__
diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h
index a87a35cf..30badeaa 100644
--- a/lang/cpp/src/key.h
+++ b/lang/cpp/src/key.h
@@ -353,4 +353,9 @@ GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(Subkey)
GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID)
GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(UserID::Signature)
+GPGMEPP_MAKE_STRCMP(ByFingerprint, .primaryFingerprint());
+GPGMEPP_MAKE_STRCMP(ByKeyID, .keyID());
+GPGMEPP_MAKE_STRCMP(ByShortKeyID, .shortKeyID());
+GPGMEPP_MAKE_STRCMP(ByChainID, .chainID());
+
#endif // __GPGMEPP_KEY_H__