Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
dbaddress.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#include "dbaddress.h"
9#include <QDataStream>
10#include <QHash>
11#include <QCryptographicHash>
12
13
14namespace QH {
15
16qint64 qHash(const DbAddress &address) {
17 return qHash(address.SHA256Hash());
18}
19
20DbAddress::DbAddress(const QString &table, const QVariant &id) {
21 this->_table = table;
22 this->_value = id;
23 recalcHash();
24
25}
26
27bool operator==(const DbAddress & left, const DbAddress &other) {
28 return left._table == other._table && left._value == other._value;
29}
30
31QDataStream &DbAddress::fromStream(QDataStream &stream) {
32 stream >> _value;
33 stream >> _table;
34 recalcHash();
35
36 return stream;
37}
38
39QDataStream &DbAddress::toStream(QDataStream &stream) const {
40 stream << _value;
41 stream << _table;
42 return stream;
43}
44
45QString DbAddress::toString() const {
46 return QString("DbAddress: table:%0, value:%1, Sha256:%2").
47 arg(_table, _value.toString(), _SHA256Hash.toHex());
48}
49
50bool operator!=(const DbAddress &left, const DbAddress &other) {
51 return !operator==(left, other);
52}
53
54bool DbAddress::isValid() const {
55 return _value.isValid() && _table.size();
56}
57
58const QString& DbAddress::table() const {
59 return _table;
60}
61
62void DbAddress::setTable(const QString &table) {
63 _table = table;
64 recalcHash();
65}
66
67const QVariant &DbAddress::id() const {
68 return _value;
69}
70
71void DbAddress::setId(const QVariant &id){
72 _value = id;
73 recalcHash();
74}
75
76QByteArray DbAddress::SHA256Hash() const {
77 return _SHA256Hash;
78}
79
80void DbAddress::recalcHash() {
81 _SHA256Hash = QCryptographicHash::hash(toBytes(), QCryptographicHash::Sha256);
82}
83
84}
The DbAddress class use to work with database addresses. Database Address it is structure with 2 valu...
Definition dbaddress.h:24
QString toString() const
toString This method return a string implementation fo this object.
Definition dbaddress.cpp:45
DbAddress()=default
QDataStream & fromStream(QDataStream &stream)
fromStream This method should be read all bytes from the stream object and full the current object.
Definition dbaddress.cpp:31
void setId(const QVariant &id)
setId This method set id for this address.
Definition dbaddress.cpp:71
QByteArray SHA256Hash() const
SHA256Hash This method return address hash. This hash using into database.
Definition dbaddress.cpp:76
QDataStream & toStream(QDataStream &stream) const
fromStream This method should be write all members of the current object to the stream object.
Definition dbaddress.cpp:39
void setTable(const QString &table)
setTable This method set new table name of address.
Definition dbaddress.cpp:62
bool isValid() const
isValid This method check object for valid.
Definition dbaddress.cpp:54
const QString & table() const
table This method return table name.
Definition dbaddress.cpp:58
const QVariant & id() const
id This method return id of object in table.
Definition dbaddress.cpp:67
QByteArray toBytes() const
toBytes This method convert a current object to bytes array.
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13
bool operator!=(const DbAddress &left, const DbAddress &other)
Definition dbaddress.cpp:50
uint qHash(NodeCoonectionStatus status)
qHash - Simple hash function of NodeCoonectionStatus
bool operator==(const DbAddress &left, const DbAddress &other)
Definition dbaddress.cpp:27