cpp: Fix version info comparison
authorAndre Heinecke <aheinecke@intevation.de>
Mon, 4 Sep 2017 09:23:56 +0000 (11:23 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Mon, 4 Sep 2017 09:23:56 +0000 (11:23 +0200)
* lang/cpp/src/engineinfo.h (EngineInfo::Version::operator<):
Fix logic.
* lang/cpp/src/engineinfo.h (EngineInfo::Version::operator>):
New.
* NEWS: Mention added API

--
This fixes a logic error that 2.2.0 < 2.1.19 would return true.

NEWS
lang/cpp/src/engineinfo.h

diff --git a/NEWS b/NEWS
index 71d9600..aee3f10 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,8 +12,9 @@ Noteworthy changes in version 1.10.0 (unreleased)
  GPGME_DELETE_FORCE          NEW.
  gpgme_op_conf_dir           NEW.
  gpgme_set_ctx_flag          EXTENDED: New flag 'auto-key-retrieve'.
- cpp: DecryptionResult::isDeVs NEW.
- cpp: Signature::isDeVs        NEW.
+ cpp: DecryptionResult::isDeVs         NEW.
+ cpp: Signature::isDeVs                NEW.
+ cpp: EngineInfo::Version::operator>   NEW.
  py: DecryptResult           EXTENDED: New boolean field 'is_de_vs'.
  py: Signature               EXTENDED: New boolean field 'is_de_vs'.
  py: GpgError                EXTENDED: Partial results in 'results'.
index b216de8..cd1b7a7 100644 (file)
@@ -71,13 +71,13 @@ public:
 
         bool operator < (const Version& other)
         {
-            if (major < other.major)
-                return true;
-            if (minor < other.minor)
-                return true;
-            if (patch < other.patch)
-                return true;
-            return false;
+            if (major > other.major ||
+                (major == other.major && minor > other.minor) ||
+                (major == other.major && minor == other.minor && patch > other.patch) ||
+                (major >= other.major && minor >= other.minor && patch >= other.patch)) {
+                return false;
+            }
+            return true;
         }
 
         bool operator < (const char* other)
@@ -85,6 +85,15 @@ public:
             return operator<(Version(other));
         }
 
+        bool operator > (const char* other)
+        {
+            return !operator<(Version(other));
+        }
+
+        bool operator > (const Version & other)
+        {
+            return !operator<(other);
+        }
         bool operator == (const Version& other)
         {
             return major == other.major