From a8a61a0a9c1d157c8866a4e0e988c6a1b1862173 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 4 Apr 2007 22:36:54 +0000 Subject: [PATCH] really hide the private stuff svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=650600 --- libscience/chemicaldataobject.cpp | 48 ++++++++++++++++++++++++++----- libscience/chemicaldataobject.h | 28 ++++++++++-------- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/libscience/chemicaldataobject.cpp b/libscience/chemicaldataobject.cpp index efaf615..c7dd2b7 100644 --- a/libscience/chemicaldataobject.cpp +++ b/libscience/chemicaldataobject.cpp @@ -17,16 +17,25 @@ * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ + #include #include "chemicaldataobject.h" -//######################## -ChemicalDataObjectPrivate::ChemicalDataObjectPrivate() +class ChemicalDataObjectPrivate : public QSharedData { -} + public: + ChemicalDataObjectPrivate(); + ~ChemicalDataObjectPrivate(); + + QVariant m_value; + QVariant m_errorValue; + ChemicalDataObject::BlueObelisk m_type; + ChemicalDataObject::BlueObeliskUnit m_unit; +}; -ChemicalDataObjectPrivate::ChemicalDataObjectPrivate(const ChemicalDataObjectPrivate &other) -: QSharedData(other) +//######################## +ChemicalDataObjectPrivate::ChemicalDataObjectPrivate() +: QSharedData() { } @@ -36,8 +45,8 @@ ChemicalDataObjectPrivate::~ChemicalDataObjectPrivate() //############## ChemicalDataObject::ChemicalDataObject( const QVariant& v, BlueObelisk type, const QVariant& errorValue ) + : d(new ChemicalDataObjectPrivate) { - d = new ChemicalDataObjectPrivate; d->m_value = v; d->m_errorValue = errorValue; d->m_type = type; @@ -45,12 +54,27 @@ ChemicalDataObject::ChemicalDataObject( const QVariant& v, BlueObelisk type, con } ChemicalDataObject::ChemicalDataObject() + : d(new ChemicalDataObjectPrivate) { - d = new ChemicalDataObjectPrivate; d->m_errorValue = QVariant(); d->m_unit = ChemicalDataObject::noUnit; } +ChemicalDataObject::ChemicalDataObject(const ChemicalDataObject &other) + : d(other.d) +{ +} + +ChemicalDataObject::~ChemicalDataObject() +{ +} + +ChemicalDataObject& ChemicalDataObject::operator=(const ChemicalDataObject &other) +{ + d = other.d; + return *this; +} + bool ChemicalDataObject::operator==( const int v ) const { if ( d->m_value.type() != QVariant::Int ) @@ -83,6 +107,16 @@ bool ChemicalDataObject::operator==( const QString& v ) const return d->m_value.toString() == v; } +bool ChemicalDataObject::operator==(const ChemicalDataObject &other) const +{ + return d == other.d; +} + +bool ChemicalDataObject::operator!=(const ChemicalDataObject &other) const +{ + return d != other.d; +} + QString ChemicalDataObject::valueAsString() const { return d->m_value.toString(); diff --git a/libscience/chemicaldataobject.h b/libscience/chemicaldataobject.h index 7ab82ab..cd32ec3 100644 --- a/libscience/chemicaldataobject.h +++ b/libscience/chemicaldataobject.h @@ -118,6 +118,16 @@ class SCIENCE_EXPORT ChemicalDataObject BlueObelisk type, const QVariant& errorValue = QVariant(0) ); + /** + * Copy constructor. + */ + ChemicalDataObject(const ChemicalDataObject &other); + + /** + * Destructor. + */ + ~ChemicalDataObject(); + /** * Set the data of this object to @p v * @param v the value of the object @@ -234,20 +244,14 @@ class SCIENCE_EXPORT ChemicalDataObject */ static BlueObeliskUnit unit( const QString& unitname ); + ChemicalDataObject& operator=(const ChemicalDataObject &other); + + bool operator==(const ChemicalDataObject &other) const; + + bool operator!=(const ChemicalDataObject &other) const; + private: QSharedDataPointer d; }; -class SCIENCE_EXPORT ChemicalDataObjectPrivate : public QSharedData -{ - public: - ChemicalDataObjectPrivate(); - ChemicalDataObjectPrivate(const ChemicalDataObjectPrivate &other); - ~ChemicalDataObjectPrivate(); - - QVariant m_value; - QVariant m_errorValue; - ChemicalDataObject::BlueObelisk m_type; - ChemicalDataObject::BlueObeliskUnit m_unit; -}; #endif // CHEMICALDATAOBJECT_H -- 2.47.3