From: Jeremy Paul Whiting Date: Mon, 23 Jul 2007 02:24:21 +0000 (+0000) Subject: article class with d-pointer without crashing X-Git-Tag: v3.92.0~16 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=235336a4687384680bd8332548963854d3763b36;p=libqmvoc.git article class with d-pointer without crashing svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=691154 --- diff --git a/kdeeducore/keduvocgrammar.cpp b/kdeeducore/keduvocgrammar.cpp index 01111de..422d810 100644 --- a/kdeeducore/keduvocgrammar.cpp +++ b/kdeeducore/keduvocgrammar.cpp @@ -160,65 +160,98 @@ QString KEduVocComparison::l3() const //================================================================= +class KEduVocArticle::Private +{ + public: + QString fem_def; + QString fem_indef; + QString mal_def; + QString mal_indef; + QString nat_def; + QString nat_indef; +}; KEduVocArticle::KEduVocArticle() +:d(new Private) { } +KEduVocArticle::KEduVocArticle(const KEduVocArticle &other) +:d(new Private) +{ + operator=(other); +} + +KEduVocArticle &KEduVocArticle::operator=(const KEduVocArticle& other) +{ + d->fem_def = other.d->fem_def; + d->fem_indef = other.d->fem_indef; + d->mal_def = other.d->mal_def; + d->mal_indef = other.d->mal_indef; + d->nat_def = other.d->nat_def; + d->nat_indef = other.d->nat_indef; + + return *this; +} KEduVocArticle::KEduVocArticle(const QString &fem_def, const QString &fem_indef, const QString &mal_def, const QString &mal_indef, const QString &nat_def, const QString &nat_indef) +:d(new Private) { setFemale (fem_def, fem_indef); setMale (mal_def, mal_indef); setNatural (nat_def, nat_indef); } +KEduVocArticle::~KEduVocArticle() +{ + delete d; +} void KEduVocArticle::setFemale(const QString &def, const QString &indef) { - fem_def = def; - fem_indef = indef; + d->fem_def = def; + d->fem_indef = indef; } void KEduVocArticle::setMale(const QString &def, const QString &indef) { - mal_def = def; - mal_indef = indef; + d->mal_def = def; + d->mal_indef = indef; } void KEduVocArticle::setNatural(const QString &def, const QString &indef) { - nat_def = def; - nat_indef = indef; + d->nat_def = def; + d->nat_indef = indef; } void KEduVocArticle::getFemale(QString *def, QString *indef) const { if (def) - *def = fem_def; + *def = d->fem_def; if (indef) - *indef = fem_indef; + *indef = d->fem_indef; } void KEduVocArticle::getMale(QString *def, QString *indef) const { if (def) - *def = mal_def; + *def = d->mal_def; if (indef) - *indef = mal_indef; + *indef = d->mal_indef; } void KEduVocArticle::getNatural(QString *def, QString *indef) const { if (def) - *def = nat_def; + *def = d->nat_def; if (indef) - *indef = nat_indef; + *indef = d->nat_indef; } //============================================================== diff --git a/kdeeducore/keduvocgrammar.h b/kdeeducore/keduvocgrammar.h index 5753bd6..5cc26e3 100644 --- a/kdeeducore/keduvocgrammar.h +++ b/kdeeducore/keduvocgrammar.h @@ -45,6 +45,8 @@ #define UL_USER_TENSE "#" // designates number of user tense +class KEduVocArticlePrivate; + /** * Class representing the articles of a language * @@ -58,6 +60,9 @@ public: * The constructor without arguments */ explicit KEduVocArticle(); + + /** copy constructor for d-pointer safety */ + KEduVocArticle(const KEduVocArticle &other); /** * The constructor with arguments @@ -70,6 +75,11 @@ public: */ KEduVocArticle( const QString &fem_def, const QString &fem_indef, const QString &mal_def, const QString &mal_indef, const QString &nat_def, const QString &nat_indef ); + /** + * default destructor, deletes the d pointer + */ + ~KEduVocArticle(); + /** * Sets the female articles * @param def const reference to a QString with the definite female article @@ -94,14 +104,12 @@ public: void getFemale (QString *def, QString *indef) const; void getMale (QString *def, QString *indef) const; void getNatural(QString *def, QString *indef) const; + + KEduVocArticle &operator=(const KEduVocArticle& other); private: - QString fem_def; - QString fem_indef; - QString mal_def; - QString mal_indef; - QString nat_def; - QString nat_indef; + class Private; + Private * const d; };