1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.h,v $
6 Date: $Date: 2008/03/07 08:40:14 $
7 Version: $Revision: 1.10 $
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,
102 /// The structure storing info on a package
103 class PackageInfoType
109 ~PackageInfoType() {}
110 /// The pointer on the package
112 /// The handler of the dynamic library
113 DynamicLibraryHandler mDynamicLibraryHandler;
115 /// The type of map of packages
116 typedef std::map< std::string, PackageInfoType > PackageMapType;
117 /// The map of packages
118 PackageMapType mPackageMap;
120 /// The executer which created the factory (if any)
123 void CloseAllPackages();
124 void ClosePackage(PackageMapType::iterator& i);
132 /// SYSTEM METHOD : Global method returning the global factory object pointer
133 inline Factory*& GlobalFactoryPointer()
135 static Factory* f = 0;
139 /// SYSTEM METHOD : Global method returning the global factory object
140 inline Factory* GetGlobalFactory()
142 if (!GlobalFactoryPointer())
144 GlobalFactoryPointer() = new Factory;
146 return GlobalFactoryPointer();
149 /// SYSTEM METHOD : Deletes the global factory pointer
150 inline void DeleteGlobalFactory()
152 if (GlobalFactoryPointer())
154 delete GlobalFactoryPointer();
158 inline void LoadPackage( const std::string& name )
160 GetGlobalFactory()->LoadPackage(name);
163 inline void UnLoadPackage( const std::string& name )
165 GetGlobalFactory()->UnLoadPackage(name);
168 inline void PrintPackages(bool details = true, bool adaptors = false)
170 GetGlobalFactory()->PrintPackages(details,adaptors);
173 inline void HelpPackage(const std::string& name, bool adaptors = false)
175 GetGlobalFactory()->HelpPackage(name,adaptors);
178 inline void HelpBlackBox(const std::string& name, bool full=true)
181 GetGlobalFactory()->HelpBlackBox(name, package, full);
184 inline void HelpBlackBox(const std::string& name, std::string& package,
188 GetGlobalFactory()->HelpBlackBox(name, package, full);
192 inline void ShowGraphTypes(const std::string& name)
194 GetGlobalFactory()->ShowGraphTypes(name);
197 inline void InsertPackage( Package* p)
199 GetGlobalFactory()->InsertPackage(p);
202 inline void RemovePackage( Package* p)
204 GetGlobalFactory()->RemovePackage(p);
207 inline const Package* GetPackage(const std::string& name)
209 return GetGlobalFactory()->GetPackage(name);
212 inline BlackBox* NewBlackBox(const std::string& type,
213 const std::string& name)
215 return GetGlobalFactory()->NewBlackBox(type,name);
218 inline BlackBox* NewAdaptor(TypeInfo typein,
220 const std::string& name)
222 return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
225 inline Connection* NewConnection(BlackBox* from,
226 const std::string& output,
228 const std::string& input)
230 return GetGlobalFactory()->NewConnection(from,output,to,input);
233 inline void WriteDotFilePackagesList(FILE *ff)
235 GetGlobalFactory()->WriteDotFilePackagesList(ff);