Pluma.hpp
00001 
00002 //
00003 // Pluma - Plug-in Management Framework
00004 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 #ifndef PLUMA_PLUMA_HPP
00026 #define PLUMA_PLUMA_HPP
00027 
00029 // Headers
00031 #include <Pluma/Config.hpp>
00032 #include <Pluma/Provider.hpp>
00033 #include <Pluma/PluginManager.hpp>
00034 
00036 // Andy macro to convert parameter to string
00038 #define PLUMA_2STRING(X) #X
00039 
00041 // Macro that helps host applications defining
00042 // their provider classes
00044 #define PLUMA_PROVIDER_HEADER(TYPE)\
00045 PLUMA_PROVIDER_HEADER_BEGIN(TYPE)\
00046 virtual TYPE* create() const = 0;\
00047 PLUMA_PROVIDER_HEADER_END
00048 
00050 // Macro that generate first part of the provider definition
00052 #define PLUMA_PROVIDER_HEADER_BEGIN(TYPE)\
00053 class TYPE##Provider: public pluma::Provider{\
00054 private:\
00055     friend class pluma::Pluma;\
00056     static const unsigned int PLUMA_INTERFACE_VERSION;\
00057     static const unsigned int PLUMA_INTERFACE_LOWEST_VERSION;\
00058     static const std::string PLUMA_PROVIDER_TYPE;\
00059     std::string plumaGetType() const;\
00060 public:\
00061     unsigned int getVersion() const;
00062 //#define PLUMA_PROVIDER_HEADER_BEGIN(TYPE)\
00063 //class TYPE##Provider: public pluma::Provider{\
00064 //private:\
00065 //    friend class pluma::Pluma;\
00066 //    static const unsigned int PLUMA_INTERFACE_VERSION;\
00067 //    static const unsigned int PLUMA_INTERFACE_LOWEST_VERSION;\
00068 //    static const std::string PLUMA_PROVIDER_TYPE;\
00069 //    std::string plumaGetType() const{ return PLUMA_PROVIDER_TYPE; }\
00070 //public:\
00071 //    unsigned int getVersion() const{ return PLUMA_INTERFACE_VERSION; }
00072 
00074 // Macro that generate last part of the provider definition
00076 #define PLUMA_PROVIDER_HEADER_END };
00077 
00079 // Macro that generate the provider declaration
00081 #define PLUMA_PROVIDER_SOURCE(TYPE, Version, LowestVersion)\
00082 const std::string TYPE##Provider::PLUMA_PROVIDER_TYPE = PLUMA_2STRING( TYPE );\
00083 const unsigned int TYPE##Provider::PLUMA_INTERFACE_VERSION = Version;\
00084 const unsigned int TYPE##Provider::PLUMA_INTERFACE_LOWEST_VERSION = LowestVersion;\
00085 std::string TYPE##Provider::plumaGetType() const{ return TYPE##Provider::PLUMA_PROVIDER_TYPE; }\
00086 unsigned int TYPE##Provider::getVersion() const{ return TYPE##Provider::PLUMA_INTERFACE_VERSION; }
00087 //#define PLUMA_PROVIDER_SOURCE(TYPE, Version, LowestVersion)\
00088 //const std::string TYPE##Provider::PLUMA_PROVIDER_TYPE = PLUMA_2STRING( TYPE );\
00089 //const unsigned int TYPE##Provider::PLUMA_INTERFACE_VERSION = Version;\
00090 //const unsigned int TYPE##Provider::PLUMA_INTERFACE_LOWEST_VERSION = LowestVersion;
00091 
00092 
00094 // Macro that helps plugins generating their provider implementations
00095 // PRE: SPECIALIZED_TYPE must inherit from BASE_TYPE
00097 #define PLUMA_INHERIT_PROVIDER(SPECIALIZED_TYPE, BASE_TYPE)\
00098 class SPECIALIZED_TYPE##Provider: public BASE_TYPE##Provider{\
00099 public:\
00100     BASE_TYPE * create() const{ return new SPECIALIZED_TYPE (); }\
00101 };
00102 
00103 
00104 namespace pluma{
00105 
00110 class Pluma: public PluginManager{
00111 
00112 public:
00117     Pluma();
00118 
00130     template<typename ProviderType>
00131     void acceptProviderType();
00132 
00143     template<typename ProviderType>
00144     void getProviders(std::vector<ProviderType*>& providers);
00145 };
00146 
00147 #include <Pluma/Pluma.inl>
00148 
00149 }
00150 
00151 
00152 #endif // PLUMA_PLUMA_HPP
00153 
00154