1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.h,v $
6 Date: $Date: 2008/03/28 13:42:17 $
7 Version: $Revision: 1.11 $
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 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* );
57 void RemovePackage( Package* );
59 const Package* GetPackage(const std::string& name) const;
60 Package* GetPackage(const std::string& name);
62 BlackBox* NewBlackBox(const std::string& type,
63 const std::string& name) const;
65 BlackBox* NewAdaptor(TypeInfo typein,
67 const std::string& name) const;
69 Connection* NewConnection(BlackBox* from,
70 const std::string& output,
72 const std::string& input) const;
74 void WriteDotFilePackagesList(FILE *ff);
86 void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
88 /// Sets the executer who created the factory (if any)
89 void SetExecuter(Executer *e) { mExecuter = e; }
90 /// Gets the executer who created the factory (if any)
91 Executer* GetExecuter() { return mExecuter; }
92 /// Gets the executer who created the factory (if any) - const
93 const Executer* GetExecuter() const { return mExecuter; }
98 bool DoLoadPackage(std::string libname,
103 /// The structure storing info on a package
104 class PackageInfoType
110 ~PackageInfoType() {}
111 /// The pointer on the package
113 /// The handler of the dynamic library
114 DynamicLibraryHandler mDynamicLibraryHandler;
116 /// The type of map of packages
117 typedef std::map< std::string, PackageInfoType > PackageMapType;
119 const PackageMapType& GetPackageMap() const { return mPackageMap; }
122 /// The map of packages
123 PackageMapType mPackageMap;
125 /// The executer which created the factory (if any)
128 void CloseAllPackages();
129 void ClosePackage(PackageMapType::iterator& i);
137 /// SYSTEM METHOD : Global method returning the global factory object pointer
138 inline Factory*& GlobalFactoryPointer()
140 static Factory* f = 0;
144 /// SYSTEM METHOD : Global method returning the global factory object
145 inline Factory* GetGlobalFactory()
147 if (!GlobalFactoryPointer())
149 GlobalFactoryPointer() = new Factory;
151 return GlobalFactoryPointer();
154 /// SYSTEM METHOD : Deletes the global factory pointer
155 inline void DeleteGlobalFactory()
157 if (GlobalFactoryPointer())
159 delete GlobalFactoryPointer();
163 inline void LoadPackage( const std::string& name )
165 GetGlobalFactory()->LoadPackage(name);
168 inline void UnLoadPackage( const std::string& name )
170 GetGlobalFactory()->UnLoadPackage(name);
173 inline void PrintPackages(bool details = true, bool adaptors = false)
175 GetGlobalFactory()->PrintPackages(details,adaptors);
178 inline void HelpPackage(const std::string& name, bool adaptors = false)
180 GetGlobalFactory()->HelpPackage(name,adaptors);
183 inline void HelpBlackBox(const std::string& name, bool full=true)
186 GetGlobalFactory()->HelpBlackBox(name, package, full);
189 inline void HelpBlackBox(const std::string& name, std::string& package,
193 GetGlobalFactory()->HelpBlackBox(name, package, full);
197 inline void ShowGraphTypes(const std::string& name)
199 GetGlobalFactory()->ShowGraphTypes(name);
202 inline void InsertPackage( Package* p)
204 GetGlobalFactory()->InsertPackage(p);
207 inline void RemovePackage( Package* p)
209 GetGlobalFactory()->RemovePackage(p);
212 inline const Package* GetPackage(const std::string& name)
214 return GetGlobalFactory()->GetPackage(name);
217 inline BlackBox* NewBlackBox(const std::string& type,
218 const std::string& name)
220 return GetGlobalFactory()->NewBlackBox(type,name);
223 inline BlackBox* NewAdaptor(TypeInfo typein,
225 const std::string& name)
227 return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
230 inline Connection* NewConnection(BlackBox* from,
231 const std::string& output,
233 const std::string& input)
235 return GetGlobalFactory()->NewConnection(from,output,to,input);
238 inline void WriteDotFilePackagesList(FILE *ff)
240 GetGlobalFactory()->WriteDotFilePackagesList(ff);