File indexing completed on 2024-09-22 04:52:49

0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 #ifndef IMAP_DATA_H
0023 #define IMAP_DATA_H
0024 
0025 #include <QTextStream>
0026 
0027 /** @short Namespace for IMAP interaction */
0028 namespace Imap
0029 {
0030 
0031 /** @short IMAP server responses */
0032 namespace Responses
0033 {
0034 
0035 /** @short Parent of all "Response Code Data" classes
0036  *
0037  * More information available in AbstractData's documentation.
0038  * */
0039 class AbstractData
0040 {
0041 public:
0042     virtual ~AbstractData();
0043     virtual QTextStream &dump(QTextStream &) const = 0;
0044     virtual bool eq(const AbstractData &other) const = 0;
0045 };
0046 
0047 /** @short Storage for "Response Code Data"
0048  *
0049  * In IMAP, each status response might contain some additional information
0050  * called "Response Code" and associated data. These data come in several
0051  * shapes and this class servers as a storage for them, as a kind of
0052  * QVariant-like wrapper around real data.
0053  * */
0054 template<class T> class RespData : public AbstractData
0055 {
0056 public:
0057     T data;
0058     RespData(const T &_data) : data(_data) {};
0059     QTextStream &dump(QTextStream &s) const override;
0060     bool eq(const AbstractData &other) const override;
0061 };
0062 
0063 /** Explicit specialization for void as we can't define a void member of a
0064  * class */
0065 template<> class RespData<void> : public AbstractData
0066 {
0067 public:
0068     QTextStream &dump(QTextStream &s) const override { return s; };
0069     bool eq(const AbstractData &other) const override;
0070 };
0071 
0072 
0073 QTextStream &operator<<(QTextStream &stream, const AbstractData &resp);
0074 
0075 inline bool operator==(const AbstractData &first, const AbstractData &other)
0076 {
0077     return first.eq(other);
0078 }
0079 
0080 inline bool operator!=(const AbstractData &first, const AbstractData &other)
0081 {
0082     return !first.eq(other);
0083 }
0084 
0085 }
0086 
0087 }
0088 
0089 #endif /* IMAP_DATA_H */