Skip to content

Commit

Permalink
args
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Gagis committed Mar 18, 2024
1 parent d22c7a0 commit 3509ebe
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/ruisapp/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ const application_factory::factory_type& application_factory::get_factory()
return f;
}

application_factory::application_factory(factory_type&& factory)
std::unique_ptr<application> application_factory::create_application(int argc, const char** argv)
{
auto args = utki::make_span(argv, argc);

if (args.empty()) {
return get_factory()(std::string_view(), nullptr);
}

return get_factory()(args.front(), args.subspan(1));
}

application_factory::application_factory(factory_type factory)
{
auto& f = this->get_factory_internal();
if (f) {
Expand Down
13 changes: 11 additions & 2 deletions src/ruisapp/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ inline application& inst()
class application_factory
{
public:
using factory_type = std::function<std::unique_ptr<application>(utki::span<const char*>)>;
using factory_type =
std::function<std::unique_ptr<application>(std::string_view executable, utki::span<const char*>)>;

/**
* @brief Constructor.
Expand All @@ -315,10 +316,18 @@ class application_factory
* @param factory - application factory function.
* @throw std::logic_error - in case a factory is already registered.
*/
application_factory(factory_type&& factory);
application_factory(factory_type factory);

static const factory_type& get_factory();

/**
* @brief Create application object.
* @param argc - number of command line arguments.
* @param argv - array of command line arguments. First argument is the
* executable filename.
*/
static std::unique_ptr<application> create_application(int argc, const char** argv);

private:
static factory_type& get_factory_internal();
};
Expand Down
2 changes: 1 addition & 1 deletion src/ruisapp/glue/android/glue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ void on_native_window_created(ANativeActivity* activity, ANativeWindow* window)
// retrieve current configuration
AConfiguration_fromAssetManager(cfg->android_configuration, native_activity->assetManager);

application* app = ruisapp::application_factory::get_factory()(nullptr).release();
application* app = ruisapp::application_factory::create_application(0, nullptr).release();

activity->instance = app;

Expand Down
2 changes: 1 addition & 1 deletion src/ruisapp/glue/unix_common.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace {

std::unique_ptr<ruisapp::application> create_app_unix(int argc, const char** argv)
{
return ruisapp::application_factory::get_factory()(utki::make_span(argv, argc));
return ruisapp::application_factory::create_application(argc, argv);
}

std::string initialize_storage_dir(const std::string& app_name)
Expand Down
2 changes: 1 addition & 1 deletion src/ruisapp/glue/windows/glue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ void application::quit() noexcept
namespace ruisapp {
void winmain(int argc, const char** argv)
{
auto app = ruisapp::application_factory::get_factory()(utki::make_span(argv, argc));
auto app = ruisapp::application_factory::create_application(argc, argv);
if (!app) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,6 @@ class application : public ruisapp::application{
}
};

const ruisapp::application_factory app_fac([](auto args){
const ruisapp::application_factory app_fac([](auto executable, auto args){
return std::make_unique<::application>();
});

0 comments on commit 3509ebe

Please sign in to comment.