qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
contactid.h
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <QByteArray>
23 #include <QString>
24 #include <cstdint>
25 #include <QHash>
26 #include <memory>
27 
28 class ContactId
29 {
30 public:
31  virtual ~ContactId();
32  ContactId(const ContactId&) = default;
33  ContactId& operator=(const ContactId&) = default;
34  ContactId(ContactId&&) = default;
35  ContactId& operator=(ContactId&&) = default;
36  bool operator==(const ContactId& other) const;
37  bool operator!=(const ContactId& other) const;
38  bool operator<(const ContactId& other) const;
39  QString toString() const;
40  QByteArray getByteArray() const;
41  const uint8_t* getData() const;
42  bool isEmpty() const;
43  virtual int getSize() const = 0;
44 
45 protected:
46  ContactId();
47  explicit ContactId(const QByteArray& rawId);
48  QByteArray id;
49 };
50 
51 inline uint qHash(const ContactId& id)
52 {
53  return qHash(id.getByteArray());
54 }
55 
56 using ContactIdPtr = std::shared_ptr<const ContactId>;
ContactId::getData
const uint8_t * getData() const
Returns a pointer to the raw id data.
Definition: contactid.cpp:88
ContactIdPtr
std::shared_ptr< const ContactId > ContactIdPtr
Definition: contactid.h:56
ContactId::isEmpty
bool isEmpty() const
Checks if the ContactId contains a id.
Definition: contactid.cpp:110
ContactId::operator==
bool operator==(const ContactId &other) const
Compares the equality of the ContactId.
Definition: contactid.cpp:49
ContactId::operator<
bool operator<(const ContactId &other) const
Compares two ContactIds.
Definition: contactid.cpp:69
ContactId::id
QByteArray id
Definition: contactid.h:48
ContactId::getSize
virtual int getSize() const =0
ContactId::operator!=
bool operator!=(const ContactId &other) const
Compares the inequality of the ContactId.
Definition: contactid.cpp:59
ContactId::operator=
ContactId & operator=(const ContactId &)=default
ContactId
Definition: contactid.h:28
ContactId::ContactId
ContactId()
The default constructor. Creates an empty id.
Definition: contactid.cpp:29
ContactId::~ContactId
virtual ~ContactId()
ContactId::toString
QString toString() const
Converts the ContactId to a uppercase hex string.
Definition: contactid.cpp:78
qHash
uint qHash(const ContactId &id)
Definition: contactid.h:51
ContactId::getByteArray
QByteArray getByteArray() const
Get a copy of the id.
Definition: contactid.cpp:101