]> Creatis software - bbtk.git/blob - kernel/src/bbtkPackage.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkPackage.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkPackage.h,v $
5   Language:  C++
6   Date:      $Date: 2008/02/04 13:02:58 $
7   Version:   $Revision: 1.3 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18 /**
19  * \file
20  * \brief Class bbtk::Package : registers black boxes descriptors and is able to create instances of the black boxes registered.
21  */
22 /**
23  * \class bbtk::Package
24  * \brief registers black boxes descriptors and is able to create instances of the black boxes registered.
25  */
26
27 #ifndef __bbtkPackage_h__
28 #define __bbtkPackage_h__
29
30 #include "bbtkBlackBox.h"
31
32 namespace bbtk
33 {
34
35   class BBTK_EXPORT Package
36   {
37   public:
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);
43     ~Package();
44     /// Returns the name of the package
45     const std::string& GetName() const { return mName; }
46
47     /// Returns the author of the package
48     const std::string& GetAuthor() const { return mAuthor; }
49
50     /// Returns the keyword of the package
51     const std::string& GetKeyword() const { return mKeyword; }
52
53     /// Returns the description of the package
54     const std::string& GetDescription() const { return mDescription; }
55
56     /// Returns the version of the package
57     const std::string& GetVersion() const { return mVersion; }
58
59     /// Returns the version of bbtk used to build the package
60     const std::string& GetBBTKVersion() const { return mBBTKVersion; }
61
62     bool ContainsBlackBox(const std::string& boxname) const;
63
64  
65     BlackBox* NewBlackBox(const std::string& type,
66                              const std::string& name) const;
67   
68     BlackBox* NewAdaptor(TypeInfo typein,
69                             TypeInfo typeout,
70                             const std::string& name) const;
71
72     bool RegisterBlackBox(BlackBoxDescriptor*); 
73     void UnRegisterBlackBox(const std::string& name); 
74
75     //   bool RegisterAdaptor(BlackBoxDescriptor*); 
76
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;
81     
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 = "",
87                         int detail = 1, 
88                         int level = 0,
89                         bool relative_link = false ) const;
90
91     void  SetDocURL(std::string url){ mDocURL=url; }
92     const std::string& GetDocURL() const { return mDocURL; }
93     
94     void  SetDocRelativeURL(std::string url){ mDocRelativeURL=url; }
95     const std::string& GetDocRelativeURL() const { return mDocRelativeURL; }
96
97
98     unsigned int GetNumberOfBlackBoxes() const { return mBlackBoxMap.size(); }
99     
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; }
107
108   private:
109     /// The name of the package
110     std::string mName;
111     /// The author of the package
112     std::string mAuthor;
113     /// The keywords of the package
114     std::string mKeyword;    
115     /// The description of the package
116     std::string mDescription;
117     /// The version of the package
118     std::string mVersion;
119     /// The version of the library bbtk used to build the package
120     std::string mBBTKVersion;
121     /// URL of the documentation of the Package (absolute path)
122     std::string mDocURL;
123     /// URL of the documentation of the Package 
124     /// (path relative to bbtk doc root)
125     std::string mDocRelativeURL;
126
127
128     /// The map of black boxes descriptors
129     BlackBoxMapType mBlackBoxMap;
130
131     /// The type of key in the map of adaptor descriptors
132     class AdaptorKey 
133     {
134     public:
135       AdaptorKey( TypeInfo typein, TypeInfo typeout) 
136         : mTypeIn(typein.name()), mTypeOut(typeout.name()) {}
137       
138       bool operator< ( const AdaptorKey& k ) const
139       {
140         //      return ( ( mTypeIn.before(k.mTypeIn) ) ||
141         //               ( ( mTypeIn == k.mTypeIn ) && 
142         //                 ( mTypeOut.before(k.mTypeOut) ) ) );
143         return ( ( mTypeIn < k.mTypeIn ) ||
144                  ( ( mTypeIn == k.mTypeIn ) && 
145                    ( mTypeOut < k.mTypeOut ) ) );
146       }
147       
148     private:
149       //      TypeInfo mTypeIn;
150       //      TypeInfo mTypeOut;
151       std::string mTypeIn;
152       std::string mTypeOut;
153     };
154     
155     //typedef std::string AdaptorKey;
156
157     /// The type of map of adaptor descriptors
158     typedef std::map< AdaptorKey, BlackBoxDescriptor*> AdaptorMapType;
159
160     /// The map of adaptors descriptors
161     AdaptorMapType mAdaptorMap;
162   };
163   // EO class Package
164   //====================================================================
165
166
167 //====================================================================
168 #if defined(_WIN32)
169   #define BBTK_PACKAGE_EXPORT __declspec( dllexport )
170 #else
171   #define BBTK_PACKAGE_EXPORT
172 #endif // defined(_WIN32) 
173 //====================================================================
174
175 //====================================================================
176 #define BBTK_DECLARE_PACKAGE(NAME)                                      \
177   extern "C"                                                            \
178   {                                                                     \
179     bbtk::Package*& NAME ## GetPackagePointer();                        \
180     BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage();        \
181     BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage(); \
182   }
183 //==================================================================== 
184
185 //==================================================================== 
186 #define BBTK_IMPLEMENT_PACKAGE(NAME,AUTHOR,DESCRIPTION,VERSION)         \
187   extern "C"                                                            \
188   {                                                                     \
189     bbtk::Package*& NAME ## GetPackagePointer()                         \
190     {                                                                   \
191       static bbtk::Package* u = 0;                                      \
192       return u;                                                         \
193     }                                                                   \
194     BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage()         \
195     {                                                                   \
196       if (NAME ## GetPackagePointer())                                  \
197         delete NAME ## GetPackagePointer();                             \
198       NAME ## GetPackagePointer() = 0;                                  \
199     }                                                                   \
200     BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage()  \
201     {                                                                   \
202       if (!NAME ## GetPackagePointer())                                 \
203         NAME ## GetPackagePointer() =                                   \
204           new bbtk::Package(#NAME,                                      \
205                             AUTHOR,     \
206                             DESCRIPTION, \
207                             VERSION,    \
208                             BBTK_STRINGIFY_SYMBOL(BBTK_VERSION)         \
209                             );                                          \
210       return NAME ## GetPackagePointer();                               \
211     }                                                                   \
212   }
213 //====================================================================  
214
215 //====================================================================
216 #define BBTK_ADD_BLACK_BOX_TO_PACKAGE(NAME,CLASS)                       \
217   bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor());
218   //====================================================================
219   
220 //====================================================================
221 #define BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \
222   bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS<TEMPLATE_PARAM>::bbDescriptor());
223   //====================================================================
224
225 //====================================================================
226 #define BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(NAME,CLASS,T1,T2)       \
227   bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS<T1,T2>::bbDescriptor()); 
228   //====================================================================
229   
230 //====================================================================
231 //#define BBTK_ADD_ADAPTOR_TO_PACKAGE(NAME,CLASS)                       \
232 //  bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); \
233 //  bool bbDummyAdaptor##NAME##CLASS = NAME ## GetPackage()->RegisterAdaptor(CLASS::bbDescriptor());
234 //====================================================================
235
236 //====================================================================
237 //#define BBTK_ADD_TEMPLATE_ADAPTOR_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \
238 //  bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS<TEMPLATE_PARAM>::bbDescriptor()); \
239 //  bool bbDummyAdaptor##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterAdaptor(CLASS<TEMPLATE_PARAM>::bbDescriptor());
240 //====================================================================
241
242 //====================================================================
243 //#define BBTK_ADD_TEMPLATE2_ADAPTOR_TO_PACKAGE(NAME,CLASS,T1,T2)       \
244 //  bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS<T1,T2>::bbDescriptor()); \
245 //    bool bbDummyAdaptor##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterAdaptor(CLASS<T1,T2>::bbDescriptor());
246   //====================================================================
247
248 }// namespace bbtk
249
250
251
252 #endif
253