Make default_application_factory support a custom factory callback
This commit is contained in:
parent
6ee75f8bae
commit
7f5d50787d
1 changed files with 16 additions and 5 deletions
|
|
@ -7,16 +7,18 @@
|
|||
namespace psemek::app
|
||||
{
|
||||
|
||||
template <typename Application>
|
||||
std::unique_ptr<application::factory> default_application_factory(application::options const & options)
|
||||
template <typename Factory>
|
||||
std::unique_ptr<application::factory> default_application_factory(application::options const & options, Factory && factory)
|
||||
{
|
||||
struct factory_impl
|
||||
: application::factory
|
||||
{
|
||||
application::options opts;
|
||||
Factory factory;
|
||||
|
||||
factory_impl(application::options const & options)
|
||||
factory_impl(application::options const & options, Factory && factory)
|
||||
: opts(options)
|
||||
, factory(std::move(factory))
|
||||
{}
|
||||
|
||||
application::options options() override
|
||||
|
|
@ -26,11 +28,20 @@ namespace psemek::app
|
|||
|
||||
std::unique_ptr<application> create(application::options const & options, application::context const & context) override
|
||||
{
|
||||
return std::make_unique<Application>(options, context);
|
||||
return factory(options, context);
|
||||
}
|
||||
};
|
||||
|
||||
return std::make_unique<factory_impl>(options);
|
||||
return std::make_unique<factory_impl>(options, std::move(factory));
|
||||
}
|
||||
|
||||
template <typename Application>
|
||||
std::unique_ptr<application::factory> default_application_factory(application::options const & options)
|
||||
{
|
||||
return default_application_factory(options, [](auto const & options, auto const & context){
|
||||
return std::make_unique<Application>(options, context);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue