From: srit Date: Mon, 26 Apr 2010 16:24:02 +0000 (+0000) Subject: Corrected tool mechanism for windows: static data members seem to be initialized... X-Git-Tag: v1.2.0~691 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=db3faf3195c84f987dea55d8116565a732d1b668;p=clitk.git Corrected tool mechanism for windows: static data members seem to be initialized only at first instantiation and not as startup (as is the case with linux gcc) => dummy global. Reimplemented singleton with private constructor and pointer member. --- diff --git a/vv/vvToolBase.h b/vv/vvToolBase.h index e1d9b9d..f28fc8b 100644 --- a/vv/vvToolBase.h +++ b/vv/vvToolBase.h @@ -29,11 +29,11 @@ public: vvToolBase(vvMainWindowBase * m); static void Initialize(); // can't be virtual, must be overwritten - static void SetToolName(QString n) { vvToolCreator::mSingleton->mToolName = n; } - static void SetToolMenuName(QString n) { vvToolCreator::mSingleton->mToolMenuName = n; } - static void SetToolIconFilename(QString n) { vvToolCreator::mSingleton->mToolIconFilename = n; } - static void SetToolTip(QString n) { vvToolCreator::mSingleton->mToolTip = n; } - static void SetToolExperimental(bool exp) { vvToolCreator::mSingleton->mExperimental = exp; } + static void SetToolName(QString n) { vvToolCreator::GetInstance()->mToolName = n; } + static void SetToolMenuName(QString n) { vvToolCreator::GetInstance()->mToolMenuName = n; } + static void SetToolIconFilename(QString n) { vvToolCreator::GetInstance()->mToolIconFilename = n; } + static void SetToolTip(QString n) { vvToolCreator::GetInstance()->mToolTip = n; } + static void SetToolExperimental(bool exp) { vvToolCreator::GetInstance()->mExperimental = exp; } void AddImage(vvImage::Pointer image,std::string filename) { CREATOR(ToolType)->GetMainWindow()->AddImage(image,filename); diff --git a/vv/vvToolCreator.h b/vv/vvToolCreator.h index 5859a2f..2ebd8e0 100644 --- a/vv/vvToolCreator.h +++ b/vv/vvToolCreator.h @@ -24,24 +24,28 @@ template class vvToolCreator: public vvToolCreatorBase { public: - vvToolCreator(QString name):vvToolCreatorBase(name) {;} + static vvToolCreator *&GetInstance(); virtual void InsertToolInMenu(vvMainWindowBase * m); virtual void MenuSpecificToolSlot() { CreateTool(); } +private: + vvToolCreator():vvToolCreatorBase(mToolCreatorName) {;} static vvToolCreator * mSingleton; + static const QString mToolCreatorName; }; //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -#define CREATOR(CLASSNAME) vvToolCreator::mSingleton +#define CREATOR(CLASSNAME) vvToolCreator::GetInstance() //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -#define ADD_TOOL(NAME) \ - template<> \ - vvToolCreator * vvToolCreator::mSingleton = \ - new vvToolCreator(#NAME); +// Initiliazes the static parameters and creates a dummy pointer (required for windows) +#define ADD_TOOL(NAME) \ + template<> const QString vvToolCreator::mToolCreatorName = #NAME; \ + template<> vvToolCreator *vvToolCreator::mSingleton = NULL; \ + const vvToolCreator *dummy##NAME = vvToolCreator::GetInstance(); //------------------------------------------------------------------------------ #include "vvToolCreator.txx" diff --git a/vv/vvToolCreator.txx b/vv/vvToolCreator.txx index 33fd9e0..47b526c 100644 --- a/vv/vvToolCreator.txx +++ b/vv/vvToolCreator.txx @@ -33,3 +33,12 @@ void vvToolCreator::InsertToolInMenu(vvMainWindowBase * m) { vvToolCreatorBase::InsertToolInMenu(mMainWindow); } //------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +template +vvToolCreator* & vvToolCreator::GetInstance() { + if(!mSingleton) + mSingleton = new vvToolCreator; + return mSingleton; +} +//------------------------------------------------------------------------------