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 8 : class GPGMEPP_EXPORT EngineInfo
38 : {
39 : public:
40 : struct Version
41 : {
42 : int major, minor, patch;
43 0 : Version()
44 : {
45 0 : major = 0;
46 0 : minor = 0;
47 0 : patch = 0;
48 0 : }
49 :
50 : Version(const std::string& version)
51 : {
52 : if (version.empty() ||
53 : std::sscanf(version.c_str(), "%d.%d.%d", &major, &minor, &patch) != 3) {
54 : major = 0;
55 : minor = 0;
56 : patch = 0;
57 : }
58 : }
59 :
60 19 : Version(const char *version)
61 : {
62 38 : if (!version ||
63 19 : std::sscanf(version, "%d.%d.%d", &major, &minor, &patch) != 3) {
64 0 : major = 0;
65 0 : minor = 0;
66 0 : patch = 0;
67 : }
68 19 : }
69 :
70 11 : bool operator < (const Version& other)
71 : {
72 11 : if (major < other.major)
73 0 : return true;
74 11 : if (minor < other.minor)
75 0 : return true;
76 11 : if (patch < other.patch)
77 0 : return true;
78 11 : return false;
79 : }
80 :
81 11 : bool operator < (const char* other)
82 : {
83 11 : return operator<(Version(other));
84 : }
85 :
86 : bool operator == (const Version& other)
87 : {
88 : return major == other.major
89 : && minor == other.minor
90 : && patch == other.patch;
91 : }
92 :
93 : bool operator == (const char* other)
94 : {
95 : return operator==(Version(other));
96 : }
97 :
98 0 : friend std::ostream& operator << (std::ostream& stream, const Version& ver)
99 : {
100 0 : stream << ver.major;
101 0 : stream << '.';
102 0 : stream << ver.minor;
103 0 : stream << '.';
104 0 : stream << ver.patch;
105 0 : return stream;
106 : }
107 : };
108 :
109 : EngineInfo();
110 : explicit EngineInfo(gpgme_engine_info_t engine);
111 :
112 : const EngineInfo &operator=(EngineInfo other)
113 : {
114 : swap(other);
115 : return *this;
116 : }
117 :
118 : void swap(EngineInfo &other)
119 : {
120 : using std::swap;
121 : swap(this->d, other.d);
122 : }
123 :
124 : bool isNull() const;
125 :
126 : Protocol protocol() const;
127 : const char *fileName() const;
128 : const char *version() const;
129 : Version engineVersion() const;
130 : const char *requiredVersion() const;
131 : const char *homeDirectory() const;
132 :
133 : private:
134 : class Private;
135 : std::shared_ptr<Private> d;
136 : };
137 :
138 : }
139 :
140 : GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION(EngineInfo)
141 :
142 : #endif // __GPGMEPP_ENGINEINFO_H__
|