LCOV - code coverage report
Current view: top level - lang/cpp/src - engineinfo.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 33 51.5 %
Date: 2018-11-14 16:53:58 Functions: 5 7 71.4 %

          Line data    Source code
       1             : /*
       2             :   engineinfo.h
       3             :   Copyright (C) 2004 Klarälvdalens Datakonsult AB
       4             :   2016 Bundesamt für Sicherheit in der Informationstechnik
       5             :   Software engineering by Intevation GmbH
       6             : 
       7             :   This file is part of GPGME++.
       8             : 
       9             :   GPGME++ is free software; you can redistribute it and/or
      10             :   modify it under the terms of the GNU Library General Public
      11             :   License as published by the Free Software Foundation; either
      12             :   version 2 of the License, or (at your option) any later version.
      13             : 
      14             :   GPGME++ is distributed in the hope that it will be useful,
      15             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :   GNU Library General Public License for more details.
      18             : 
      19             :   You should have received a copy of the GNU Library General Public License
      20             :   along with GPGME++; see the file COPYING.LIB.  If not, write to the
      21             :   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      22             :   Boston, MA 02110-1301, USA.
      23             : */
      24             : 
      25             : #ifndef __GPGMEPP_ENGINEINFO_H__
      26             : #define __GPGMEPP_ENGINEINFO_H__
      27             : 
      28             : #include "global.h"
      29             : 
      30             : #include <memory>
      31             : 
      32             : #include <algorithm>
      33             : #include <string>
      34             : #include <iostream>
      35             : 
      36             : namespace GpgME
      37             : {
      38             : 
      39           9 : class GPGMEPP_EXPORT EngineInfo
      40             : {
      41             : public:
      42             :     struct Version
      43             :     {
      44             :         int major, minor, patch;
      45           0 :         Version()
      46           0 :         {
      47           0 :           major = 0;
      48           0 :           minor = 0;
      49           0 :           patch = 0;
      50           0 :         }
      51             : 
      52             :         Version(const std::string& version)
      53             :         {
      54             :             if (version.empty() ||
      55             :                 std::sscanf(version.c_str(), "%d.%d.%d", &major, &minor, &patch) != 3) {
      56             :                 major = 0;
      57             :                 minor = 0;
      58             :                 patch = 0;
      59             :             }
      60             :         }
      61             : 
      62          43 :         Version(const char *version)
      63          43 :         {
      64          86 :             if (!version ||
      65          43 :                 std::sscanf(version, "%d.%d.%d", &major, &minor, &patch) != 3) {
      66           0 :                 major = 0;
      67           0 :                 minor = 0;
      68           0 :                 patch = 0;
      69             :             }
      70          43 :         }
      71             : 
      72          25 :         bool operator < (const Version& other)
      73             :         {
      74          49 :             if (major > other.major ||
      75          53 :                 (major == other.major && minor > other.minor) ||
      76          17 :                 (major == other.major && minor == other.minor && patch > other.patch) ||
      77           8 :                 (major >= other.major && minor >= other.minor && patch >= other.patch)) {
      78          21 :                 return false;
      79             :             }
      80           4 :             return true;
      81             :         }
      82             : 
      83          16 :         bool operator < (const char* other)
      84             :         {
      85          16 :             return operator<(Version(other));
      86             :         }
      87             : 
      88             :         bool operator > (const char* other)
      89             :         {
      90             :             return !operator<(Version(other));
      91             :         }
      92             : 
      93           4 :         bool operator > (const Version & other)
      94             :         {
      95           4 :             return !operator<(other);
      96             :         }
      97             :         bool operator == (const Version& other)
      98             :         {
      99             :             return major == other.major
     100             :                 && minor == other.minor
     101             :                 && patch == other.patch;
     102             :         }
     103             : 
     104             :         bool operator == (const char* other)
     105             :         {
     106             :             return operator==(Version(other));
     107             :         }
     108             : 
     109           0 :         friend std::ostream& operator << (std::ostream& stream, const Version& ver)
     110             :         {
     111           0 :             stream << ver.major;
     112           0 :             stream << '.';
     113           0 :             stream << ver.minor;
     114           0 :             stream << '.';
     115           0 :             stream << ver.patch;
     116           0 :             return stream;
     117             :         }
     118             :     };
     119             : 
     120             :     EngineInfo();
     121             :     explicit EngineInfo(gpgme_engine_info_t engine);
     122             : 
     123             :     const EngineInfo &operator=(EngineInfo other)
     124             :     {
     125             :         swap(other);
     126             :         return *this;
     127             :     }
     128             : 
     129             :     void swap(EngineInfo &other)
     130             :     {
     131             :         using std::swap;
     132             :         swap(this->d, other.d);
     133             :     }
     134             : 
     135             :     bool isNull() const;
     136             : 
     137             :     Protocol protocol() const;
     138             :     const char *fileName() const;
     139             :     const char *version() const;
     140             :     Version engineVersion() const;
     141             :     const char *requiredVersion() const;
     142             :     const char *homeDirectory() const;
     143             : 
     144             : private:
     145             :     class Private;
     146             :     std::shared_ptr<Private> d;
     147             : };
     148             : 
     149             : }
     150             : 
     151             : GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(EngineInfo)
     152             : 
     153             : #endif // __GPGMEPP_ENGINEINFO_H__

Generated by: LCOV version 1.13