1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.h,v $
6 Date: $Date: 2008/02/14 13:44:25 $
7 Version: $Revision: 1.7 $
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 void UnLoadPackage( const std::string& name );
49 void PrintPackages(bool details = true, bool adaptors = false) const;
50 void HelpPackage(const std::string& name, bool adaptors = false) const;
51 void HelpBlackBox(const std::string& name, std::string& package,
52 bool full=true ) const;
53 void ShowGraphTypes(const std::string& name) const;
54 void InsertPackage( Package* );
55 void RemovePackage( Package* );
57 const Package* GetPackage(const std::string& name) const;
58 Package* GetPackage(const std::string& name);
60 BlackBox* NewBlackBox(const std::string& type,
61 const std::string& name) const;
63 BlackBox* NewAdaptor(TypeInfo typein,
65 const std::string& name) const;
67 Connection* NewConnection(BlackBox* from,
68 const std::string& output,
70 const std::string& input) const;
72 void WriteDotFilePackagesList(FILE *ff);
83 void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
87 bool DoLoadPackage(std::string libname,
91 /// The structure storing info on a package
99 /// The pointer on the package
101 /// The handler of the dynamic library
102 DynamicLibraryHandler mDynamicLibraryHandler;
104 /// The type of map of packages
105 typedef std::map< std::string, PackageInfoType > PackageMapType;
106 /// The map of packages
107 PackageMapType mPackageMap;
109 void CloseAllPackages();
110 void ClosePackage(PackageMapType::iterator& i);
116 /// SYSTEM METHOD : Global method returning the global factory object pointer
117 inline Factory*& GlobalFactoryPointer()
119 static Factory* f = 0;
123 /// SYSTEM METHOD : Global method returning the global factory object
124 inline Factory* GetGlobalFactory()
126 if (!GlobalFactoryPointer())
128 GlobalFactoryPointer() = new Factory;
130 return GlobalFactoryPointer();
133 /// SYSTEM METHOD : Deletes the global factory pointer
134 inline void DeleteGlobalFactory()
136 if (GlobalFactoryPointer())
138 delete GlobalFactoryPointer();
142 inline void LoadPackage( const std::string& name,
143 bool use_configuration_file = true)
145 GetGlobalFactory()->LoadPackage(name,use_configuration_file);
148 inline void UnLoadPackage( const std::string& name )
150 GetGlobalFactory()->UnLoadPackage(name);
153 inline void PrintPackages(bool details = true, bool adaptors = false)
155 GetGlobalFactory()->PrintPackages(details,adaptors);
158 inline void HelpPackage(const std::string& name, bool adaptors = false)
160 GetGlobalFactory()->HelpPackage(name,adaptors);
163 inline void HelpBlackBox(const std::string& name, bool full=true)
166 GetGlobalFactory()->HelpBlackBox(name, package, full);
169 inline void HelpBlackBox(const std::string& name, std::string& package,
173 GetGlobalFactory()->HelpBlackBox(name, package, full);
177 inline void ShowGraphTypes(const std::string& name)
179 GetGlobalFactory()->ShowGraphTypes(name);
182 inline void InsertPackage( Package* p)
184 GetGlobalFactory()->InsertPackage(p);
187 inline void RemovePackage( Package* p)
189 GetGlobalFactory()->RemovePackage(p);
192 inline const Package* GetPackage(const std::string& name)
194 return GetGlobalFactory()->GetPackage(name);
197 inline BlackBox* NewBlackBox(const std::string& type,
198 const std::string& name)
200 return GetGlobalFactory()->NewBlackBox(type,name);
203 inline BlackBox* NewAdaptor(TypeInfo typein,
205 const std::string& name)
207 return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
210 inline Connection* NewConnection(BlackBox* from,
211 const std::string& output,
213 const std::string& input)
215 return GetGlobalFactory()->NewConnection(from,output,to,input);
218 inline void WriteDotFilePackagesList(FILE *ff)
220 GetGlobalFactory()->WriteDotFilePackagesList(ff);