]> Creatis software - clitk.git/commitdiff
Corrected tool mechanism for windows: static data members seem to be initialized...
authorsrit <srit>
Mon, 26 Apr 2010 16:24:02 +0000 (16:24 +0000)
committersrit <srit>
Mon, 26 Apr 2010 16:24:02 +0000 (16:24 +0000)
at first instantiation and not as startup (as is the case with linux gcc) => dummy global.
Reimplemented singleton with private constructor and pointer member.

vv/vvToolBase.h
vv/vvToolCreator.h
vv/vvToolCreator.txx

index e1d9b9dd7fc9bb774004bc17133f62cc0214a0c7..f28fc8bb5aaea4b960d5aa745897c39e3d4ff28f 100644 (file)
@@ -29,11 +29,11 @@ public:
   vvToolBase(vvMainWindowBase * m);
   static void Initialize();  // can't be virtual, must be overwritten
 
-  static void SetToolName(QString n) { vvToolCreator<ToolType>::mSingleton->mToolName = n; }
-  static void SetToolMenuName(QString n) { vvToolCreator<ToolType>::mSingleton->mToolMenuName = n; }
-  static void SetToolIconFilename(QString n) { vvToolCreator<ToolType>::mSingleton->mToolIconFilename = n; }
-  static void SetToolTip(QString n) { vvToolCreator<ToolType>::mSingleton->mToolTip = n; }
-  static void SetToolExperimental(bool exp) { vvToolCreator<ToolType>::mSingleton->mExperimental = exp; }
+  static void SetToolName(QString n) { vvToolCreator<ToolType>::GetInstance()->mToolName = n; }
+  static void SetToolMenuName(QString n) { vvToolCreator<ToolType>::GetInstance()->mToolMenuName = n; }
+  static void SetToolIconFilename(QString n) { vvToolCreator<ToolType>::GetInstance()->mToolIconFilename = n; }
+  static void SetToolTip(QString n) { vvToolCreator<ToolType>::GetInstance()->mToolTip = n; }
+  static void SetToolExperimental(bool exp) { vvToolCreator<ToolType>::GetInstance()->mExperimental = exp; }
 
   void AddImage(vvImage::Pointer image,std::string filename) {
     CREATOR(ToolType)->GetMainWindow()->AddImage(image,filename); 
index 5859a2f1e71dec01f2e4046701edf871b24af2b7..2ebd8e095ab5b25c7dd933842c302b383be7823b 100644 (file)
 template<class ToolType>
 class vvToolCreator: public vvToolCreatorBase {
 public:
-  vvToolCreator(QString name):vvToolCreatorBase(name) {;}
+  static vvToolCreator<ToolType> *&GetInstance();
   virtual void InsertToolInMenu(vvMainWindowBase * m);
   virtual void MenuSpecificToolSlot() { CreateTool<ToolType>(); }
+private:
+  vvToolCreator():vvToolCreatorBase(mToolCreatorName) {;}
   static vvToolCreator<ToolType> * mSingleton;
+  static const QString mToolCreatorName;
 };
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-#define CREATOR(CLASSNAME) vvToolCreator<CLASSNAME>::mSingleton
+#define CREATOR(CLASSNAME) vvToolCreator<CLASSNAME>::GetInstance()
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-#define ADD_TOOL(NAME)                                          \
-  template<>                                                    \
-  vvToolCreator<NAME> * vvToolCreator<NAME>::mSingleton =       \
-    new vvToolCreator<NAME>(#NAME);
+// Initiliazes the static parameters and creates a dummy pointer (required for windows)
+#define ADD_TOOL(NAME)                                                           \
+  template<> const QString        vvToolCreator<NAME>::mToolCreatorName = #NAME; \
+  template<> vvToolCreator<NAME> *vvToolCreator<NAME>::mSingleton       = NULL;  \
+  const vvToolCreator<NAME> *dummy##NAME = vvToolCreator<NAME>::GetInstance();
 //------------------------------------------------------------------------------
 
 #include "vvToolCreator.txx"
index 33fd9e040c24bd46e776f07e366dfc31e72ba1fe..47b526ce85a1af279fb82cb6298ec831815b6356 100644 (file)
@@ -33,3 +33,12 @@ void vvToolCreator<ToolType>::InsertToolInMenu(vvMainWindowBase * m) {
   vvToolCreatorBase::InsertToolInMenu(mMainWindow); 
 }
 //------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+template<class ToolType>
+vvToolCreator<ToolType>* & vvToolCreator<ToolType>::GetInstance() { 
+  if(!mSingleton)
+    mSingleton = new vvToolCreator<ToolType>;
+  return mSingleton;
+}
+//------------------------------------------------------------------------------