Pluma.hpp
1 //
3 // Pluma - Plug-in Management Framework
4 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef PLUMA_PLUMA_HPP
26 #define PLUMA_PLUMA_HPP
27 
29 // Headers
31 #include <Pluma/Config.hpp>
32 #include <Pluma/Provider.hpp>
33 #include <Pluma/PluginManager.hpp>
34 
36 // Andy macro to convert parameter to string
38 #define PLUMA_2STRING(X) #X
39 
41 // Macro that helps host applications defining
42 // their provider classes
44 #define PLUMA_PROVIDER_HEADER(TYPE)\
45 PLUMA_PROVIDER_HEADER_BEGIN(TYPE)\
46 virtual TYPE* create() const = 0;\
47 PLUMA_PROVIDER_HEADER_END
48 
50 // Macro that generate first part of the provider definition
52 #define PLUMA_PROVIDER_HEADER_BEGIN(TYPE)\
53 class TYPE##Provider: public pluma::Provider{\
54 private:\
55  friend class pluma::Pluma;\
56  static const unsigned int PLUMA_INTERFACE_VERSION;\
57  static const unsigned int PLUMA_INTERFACE_LOWEST_VERSION;\
58  static const std::string PLUMA_PROVIDER_TYPE;\
59  std::string plumaGetType() const{ return PLUMA_PROVIDER_TYPE; }\
60 public:\
61  unsigned int getVersion() const{ return PLUMA_INTERFACE_VERSION; }
62 
64 // Macro that generate last part of the provider definition
66 #define PLUMA_PROVIDER_HEADER_END };
67 
69 // Macro that generate the provider declaration
71 #define PLUMA_PROVIDER_SOURCE(TYPE, Version, LowestVersion)\
72 const std::string TYPE##Provider::PLUMA_PROVIDER_TYPE = PLUMA_2STRING( TYPE );\
73 const unsigned int TYPE##Provider::PLUMA_INTERFACE_VERSION = Version;\
74 const unsigned int TYPE##Provider::PLUMA_INTERFACE_LOWEST_VERSION = LowestVersion;
75 
76 
78 // Macro that helps plugins generating their provider implementations
79 // PRE: SPECIALIZED_TYPE must inherit from BASE_TYPE
81 #define PLUMA_INHERIT_PROVIDER(SPECIALIZED_TYPE, BASE_TYPE)\
82 class SPECIALIZED_TYPE##Provider: public BASE_TYPE##Provider{\
83 public:\
84  BASE_TYPE * create() const{ return new SPECIALIZED_TYPE (); }\
85 };
86 
87 
88 namespace pluma{
89 
94 class Pluma: public PluginManager{
95 
96 public:
101  Pluma();
102 
114  template<typename ProviderType>
115  void acceptProviderType();
116 
127  template<typename ProviderType>
128  void getProviders(std::vector<ProviderType*>& providers);
129 };
130 
131 #include <Pluma/Pluma.inl>
132 
133 }
134 
135 
136 #endif // PLUMA_PLUMA_HPP
137 
138 
Manages loaded plugins.
Pluma plugins management.
Definition: Pluma.hpp:94
void getProviders(std::vector< ProviderType * > &providers)
Get the stored providers of a certain type.
void acceptProviderType()
Tell Pluma to accept a certain type of providers.
Pluma()
Default Constructor.
Definition: Pluma.inl:27