LCOV - code coverage report
Current view: top level - lang/cpp/src - keylistresult.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 41 31.7 %
Date: 2018-11-14 16:53:58 Functions: 6 12 50.0 %

          Line data    Source code
       1             : /*
       2             :   keylistresult.cpp - wraps a gpgme keylist result
       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             : #ifdef HAVE_CONFIG_H
      26             :  #include "config.h"
      27             : #endif
      28             : 
      29             : #include <keylistresult.h>
      30             : #include "result_p.h"
      31             : 
      32             : #include <gpgme.h>
      33             : 
      34             : #include <cstring>
      35             : #include <cassert>
      36             : 
      37             : class GpgME::KeyListResult::Private
      38             : {
      39             : public:
      40          17 :     Private(const _gpgme_op_keylist_result &r) : res(r) {}
      41           0 :     Private(const Private &other) : res(other.res) {}
      42             : 
      43             :     _gpgme_op_keylist_result res;
      44             : };
      45             : 
      46           0 : GpgME::KeyListResult::KeyListResult(gpgme_ctx_t ctx, int error)
      47           0 :     : GpgME::Result(error), d()
      48             : {
      49           0 :     init(ctx);
      50           0 : }
      51             : 
      52          17 : GpgME::KeyListResult::KeyListResult(gpgme_ctx_t ctx, const Error &error)
      53          17 :     : GpgME::Result(error), d()
      54             : {
      55          17 :     init(ctx);
      56          17 : }
      57             : 
      58          17 : void GpgME::KeyListResult::init(gpgme_ctx_t ctx)
      59             : {
      60          17 :     if (!ctx) {
      61           0 :         return;
      62             :     }
      63          17 :     gpgme_keylist_result_t res = gpgme_op_keylist_result(ctx);
      64          17 :     if (!res) {
      65           0 :         return;
      66             :     }
      67          17 :     d.reset(new Private(*res));
      68             : }
      69             : 
      70           0 : GpgME::KeyListResult::KeyListResult(const Error &error, const _gpgme_op_keylist_result &res)
      71           0 :     : GpgME::Result(error), d(new Private(res))
      72             : {
      73             : 
      74           0 : }
      75             : 
      76          31 : make_standard_stuff(KeyListResult)
      77             : 
      78           0 : void GpgME::KeyListResult::detach()
      79             : {
      80           0 :     if (!d || d.unique()) {
      81           0 :         return;
      82             :     }
      83           0 :     d.reset(new Private(*d));
      84             : }
      85             : 
      86           0 : void GpgME::KeyListResult::mergeWith(const KeyListResult &other)
      87             : {
      88           0 :     if (other.isNull()) {
      89           0 :         return;
      90             :     }
      91           0 :     if (isNull()) {   // just assign
      92           0 :         operator=(other);
      93           0 :         return;
      94             :     }
      95             :     // merge the truncated flag (try to keep detaching to a minimum):
      96           0 :     if (other.isTruncated() && !this->isTruncated()) {
      97           0 :         assert(other.d);
      98           0 :         detach();
      99           0 :         if (!d) {
     100           0 :             d.reset(new Private(*other.d));
     101             :         } else {
     102           0 :             d->res.truncated = true;
     103             :         }
     104             :     }
     105           0 :     if (! bool(error())) {    // only merge the error when there was none yet.
     106           0 :         Result::operator=(other);
     107             :     }
     108             : }
     109             : 
     110           1 : bool GpgME::KeyListResult::isTruncated() const
     111             : {
     112           1 :     return d && d->res.truncated;
     113             : }

Generated by: LCOV version 1.13