2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkFactory.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.19 $
34 =========================================================================*/
40 *\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.
44 *\brief Can load and unload dynamic libraries containing black boxes packages and create instances of the black boxes registered in the packages loaded.
49 #ifndef __bbtkFactory_h__
50 #define __bbtkFactory_h__
52 #include "bbtkPackage.h"
58 BBTK_FORWARD_DECLARE_POINTER(Executer);
60 class BBTK_EXPORT Factory : public Object
62 BBTK_OBJECT_INTERFACE(Factory);
63 typedef Object Superclass;
67 // @name Packages management
69 /// Pushes back the names of the Package s which are in the Factory
70 void GetPackagesList(std::vector<std::string>&);
71 /// Loads a dynamic library which contains a Package
72 void LoadPackage( const std::string& name );
73 /// Unloads a Package which was loaded from a dynamic library
74 void UnLoadPackage( const std::string& name );
75 /// Inserts a Package in the Factory
76 void InsertPackage( Package::Pointer );
77 /// Removess a Package from the Factory
78 void RemovePackage( Package::Pointer );
79 /// Returns the pointer on a Package provided by name
80 Package::Pointer GetPackage(const std::string& name) const;
81 /// The type of map of packages
82 typedef std::map< std::string, Package::Pointer > PackageMapType;
83 /// Returns the map of Packages
84 const PackageMapType& GetPackageMap() const { return mPackageMap; }
87 // @name Methods which print help
89 /// Prints the list of Package
90 void PrintHelpListPackages(bool details = true,
91 bool adaptors = false) const;
92 /// Prints help on a particular Package
93 void PrintHelpPackage(const std::string& name,
94 bool adaptors = false) const;
95 /// Prints help on a BlackBoxDescriptor
96 void PrintHelpDescriptor(const std::string& name,
98 bool full=true ) const;
100 void ShowGraphTypes(const std::string& name) const;
104 /// @name Object creation methods
106 BlackBox::Pointer NewBlackBox(const std::string& type,
107 const std::string& name) const;
109 BlackBox::Pointer NewAdaptor(const DataInfo& typein,
110 const DataInfo& typeout,
111 const std::string& name) const;
113 BlackBox::Pointer NewWidgetAdaptor(const DataInfo& typein,
114 const DataInfo& typeout,
115 const std::string& name) const;
117 Connection::Pointer NewConnection(BlackBox::Pointer from,
118 const std::string& output,
119 BlackBox::Pointer to,
120 const std::string& input) const;
123 /// @name Package inspection methods
124 /// Allow to test if an Adaptor is present in the packages WITHOUT instanciating it
126 bool FindAdaptor(const DataInfo& typein,
127 const DataInfo& typeout,
128 std::string& adaptor) const;
130 bool FindWidgetAdaptor(const DataInfo& typein,
131 const DataInfo& typeout,
132 std::string& adaptor) const;
134 bool FindWidgetAdaptor2(const DataInfo& typein,
135 const DataInfo& typeout,
137 std::string& adaptor) const;
140 void WriteDotFilePackagesList(FILE *ff);
142 /// Releases all the packages of the Factory
155 void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
157 /// Sets the executer who created the factory (if any)
158 void SetExecuter(ExecuterPointer e) { mExecuter = e; }
159 /// Gets the executer who created the factory (if any)
160 ExecuterPointer GetExecuter() { return mExecuter.lock(); }
161 /// Gets the executer who created the factory (if any) - const
162 // const Executer::Pointer GetExecuter() const { return mExecuter.lock(); }
164 std::string GetPackageNameOfaBlackBox(std::string boxType);
170 /// The map of packages
171 PackageMapType mPackageMap;
173 /// The executer which created the factory (if any)
174 ExecuterWeakPointer mExecuter;
176 bool DoLoadPackage(std::string libname,
179 void CloseAllPackages();
180 void ClosePackage(PackageMapType::iterator& i);