File indexing completed on 2024-11-10 04:40:44

0001 /*
0002     SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "relation.h"
0008 
0009 #include "item.h"
0010 
0011 using namespace Akonadi;
0012 
0013 const char *Akonadi::Relation::GENERIC = "GENERIC";
0014 
0015 class Akonadi::RelationPrivate : public QSharedData
0016 {
0017 public:
0018     Item left;
0019     Item right;
0020     QByteArray type;
0021     QByteArray remoteId;
0022 };
0023 
0024 Relation::Relation()
0025     : d(new RelationPrivate)
0026 {
0027 }
0028 
0029 Relation::Relation(const QByteArray &type, const Item &left, const Item &right)
0030     : d(new RelationPrivate)
0031 {
0032     d->left = left;
0033     d->right = right;
0034     d->type = type;
0035 }
0036 
0037 Relation::Relation(const Relation &other) = default;
0038 
0039 Relation::Relation(Relation &&) noexcept = default;
0040 
0041 Relation::~Relation() = default;
0042 
0043 Relation &Relation::operator=(const Relation &) = default;
0044 
0045 Relation &Relation::operator=(Relation &&) noexcept = default;
0046 
0047 bool Relation::operator==(const Relation &other) const
0048 {
0049     if (isValid() && other.isValid()) {
0050         return d->left == other.d->left && d->right == other.d->right && d->type == other.d->type && d->remoteId == other.d->remoteId;
0051     }
0052     return false;
0053 }
0054 
0055 bool Relation::operator!=(const Relation &other) const
0056 {
0057     return !operator==(other);
0058 }
0059 
0060 void Relation::setLeft(const Item &left)
0061 {
0062     d->left = left;
0063 }
0064 
0065 Item Relation::left() const
0066 {
0067     return d->left;
0068 }
0069 
0070 void Relation::setRight(const Item &right)
0071 {
0072     d->right = right;
0073 }
0074 
0075 Item Relation::right() const
0076 {
0077     return d->right;
0078 }
0079 
0080 void Relation::setType(const QByteArray &type)
0081 {
0082     d->type = type;
0083 }
0084 
0085 QByteArray Relation::type() const
0086 {
0087     return d->type;
0088 }
0089 
0090 void Relation::setRemoteId(const QByteArray &remoteId)
0091 {
0092     d->remoteId = remoteId;
0093 }
0094 
0095 QByteArray Relation::remoteId() const
0096 {
0097     return d->remoteId;
0098 }
0099 
0100 bool Relation::isValid() const
0101 {
0102     return (d->left.isValid() || !d->left.remoteId().isEmpty()) && (d->right.isValid() || !d->right.remoteId().isEmpty()) && !d->type.isEmpty();
0103 }
0104 
0105 size_t Akonadi::qHash(const Relation &relation, size_t seed) noexcept
0106 {
0107     return ::qHashMulti(seed, relation.left(), relation.right(), relation.type(), relation.remoteId());
0108 }
0109 
0110 QDebug &operator<<(QDebug &debug, const Relation &relation)
0111 {
0112     debug << "Akonadi::Relation( TYPE " << relation.type() << ", LEFT " << relation.left().id() << ", RIGHT " << relation.right().id() << ", REMOTEID "
0113           << relation.remoteId() << ")";
0114     return debug;
0115 }