1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.h,v $
6 Date: $Date: 2008/04/08 06:59:30 $
7 Version: $Revision: 1.12 $
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 Connection* NewConnection(BlackBox* from,
83 const std::string& output,
85 const std::string& input) const;
87 void WriteDotFilePackagesList(FILE *ff);
99 void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
101 /// Sets the executer who created the factory (if any)
102 void SetExecuter(Executer *e) { mExecuter = e; }
103 /// Gets the executer who created the factory (if any)
104 Executer* GetExecuter() { return mExecuter; }
105 /// Gets the executer who created the factory (if any) - const
106 const Executer* GetExecuter() const { return mExecuter; }
111 bool DoLoadPackage(std::string libname,
116 /// The structure storing info on a package
117 class PackageInfoType
123 ~PackageInfoType() {}
124 /// The pointer on the package
126 /// The handler of the dynamic library
127 DynamicLibraryHandler mDynamicLibraryHandler;
129 /// The type of map of packages
130 typedef std::map< std::string, PackageInfoType > PackageMapType;
132 const PackageMapType& GetPackageMap() const { return mPackageMap; }
135 /// The map of packages
136 PackageMapType mPackageMap;
138 /// The executer which created the factory (if any)
141 void CloseAllPackages();
142 void ClosePackage(PackageMapType::iterator& i);
150 /// SYSTEM METHOD : Global method returning the global factory object pointer
151 inline Factory*& GlobalFactoryPointer()
153 static Factory* f = 0;
157 /// SYSTEM METHOD : Global method returning the global factory object
158 inline Factory* GetGlobalFactory()
160 if (!GlobalFactoryPointer())
162 GlobalFactoryPointer() = new Factory;
164 return GlobalFactoryPointer();
167 /// SYSTEM METHOD : Deletes the global factory pointer
168 inline void DeleteGlobalFactory()
170 if (GlobalFactoryPointer())
172 delete GlobalFactoryPointer();
176 inline void LoadPackage( const std::string& name )
178 GetGlobalFactory()->LoadPackage(name);
181 inline void UnLoadPackage( const std::string& name )
183 GetGlobalFactory()->UnLoadPackage(name);
186 inline void PrintPackages(bool details = true, bool adaptors = false)
188 GetGlobalFactory()->PrintPackages(details,adaptors);
191 inline void HelpPackage(const std::string& name, bool adaptors = false)
193 GetGlobalFactory()->HelpPackage(name,adaptors);
196 inline void HelpBlackBox(const std::string& name, bool full=true)
199 GetGlobalFactory()->HelpBlackBox(name, package, full);
202 inline void HelpBlackBox(const std::string& name, std::string& package,
206 GetGlobalFactory()->HelpBlackBox(name, package, full);
210 inline void ShowGraphTypes(const std::string& name)
212 GetGlobalFactory()->ShowGraphTypes(name);
215 inline void InsertPackage( Package* p)
217 GetGlobalFactory()->InsertPackage(p);
220 inline void RemovePackage( Package* p)
222 GetGlobalFactory()->RemovePackage(p);
225 inline const Package* GetPackage(const std::string& name)
227 return GetGlobalFactory()->GetPackage(name);
230 inline BlackBox* NewBlackBox(const std::string& type,
231 const std::string& name)
233 return GetGlobalFactory()->NewBlackBox(type,name);
236 inline BlackBox* NewAdaptor(TypeInfo typein,
238 const std::string& name)
240 return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
243 inline Connection* NewConnection(BlackBox* from,
244 const std::string& output,
246 const std::string& input)
248 return GetGlobalFactory()->NewConnection(from,output,to,input);
251 inline void WriteDotFilePackagesList(FILE *ff)
253 GetGlobalFactory()->WriteDotFilePackagesList(ff);