1 /*=========================================================================
4 Module: $RCSfile: bbtkPackage.h,v $
6 Date: $Date: 2008/03/07 08:40:14 $
7 Version: $Revision: 1.5 $
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::Package : registers black boxes descriptors and is able to create instances of the black boxes registered.
23 * \class bbtk::Package
24 * \brief registers black boxes descriptors and is able to create instances of the black boxes registered.
27 #ifndef __bbtkPackage_h__
28 #define __bbtkPackage_h__
30 #include "bbtkBlackBox.h"
35 class BBTK_EXPORT Package
38 Package(const std::string& name,
39 const std::string& author,
40 const std::string& description,
41 const std::string& version,
42 const std::string& BBTKVersion);
44 /// Returns the name of the package
45 const std::string& GetName() const { return mName; }
47 /// Returns the author of the package
48 const std::string& GetAuthor() const { return mAuthor; }
50 /// Returns the category of the package
51 const std::string& GetCategory() const { return mCategory; }
53 /// Returns the description of the package
54 const std::string& GetDescription() const { return mDescription; }
56 /// Returns the version of the package
57 const std::string& GetVersion() const { return mVersion; }
59 /// Returns the version of bbtk used to build the package
60 const std::string& GetBBTKVersion() const { return mBBTKVersion; }
62 bool ContainsBlackBox(const std::string& boxname) const;
65 BlackBox* NewBlackBox(const std::string& type,
66 const std::string& name) const;
68 BlackBox* NewAdaptor(TypeInfo typein,
70 const std::string& name) const;
72 bool RegisterBlackBox(BlackBoxDescriptor*);
73 void UnRegisterBlackBox(const std::string& name);
75 // bool RegisterAdaptor(BlackBoxDescriptor*);
77 void PrintBlackBoxes(bool description = false,
78 bool adaptors = false) const;
79 void PrintAdaptors(bool description = false) const;
80 void HelpBlackBox(const std::string& name, bool full=true) const;
82 void CreateHtmlPage(const std::string& filename,
83 const std::string& caller = "?",
84 const std::string& source = "?",
85 const std::string& custom_header = "",
86 const std::string& custom_title = "",
89 bool relative_link = false ) const;
91 void SetDocURL(std::string url){ mDocURL=url; }
92 const std::string& GetDocURL() const { return mDocURL; }
94 void SetDocRelativeURL(std::string url){ mDocRelativeURL=url; }
95 const std::string& GetDocRelativeURL() const { return mDocRelativeURL; }
98 unsigned int GetNumberOfBlackBoxes() const { return mBlackBoxMap.size(); }
100 /// Changes the name of a black box type
101 void ChangeBlackBoxName( const std::string& oldname,
102 const std::string& newname );
103 /// The type of map of descriptors
104 typedef std::map< std::string, BlackBoxDescriptor*> BlackBoxMapType;
105 const BlackBoxMapType& GetBlackBoxMap() const { return mBlackBoxMap; }
106 BlackBoxMapType& GetBlackBoxMap() { return mBlackBoxMap; }
108 // Factories management
109 /// Adds the factory to the set of factories which use the package
110 void AddFactory(Factory* f) { mFactorySet.insert(f); }
111 /// Removes the factory from the set of factories which use the package
112 void RemoveFactory(Factory* f) { mFactorySet.erase(f); }
114 /// Gets the set of factories which use the package
115 std::set<Factory*>& GetFactorySet() { return mFactorySet; }
116 /// Gets the set of factories which use the package (const)
117 const std::set<Factory*>& GetFactorySet() const { return mFactorySet; }
121 /// The name of the package
123 /// The author of the package
125 /// The categories of the package
126 std::string mCategory;
127 /// The description of the package
128 std::string mDescription;
129 /// The version of the package
130 std::string mVersion;
131 /// The version of the library bbtk used to build the package
132 std::string mBBTKVersion;
133 /// URL of the documentation of the Package (absolute path)
135 /// URL of the documentation of the Package
136 /// (path relative to bbtk doc root)
137 std::string mDocRelativeURL;
140 /// The map of black boxes descriptors
141 BlackBoxMapType mBlackBoxMap;
143 /// The type of key in the map of adaptor descriptors
147 AdaptorKey( TypeInfo typein, TypeInfo typeout)
148 : mTypeIn(typein.name()), mTypeOut(typeout.name()) {}
150 bool operator< ( const AdaptorKey& k ) const
152 // return ( ( mTypeIn.before(k.mTypeIn) ) ||
153 // ( ( mTypeIn == k.mTypeIn ) &&
154 // ( mTypeOut.before(k.mTypeOut) ) ) );
155 return ( ( mTypeIn < k.mTypeIn ) ||
156 ( ( mTypeIn == k.mTypeIn ) &&
157 ( mTypeOut < k.mTypeOut ) ) );
162 // TypeInfo mTypeOut;
164 std::string mTypeOut;
167 /// The type of map of adaptor descriptors
168 typedef std::map< AdaptorKey, BlackBoxDescriptor*> AdaptorMapType;
170 /// The map of adaptors descriptors
171 AdaptorMapType mAdaptorMap;
174 /// The set of factories which contain the package
175 std::set<Factory*> mFactorySet;
179 //====================================================================
182 //====================================================================
184 #define BBTK_PACKAGE_EXPORT __declspec( dllexport )
186 #define BBTK_PACKAGE_EXPORT
187 #endif // defined(_WIN32)
188 //====================================================================
190 //====================================================================
191 #define BBTK_DECLARE_PACKAGE(NAME) \
194 bbtk::Package*& NAME ## GetPackagePointer(); \
195 BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage(); \
196 BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage(); \
198 //====================================================================
200 //====================================================================
201 #define BBTK_IMPLEMENT_PACKAGE(NAME,AUTHOR,DESCRIPTION,VERSION) \
204 bbtk::Package*& NAME ## GetPackagePointer() \
206 static bbtk::Package* u = 0; \
209 BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage() \
211 if (NAME ## GetPackagePointer()) \
212 delete NAME ## GetPackagePointer(); \
213 NAME ## GetPackagePointer() = 0; \
215 BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage() \
217 if (!NAME ## GetPackagePointer()) \
218 NAME ## GetPackagePointer() = \
219 new bbtk::Package(#NAME, \
223 BBTK_STRINGIFY_SYMBOL(BBTK_VERSION) \
225 return NAME ## GetPackagePointer(); \
228 //====================================================================
230 //====================================================================
231 #define BBTK_ADD_BLACK_BOX_TO_PACKAGE(NAME,CLASS) \
232 bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor());
233 //====================================================================
235 //====================================================================
236 #define BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \
237 bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS<TEMPLATE_PARAM>::bbDescriptor());
238 //====================================================================
240 //====================================================================
241 #define BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(NAME,CLASS,T1,T2) \
242 bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS<T1,T2>::bbDescriptor());
243 //====================================================================
245 //====================================================================
246 //#define BBTK_ADD_ADAPTOR_TO_PACKAGE(NAME,CLASS) \
247 // bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); \
248 // bool bbDummyAdaptor##NAME##CLASS = NAME ## GetPackage()->RegisterAdaptor(CLASS::bbDescriptor());
249 //====================================================================
251 //====================================================================
252 //#define BBTK_ADD_TEMPLATE_ADAPTOR_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \
253 // bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS<TEMPLATE_PARAM>::bbDescriptor()); \
254 // bool bbDummyAdaptor##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterAdaptor(CLASS<TEMPLATE_PARAM>::bbDescriptor());
255 //====================================================================
257 //====================================================================
258 //#define BBTK_ADD_TEMPLATE2_ADAPTOR_TO_PACKAGE(NAME,CLASS,T1,T2) \
259 // bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS<T1,T2>::bbDescriptor()); \
260 // bool bbDummyAdaptor##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterAdaptor(CLASS<T1,T2>::bbDescriptor());
261 //====================================================================