/*========================================================================= Program: bbtk Module: $RCSfile: bbtkPackage.h,v $ Language: C++ Date: $Date: 2008/01/22 15:02:00 $ Version: $Revision: 1.1.1.1 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ /** * \file * \brief Class bbtk::Package : registers black boxes descriptors and is able to create instances of the black boxes registered. */ /** * \class bbtk::Package * \brief registers black boxes descriptors and is able to create instances of the black boxes registered. */ #ifndef __bbtkPackage_h__ #define __bbtkPackage_h__ #include "bbtkBlackBox.h" namespace bbtk { class BBTK_EXPORT Package { public: Package(const std::string& name, const std::string& author, const std::string& description, const std::string& version, const std::string& BBTKVersion); ~Package(); /// Returns the name of the package const std::string& GetName() const { return mName; } /// Returns the author of the package const std::string& GetAuthor() const { return mAuthor; } /// Returns the description of the package const std::string& GetDescription() const { return mDescription; } /// Returns the version of the package const std::string& GetVersion() const { return mVersion; } /// Returns the version of bbtk used to build the package const std::string& GetBBTKVersion() const { return mBBTKVersion; } bool ContainsBlackBox(const std::string& boxname) const; BlackBox* NewBlackBox(const std::string& type, const std::string& name) const; BlackBox* NewAdaptor(TypeInfo typein, TypeInfo typeout, const std::string& name) const; bool RegisterBlackBox(BlackBoxDescriptor*); void UnRegisterBlackBox(const std::string& name); // bool RegisterAdaptor(BlackBoxDescriptor*); void PrintBlackBoxes(bool description = false, bool adaptors = false) const; void PrintAdaptors(bool description = false) const; void HelpBlackBox(const std::string& name, bool full=true) const; void CreateHtmlPage(const std::string& filename, const std::string& caller = "?", const std::string& source = "?", const std::string& custom_header = "", const std::string& custom_title = "", int detail = 1, int level = 0, bool relative_link = false ) const; void SetDocURL(std::string url){ mDocURL=url; } const std::string& GetDocURL() const { return mDocURL; } void SetDocRelativeURL(std::string url){ mDocRelativeURL=url; } const std::string& GetDocRelativeURL() const { return mDocRelativeURL; } unsigned int GetNumberOfBlackBoxes() const { return mBlackBoxMap.size(); } /// Changes the name of a black box type void ChangeBlackBoxName( const std::string& oldname, const std::string& newname ); private: /// The name of the package std::string mName; /// The author of the package std::string mAuthor; /// The description of the package std::string mDescription; /// The version of the package std::string mVersion; /// The version of the library bbtk used to build the package std::string mBBTKVersion; /// URL of the documentation of the Package (absolute path) std::string mDocURL; /// URL of the documentation of the Package /// (path relative to bbtk doc root) std::string mDocRelativeURL; /// The type of map of descriptors typedef std::map< std::string, BlackBoxDescriptor*> BlackBoxMapType; /// The map of black boxes descriptors BlackBoxMapType mBlackBoxMap; /// The type of key in the map of adaptor descriptors class AdaptorKey { public: AdaptorKey( TypeInfo typein, TypeInfo typeout) : mTypeIn(typein.name()), mTypeOut(typeout.name()) {} bool operator< ( const AdaptorKey& k ) const { // return ( ( mTypeIn.before(k.mTypeIn) ) || // ( ( mTypeIn == k.mTypeIn ) && // ( mTypeOut.before(k.mTypeOut) ) ) ); return ( ( mTypeIn < k.mTypeIn ) || ( ( mTypeIn == k.mTypeIn ) && ( mTypeOut < k.mTypeOut ) ) ); } private: // TypeInfo mTypeIn; // TypeInfo mTypeOut; std::string mTypeIn; std::string mTypeOut; }; //typedef std::string AdaptorKey; /// The type of map of adaptor descriptors typedef std::map< AdaptorKey, BlackBoxDescriptor*> AdaptorMapType; /// The map of adaptors descriptors AdaptorMapType mAdaptorMap; }; // EO class Package //==================================================================== //==================================================================== #if defined(_WIN32) #define BBTK_PACKAGE_EXPORT __declspec( dllexport ) #else #define BBTK_PACKAGE_EXPORT #endif // defined(_WIN32) //==================================================================== //==================================================================== #define BBTK_DECLARE_PACKAGE(NAME) \ extern "C" \ { \ bbtk::Package*& NAME ## GetPackagePointer(); \ BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage(); \ BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage(); \ } //==================================================================== //==================================================================== #define BBTK_IMPLEMENT_PACKAGE(NAME,AUTHOR,DESCRIPTION,VERSION) \ extern "C" \ { \ bbtk::Package*& NAME ## GetPackagePointer() \ { \ static bbtk::Package* u = 0; \ return u; \ } \ BBTK_PACKAGE_EXPORT void BBTK_CDECL NAME ## DeletePackage() \ { \ if (NAME ## GetPackagePointer()) \ delete NAME ## GetPackagePointer(); \ NAME ## GetPackagePointer() = 0; \ } \ BBTK_PACKAGE_EXPORT bbtk::Package* BBTK_CDECL NAME ## GetPackage() \ { \ if (!NAME ## GetPackagePointer()) \ NAME ## GetPackagePointer() = \ new bbtk::Package(#NAME, \ AUTHOR, \ DESCRIPTION, \ VERSION, \ BBTK_STRINGIFY_SYMBOL(BBTK_VERSION) \ ); \ return NAME ## GetPackagePointer(); \ } \ } //==================================================================== //==================================================================== #define BBTK_ADD_BLACK_BOX_TO_PACKAGE(NAME,CLASS) \ bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); //==================================================================== //==================================================================== #define BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \ bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); //==================================================================== //==================================================================== #define BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(NAME,CLASS,T1,T2) \ bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); //==================================================================== //==================================================================== //#define BBTK_ADD_ADAPTOR_TO_PACKAGE(NAME,CLASS) \ // bool bbDummy##NAME##CLASS = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); \ // bool bbDummyAdaptor##NAME##CLASS = NAME ## GetPackage()->RegisterAdaptor(CLASS::bbDescriptor()); //==================================================================== //==================================================================== //#define BBTK_ADD_TEMPLATE_ADAPTOR_TO_PACKAGE(NAME,CLASS,TEMPLATE_PARAM) \ // bool bbDummy##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); \ // bool bbDummyAdaptor##NAME##CLASS##TEMPLATE_PARAM = NAME ## GetPackage()->RegisterAdaptor(CLASS::bbDescriptor()); //==================================================================== //==================================================================== //#define BBTK_ADD_TEMPLATE2_ADAPTOR_TO_PACKAGE(NAME,CLASS,T1,T2) \ // bool bbDummy##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterBlackBox(CLASS::bbDescriptor()); \ // bool bbDummyAdaptor##NAME##CLASS##T1##T2 = NAME ## GetPackage()->RegisterAdaptor(CLASS::bbDescriptor()); //==================================================================== }// namespace bbtk #endif