1 /*=========================================================================
4 Module: $RCSfile: bbtkPackage.h,v $
6 Date: $Date: 2008/01/22 15:02:00 $
7 Version: $Revision: 1.1 $
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; }
46 /// Returns the author of the package
47 const std::string& GetAuthor() const { return mAuthor; }
48 /// Returns the description of the package
49 const std::string& GetDescription() const { return mDescription; }
50 /// Returns the version of the package
51 const std::string& GetVersion() const { return mVersion; }
52 /// Returns the version of bbtk used to build the package
53 const std::string& GetBBTKVersion() const { return mBBTKVersion; }
55 bool ContainsBlackBox(const std::string& boxname) const;
58 BlackBox* NewBlackBox(const std::string& type,
59 const std::string& name) const;
61 BlackBox* NewAdaptor(TypeInfo typein,
63 const std::string& name) const;
65 bool RegisterBlackBox(BlackBoxDescriptor*);
66 void UnRegisterBlackBox(const std::string& name);
68 // bool RegisterAdaptor(BlackBoxDescriptor*);
70 void PrintBlackBoxes(bool description = false,
71 bool adaptors = false) const;
72 void PrintAdaptors(bool description = false) const;
73 void HelpBlackBox(const std::string& name, bool full=true) const;
75 void CreateHtmlPage(const std::string& filename,
76 const std::string& caller = "?",
77 const std::string& source = "?",
78 const std::string& custom_header = "",
79 const std::string& custom_title = "",
82 bool relative_link = false ) const;
84 void SetDocURL(std::string url){ mDocURL=url; }
85 const std::string& GetDocURL() const { return mDocURL; }
87 void SetDocRelativeURL(std::string url){ mDocRelativeURL=url; }
88 const std::string& GetDocRelativeURL() const { return mDocRelativeURL; }
91 unsigned int GetNumberOfBlackBoxes() const { return mBlackBoxMap.size(); }
93 /// Changes the name of a black box type
94 void ChangeBlackBoxName( const std::string& oldname,
95 const std::string& newname );
98 /// The name of the package
100 /// The author of the package
102 /// The description of the package
103 std::string mDescription;
104 /// The version of the package
105 std::string mVersion;
106 /// The version of the library bbtk used to build the package
107 std::string mBBTKVersion;
108 /// URL of the documentation of the Package (absolute path)
110 /// URL of the documentation of the Package
111 /// (path relative to bbtk doc root)
112 std::string mDocRelativeURL;
115 /// The type of map of descriptors
116 typedef std::map< std::string, BlackBoxDescriptor*> BlackBoxMapType;
117 /// The map of black boxes descriptors
118 BlackBoxMapType mBlackBoxMap;
120 /// The type of key in the map of adaptor descriptors
124 AdaptorKey( TypeInfo typein, TypeInfo typeout)
125 : mTypeIn(typein.name()), mTypeOut(typeout.name()) {}
127 bool operator< ( const AdaptorKey& k ) const
129 // return ( ( mTypeIn.before(k.mTypeIn) ) ||
130 // ( ( mTypeIn == k.mTypeIn ) &&
131 // ( mTypeOut.before(k.mTypeOut) ) ) );
132 return ( ( mTypeIn < k.mTypeIn ) ||
133 ( ( mTypeIn == k.mTypeIn ) &&
134 ( mTypeOut < k.mTypeOut ) ) );
139 // TypeInfo mTypeOut;
141 std::string mTypeOut;
144 //typedef std::string AdaptorKey;
146 /// The type of map of adaptor descriptors
147 typedef std::map< AdaptorKey, BlackBoxDescriptor*> AdaptorMapType;
149 /// The map of adaptors descriptors
150 AdaptorMapType mAdaptorMap;
153 //====================================================================
156 //====================================================================
158 #define BBTK_PACKAGE_EXPORT __declspec( dllexport )
160 #define BBTK_PACKAGE_EXPORT
161 #endif // defined(_WIN32)
162 //====================================================================
164 //====================================================================
165 #define BBTK_DECLARE_PACKAGE(NAME) \
168 bbtk::Package*& NAME ## GetPackagePointer(); \
169 BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage(); \
170 BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage(); \
172 //====================================================================
174 //====================================================================
175 #define BBTK_IMPLEMENT_PACKAGE(NAME,AUTHOR,DESCRIPTION,VERSION) \
178 bbtk::Package*& NAME ## GetPackagePointer() \
180 static bbtk::Package* u = 0; \
183 BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage() \
185 if (NAME ## GetPackagePointer()) \
186 delete NAME ## GetPackagePointer(); \
187 NAME ## GetPackagePointer() = 0; \
189 BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage() \
191 if (!NAME ## GetPackagePointer()) \
192 NAME ## GetPackagePointer() = \
193 new bbtk::Package(#NAME, \
197 BBTK_STRINGIFY_SYMBOL(BBTK_VERSION) \
199 return NAME ## GetPackagePointer(); \
202 //====================================================================
204 //====================================================================
205 #define BBTK_ADD_BLACK_BOX_TO_PACKAGE(NAME,CLASS) \
206 bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor());
207 //====================================================================
209 //====================================================================
210 #define BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \
211 bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS<TEMPLATE_PARAM>::bbDescriptor());
212 //====================================================================
214 //====================================================================
215 #define BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(NAME,CLASS,T1,T2) \
216 bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS<T1,T2>::bbDescriptor());
217 //====================================================================
219 //====================================================================
220 //#define BBTK_ADD_ADAPTOR_TO_PACKAGE(NAME,CLASS) \
221 // bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); \
222 // bool bbDummyAdaptor##NAME##CLASS = NAME ## GetPackage()->RegisterAdaptor(CLASS::bbDescriptor());
223 //====================================================================
225 //====================================================================
226 //#define BBTK_ADD_TEMPLATE_ADAPTOR_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \
227 // bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS<TEMPLATE_PARAM>::bbDescriptor()); \
228 // bool bbDummyAdaptor##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterAdaptor(CLASS<TEMPLATE_PARAM>::bbDescriptor());
229 //====================================================================
231 //====================================================================
232 //#define BBTK_ADD_TEMPLATE2_ADAPTOR_TO_PACKAGE(NAME,CLASS,T1,T2) \
233 // bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS<T1,T2>::bbDescriptor()); \
234 // bool bbDummyAdaptor##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterAdaptor(CLASS<T1,T2>::bbDescriptor());
235 //====================================================================