]> Git trees. - libqmvoc.git/commitdiff
article class with d-pointer without crashing
authorJeremy Paul Whiting <jpwhiting@kde.org>
Mon, 23 Jul 2007 02:24:21 +0000 (02:24 +0000)
committerJeremy Paul Whiting <jpwhiting@kde.org>
Mon, 23 Jul 2007 02:24:21 +0000 (02:24 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=691154

kdeeducore/keduvocgrammar.cpp
kdeeducore/keduvocgrammar.h

index 01111de2b9e7c485fa157242db3cebf54fc89565..422d810f858e736631c7901bb9a7c1edc00975d9 100644 (file)
@@ -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;
 }
 
 //==============================================================
index 5753bd6c451e0e14fe8bc7354ea7947c6c8ec7da..5cc26e38ab8bc4a759dd91af90aec153a2342598 100644 (file)
@@ -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;
 };