1 /*=========================================================================
3 Module: $RCSfile: bbtkFactory.h,v $
5 Date: $Date: 2010/09/12 14:52:25 $
6 Version: $Revision: 1.18 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 *\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.
37 *\brief Can load and unload dynamic libraries containing black boxes packages and create instances of the black boxes registered in the packages loaded.
42 #ifndef __bbtkFactory_h__
43 #define __bbtkFactory_h__
45 #include "bbtkPackage.h"
51 BBTK_FORWARD_DECLARE_POINTER(Executer);
53 class BBTK_EXPORT Factory : public Object
55 BBTK_OBJECT_INTERFACE(Factory);
56 typedef Object Superclass;
60 // @name Packages management
62 /// Pushes back the names of the Package s which are in the Factory
63 void GetPackagesList(std::vector<std::string>&);
64 /// Loads a dynamic library which contains a Package
65 void LoadPackage( const std::string& name );
66 /// Unloads a Package which was loaded from a dynamic library
67 void UnLoadPackage( const std::string& name );
68 /// Inserts a Package in the Factory
69 void InsertPackage( Package::Pointer );
70 /// Removess a Package from the Factory
71 void RemovePackage( Package::Pointer );
72 /// Returns the pointer on a Package provided by name
73 Package::Pointer GetPackage(const std::string& name) const;
74 /// The type of map of packages
75 typedef std::map< std::string, Package::Pointer > PackageMapType;
76 /// Returns the map of Packages
77 const PackageMapType& GetPackageMap() const { return mPackageMap; }
80 // @name Methods which print help
82 /// Prints the list of Package
83 void PrintHelpListPackages(bool details = true,
84 bool adaptors = false) const;
85 /// Prints help on a particular Package
86 void PrintHelpPackage(const std::string& name,
87 bool adaptors = false) const;
88 /// Prints help on a BlackBoxDescriptor
89 void PrintHelpDescriptor(const std::string& name,
91 bool full=true ) const;
93 void ShowGraphTypes(const std::string& name) const;
97 /// @name Object creation methods
99 BlackBox::Pointer NewBlackBox(const std::string& type,
100 const std::string& name) const;
102 BlackBox::Pointer NewAdaptor(const DataInfo& typein,
103 const DataInfo& typeout,
104 const std::string& name) const;
106 BlackBox::Pointer NewWidgetAdaptor(const DataInfo& typein,
107 const DataInfo& typeout,
108 const std::string& name) const;
110 Connection::Pointer NewConnection(BlackBox::Pointer from,
111 const std::string& output,
112 BlackBox::Pointer to,
113 const std::string& input) const;
116 /// @name Package inspection methods
117 /// Allow to test if an Adaptor is present in the packages WITHOUT instanciating it
119 bool FindAdaptor(const DataInfo& typein,
120 const DataInfo& typeout,
121 std::string& adaptor) const;
123 bool FindWidgetAdaptor(const DataInfo& typein,
124 const DataInfo& typeout,
125 std::string& adaptor) const;
127 bool FindWidgetAdaptor2(const DataInfo& typein,
128 const DataInfo& typeout,
130 std::string& adaptor) const;
133 void WriteDotFilePackagesList(FILE *ff);
135 /// Releases all the packages of the Factory
148 void CreateHtmlIndex(IndexEntryType type, const std::string& filename);
150 /// Sets the executer who created the factory (if any)
151 void SetExecuter(ExecuterPointer e) { mExecuter = e; }
152 /// Gets the executer who created the factory (if any)
153 ExecuterPointer GetExecuter() { return mExecuter.lock(); }
154 /// Gets the executer who created the factory (if any) - const
155 // const Executer::Pointer GetExecuter() const { return mExecuter.lock(); }
157 std::string GetPackageNameOfaBlackBox(std::string boxType);
163 /// The map of packages
164 PackageMapType mPackageMap;
166 /// The executer which created the factory (if any)
167 ExecuterWeakPointer mExecuter;
169 bool DoLoadPackage(std::string libname,
172 void CloseAllPackages();
173 void ClosePackage(PackageMapType::iterator& i);