]> Creatis software - bbtk.git/blob - kernel/src/bbtkFactory.h
0d0560ac7d4eabf750c5393ed00218b068115958
[bbtk.git] / kernel / src / bbtkFactory.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkFactory.h,v $
5   Language:  C++
6   Date:      $Date: 2008/04/18 12:59:15 $
7   Version:   $Revision: 1.14 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See doc/license.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *\file
20  *\brief Class bbtk::Factory : can load and unload dynamic libraries containing black boxes packages and create instances of the black boxes registered in the packages loaded.
21  */
22 /**
23  *\class bbtk::Factory
24  *\brief Can load and unload dynamic libraries containing black boxes packages and create instances of the black boxes registered in the packages loaded.
25  *
26  */
27
28
29 #ifndef __bbtkFactory_h__
30 #define __bbtkFactory_h__
31
32 #include "bbtkPackage.h"
33
34 namespace bbtk
35 {
36
37   class Executer;
38   BBTK_FORWARD_DECLARE_POINTER(Executer);
39
40   class BBTK_EXPORT Factory : public Object
41   {
42     BBTK_OBJECT_INTERFACE(Factory);
43     typedef Object Superclass;
44   public:
45     static Pointer New();
46
47     
48     void GetPackagesList(std::vector<std::string>&);
49     void LoadPackage( const std::string& name );
50     void UnLoadPackage( const std::string& name );
51     void PrintPackages(bool details = true, bool adaptors = false) const;
52     void HelpPackage(const std::string& name, bool adaptors = false) const;
53     void HelpBlackBox(const std::string& name, std::string& package,
54                       bool full=true ) const;
55     void ShowGraphTypes(const std::string& name) const;
56     void InsertPackage( Package::Pointer );
57     void RemovePackage( Package::Pointer );
58
59     Package::Pointer GetPackage(const std::string& name) const;
60
61     
62     BlackBox::Pointer NewBlackBox(const std::string& type, 
63                           const std::string& name) const;
64     
65     BlackBox::Pointer NewAdaptor(const DataInfo& typein,
66                          const DataInfo& typeout,
67                          const std::string& name) const;
68
69     BlackBox::Pointer NewWidgetAdaptor(const DataInfo& typein,
70                                const DataInfo& typeout,
71                                const std::string& name) const;
72
73     bool FindAdaptor(const DataInfo& typein,
74                      const DataInfo& typeout,
75                      std::string& adaptor) const;
76
77     bool FindWidgetAdaptor(const DataInfo& typein,
78                            const DataInfo& typeout,
79                            std::string& adaptor) const;
80     
81     bool FindWidgetAdaptor2(const DataInfo& typein,
82                             const DataInfo& typeout,
83                             std::string& widget,
84                             std::string& adaptor) const;
85
86     Connection::Pointer NewConnection(BlackBox::Pointer from,
87                                       const std::string& output,
88                                       BlackBox::Pointer to,
89                                       const std::string& input) const;
90
91     void WriteDotFilePackagesList(FILE *ff);
92
93     void Reset();
94     
95     void CheckPackages() const;
96
97     typedef enum
98       {
99         Packages,
100         Categories,
101         Initials,
102         Adaptors
103       }
104       IndexEntryType;
105     void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
106
107     /// Sets the executer who created the factory (if any)
108     void SetExecuter(ExecuterPointer e) { mExecuter = e; }
109     /// Gets the executer who created the factory (if any)
110     ExecuterPointer GetExecuter();// { return mExecuter.lock(); }
111     /// Gets the executer who created the factory (if any) - const
112     //    const Executer::Pointer GetExecuter() const { return mExecuter.lock(); }
113
114
115   private:
116
117     bool DoLoadPackage(std::string libname,
118                        std::string pkgname,
119                        std::string path);
120
121   public:
122
123     /// The type of map of packages
124     typedef std::map< std::string, Package::Pointer > PackageMapType;
125
126     const PackageMapType& GetPackageMap() const { return mPackageMap; }
127
128   private:
129     /// The map of packages
130     PackageMapType mPackageMap;
131
132     /// The executer which created the factory (if any)
133     ExecuterWeakPointer mExecuter;
134
135     void CloseAllPackages();
136     void ClosePackage(PackageMapType::iterator& i);
137
138   };
139   // class Factory
140
141
142
143 }// namespace bbtk
144
145
146
147 #endif
148