]> Creatis software - bbtk.git/blob - kernel/src/bbtkPackage.h
Recreated the complete cvs tree because the project architecture deeply changed
[bbtk.git] / kernel / src / bbtkPackage.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkPackage.h,v $
5   Language:  C++
6   Date:      $Date: 2008/01/22 15:02:00 $
7   Version:   $Revision: 1.1.1.1 $
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     /// 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; }
54   
55     bool ContainsBlackBox(const std::string& boxname) const;
56
57   
58     BlackBox* NewBlackBox(const std::string& type, 
59                              const std::string& name) const;
60   
61     BlackBox* NewAdaptor(TypeInfo typein,
62                             TypeInfo typeout,
63                             const std::string& name) const;
64
65     bool RegisterBlackBox(BlackBoxDescriptor*); 
66     void UnRegisterBlackBox(const std::string& name); 
67
68     //   bool RegisterAdaptor(BlackBoxDescriptor*); 
69
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;
74     
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 = "",
80                         int detail = 1, 
81                         int level = 0,
82                         bool relative_link = false ) const;
83
84     void  SetDocURL(std::string url){ mDocURL=url; }
85     const std::string& GetDocURL() const { return mDocURL; }
86     
87     void  SetDocRelativeURL(std::string url){ mDocRelativeURL=url; }
88     const std::string& GetDocRelativeURL() const { return mDocRelativeURL; }
89
90
91     unsigned int GetNumberOfBlackBoxes() const { return mBlackBoxMap.size(); }
92     
93     /// Changes the name of a black box type
94     void ChangeBlackBoxName( const std::string& oldname, 
95                              const std::string& newname );
96
97   private:
98     /// The name of the package
99     std::string mName;
100     /// The author of the package
101     std::string mAuthor;
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)
109     std::string mDocURL;
110     /// URL of the documentation of the Package 
111     /// (path relative to bbtk doc root)
112     std::string mDocRelativeURL;
113
114
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;
119
120     /// The type of key in the map of adaptor descriptors
121     class AdaptorKey 
122     {
123     public:
124       AdaptorKey( TypeInfo typein, TypeInfo typeout) 
125         : mTypeIn(typein.name()), mTypeOut(typeout.name()) {}
126       
127       bool operator< ( const AdaptorKey& k ) const
128       {
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 ) ) );
135       }
136       
137     private:
138       //      TypeInfo mTypeIn;
139       //      TypeInfo mTypeOut;
140       std::string mTypeIn;
141       std::string mTypeOut;
142     };
143     
144     //typedef std::string AdaptorKey;
145
146     /// The type of map of adaptor descriptors
147     typedef std::map< AdaptorKey, BlackBoxDescriptor*> AdaptorMapType;
148
149     /// The map of adaptors descriptors
150     AdaptorMapType mAdaptorMap;
151   };
152   // EO class Package
153   //====================================================================
154
155
156 //====================================================================
157 #if defined(_WIN32)
158   #define BBTK_PACKAGE_EXPORT __declspec( dllexport )
159 #else
160   #define BBTK_PACKAGE_EXPORT
161 #endif // defined(_WIN32) 
162 //====================================================================
163
164 //====================================================================
165 #define BBTK_DECLARE_PACKAGE(NAME)                                      \
166   extern "C"                                                            \
167   {                                                                     \
168     bbtk::Package*& NAME ## GetPackagePointer();                        \
169     BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage();        \
170     BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage(); \
171   }
172 //==================================================================== 
173
174 //==================================================================== 
175 #define BBTK_IMPLEMENT_PACKAGE(NAME,AUTHOR,DESCRIPTION,VERSION)         \
176   extern "C"                                                            \
177   {                                                                     \
178     bbtk::Package*& NAME ## GetPackagePointer()                         \
179     {                                                                   \
180       static bbtk::Package* u = 0;                                      \
181       return u;                                                         \
182     }                                                                   \
183     BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage()         \
184     {                                                                   \
185       if (NAME ## GetPackagePointer())                                  \
186         delete NAME ## GetPackagePointer();                             \
187       NAME ## GetPackagePointer() = 0;                                  \
188     }                                                                   \
189     BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage()  \
190     {                                                                   \
191       if (!NAME ## GetPackagePointer())                                 \
192         NAME ## GetPackagePointer() =                                   \
193           new bbtk::Package(#NAME,                                      \
194                             AUTHOR,     \
195                             DESCRIPTION, \
196                             VERSION,    \
197                             BBTK_STRINGIFY_SYMBOL(BBTK_VERSION)         \
198                             );                                          \
199       return NAME ## GetPackagePointer();                               \
200     }                                                                   \
201   }
202 //====================================================================  
203
204 //====================================================================
205 #define BBTK_ADD_BLACK_BOX_TO_PACKAGE(NAME,CLASS)                       \
206   bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor());
207   //====================================================================
208   
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   //====================================================================
213
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   //====================================================================
218   
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 //====================================================================
224
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 //====================================================================
230
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   //====================================================================
236
237 }// namespace bbtk
238
239
240
241 #endif
242