Skip to content

Commit b23018c

Browse files
committed
update
1 parent ebe609d commit b23018c

6 files changed

Lines changed: 38 additions & 15 deletions

File tree

src/ruisapp/application.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,25 @@ const application_factory::factory_type& application_factory::get_factory()
149149
return f;
150150
}
151151

152-
std::unique_ptr<application> application_factory::create_application(int argc, const char** argv)
152+
std::unique_ptr<application> application_factory::make_application(
153+
int argc, //
154+
const char** argv
155+
)
153156
{
154-
auto args = utki::make_span(argv, argc);
157+
auto cli_args = utki::make_span(argv, argc);
155158

156-
if (args.empty()) {
159+
if (cli_args.empty()) {
157160
return get_factory()(std::string_view(), {});
158161
}
159162

160-
return get_factory()(args.front(), args.subspan(1));
163+
std::string_view executable = cli_args.front();
164+
165+
std::vector<std::string_view> args;
166+
for (const auto& a : cli_args.subspan(1)) {
167+
args.emplace_back(a);
168+
}
169+
170+
return get_factory()(executable, args);
161171
}
162172

163173
application_factory::application_factory(factory_type factory)

src/ruisapp/application.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ struct window_params {
8585
/**
8686
* @brief Base singleton class of application.
8787
* An application should subclass this class and return an instance from the
88-
* application factory function create_application(), see application.hpp for
89-
* details. When instance of this class is created it also creates a window and
88+
* application_factory, see application_factory for details.
89+
* When instance of this class is created it also creates a window and
9090
* initializes rendering API (e.g. OpenGL or OpenGL ES).
9191
*/
9292
class application : public utki::intrusive_singleton<application>
@@ -307,8 +307,10 @@ inline application& inst()
307307
class application_factory
308308
{
309309
public:
310-
using factory_type =
311-
std::function<std::unique_ptr<application>(std::string_view executable, utki::span<const char*> args)>;
310+
using factory_type = std::function<std::unique_ptr<application>(
311+
std::string_view executable, //
312+
utki::span<std::string_view> args
313+
)>;
312314

313315
/**
314316
* @brief Constructor.
@@ -319,6 +321,11 @@ class application_factory
319321
*/
320322
application_factory(factory_type factory);
321323

324+
/**
325+
* @brief Get registered factory function.
326+
* @return Registered factory function.
327+
* @throw std::logic_error if no factory function was registered, i.e. application_factory instance is not created.
328+
*/
322329
static const factory_type& get_factory();
323330

324331
/**
@@ -327,7 +334,10 @@ class application_factory
327334
* @param argv - array of command line arguments. First argument is the
328335
* executable filename.
329336
*/
330-
static std::unique_ptr<application> create_application(int argc, const char** argv);
337+
static std::unique_ptr<application> make_application(
338+
int argc, //
339+
const char** argv
340+
);
331341

332342
private:
333343
static factory_type& get_factory_internal();

src/ruisapp/glue/android/glue.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ void on_native_window_created(ANativeActivity* activity, ANativeWindow* window)
15871587
// retrieve current configuration
15881588
AConfiguration_fromAssetManager(cfg->android_configuration, native_activity->assetManager);
15891589

1590-
application* app = ruisapp::application_factory::create_application(0, nullptr).release();
1590+
application* app = ruisapp::application_factory::make_application(0, nullptr).release();
15911591

15921592
// TODO: check if app == nullptr
15931593

src/ruisapp/glue/sdl/glue.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ void main_loop_iteration(void* user_data)
754754

755755
int main(int argc, const char** argv)
756756
{
757-
std::unique_ptr<ruisapp::application> app = ruisapp::application_factory::create_application(argc, argv);
757+
std::unique_ptr<ruisapp::application> app = ruisapp::application_factory::make_application(argc, argv);
758758
if (!app) {
759759
// Not an error. The application just did not show any GUI to the user.
760760
return 0;

src/ruisapp/glue/unix_common.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace {
2727

2828
std::unique_ptr<ruisapp::application> create_app_unix(int argc, const char** argv)
2929
{
30-
return ruisapp::application_factory::create_application(argc, argv);
30+
return ruisapp::application_factory::make_application(argc, argv);
3131
}
3232

3333
std::string get_xdg_dir_home(

src/ruisapp/glue/windows/glue.cxx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,14 @@ void application::quit() noexcept
745745
}
746746

747747
namespace ruisapp {
748-
void winmain(int argc, const char** argv)
748+
void winmain(
749+
int argc, //
750+
const char** argv
751+
)
749752
{
750-
auto app = ruisapp::application_factory::create_application(argc, argv);
753+
auto app = ruisapp::application_factory::make_application(argc, argv);
751754
if (!app) {
752-
// Not an error. The application just did not show any GUI to the user.
755+
// Not an error. The application just did not show any GUI to the user and exited normally.
753756
return;
754757
}
755758

0 commit comments

Comments
 (0)