[Pkg-gnupg-commit] [gpgme] 54/412: Cpp: Add string comparators for keys

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 1bb162a54ba480413c4da07f2578efe6860494c0
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Mon Apr 11 17:02:04 2016 +0200

    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.
---
 lang/cpp/src/global.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lang/cpp/src/key.h    |  5 +++++
 2 files changed, 56 insertions(+)

diff --git a/lang/cpp/src/global.h b/lang/cpp/src/global.h
index b48ec07..9be5202 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 a87a35c..30badea 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__

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list