Refactoring.

Code style.
This commit is contained in:
Roman Telezhynskyi 2023-06-24 09:33:01 +03:00
parent 914a2c9d09
commit 8b29cd6b36

View File

@ -29,26 +29,26 @@
#ifndef VCONTAINER_H #ifndef VCONTAINER_H
#define VCONTAINER_H #define VCONTAINER_H
#include <qcompilerdetection.h>
#include <QCoreApplication> #include <QCoreApplication>
#include <QHash> #include <QHash>
#include <QMap> #include <QMap>
#include <QMessageLogger> #include <QMessageLogger>
#include <QSet> #include <QSet>
#include <QSharedPointer>
#include <QSharedData> #include <QSharedData>
#include <QSharedDataPointer> #include <QSharedDataPointer>
#include <QSharedPointer>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QTypeInfo> #include <QTypeInfo>
#include <QtGlobal> #include <QtGlobal>
#include <new> #include <new>
#include <qcompilerdetection.h>
#include "../vmisc/def.h"
#include "../ifc/exception/vexceptionbadid.h" #include "../ifc/exception/vexceptionbadid.h"
#include "../vgeometry/vabstractcubicbezierpath.h" #include "../vgeometry/vabstractcubicbezierpath.h"
#include "../vgeometry/vabstractcurve.h" #include "../vgeometry/vabstractcurve.h"
#include "../vgeometry/vgobject.h" #include "../vgeometry/vgobject.h"
#include "../vmisc/def.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
@ -76,7 +76,6 @@ QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
class VContainerData final : public QSharedData //-V690 class VContainerData final : public QSharedData //-V690
{ {
public: public:
VContainerData(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace) VContainerData(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace)
: calculationObjects(QHash<quint32, QSharedPointer<VGObject>>()), : calculationObjects(QHash<quint32, QSharedPointer<VGObject>>()),
modelingObjects(QSharedPointer<QHash<quint32, QSharedPointer<VGObject>>>::create()), modelingObjects(QSharedPointer<QHash<quint32, QSharedPointer<VGObject>>>::create()),
@ -86,7 +85,8 @@ public:
trVars(trVars), trVars(trVars),
patternUnit(patternUnit), patternUnit(patternUnit),
nspace(nspace) nspace(nspace)
{} {
}
VContainerData(const VContainerData &data) VContainerData(const VContainerData &data)
: QSharedData(data), : QSharedData(data),
@ -98,7 +98,8 @@ public:
trVars(data.trVars), trVars(data.trVars),
patternUnit(data.patternUnit), patternUnit(data.patternUnit),
nspace(data.nspace) nspace(data.nspace)
{} {
}
virtual ~VContainerData(); virtual ~VContainerData();
@ -131,6 +132,7 @@ QT_WARNING_POP
class VContainer class VContainer
{ {
Q_DECLARE_TR_FUNCTIONS(VContainer) // NOLINT Q_DECLARE_TR_FUNCTIONS(VContainer) // NOLINT
public: public:
VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace); VContainer(const VTranslateVars *trVars, const Unit *patternUnit, const QString &nspace);
VContainer(const VContainer &data); VContainer(const VContainer &data);
@ -141,7 +143,8 @@ public:
auto operator=(const VContainer &data) -> VContainer &; auto operator=(const VContainer &data) -> VContainer &;
#ifdef Q_COMPILER_RVALUE_REFS #ifdef Q_COMPILER_RVALUE_REFS
VContainer(VContainer &&data) Q_DECL_NOTHROW; VContainer(VContainer &&data) Q_DECL_NOTHROW;
auto operator=(VContainer &&data) Q_DECL_NOTHROW->VContainer &; auto operator=(VContainer &&data) Q_DECL_NOTHROW
->VContainer &;
#endif #endif
static auto UniqueNamespace() -> QString; static auto UniqueNamespace() -> QString;
@ -166,27 +169,20 @@ public:
auto AddPiece(const VPiece &detail) -> quint32; auto AddPiece(const VPiece &detail) -> quint32;
auto AddPiecePath(const VPiecePath &path) -> quint32; auto AddPiecePath(const VPiecePath &path) -> quint32;
void AddLine(const quint32 &firstPointId, const quint32 &secondPointId); void AddLine(const quint32 &firstPointId, const quint32 &secondPointId);
void AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32 &id, void AddArc(const QSharedPointer<VAbstractCurve> &arc, const quint32 &id, const quint32 &parentId = NULL_ID);
const quint32 &parentId = NULL_ID);
void AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId = NULL_ID); void AddSpline(const QSharedPointer<VAbstractBezier> &curve, quint32 id, quint32 parentId = NULL_ID);
void AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierPath> &curve, const quint32 &id, void AddCurveWithSegments(const QSharedPointer<VAbstractCubicBezierPath> &curve, const quint32 &id,
quint32 parentId = NULL_ID); quint32 parentId = NULL_ID);
template <typename T> template <typename T> void AddUniqueVariable(T *var);
void AddUniqueVariable(T *var); template <typename T> void AddUniqueVariable(const QSharedPointer<T> &var);
template <typename T> template <typename T> void AddVariable(T *var);
void AddUniqueVariable(const QSharedPointer<T> &var); template <typename T> void AddVariable(const QSharedPointer<T> &var);
template <typename T>
void AddVariable(T *var);
template <typename T>
void AddVariable(const QSharedPointer<T> &var);
void RemoveVariable(const QString &name); void RemoveVariable(const QString &name);
void RemovePiece(quint32 id); void RemovePiece(quint32 id);
template <class T> template <class T> void UpdateGObject(quint32 id, T *obj);
void UpdateGObject(quint32 id, T* obj); template <class T> void UpdateGObject(quint32 id, const QSharedPointer<T> &obj);
template <class T>
void UpdateGObject(quint32 id, const QSharedPointer<T> &obj);
void UpdatePiece(quint32 id, const VPiece &detail); void UpdatePiece(quint32 id, const VPiece &detail);
void UpdatePiecePath(quint32 id, const VPiecePath &path); void UpdatePiecePath(quint32 id, const VPiecePath &path);
@ -246,8 +242,7 @@ private:
template <class T> auto qHash(const QSharedPointer<T> &p) -> uint; template <class T> auto qHash(const QSharedPointer<T> &p) -> uint;
template <typename T> template <typename T> void UpdateObject(const quint32 &id, const QSharedPointer<T> &point);
void UpdateObject(const quint32 &id, const QSharedPointer<T> &point);
template <typename T> auto DataVar(const VarType &type) const -> const QMap<QString, QSharedPointer<T>>; template <typename T> auto DataVar(const VarType &type) const -> const QMap<QString, QSharedPointer<T>>;
@ -287,7 +282,6 @@ template <typename T> auto VContainer::GeometricObject(const quint32 &id) const
return obj; return obj;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GetVariable return varible by name * @brief GetVariable return varible by name
@ -317,15 +311,13 @@ template <typename T> auto VContainer::GetVariable(const QString &name) const ->
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> void VContainer::AddUniqueVariable(T *var)
void VContainer::AddUniqueVariable(T *var)
{ {
AddUniqueVariable(QSharedPointer<T>(var)); AddUniqueVariable(QSharedPointer<T>(var));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> void VContainer::AddUniqueVariable(const QSharedPointer<T> &var)
void VContainer::AddUniqueVariable(const QSharedPointer<T> &var)
{ {
AddVariable(var); AddVariable(var);
@ -336,15 +328,13 @@ void VContainer::AddUniqueVariable(const QSharedPointer<T> &var)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> void VContainer::AddVariable(T *var)
void VContainer::AddVariable(T *var)
{ {
AddVariable(QSharedPointer<T>(var)); AddVariable(QSharedPointer<T>(var));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> void VContainer::AddVariable(const QSharedPointer<T> &var)
void VContainer::AddVariable(const QSharedPointer<T> &var)
{ {
SCASSERT(not var->GetName().isEmpty()) SCASSERT(not var->GetName().isEmpty())
AddVariable(var, var->GetName()); AddVariable(var, var->GetName());
@ -356,8 +346,7 @@ void VContainer::AddVariable(const QSharedPointer<T> &var)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T> void VContainer::AddVariable(const QSharedPointer<T> &var, const QString &name)
void VContainer::AddVariable(const QSharedPointer<T> &var, const QString &name)
{ {
if (name.isEmpty()) if (name.isEmpty())
{ {
@ -398,16 +387,14 @@ template <class T> auto VContainer::qHash(const QSharedPointer<T> &p) -> uint
* @param id id of existing GObject * @param id id of existing GObject
* @param obj object * @param obj object
*/ */
template <class T> template <class T> void VContainer::UpdateGObject(quint32 id, T *obj)
void VContainer::UpdateGObject(quint32 id, T* obj)
{ {
SCASSERT(obj != nullptr) SCASSERT(obj != nullptr)
UpdateGObject(id, QSharedPointer<T>(obj)); UpdateGObject(id, QSharedPointer<T>(obj));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <class T> template <class T> void VContainer::UpdateGObject(quint32 id, const QSharedPointer<T> &obj)
void VContainer::UpdateGObject(quint32 id, const QSharedPointer<T> &obj)
{ {
SCASSERT(not obj.isNull()) SCASSERT(not obj.isNull())
UpdateObject(id, obj); UpdateObject(id, obj);
@ -420,8 +407,7 @@ void VContainer::UpdateGObject(quint32 id, const QSharedPointer<T> &obj)
* @param id id of existing object * @param id id of existing object
* @param point object * @param point object
*/ */
template <typename T> template <typename T> void VContainer::UpdateObject(const quint32 &id, const QSharedPointer<T> &point)
void VContainer::UpdateObject(const quint32 &id, const QSharedPointer<T> &point)
{ {
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712 Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
SCASSERT(point.isNull() == false) SCASSERT(point.isNull() == false)