1 #ifndef MSP_CORE_APPLICATION_H_
2 #define MSP_CORE_APPLICATION_H_
9 Base class for applications. See also RegisteredApplication.
19 virtual ~Starter() { }
21 virtual Application *create_app(int, char **) = 0;
28 static Starter *starter_;
29 static Application *app_;
32 Application(const Application &);
33 Application &operator=(const Application &);
37 virtual ~Application() { }
39 /** Constructs an instance of the registered application class and runs it.
40 If the application throws a usage_error, a help message is printed. The
41 GetOpt class will throw such exceptions automatically in error conditions.
43 This function can only be called once. The global main() function provided
44 by the library normally does it automatically at program startup. */
45 static int run(int, char **, void * =0);
47 static void *get_data() { return data_; }
50 /** Default main loop. Calls tick() repeatedly until exit() is called. A
51 custom main loop should monitor the done member variable and return
55 /** Sets the specified signal to be delivered to the sighandler member
57 void catch_signal(int);
59 /** Causes the application to exit gracefully with the given exit code. */
62 virtual void tick() { }
63 virtual void sighandler(int) { }
66 /** Static wrapper function to call a member function of the Application
68 static void sighandler_(int);
73 Registers the class to be used for program startup. The main application class
74 should be derived from this.
77 class RegisteredApplication: public Application
80 class Starter: public Application::Starter
83 Application *create_app(int argc, char **argv) { return new T(argc, argv); }
86 static Starter starter_;
89 // Force the starter into existence
90 RegisteredApplication() { (void)starter_; }
94 typename RegisteredApplication<T>::Starter RegisteredApplication<T>::starter_;