From 8f274990e05929df666190225562a6018a61f347 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 20 Aug 2014 19:31:15 +0300 Subject: [PATCH] Implicit Sharing for class VIncrement. --HG-- branch : develop --- src/app/container/container.pri | 3 +- src/app/container/vincrement.cpp | 29 +++++++++++++--- src/app/container/vincrement.h | 25 ++------------ src/app/container/vincrement_p.h | 58 ++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 src/app/container/vincrement_p.h diff --git a/src/app/container/container.pri b/src/app/container/container.pri index 8438d1a65..7ee5145f1 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -25,4 +25,5 @@ HEADERS += \ container/vlinelength.h \ container/vsplinelength.h \ container/vinternalvariable_p.h \ - container/vvariable_p.h + container/vvariable_p.h \ + container/vincrement_p.h diff --git a/src/app/container/vincrement.cpp b/src/app/container/vincrement.cpp index 4bfce0166..df9de9cfe 100644 --- a/src/app/container/vincrement.cpp +++ b/src/app/container/vincrement.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "vincrement.h" +#include "vincrement_p.h" #include "../options.h" //--------------------------------------------------------------------------------------------------------------------- @@ -34,7 +35,7 @@ * @brief VIncrement create enpty increment */ VIncrement::VIncrement() - :VVariable(), id(NULL_ID) + :VVariable(), d(new VIncrementData) { SetType(VarType::Increment); } @@ -50,14 +51,14 @@ VIncrement::VIncrement() * @param description description of increment */ VIncrement::VIncrement(const QString &name, quint32 id, qreal base, qreal ksize, qreal kheight, QString description) - :VVariable(name, base, ksize, kheight, description), id(id) + :VVariable(name, base, ksize, kheight, description), d(new VIncrementData(id)) { SetType(VarType::Increment); } //--------------------------------------------------------------------------------------------------------------------- VIncrement::VIncrement(const VIncrement &incr) - :VVariable(incr), id(incr.getId()) + :VVariable(incr), d(incr.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -68,10 +69,30 @@ VIncrement &VIncrement::operator=(const VIncrement &incr) return *this; } VVariable::operator=(incr); - this->id = incr.getId(); + d = incr.d; return *this; } //--------------------------------------------------------------------------------------------------------------------- VIncrement::~VIncrement() {} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief getId return id of row + * @return id + */ +quint32 VIncrement::getId() const +{ + return d->id; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief setId set id of row + * @param value id + */ +void VIncrement::setId(const quint32 &value) +{ + d->id = value; +} diff --git a/src/app/container/vincrement.h b/src/app/container/vincrement.h index 866462ef5..e82806892 100644 --- a/src/app/container/vincrement.h +++ b/src/app/container/vincrement.h @@ -31,6 +31,8 @@ #include "vvariable.h" +class VIncrementData; + /** * @brief The VIncrement class keep data row of increment table */ @@ -47,28 +49,7 @@ public: quint32 getId() const; void setId(const quint32 &value); private: - /** @brief id each increment have unique identificator */ - quint32 id; + QSharedDataPointer d; }; -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief getId return id of row - * @return id - */ -inline quint32 VIncrement::getId() const -{ - return id; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief setId set id of row - * @param value id - */ -inline void VIncrement::setId(const quint32 &value) -{ - id = value; -} - #endif // VINCREMENTTABLEROW_H diff --git a/src/app/container/vincrement_p.h b/src/app/container/vincrement_p.h new file mode 100644 index 000000000..eab9edbd0 --- /dev/null +++ b/src/app/container/vincrement_p.h @@ -0,0 +1,58 @@ +/************************************************************************ + ** + ** @file vincrement_p.h + ** @author Roman Telezhynskyi + ** @date 20 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VINCREMENT_P_H +#define VINCREMENT_P_H + +#include +#include "../options.h" + +class VIncrementData : public QSharedData +{ +public: + + VIncrementData() + :id(NULL_ID) + {} + + VIncrementData(quint32 id) + :id(id) + {} + + VIncrementData(const VIncrementData &incr) + :QSharedData(incr), id(incr.id) + {} + + virtual ~VIncrementData() {} + + /** @brief id each increment have unique identificator */ + quint32 id; +}; + + +#endif // VINCREMENT_P_H