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

Generated by: LCOV version 1.11