Cpp / Qt: Reduce boost usage (memory and tuple)
[gpgme.git] / lang / cpp / src / encryptionresult.h
1 /*
2   encryptionresult.h - wraps a gpgme sign 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 #ifndef __GPGMEPP_ENCRYPTIONRESULT_H__
24 #define __GPGMEPP_ENCRYPTIONRESULT_H__
25
26 #include "gpgmefw.h"
27 #include "result.h"
28 #include "gpgmepp_export.h"
29
30 #include <memory>
31
32 #include <vector>
33 #include <iosfwd>
34
35 namespace GpgME
36 {
37
38 class Error;
39 class InvalidRecipient;
40
41 class GPGMEPP_EXPORT EncryptionResult : public Result
42 {
43 public:
44     EncryptionResult();
45     EncryptionResult(gpgme_ctx_t ctx, int error);
46     EncryptionResult(gpgme_ctx_t ctx, const Error &error);
47     EncryptionResult(const Error &err);
48
49     const EncryptionResult &operator=(EncryptionResult other)
50     {
51         swap(other);
52         return *this;
53     }
54
55     void swap(EncryptionResult &other)
56     {
57         Result::swap(other);
58         using std::swap;
59         swap(this->d, other.d);
60     }
61
62     bool isNull() const;
63
64     unsigned int numInvalidRecipients() const;
65
66     InvalidRecipient invalidEncryptionKey(unsigned int index) const;
67     std::vector<InvalidRecipient> invalidEncryptionKeys() const;
68
69     class Private;
70 private:
71     void init(gpgme_ctx_t ctx);
72     std::shared_ptr<Private> d;
73 };
74
75 GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const EncryptionResult &result);
76
77 class GPGMEPP_EXPORT InvalidRecipient
78 {
79     friend class ::GpgME::EncryptionResult;
80     InvalidRecipient(const std::shared_ptr<EncryptionResult::Private> &parent, unsigned int index);
81 public:
82     InvalidRecipient();
83
84     const InvalidRecipient &operator=(InvalidRecipient other)
85     {
86         swap(other);
87         return *this;
88     }
89
90     void swap(InvalidRecipient &other)
91     {
92         using std::swap;
93         swap(this->d, other.d);
94     }
95
96     bool isNull() const;
97
98     const char *fingerprint() const;
99     Error reason() const;
100
101 private:
102     std::shared_ptr<EncryptionResult::Private> d;
103     unsigned int idx;
104 };
105
106 GPGMEPP_EXPORT std::ostream &operator<<(std::ostream &os, const InvalidRecipient &recipient);
107
108 }
109
110 GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(EncryptionResult)
111 GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(InvalidRecipient)
112
113 #endif // __GPGMEPP_ENCRYPTIONRESULT_H__