1 /*=========================================================================
4 Module: $RCSfile: bbtkFactory.h,v $
6 Date: $Date: 2008/01/22 16:55:04 $
7 Version: $Revision: 1.2 $
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, 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);
78 bool DoLoadPackage(std::string libname,
83 /// The structure storing info on a package
91 /// The pointer on the package
93 /// The handler of the dynamic library
94 DynamicLibraryHandler mDynamicLibraryHandler;
96 /// The type of map of packages
97 typedef std::map< std::string, PackageInfoType > PackageMapType;
98 /// The map of packages
99 PackageMapType mPackageMap;
101 void CloseAllPackages();
102 void ClosePackage(PackageMapType::iterator& i);
108 /// SYSTEM METHOD : Global method returning the global factory object pointer
109 inline Factory*& GlobalFactoryPointer()
111 static Factory* f = 0;
115 /// SYSTEM METHOD : Global method returning the global factory object
116 inline Factory* GetGlobalFactory()
118 if (!GlobalFactoryPointer())
120 GlobalFactoryPointer() = new Factory;
122 return GlobalFactoryPointer();
125 /// SYSTEM METHOD : Deletes the global factory pointer
126 inline void DeleteGlobalFactory()
128 if (GlobalFactoryPointer())
130 delete GlobalFactoryPointer();
134 inline void LoadPackage( const std::string& name,
135 bool use_configuration_file = true, bool verbose = false )
137 GetGlobalFactory()->LoadPackage(name,use_configuration_file, verbose);
140 inline void UnLoadPackage( const std::string& name )
142 GetGlobalFactory()->UnLoadPackage(name);
145 inline void PrintPackages(bool details = true, bool adaptors = false)
147 GetGlobalFactory()->PrintPackages(details,adaptors);
150 inline void HelpPackage(const std::string& name, bool adaptors = false)
152 GetGlobalFactory()->HelpPackage(name,adaptors);
155 inline void HelpBlackBox(const std::string& name, bool full=true)
157 GetGlobalFactory()->HelpBlackBox(name,full);
161 inline void ShowGraphTypes(const std::string& name)
163 GetGlobalFactory()->ShowGraphTypes(name);
166 inline void InsertPackage( Package* p)
168 GetGlobalFactory()->InsertPackage(p);
171 inline void RemovePackage( Package* p)
173 GetGlobalFactory()->RemovePackage(p);
176 inline const Package* GetPackage(const std::string& name)
178 return GetGlobalFactory()->GetPackage(name);
181 inline BlackBox* NewBlackBox(const std::string& type,
182 const std::string& name)
184 return GetGlobalFactory()->NewBlackBox(type,name);
187 inline BlackBox* NewAdaptor(TypeInfo typein,
189 const std::string& name)
191 return GetGlobalFactory()->NewAdaptor(typein,typeout,name);
194 inline Connection* NewConnection(BlackBox* from,
195 const std::string& output,
197 const std::string& input)
199 return GetGlobalFactory()->NewConnection(from,output,to,input);
202 inline void WriteDotFilePackagesList(FILE *ff)
204 GetGlobalFactory()->WriteDotFilePackagesList(ff);