]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkExecuter.cxx
Global factory in course of removal... does not compile but have to commit to continu...
[bbtk.git] / kernel / src / bbtkExecuter.cxx
index 7d24b70fa357ac6f29a5847e0ef11ebef1bd38c9..241573ade7462e73776fdfb48f29080613897eff 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkExecuter.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/02/14 20:57:27 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2008/03/07 08:40:14 $
+  Version:   $Revision: 1.13 $
 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -40,14 +40,16 @@ namespace bbtk
  *
  */
   Executer::Executer()
-    : mPackage(0),
-      mRoot(0),
-      mNoExecMode(false),
-      mDialogMode(NoDialog)
+    : 
+    mFactory(0),
+    mRootPackage(0),
+    mRootCBB(0),
+    mNoExecMode(false),
+    mDialogMode(NoDialog)
   {
-    //VirtualExec();
-    
     bbtkDebugMessageInc("Kernel",9,"Executer::Executer()" <<std::endl);
+    mFactory = new Factory;
+    mFactory->SetExecuter(this);
     Reset();
     bbtkDebugDecTab("Kernel",9);
   }
@@ -57,17 +59,19 @@ namespace bbtk
  */
   Executer::~Executer()
   {
-std::cout << "====================================================== delete Executer\n";  
+    //std::cout << "===================================== delete Executer\n";  
      bbtkDebugMessageInc("Kernel",9,"Executer::~Executer()" <<std::endl);
-     if (mRoot) 
+     if (mRootCBB
      {
-        mPackage->UnRegisterBlackBox("workspace");
-        delete mRoot;
+        mRootPackage->UnRegisterBlackBox("workspace");
+        delete mRootCBB;
      }
-     if (mPackage)
+     if (mRootPackage)
      {
-        GetGlobalFactory()->UnLoadPackage("user");
+        GetFactory()->UnLoadPackage("user");
      }
+     delete mFactory;
+
      bbtkDebugDecTab("Kernel",9);
   }
 
@@ -85,38 +89,41 @@ std::cout << "====================================================== delete Exec
     // all user defined CBB otherwise any instance 
     // of a user CBB that is in the 'workspace' would try to 
     // access a user CBB descriptor which has been previously freed
-    if (mRoot)
+    if (mRootCBB)
     {
-       mPackage->UnRegisterBlackBox(mRoot->GetTypeName());
-       delete mRoot;
+       mRootPackage->UnRegisterBlackBox(mRootCBB->GetTypeName());
+       delete mRootCBB;
     }
-    if (mPackage)
+    if (mRootPackage)
     {
-       GetGlobalFactory()->UnLoadPackage("user");
+       GetFactory()->UnLoadPackage("user");
     }
-    GetGlobalFactory()->Reset();
+    GetFactory()->Reset();
+
     // Create user package
-    mPackage = new Package("user","internal to bbi",
+    mRootPackage = new Package("user","internal to bbi",
                            "User defined black boxes",
                            "",
                            BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
     // Create user workspace
-    mRoot = new ComplexBlackBoxDescriptor("workspace"); //,f);
-    mRoot->AddToAuthor("bbi (internal)");
-    mRoot->AddToDescription("User's workspace");
-    mOpenDefinition.push_back(CBBDefinition(mRoot,"user"));
+    mRootCBB = new ComplexBlackBoxDescriptor("workspace"); //,f);
+    mRootCBB->AddToAuthor("bbi (internal)");
+    mRootCBB->AddToDescription("User's workspace");
+    mOpenDefinition.push_back(CBBDefinition(mRootCBB,"user"));
     // Register it into the user package
-    mPackage->RegisterBlackBox(mRoot);
+    mRootPackage->RegisterBlackBox(mRootCBB);
     // Insert the user package in the factory
-    InsertPackage(mPackage);
-    mOpenPackage.push_back(mPackage);
+    GetFactory()->InsertPackage(mRootPackage);
+    // And in the list of open packages
+    mOpenPackage.push_back(mRootPackage);
+
     bbtkDebugDecTab("Kernel",9);
   }
 
   /// changes the workspace name
   void Executer::SetWorkspaceName( const std::string& n )
   {
-    mPackage->ChangeBlackBoxName( mRoot->GetTypeName(), n );
+    mRootPackage->ChangeBlackBoxName( mRootCBB->GetTypeName(), n );
   }
   
   void Executer::BeginPackage (const std::string &name)
@@ -126,7 +133,7 @@ std::cout << "====================================================== delete Exec
      Package* p;
      try 
       {
-         p = GetGlobalFactory()->GetPackage(name);
+         p = GetFactory()->GetPackage(name);
       }
     catch (Exception e)
       {
@@ -135,7 +142,7 @@ std::cout << "====================================================== delete Exec
                          "",
                          "",
                          BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
-         InsertPackage(p);
+         GetFactory()->InsertPackage(p);
       }
      mOpenPackage.push_back(p);
   }
@@ -176,30 +183,30 @@ std::cout << "====================================================== delete Exec
     Package* p;
     std::string pname(mOpenDefinition.back().package);
     if (pname.size()>0)
-    {
-      try
       {
-         p = GetGlobalFactory()->GetPackage(pname);
+       try
+         {
+           p = GetFactory()->GetPackage(pname);
+         }
+       catch (Exception e)
+         {
+           p = new Package(pname,
+                           "",
+                           "",
+                           "",
+                           BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
+           GetFactory()->InsertPackage(p);
+         }
       }
-      catch (Exception e)
+    else
       {
-            p = new Package(pname,
-                       "",
-                       "",
-                       "",
-                       BBTK_STRINGIFY_SYMBOL(BBTK_VERSION));
-           InsertPackage(p);
+       p = mOpenPackage.back();
       }
-    }
-    else
-    {
-       p = mOpenPackage.back();
-    }
     p->RegisterBlackBox(Current());
-
+    
     mOpenDefinition.pop_back();
   }
-
+  
 
   void Executer::Create ( const std::string& nodeType, 
                           const std::string& nodeName)
@@ -231,7 +238,7 @@ std::cout << "====================================================== delete Exec
   void Executer::Update (const std::string &nodeName) // would 'Execute' be more meaningfull ?
   {
  // if in root
-     if (Current()==mRoot) 
+     if (Current()==mRootCBB
      {
         if (!mNoExecMode) 
         {
@@ -253,7 +260,7 @@ std::cout << "====================================================== delete Exec
                                const std::string& help)
   {
     // If the input is defined in the Root box
-    if (Current()==mRoot) 
+    if (Current()==mRootCBB
       {
       // If the dialog mode is set to NoDialog
       // and the user passed the name in the Inputs map 
@@ -323,15 +330,15 @@ std::cout << "====================================================== delete Exec
     if ( b->bbGetInputType(input) !=  typeid(std::string) ) 
       {
          BlackBox* a =
-         NewAdaptor(typeid(std::string),
-                    b->bbGetInputType(input),
-                    "tmp");
+          GetFactory()->NewAdaptor(typeid(std::string),
+                                   b->bbGetInputType(input),
+                                   "tmp");
          if (!a) 
-         {
-            bbtkError("No <"<<
-                      TypeName(b->bbGetInputType(input))
-                      <<"> to <std::string> found");
-         }
+          {
+            bbtkError("No <"<<
+                      TypeName(b->bbGetInputType(input))
+                      <<"> to <std::string> found");
+          }
          std::string v(value);
          a->bbSetInput("In",v);
          a->bbExecute();
@@ -355,55 +362,55 @@ std::cout << "====================================================== delete Exec
     // Looks for the adaptor
     if (b->bbGetOutputType(output) != typeid(std::string)) 
       {
-      BlackBox* a =
-          NewAdaptor(
-             b->bbGetOutputType(output),
-             typeid(std::string),
-             "tmp");
-      if (!a) 
-        {
-        bbtkError("No <"<<
-                   TypeName(b->bbGetOutputType(output))
-                   <<"> to <std::string> found");
-        }
+       BlackBox* a =
+          GetFactory()->NewAdaptor(
+                                  b->bbGetOutputType(output),
+                                  typeid(std::string),
+                                  "tmp");
+       if (!a) 
+         {
+           bbtkError("No <"<<
+                     TypeName(b->bbGetOutputType(output))
+                     <<"> to <std::string> found");
+         }
         b->bbExecute();
-
+       
         a->bbSetInput("In",b->bbGetOutput(output));
         a->bbExecute();
         std::string r = a->bbGetOutput("Out").unsafe_get<std::string>();
-       //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
-       //   std::cout << a->bbGetOutput("Out").unsafe_get<std::string>() 
-       //             << std::endl;
-       //std::string v(value);
-       //b->bbSetInput(input,a->bbGetOutput("Out"));
+       //std::string v = *((std::string*)a->bbGetOutput("Out")) ;
+       //   std::cout << a->bbGetOutput("Out").unsafe_get<std::string>() 
+       //             << std::endl;
+       //std::string v(value);
+       //b->bbSetInput(input,a->bbGetOutput("Out"));
         a->bbDelete();
         return r;
       }
     else
       {
-       b->bbExecute();
-       return b->bbGetOutput(output).unsafe_get<std::string>();
-       // std::string v = *((std::string*)b->bbGetOutput(output)) ;
-       // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>() 
-       //   << std::endl;
-       // b->bbSetInput(input,&v);
+       b->bbExecute();
+       return b->bbGetOutput(output).unsafe_get<std::string>();
+       // std::string v = *((std::string*)b->bbGetOutput(output)) ;
+       // std::cout << b->bbGetOutput("Out").unsafe_get<std::string>() 
+       //   << std::endl;
+       // b->bbSetInput(input,&v);
       }
   }
 
 
   void Executer::Author(const std::string &authorName)
   {
-    Current()->AddToAuthor(authorName,Current()==mRoot);
+    Current()->AddToAuthor(authorName,Current()==mRootCBB);
   }
 
   void Executer::Category(const std::string &category)
   {
-    Current()->AddToCategory(category,Current()==mRoot);
+    Current()->AddToCategory(category,Current()==mRootCBB);
   }
 
   void Executer::Description(const std::string &d)
   {
-     Current()->AddToDescription(d,Current()==mRoot);
+    Current()->AddToDescription(d,Current()==mRootCBB);
   }
 
 
@@ -457,11 +464,11 @@ std::cout << "====================================================== delete Exec
     Package* p;
     try
     {
-       p = GetGlobalFactory()->GetPackage(nameblackbox);
+       p = GetFactory()->GetPackage(nameblackbox);
     }
     catch (Exception e)
     {
-       p = mPackage;
+       p = mRootPackage;
     }
     // Generating documentation-help of workspace
     p->SetDocURL(filename_rootHtml);