From ed20c95fff998cb25457e5b9d95bce312816ebd9 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 12 Jun 2010 11:22:10 +0200 Subject: Created singleton for SmUberModel Implemented a singleton for SmUberModel. --- shemov.pro | 6 ++++-- smubermodelsingleton.cpp | 18 ++++++++++++++++++ smubermodelsingleton.h | 24 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 smubermodelsingleton.cpp create mode 100644 smubermodelsingleton.h diff --git a/shemov.pro b/shemov.pro index 937117b..dfb9014 100644 --- a/shemov.pro +++ b/shemov.pro @@ -48,7 +48,8 @@ SOURCES = main.cpp \ archiveitemeditdialog.cpp \ smtreeitem.cpp \ smtreemodel.cpp \ - smubermodel.cpp + smubermodel.cpp \ + smubermodelsingleton.cpp HEADERS = listitem.h \ listmodel.h \ movieitem.h \ @@ -92,6 +93,7 @@ HEADERS = listitem.h \ archiveitemeditdialog.h \ smtreeitem.h \ smtreemodel.h \ - smubermodel.h + smubermodel.h \ + smubermodelsingleton.h LIBS += -lmagic RESOURCES = shemov.qrc diff --git a/smubermodelsingleton.cpp b/smubermodelsingleton.cpp new file mode 100644 index 0000000..ef3d1e3 --- /dev/null +++ b/smubermodelsingleton.cpp @@ -0,0 +1,18 @@ +/* + This program 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 + 2 of the License, or (at your option) any later version. +*/ + +#include "smubermodelsingleton.h" +#include "smubermodel.h" + +SmUberModel *SmUberModelSingleton::mInstance = 0; + +SmUberModel *SmUberModelSingleton::instance(){ + if(!mInstance){ + mInstance = new SmUberModel; + } + return mInstance; +} diff --git a/smubermodelsingleton.h b/smubermodelsingleton.h new file mode 100644 index 0000000..80b2313 --- /dev/null +++ b/smubermodelsingleton.h @@ -0,0 +1,24 @@ +/* + This program 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 + 2 of the License, or (at your option) any later version. +*/ + +#ifndef SMUBERMODELSINGLETON_H +#define SMUBERMODELSINGLETON_H + +class SmUberModel; + +class SmUberModelSingleton { + public: + static SmUberModel *instance(); + + private: + SmUberModelSingleton() {} + SmUberModelSingleton(const SmUberModelSingleton &other); + SmUberModelSingleton &operator=(const SmUberModelSingleton &other); + static SmUberModel *mInstance; +}; + +#endif -- cgit v1.2.3-70-g09d2