From ef00e4dbf01c28c2aca2d5780784777680b13c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BCller?= Date: Thu, 4 Jun 2015 15:58:38 +0200 Subject: [PATCH] trivial: separated class definition and definition of templated member functions --HG-- branch : develop --- src/app/container/vcontainer.cpp | 6 + src/app/container/vcontainer.h | 193 +++++++++++++++++-------------- 2 files changed, 113 insertions(+), 86 deletions(-) diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 020da9bb9..cd8164ac4 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -160,6 +160,12 @@ quint32 VContainer::AddDetail(VDetail detail) return id; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VContainer::getId() +{ + return _id; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief getNextId generate next unique id diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 3d7600d38..d0caf76c6 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -95,62 +95,13 @@ public: ~VContainer(); template - const QSharedPointer GeometricObject(const quint32 &id) const - { - QSharedPointer gObj = QSharedPointer(); - if (d->gObjects.contains(id)) - { - gObj = d->gObjects.value(id); - } - else - { - throw VExceptionBadId(tr("Can't find object"), id); - } - - try - { - QSharedPointer obj = qSharedPointerDynamicCast(gObj); - SCASSERT(obj.isNull() == false); - return obj; - } - catch (const std::bad_alloc &) - { - throw VExceptionBadId(tr("Can't cast object"), id); - } - } - + const QSharedPointer GeometricObject(const quint32 &id) const; const QSharedPointer GetGObject(quint32 id) const; const VDetail GetDetail(quint32 id) const; qreal GetTableValue(const QString& name) const; template - /** - * @brief GetVariable return varible by name - * @param name variable's name - * @return variable - */ - QSharedPointer GetVariable(QString name) const - { - SCASSERT(name.isEmpty()==false); - if (d->variables.contains(name)) - { - try - { - QSharedPointer value = qSharedPointerDynamicCast(d->variables.value(name)); - SCASSERT(value.isNull() == false); - return value; - } - catch (const std::bad_alloc &) - { - throw VExceptionBadId(tr("Can't cast object"), name); - } - } - else - { - throw VExceptionBadId(tr("Can't find object"), name); - } - } - - static quint32 getId(){return _id;} + QSharedPointer GetVariable(QString name) const; + static quint32 getId(); static quint32 getNextId(); static void UpdateId(quint32 newId); @@ -160,37 +111,9 @@ public: void AddArc(const quint32 &arcId, const quint32 &parentId = 0); template - void AddCurve(const quint32 &id, const quint32 &parentId = 0) - { - const QSharedPointer curve = GeometricObject(id); - - VSplineLength *length = new VSplineLength(id, parentId, curve.data()); - AddVariable(length->GetName(), length); - - VSplineAngle *startAngle = new VSplineAngle(id, parentId, curve.data(), CurveAngle::StartAngle); - AddVariable(startAngle->GetName(), startAngle); - - VSplineAngle *endAngle = new VSplineAngle(id, parentId, curve.data(), CurveAngle::EndAngle); - AddVariable(endAngle->GetName(), endAngle); - } - + void AddCurve(const quint32 &id, const quint32 &parentId = 0); template - void AddVariable(const QString& name, T *var) - { - if (d->variables.contains(name)) - { - if (d->variables.value(name)->GetType() == var->GetType()) - { - d->variables[name].clear(); - } - else - { - throw VExceptionBadId(tr("Can't find object. Type mismatch."), name); - } - } - d->variables[name] = QSharedPointer(var); - uniqueNames.insert(name); - } + void AddVariable(const QString& name, T *var); void UpdateGObject(quint32 id, VGObject* obj); void UpdateDetail(quint32 id, const VDetail &detail); @@ -243,10 +166,7 @@ private: QSharedDataPointer d; template - uint qHash( const QSharedPointer &p ) - { - return qHash( p.data() ); - } + uint qHash( const QSharedPointer &p ); template // cppcheck-suppress functionStatic @@ -262,4 +182,105 @@ private: const QMap > DataVar(const VarType &type) const; }; + + +/* +* Defintion of templated member functions of VContainer +*/ + +//--------------------------------------------------------------------------------------------------------------------- +template +const QSharedPointer VContainer::GeometricObject(const quint32 &id) const +{ + QSharedPointer gObj = QSharedPointer(); + if (d->gObjects.contains(id)) + { + gObj = d->gObjects.value(id); + } + else + { + throw VExceptionBadId(tr("Can't find object"), id); + } + try + { + QSharedPointer obj = qSharedPointerDynamicCast(gObj); + SCASSERT(obj.isNull() == false); + return obj; + } + catch (const std::bad_alloc &) + { + throw VExceptionBadId(tr("Can't cast object"), id); + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +/** +* @brief GetVariable return varible by name +* @param name variable's name +* @return variable +*/ +template +QSharedPointer VContainer::GetVariable(QString name) const +{ + SCASSERT(name.isEmpty()==false); + if (d->variables.contains(name)) + { + try + { + QSharedPointer value = qSharedPointerDynamicCast(d->variables.value(name)); + SCASSERT(value.isNull() == false); + return value; + } + catch (const std::bad_alloc &) + { + throw VExceptionBadId(tr("Can't cast object"), name); + } + } + else + { + throw VExceptionBadId(tr("Can't find object"), name); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VContainer::AddCurve(const quint32 &id, const quint32 &parentId) +{ + const QSharedPointer curve = GeometricObject(id); + VSplineLength *length = new VSplineLength(id, parentId, curve.data()); + AddVariable(length->GetName(), length); + + VSplineAngle *startAngle = new VSplineAngle(id, parentId, curve.data(), CurveAngle::StartAngle); + AddVariable(startAngle->GetName(), startAngle); + + VSplineAngle *endAngle = new VSplineAngle(id, parentId, curve.data(), CurveAngle::EndAngle); + AddVariable(endAngle->GetName(), endAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VContainer::AddVariable(const QString& name, T *var) +{ + if (d->variables.contains(name)) + { + if (d->variables.value(name)->GetType() == var->GetType()) + { + d->variables[name].clear(); + } + else + { + throw VExceptionBadId(tr("Can't find object. Type mismatch."), name); + } + } + d->variables[name] = QSharedPointer(var); + uniqueNames.insert(name); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +uint VContainer::qHash( const QSharedPointer &p ) +{ + return qHash( p.data() ); +} #endif // VCONTAINER_H