]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkFactory.cxx
#3403 vtk8itk5wx3-macos
[bbtk.git] / kernel / src / bbtkFactory.cxx
index 669a9fbc7cfe05bc69a60627b554cec70568a28e..9e4ee36bf07156dfff2d636902e831ace604c8b5 100644 (file)
@@ -106,7 +106,6 @@ namespace bbtk
                               std::string pkgname,
                               std::string path)
   {
-    
     Package::Pointer p = Package::CreateFromDynamicLibrary(libname,
                                                           pkgname,
                                                           path);
@@ -125,8 +124,7 @@ namespace bbtk
        mPackageMap[pkgname] = p;
        return true;
       }
-    return false;
-    
+    return false;    
   }
   
   //===================================================================
@@ -148,7 +146,6 @@ namespace bbtk
   void Factory::LoadPackage( const std::string& name )
   {
          
-         
   // Note : in the following :
   // name : the user supplied name
   //      - abreviated name    e.g.       pkg   pkg.so   libbpkg   libbbpkg.so
@@ -157,9 +154,7 @@ namespace bbtk
   //          same for Windows, with      c:, d: ...
   //
   // lastname : string before the last / (if any), or user supplied name
-         
-        
-         
+                 
        if(name != ""){
                bbtkDebugMessageInc("kernel",7,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
                bbtkMessage("debug",1,"Factory::LoadPackage(\""<<name<<"\")"<<std::endl);
@@ -186,7 +181,6 @@ namespace bbtk
 //                     std::cout << (*it).first << " ";
 //             std::cout << std::endl;
 
-               
                if (iUnload != mPackageMap.end())
                {
                  bbtkMessage("output",2,"["<< pkgname <<"] already loaded" << std::endl);
@@ -213,7 +207,7 @@ namespace bbtk
                          return;
                   }
 
-                 // std::string path = Utilities::ExpandLibName(upath, false);
+        // std::string path = Utilities::ExpandLibName(upath, false);
 
                   std::string path = Utilities::ExpandLibName(name,false); // keep last item, here.
                   if (path != "")
@@ -228,24 +222,18 @@ namespace bbtk
                          // The following is *NOT* a debug time message :
                          // It's a user intended message.
                          // Please don't remove it.
-                       bbtkMessage("output",3,"   [" <<libname 
-                               <<"] : doesn't exist" <<std::endl);
-                         }
-                         else
-                         {
+                               bbtkMessage("output",3,"   [" << libname <<"] : doesn't exist" <<std::endl);
+                       } else {
                                 ok = DoLoadPackage( libname, pkgname, path);         
-                         }
-                  }
-                  else
-                  {
+                       }
+                  } else {
                          bbtkError("Path ["<<upath<<"] doesn't exist");
                          return;
                   }
-               }
-               else     // ----------------------------------------------------- iterate on the paths  
+               } else     // ----------------------------------------------------- iterate on the paths  
                {
 
-               std::string path = ".";
+        std::string path = ".";
                package_paths = ConfigurationFile::GetInstance().Get_package_paths();
                std::vector<std::string>::iterator i;
                for (i=package_paths.begin();i!=package_paths.end();++i)
@@ -280,7 +268,6 @@ namespace bbtk
                        foundFile = true; 
 
                  // Try to Load the library
-
                        ok = DoLoadPackage( libname, pkgname, path);
                        if (ok)
                        {
@@ -288,7 +275,6 @@ namespace bbtk
                        }
                break; // we stop iterating even if error : have to signal it to user
                } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
-
        }
 
                if( !ok )  // nothing was loaded
@@ -317,9 +303,6 @@ namespace bbtk
                }       
                bbtkMessage("output",2,"[" << libname << "] loaded" << std::endl);
        }
-
-    
-
   }
 
   //===================================================================
@@ -548,23 +531,47 @@ namespace bbtk
 
     bbtkDebugDecTab("kernel",9);
   }
-  //===================================================================
   
 
-//     ups3 EED borrame        
+  //===================================================================
        std::string Factory::GetPackageNameOfaBlackBox(std::string boxType)
        {
-               std::string result="<void bbtk package name>";
+               std::string packageName="<void bbtk package name>";
                PackageMapType::const_iterator i;
-               for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
-               {
-                       if ( i->second->ifBoxExist( boxType ) == true)
+
+               std::size_t found = boxType.find(":");
+               if (found!=std::string::npos)
+               {
+                       packageName     = boxType.substr(0,found);
+               } else {
+                       for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
                        {
-                               result = i->first;
-                       }
-               }
-               return result;
+                               if ( i->second->ifBoxExist( boxType ) == true)
+                               {
+                                       packageName = i->first;
+                               } // if ifBoxExist
+                       } // for i
+
+               } // if found
+               return packageName;
        }
+
+  //===================================================================
+       std::string Factory::GetTypeNameOfaBlackBox(std::string boxType)
+       {
+               std::string typeName="<void bbtk type name>";
+
+               std::size_t found = boxType.find(":");
+               if (found!=std::string::npos)
+               {
+                       typeName                = boxType.substr(found+1);
+               } else {
+                       typeName=boxType;
+               } // if found
+               return typeName;
+       }
+
+
        
        
   //===================================================================
@@ -572,20 +579,52 @@ namespace bbtk
   BlackBox::Pointer Factory::NewBlackBox(const std::string& type, 
                                  const std::string& name) const
   {
-    bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
+       bbtkDebugMessageInc("kernel",7,"Factory::NewBlackBox(\""
                         <<type<<"\",\""<<name<<"\")"<<std::endl);
 
     BlackBox::Pointer b; 
     PackageMapType::const_iterator i;
-    for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
-      {
-      b = i->second->NewBlackBox(type,name);
-      if (b) break; 
-      }
+
+       std::string tmp = type;
+       std::string packageName = ((bbtk::Factory*)this)->GetPackageNameOfaBlackBox(tmp);
+       std::string type2               = ((bbtk::Factory*)this)->GetTypeNameOfaBlackBox(tmp);
+       i = mPackageMap.find(packageName);
+       if (i != mPackageMap.end())
+       {
+               b = i->second->NewBlackBox(type2,name);
+       } else {
+               b =BlackBox::Pointer();
+       }
+
+/*
+       std::size_t found = type.find(":");
+       if (found!=std::string::npos)
+       {
+               std::string packageName = type.substr(0,found);
+               std::string type2               = type.substr(found+1);
+               i = mPackageMap.find(packageName);
+               if (i != mPackageMap.end())
+               {
+               b = i->second->NewBlackBox(type2,name);
+               } else {
+                       b =BlackBox::Pointer();
+               }
+       } else {
+       for (i = mPackageMap.begin(); i!=mPackageMap.end(); ++i )
+       {
+               b = i->second->NewBlackBox(type,name);
+               if (b) break; 
+       } // for i
+
+       } // if found :
+*/
+
+
     if (!b) 
-      {
-       bbtkError("black box type \""<<type<<"\" unknown");
-      } 
+    {
+       bbtkError("black box type \""<<type<<"\" unknown");
+    }  // if !b
+
 
     bbtkDebugDecTab("kernel",7);
     return b;