139 lines
5.0 KiB
C++
139 lines
5.0 KiB
C++
/****************************************************************************
|
|
** Copyright (c) 2025 Evgeny Teterin (nayk) <nayk@nxt.ru>
|
|
** All right reserved.
|
|
**
|
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
** a copy of this software and associated documentation files (the
|
|
** "Software"), to deal in the Software without restriction, including
|
|
** without limitation the rights to use, copy, modify, merge, publish,
|
|
** distribute, sublicense, and/or sell copies of the Software, and to
|
|
** permit persons to whom the Software is furnished to do so, subject to
|
|
** the following conditions:
|
|
**
|
|
** The above copyright notice and this permission notice shall be
|
|
** included in all copies or substantial portions of the Software.
|
|
**
|
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
**
|
|
****************************************************************************/
|
|
#include "error_object.h"
|
|
#include <QtCore/QSharedData>
|
|
|
|
namespace nayk { //=============================================================
|
|
|
|
//==============================================================================
|
|
class ErrorObjectData : public QSharedData
|
|
{
|
|
public:
|
|
int module {-1};
|
|
int code {-1};
|
|
QString text;
|
|
QDateTime dateTime {QDateTime::currentDateTime()};
|
|
};
|
|
//==============================================================================
|
|
void regiserErrorObjectMetaType()
|
|
{
|
|
if ( !QMetaType::isRegistered( qMetaTypeId<nayk::ErrorObject>() ) ) {
|
|
|
|
qRegisterMetaType<nayk::ErrorObject>();
|
|
}
|
|
}
|
|
//==============================================================================
|
|
ErrorObject::ErrorObject()
|
|
: d(new ErrorObjectData)
|
|
{
|
|
regiserErrorObjectMetaType();
|
|
}
|
|
//==============================================================================
|
|
ErrorObject::ErrorObject(int module, int code, const QString &text, const QDateTime &dateTime)
|
|
: d(new ErrorObjectData)
|
|
{
|
|
regiserErrorObjectMetaType();
|
|
|
|
d->module = module;
|
|
d->code = code;
|
|
d->text = text;
|
|
d->dateTime = dateTime;
|
|
}
|
|
//==============================================================================
|
|
ErrorObject::ErrorObject(const ErrorObject &other) = default;
|
|
//==============================================================================
|
|
ErrorObject &ErrorObject::operator=(const ErrorObject &other) = default;
|
|
//==============================================================================
|
|
ErrorObject::~ErrorObject() = default;
|
|
//==============================================================================
|
|
int ErrorObject::module() const
|
|
{
|
|
return d->module;
|
|
}
|
|
//==============================================================================
|
|
void ErrorObject::setModule(int module)
|
|
{
|
|
d->module = module;
|
|
}
|
|
//==============================================================================
|
|
int ErrorObject::code() const
|
|
{
|
|
return d->code;
|
|
}
|
|
//==============================================================================
|
|
void ErrorObject::setCode(int code)
|
|
{
|
|
d->code = code;
|
|
}
|
|
//==============================================================================
|
|
QString ErrorObject::text() const
|
|
{
|
|
return d->text;
|
|
}
|
|
//==============================================================================
|
|
void ErrorObject::setText(const QString &text)
|
|
{
|
|
d->text = text;
|
|
}
|
|
//==============================================================================
|
|
QDateTime ErrorObject::dateTime() const
|
|
{
|
|
return d->dateTime;
|
|
}
|
|
//==============================================================================
|
|
void ErrorObject::setDateTime(const QDateTime &dateTime)
|
|
{
|
|
d->dateTime = dateTime;
|
|
}
|
|
//==============================================================================
|
|
bool ErrorObject::isValid() const
|
|
{
|
|
return (d->module >= 0) && ((d->code >= 0) || !d->text.isEmpty());
|
|
}
|
|
//==============================================================================
|
|
bool ErrorObject::operator==(const ErrorObject &other) const
|
|
{
|
|
return (d->module == other.d->module) &&
|
|
(d->dateTime == other.d->dateTime) &&
|
|
(
|
|
((d->code == other.d->code) && (d->code >= 0))
|
|
||
|
|
((d->code < 0) && (other.d->code < 0) && (d->text == other.text()))
|
|
);
|
|
}
|
|
//==============================================================================
|
|
bool ErrorObject::operator!=(const ErrorObject &other) const
|
|
{
|
|
return !(*this == other);
|
|
}
|
|
//==============================================================================
|
|
ErrorObject ErrorObject::copy() const
|
|
{
|
|
return *this;
|
|
}
|
|
//==============================================================================
|
|
|
|
} // namespace nayk //==========================================================
|