]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkFactory.h
=== MAJOR RELEASE ====
[bbtk.git] / kernel / src / bbtkFactory.h
index 35c04e6e3e42e21f812502ccba739f8d27e325a2..0d0560ac7d4eabf750c5393ed00218b068115958 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkFactory.h,v $
   Language:  C++
-  Date:      $Date: 2008/03/03 14:55:55 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2008/04/18 12:59:15 $
+  Version:   $Revision: 1.14 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See doc/license.txt or
 #ifndef __bbtkFactory_h__
 #define __bbtkFactory_h__
 
-//#include "bbtkBlackBox.h"
 #include "bbtkPackage.h"
-#include "bbtkDynamicLibraryHandling.h"
 
 namespace bbtk
 {
-  class BBTK_EXPORT Factory
-  {
 
-  public:
+  class Executer;
+  BBTK_FORWARD_DECLARE_POINTER(Executer);
 
-    Factory();
-    ~Factory();
+  class BBTK_EXPORT Factory : public Object
+  {
+    BBTK_OBJECT_INTERFACE(Factory);
+    typedef Object Superclass;
+  public:
+    static Pointer New();
 
+    
+    void GetPackagesList(std::vector<std::string>&);
     void LoadPackage( const std::string& name );
     void UnLoadPackage( const std::string& name );
     void PrintPackages(bool details = true, bool adaptors = false) const;
@@ -50,28 +53,47 @@ namespace bbtk
     void HelpBlackBox(const std::string& name, std::string& package,
                      bool full=true ) const;
     void ShowGraphTypes(const std::string& name) const;
-    void InsertPackage( Package* );
-    void RemovePackage( Package* );
+    void InsertPackage( Package::Pointer );
+    void RemovePackage( Package::Pointer );
+
+    Package::Pointer GetPackage(const std::string& name) const;
 
-    const Package* GetPackage(const std::string& name) const;
-    Package* GetPackage(const std::string& name);
     
-    BlackBox* NewBlackBox(const std::string& type, 
+    BlackBox::Pointer NewBlackBox(const std::string& type, 
                           const std::string& name) const;
     
-    BlackBox* NewAdaptor(TypeInfo typein,
-                         TypeInfo typeout,
+    BlackBox::Pointer NewAdaptor(const DataInfo& typein,
+                        const DataInfo& typeout,
                          const std::string& name) const;
+
+    BlackBox::Pointer NewWidgetAdaptor(const DataInfo& typein,
+                              const DataInfo& typeout,
+                              const std::string& name) const;
+
+    bool FindAdaptor(const DataInfo& typein,
+                    const DataInfo& typeout,
+                    std::string& adaptor) const;
+
+    bool FindWidgetAdaptor(const DataInfo& typein,
+                          const DataInfo& typeout,
+                          std::string& adaptor) const;
     
-    Connection* NewConnection(BlackBox* from,
-                              const std::string& output,
-                              BlackBox* to,
-                              const std::string& input) const;
+    bool FindWidgetAdaptor2(const DataInfo& typein,
+                           const DataInfo& typeout,
+                           std::string& widget,
+                           std::string& adaptor) const;
+
+    Connection::Pointer NewConnection(BlackBox::Pointer from,
+                                     const std::string& output,
+                                     BlackBox::Pointer to,
+                                     const std::string& input) const;
 
     void WriteDotFilePackagesList(FILE *ff);
 
     void Reset();
     
+    void CheckPackages() const;
+
     typedef enum
       {
        Packages,
@@ -82,30 +104,34 @@ namespace bbtk
       IndexEntryType;
     void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
 
+    /// Sets the executer who created the factory (if any)
+    void SetExecuter(ExecuterPointer e) { mExecuter = e; }
+    /// Gets the executer who created the factory (if any)
+    ExecuterPointer GetExecuter();// { return mExecuter.lock(); }
+    /// Gets the executer who created the factory (if any) - const
+    //    const Executer::Pointer GetExecuter() const { return mExecuter.lock(); }
+
+
   private:
 
     bool DoLoadPackage(std::string libname,
                       std::string pkgname,
                       std::string path);
 
-    /// The structure storing info on a package
-    class PackageInfoType
-    {
-    public :
-      /// Ctor
-      PackageInfoType() {}
-      /// Dtor
-      ~PackageInfoType() {}
-      /// The pointer on the package
-      Package* mPackage;
-      /// The handler of the dynamic library 
-      DynamicLibraryHandler mDynamicLibraryHandler;
-    };
+  public:
+
     /// The type of map of packages
-    typedef std::map< std::string, PackageInfoType > PackageMapType;
+    typedef std::map< std::string, Package::Pointer > PackageMapType;
+
+    const PackageMapType& GetPackageMap() const { return mPackageMap; }
+
+  private:
     /// The map of packages
     PackageMapType mPackageMap;
 
+    /// The executer which created the factory (if any)
+    ExecuterWeakPointer mExecuter;
+
     void CloseAllPackages();
     void ClosePackage(PackageMapType::iterator& i);
 
@@ -113,111 +139,6 @@ namespace bbtk
   // class Factory
 
 
-  /// SYSTEM METHOD : Global method returning the global factory object pointer
-  inline Factory*& GlobalFactoryPointer() 
-  {
-    static Factory* f = 0;
-    return f;
-  }
-
-  /// SYSTEM METHOD : Global method returning the global factory object 
-  inline Factory* GetGlobalFactory() 
-  {
-    if (!GlobalFactoryPointer()) 
-    {
-       GlobalFactoryPointer() = new Factory;
-    }
-    return GlobalFactoryPointer();
-  }
-
-  /// SYSTEM METHOD : Deletes the global factory pointer
-  inline void DeleteGlobalFactory() 
-  {
-    if (GlobalFactoryPointer()) 
-    {
-      delete GlobalFactoryPointer();
-    }
-  }
-
-  inline void LoadPackage( const std::string& name )
-  {
-    GetGlobalFactory()->LoadPackage(name);
-  }
-
-  inline void UnLoadPackage( const std::string& name )
-  { 
-    GetGlobalFactory()->UnLoadPackage(name);
-  }
-
-  inline void PrintPackages(bool details = true, bool adaptors = false)
-  {
-    GetGlobalFactory()->PrintPackages(details,adaptors);
-  }
-
-  inline void HelpPackage(const std::string& name, bool adaptors = false) 
-  {
-    GetGlobalFactory()->HelpPackage(name,adaptors);
-  }
-  
-  inline void HelpBlackBox(const std::string& name, bool full=true) 
-  {
-    std::string package; 
-    GetGlobalFactory()->HelpBlackBox(name, package, full);
-  }
-
-  inline void HelpBlackBox(const std::string& name, std::string& package,
-                          bool full=true
-                          )
-  {
-    GetGlobalFactory()->HelpBlackBox(name, package, full);
-  }
-
-
-  inline void ShowGraphTypes(const std::string& name)
-  {
-    GetGlobalFactory()->ShowGraphTypes(name);
-  }
-
-  inline void InsertPackage( Package* p)
-  {
-    GetGlobalFactory()->InsertPackage(p);
-  }
-
-  inline void RemovePackage( Package* p)
-  {
-    GetGlobalFactory()->RemovePackage(p);
-  }
-  
-  inline const Package* GetPackage(const std::string& name) 
-  {
-    return GetGlobalFactory()->GetPackage(name);
-  }
-    
-  inline BlackBox* NewBlackBox(const std::string& type, 
-                               const std::string& name) 
-  {
-    return GetGlobalFactory()->NewBlackBox(type,name);
-  }
-    
-  inline BlackBox* NewAdaptor(TypeInfo typein,
-                              TypeInfo typeout,
-                              const std::string& name) 
-  {
-    return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
-  }
-  
-  inline Connection* NewConnection(BlackBox* from,
-                                   const std::string& output,
-                                   BlackBox* to,
-                                   const std::string& input) 
-  {
-    return GetGlobalFactory()->NewConnection(from,output,to,input);
-  }
-  
-  inline void WriteDotFilePackagesList(FILE *ff)
-  {
-    GetGlobalFactory()->WriteDotFilePackagesList(ff);
-  }
 
 }// namespace bbtk