3 This file is part of libmspcore
4 Copyright © 2006-2008, 2011 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_CORE_APPLICATION_H_
9 #define MSP_CORE_APPLICATION_H_
14 Base class for applications. Inherit the main class from this and add a static
15 member of type RegApp<MainClass>.
25 virtual ~Starter() { }
27 virtual Application *create_app(int, char **) = 0;
28 virtual void usage(const char *, const char *, bool) = 0;
35 static Starter *starter_;
36 static Application *app_;
39 Application(const Application &);
40 Application &operator=(const Application &);
44 virtual ~Application() { }
46 static int run(int, char **, void * =0);
47 static void usage(const char *, const char *, bool);
48 static void *get_data() { return data_; }
52 void catch_signal(int);
54 virtual void tick() { }
55 virtual void sighandler(int) { }
57 static void sighandler_(int);
62 class RegisteredApplication: public Application
65 class Starter: public Application::Starter
68 Application *create_app(int argc, char **argv) { return new T(argc, argv); }
69 void usage(const char *r, const char *a, bool b) { T::usage(r, a, b); }
72 static Starter starter_;
75 // Force the starter into existence
76 RegisteredApplication() { (void)starter_; }
80 typename RegisteredApplication<T>::Starter RegisteredApplication<T>::starter_;