-
Notifications
You must be signed in to change notification settings - Fork 95
/
mf_plugins.cpp
43 lines (33 loc) · 1.74 KB
/
mf_plugins.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <boost/container/flat_map.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <steemit/manifest/plugins.hpp>
#include <mf_internal_plugins.inc>
#include <mf_external_plugins.inc>
#define STEEMIT_DECLARE_PLUGIN_CREATOR( r, data, x ) \
std::shared_ptr< steemit::app::abstract_plugin > BOOST_PP_CAT( create_, BOOST_PP_CAT( x, _plugin ) )( steemit::app::application* app );
namespace steemit { namespace plugin {
BOOST_PP_SEQ_FOR_EACH( STEEMIT_DECLARE_PLUGIN_CREATOR, _, STEEMIT_INTERNAL_PLUGIN_LIST )
BOOST_PP_SEQ_FOR_EACH( STEEMIT_DECLARE_PLUGIN_CREATOR, _, STEEMIT_EXTERNAL_PLUGIN_LIST )
boost::container::flat_map< std::string, std::function< std::shared_ptr< steemit::app::abstract_plugin >( steemit::app::application* app ) > > plugin_factories_by_name;
#define STEEMIT_REGISTER_PLUGIN_FACTORY( r, data, x ) \
plugin_factories_by_name[ #x ] = []( steemit::app::application* app ) -> std::shared_ptr< steemit::app::abstract_plugin >{ return BOOST_PP_CAT( create_, BOOST_PP_CAT( x, _plugin( app ) ) ); };
void initialize_plugin_factories()
{
BOOST_PP_SEQ_FOR_EACH( STEEMIT_REGISTER_PLUGIN_FACTORY, _, STEEMIT_INTERNAL_PLUGIN_LIST )
BOOST_PP_SEQ_FOR_EACH( STEEMIT_REGISTER_PLUGIN_FACTORY, _, STEEMIT_EXTERNAL_PLUGIN_LIST )
}
std::shared_ptr< steemit::app::abstract_plugin > create_plugin( const std::string& name, steemit::app::application* app )
{
auto it = plugin_factories_by_name.find( name );
if( it == plugin_factories_by_name.end() )
return std::shared_ptr< steemit::app::abstract_plugin >();
return it->second( app );
}
std::vector< std::string > get_available_plugins()
{
std::vector< std::string > result;
for( const auto& e : plugin_factories_by_name )
result.push_back( e.first );
return result;
}
} }