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

Generated by: LCOV version 1.11