LCOV - code coverage report
Current view: top level - lang/cpp/src - engineinfo.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 18 66.7 %
Date: 2016-09-12 13:07:23 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.11