]> Creatis software - bbtk.git/blob - kernel/src/bbtkFactory.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkFactory.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkFactory.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:13 $
6   Version:   $Revision: 1.16 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *\file
33  *\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.
34  */
35 /**
36  *\class bbtk::Factory
37  *\brief Can load and unload dynamic libraries containing black boxes packages and create instances of the black boxes registered in the packages loaded.
38  *
39  */
40
41
42 #ifndef __bbtkFactory_h__
43 #define __bbtkFactory_h__
44
45 #include "bbtkPackage.h"
46
47 namespace bbtk
48 {
49
50   class Executer;
51   BBTK_FORWARD_DECLARE_POINTER(Executer);
52
53   class BBTK_EXPORT Factory : public Object
54   {
55     BBTK_OBJECT_INTERFACE(Factory);
56     typedef Object Superclass;
57   public:
58     static Pointer New();
59
60     
61     void GetPackagesList(std::vector<std::string>&);
62     void LoadPackage( const std::string& name );
63     void UnLoadPackage( const std::string& name );
64     void PrintPackages(bool details = true, bool adaptors = false) const;
65     void HelpPackage(const std::string& name, bool adaptors = false) const;
66     void HelpBlackBox(const std::string& name, std::string& package,
67                       bool full=true ) const;
68     void ShowGraphTypes(const std::string& name) const;
69     void InsertPackage( Package::Pointer );
70     void RemovePackage( Package::Pointer );
71
72     Package::Pointer GetPackage(const std::string& name) const;
73
74     
75     BlackBox::Pointer NewBlackBox(const std::string& type, 
76                           const std::string& name) const;
77     
78     BlackBox::Pointer NewAdaptor(const DataInfo& typein,
79                          const DataInfo& typeout,
80                          const std::string& name) const;
81
82     BlackBox::Pointer NewWidgetAdaptor(const DataInfo& typein,
83                                const DataInfo& typeout,
84                                const std::string& name) const;
85
86     bool FindAdaptor(const DataInfo& typein,
87                      const DataInfo& typeout,
88                      std::string& adaptor) const;
89
90     bool FindWidgetAdaptor(const DataInfo& typein,
91                            const DataInfo& typeout,
92                            std::string& adaptor) const;
93     
94     bool FindWidgetAdaptor2(const DataInfo& typein,
95                             const DataInfo& typeout,
96                             std::string& widget,
97                             std::string& adaptor) const;
98
99     Connection::Pointer NewConnection(BlackBox::Pointer from,
100                                       const std::string& output,
101                                       BlackBox::Pointer to,
102                                       const std::string& input) const;
103
104     void WriteDotFilePackagesList(FILE *ff);
105
106     void Reset();
107     
108     void CheckPackages() const;
109
110     typedef enum
111       {
112         Packages,
113         Categories,
114         Initials,
115         Adaptors
116       }
117       IndexEntryType;
118     void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
119
120     /// Sets the executer who created the factory (if any)
121     void SetExecuter(ExecuterPointer e) { mExecuter = e; }
122     /// Gets the executer who created the factory (if any)
123     ExecuterPointer GetExecuter() { return mExecuter.lock(); }
124     /// Gets the executer who created the factory (if any) - const
125     //    const Executer::Pointer GetExecuter() const { return mExecuter.lock(); }
126
127
128   private:
129
130     bool DoLoadPackage(std::string libname,
131                        std::string pkgname,
132                        std::string path);
133
134   public:
135
136     /// The type of map of packages
137     typedef std::map< std::string, Package::Pointer > PackageMapType;
138
139     const PackageMapType& GetPackageMap() const { return mPackageMap; }
140
141   private:
142     /// The map of packages
143     PackageMapType mPackageMap;
144
145     /// The executer which created the factory (if any)
146     ExecuterWeakPointer mExecuter;
147
148     void CloseAllPackages();
149     void ClosePackage(PackageMapType::iterator& i);
150
151   };
152   // class Factory
153
154
155
156 }// namespace bbtk
157
158
159
160 #endif
161