1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.h,v $
6 Date: $Date: 2008/02/14 11:38:58 $
7 Version: $Revision: 1.6 $
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"
38 class BBTK_EXPORT Factory
46 void LoadPackage( const std::string& name,
47 bool use_configuration_file = true,
48 bool verbose = false );
49 void UnLoadPackage( const std::string& name );
50 void PrintPackages(bool details = true, bool adaptors = false) const;
51 void HelpPackage(const std::string& name, bool adaptors = false) const;
52 void HelpBlackBox(const std::string& name, std::string& package,
53 bool full=true ) const;
54 void ShowGraphTypes(const std::string& name) const;
55 void InsertPackage( Package* );
56 void RemovePackage( Package* );
58 const Package* GetPackage(const std::string& name) const;
59 Package* GetPackage(const std::string& name);
61 BlackBox* NewBlackBox(const std::string& type,
62 const std::string& name) const;
64 BlackBox* NewAdaptor(TypeInfo typein,
66 const std::string& name) const;
68 Connection* NewConnection(BlackBox* from,
69 const std::string& output,
71 const std::string& input) const;
73 void WriteDotFilePackagesList(FILE *ff);
84 void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
88 bool DoLoadPackage(std::string libname,
93 /// The structure storing info on a package
100 ~PackageInfoType() {}
101 /// The pointer on the package
103 /// The handler of the dynamic library
104 DynamicLibraryHandler mDynamicLibraryHandler;
106 /// The type of map of packages
107 typedef std::map< std::string, PackageInfoType > PackageMapType;
108 /// The map of packages
109 PackageMapType mPackageMap;
111 void CloseAllPackages();
112 void ClosePackage(PackageMapType::iterator& i);
118 /// SYSTEM METHOD : Global method returning the global factory object pointer
119 inline Factory*& GlobalFactoryPointer()
121 static Factory* f = 0;
125 /// SYSTEM METHOD : Global method returning the global factory object
126 inline Factory* GetGlobalFactory()
128 if (!GlobalFactoryPointer())
130 GlobalFactoryPointer() = new Factory;
132 return GlobalFactoryPointer();
135 /// SYSTEM METHOD : Deletes the global factory pointer
136 inline void DeleteGlobalFactory()
138 if (GlobalFactoryPointer())
140 delete GlobalFactoryPointer();
144 inline void LoadPackage( const std::string& name,
145 bool use_configuration_file = true, bool verbose = false )
147 GetGlobalFactory()->LoadPackage(name,use_configuration_file, verbose);
150 inline void UnLoadPackage( const std::string& name )
152 GetGlobalFactory()->UnLoadPackage(name);
155 inline void PrintPackages(bool details = true, bool adaptors = false)
157 GetGlobalFactory()->PrintPackages(details,adaptors);
160 inline void HelpPackage(const std::string& name, bool adaptors = false)
162 GetGlobalFactory()->HelpPackage(name,adaptors);
165 inline void HelpBlackBox(const std::string& name, bool full=true)
168 GetGlobalFactory()->HelpBlackBox(name, package, full);
171 inline void HelpBlackBox(const std::string& name, std::string& package,
175 GetGlobalFactory()->HelpBlackBox(name, package, full);
179 inline void ShowGraphTypes(const std::string& name)
181 GetGlobalFactory()->ShowGraphTypes(name);
184 inline void InsertPackage( Package* p)
186 GetGlobalFactory()->InsertPackage(p);
189 inline void RemovePackage( Package* p)
191 GetGlobalFactory()->RemovePackage(p);
194 inline const Package* GetPackage(const std::string& name)
196 return GetGlobalFactory()->GetPackage(name);
199 inline BlackBox* NewBlackBox(const std::string& type,
200 const std::string& name)
202 return GetGlobalFactory()->NewBlackBox(type,name);
205 inline BlackBox* NewAdaptor(TypeInfo typein,
207 const std::string& name)
209 return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
212 inline Connection* NewConnection(BlackBox* from,
213 const std::string& output,
215 const std::string& input)
217 return GetGlobalFactory()->NewConnection(from,output,to,input);
220 inline void WriteDotFilePackagesList(FILE *ff)
222 GetGlobalFactory()->WriteDotFilePackagesList(ff);