qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
contactid.cpp
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 #include <QByteArray>
21 #include <QString>
22 #include <cstdint>
23 #include <QHash>
24 #include "src/core/contactid.h"
25 
30  : id()
31 {
32 }
33 ContactId::~ContactId() = default;
34 
39 ContactId::ContactId(const QByteArray& rawId)
40 {
41  id = QByteArray(rawId);
42 }
43 
49 bool ContactId::operator==(const ContactId& other) const
50 {
51  return id == other.id;
52 }
53 
59 bool ContactId::operator!=(const ContactId& other) const
60 {
61  return id != other.id;
62 }
63 
69 bool ContactId::operator<(const ContactId& other) const
70 {
71  return id < other.id;
72 }
73 
78 QString ContactId::toString() const
79 {
80  return id.toHex().toUpper();
81 }
82 
88 const uint8_t* ContactId::getData() const
89 {
90  if (id.isEmpty()) {
91  return nullptr;
92  }
93 
94  return reinterpret_cast<const uint8_t*>(id.constData());
95 }
96 
101 QByteArray ContactId::getByteArray() const
102 {
103  return QByteArray(id); // TODO: Is a copy really necessary?
104 }
105 
110 bool ContactId::isEmpty() const
111 {
112  return id.isEmpty();
113 }
ContactId::getData
const uint8_t * getData() const
Returns a pointer to the raw id data.
Definition: contactid.cpp:88
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.h
ContactId::operator!=
bool operator!=(const ContactId &other) const
Compares the inequality of the ContactId.
Definition: contactid.cpp:59
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
ContactId::getByteArray
QByteArray getByteArray() const
Get a copy of the id.
Definition: contactid.cpp:101