From d922edd4bc7f13b9116799bddfe72db776f615e7 Mon Sep 17 00:00:00 2001 From: Aki Koskinen Date: Sat, 27 Mar 2010 20:03:01 +0200 Subject: [PATCH] Changed KKJ class to use private member implementation --- src/kkj.cpp | 32 ++++++++++++++++++++++++++++---- src/kkj.h | 21 +++++++++++++++++++-- src/kkj_p.h | 40 ++++++++++++++++++++++++++++++++++++++++ src/src.pro | 7 +++++-- 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 src/kkj_p.h diff --git a/src/kkj.cpp b/src/kkj.cpp index d60da50..2724ce0 100644 --- a/src/kkj.cpp +++ b/src/kkj.cpp @@ -1,9 +1,31 @@ #include "kkj.h" +#include "kkj_p.h" + +KKJPrivate::~KKJPrivate() +{ +} + +void KKJPrivate::init(unsigned int northing, unsigned int easting) +{ + this->northing = northing; + this->easting = easting; +} + KKJ::KKJ(unsigned int northing, unsigned int easting) : - mNorthing(northing), - mEasting(easting) + d_ptr(new KKJPrivate) +{ + Q_D(KKJ); + d->q_ptr = this; + d->init(northing, easting); +} + +KKJ::KKJ(KKJPrivate &dd, unsigned int northing, unsigned int easting) : + d_ptr(&dd) { + Q_D(KKJ); + d->q_ptr = this; + d->init(northing, easting); } KKJ::~KKJ() @@ -12,10 +34,12 @@ KKJ::~KKJ() unsigned int KKJ::northing() const { - return mNorthing; + Q_D(const KKJ); + return d->northing; } unsigned int KKJ::easting() const { - return mEasting; + Q_D(const KKJ); + return d->easting; } diff --git a/src/kkj.h b/src/kkj.h index 3afb9b2..ac148fa 100644 --- a/src/kkj.h +++ b/src/kkj.h @@ -1,6 +1,10 @@ #ifndef KKJ_H #define KKJ_H +#include + +class KKJPrivate; + /** * A class representing the Finnish KKJ coordinate. */ @@ -31,9 +35,22 @@ public: */ unsigned int easting() const; +protected: + /** + * Constructs a new KKJ coordinate with the given values. + * @param dd a private implementation member. + * @param northing the northing coordinate. + * @param easting the easting coordinate. + */ + KKJ(KKJPrivate &dd, unsigned int northing, unsigned int easting); + + private: - unsigned int mNorthing; - unsigned int mEasting; + /// Pointer to the private member + KKJPrivate *const d_ptr; + + Q_DECLARE_PRIVATE(KKJ) + }; #endif // KKJ_H diff --git a/src/kkj_p.h b/src/kkj_p.h new file mode 100644 index 0000000..61b7fa5 --- /dev/null +++ b/src/kkj_p.h @@ -0,0 +1,40 @@ +#ifndef KKJ_P_H +#define KKJ_P_H + +#include + +class KKJ; + +/** + * A private member class for class KKJ. + */ +class KKJPrivate +{ +public: + /** + * Destructor. + */ + virtual ~KKJPrivate(); + +private: + /** + * Initializes the private class. + * @param northing the northing of the coordinate. + * @param easting the easting of the coordinate. + */ + void init(unsigned int northing, unsigned int easting); + + /// The northing of the coordinate. + unsigned int northing; + + /// The easting of the coordinate. + unsigned int easting; + + /// The concrete class owning this private implementation member. + KKJ *q_ptr; + + Q_DECLARE_PUBLIC(KKJ) + +}; + +#endif // KKJ_P_H diff --git a/src/src.pro b/src/src.pro index ec3edc3..854efac 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,9 +1,12 @@ TEMPLATE = lib TARGET = ptascommon -INSTALL_HEADERS += \ +INSTALL_HEADERS = \ kkj.h +PRIVATE_HEADERS = \ + kkj_p.h HEADERS += \ - $$INSTALL_HEADERS + $$INSTALL_HEADERS \ + $$PRIVATE_HEADERS SOURCES += \ kkj.cpp -- 1.7.9.5