1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.h,v $
6 Date: $Date: 2008/04/09 11:16:57 $
7 Version: $Revision: 1.13 $
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.
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.
17 =========================================================================*/
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.
24 *\brief Can load and unload dynamic libraries containing black boxes packages and create instances of the black boxes registered in the packages loaded.
29 #ifndef __bbtkFactory_h__
30 #define __bbtkFactory_h__
32 //#include "bbtkBlackBox.h"
33 #include "bbtkPackage.h"
34 #include "bbtkDynamicLibraryHandling.h"
41 class BBTK_EXPORT Factory
49 void GetPackagesList(std::vector<std::string>&);
50 void LoadPackage( const std::string& name );
51 void UnLoadPackage( const std::string& name );
52 void PrintPackages(bool details = true, bool adaptors = false) const;
53 void HelpPackage(const std::string& name, bool adaptors = false) const;
54 void HelpBlackBox(const std::string& name, std::string& package,
55 bool full=true ) const;
56 void ShowGraphTypes(const std::string& name) const;
57 void InsertPackage( Package* );
58 void RemovePackage( Package* );
60 const Package* GetPackage(const std::string& name) const;
61 Package* GetPackage(const std::string& name);
63 BlackBox* NewBlackBox(const std::string& type,
64 const std::string& name) const;
66 BlackBox* NewAdaptor(const DataInfo& typein,
67 const DataInfo& typeout,
68 const std::string& name) const;
70 BlackBox* NewWidgetAdaptor(const DataInfo& typein,
71 const DataInfo& typeout,
72 const std::string& name) const;
74 bool FindAdaptor(const DataInfo& typein,
75 const DataInfo& typeout,
76 std::string& adaptor) const;
78 bool FindWidgetAdaptor(const DataInfo& typein,
79 const DataInfo& typeout,
80 std::string& adaptor) const;
82 bool FindWidgetAdaptor2(const DataInfo& typein,
83 const DataInfo& typeout,
85 std::string& adaptor) const;
87 Connection* NewConnection(BlackBox* from,
88 const std::string& output,
90 const std::string& input) const;
92 void WriteDotFilePackagesList(FILE *ff);
96 void CheckPackages() const;
106 void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
108 /// Sets the executer who created the factory (if any)
109 void SetExecuter(Executer *e) { mExecuter = e; }
110 /// Gets the executer who created the factory (if any)
111 Executer* GetExecuter() { return mExecuter; }
112 /// Gets the executer who created the factory (if any) - const
113 const Executer* GetExecuter() const { return mExecuter; }
118 bool DoLoadPackage(std::string libname,
123 /// The structure storing info on a package
124 class PackageInfoType
130 ~PackageInfoType() {}
131 /// The pointer on the package
133 /// The handler of the dynamic library
134 DynamicLibraryHandler mDynamicLibraryHandler;
136 /// The type of map of packages
137 typedef std::map< std::string, PackageInfoType > PackageMapType;
139 const PackageMapType& GetPackageMap() const { return mPackageMap; }
142 /// The map of packages
143 PackageMapType mPackageMap;
145 /// The executer which created the factory (if any)
148 void CloseAllPackages();
149 void ClosePackage(PackageMapType::iterator& i);
157 /// SYSTEM METHOD : Global method returning the global factory object pointer
158 inline Factory*& GlobalFactoryPointer()
160 static Factory* f = 0;
164 /// SYSTEM METHOD : Global method returning the global factory object
165 inline Factory* GetGlobalFactory()
167 if (!GlobalFactoryPointer())
169 GlobalFactoryPointer() = new Factory;
171 return GlobalFactoryPointer();
174 /// SYSTEM METHOD : Deletes the global factory pointer
175 inline void DeleteGlobalFactory()
177 if (GlobalFactoryPointer())
179 delete GlobalFactoryPointer();
183 inline void LoadPackage( const std::string& name )
185 GetGlobalFactory()->LoadPackage(name);
188 inline void UnLoadPackage( const std::string& name )
190 GetGlobalFactory()->UnLoadPackage(name);
193 inline void PrintPackages(bool details = true, bool adaptors = false)
195 GetGlobalFactory()->PrintPackages(details,adaptors);
198 inline void HelpPackage(const std::string& name, bool adaptors = false)
200 GetGlobalFactory()->HelpPackage(name,adaptors);
203 inline void HelpBlackBox(const std::string& name, bool full=true)
206 GetGlobalFactory()->HelpBlackBox(name, package, full);
209 inline void HelpBlackBox(const std::string& name, std::string& package,
213 GetGlobalFactory()->HelpBlackBox(name, package, full);
217 inline void ShowGraphTypes(const std::string& name)
219 GetGlobalFactory()->ShowGraphTypes(name);
222 inline void InsertPackage( Package* p)
224 GetGlobalFactory()->InsertPackage(p);
227 inline void RemovePackage( Package* p)
229 GetGlobalFactory()->RemovePackage(p);
232 inline const Package* GetPackage(const std::string& name)
234 return GetGlobalFactory()->GetPackage(name);
237 inline BlackBox* NewBlackBox(const std::string& type,
238 const std::string& name)
240 return GetGlobalFactory()->NewBlackBox(type,name);
243 inline BlackBox* NewAdaptor(TypeInfo typein,
245 const std::string& name)
247 return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
250 inline Connection* NewConnection(BlackBox* from,
251 const std::string& output,
253 const std::string& input)
255 return GetGlobalFactory()->NewConnection(from,output,to,input);
258 inline void WriteDotFilePackagesList(FILE *ff)
260 GetGlobalFactory()->WriteDotFilePackagesList(ff);