5,530
社区成员
发帖
与我相关
我的任务
分享
class App
{
public:
App();
virtual ~App();
void go(int argc, char** argv);
protected:
virtual void parse_options(int argc, char** argv) = 0;
virtual void validate_options() = 0;
virtual void show_options() = 0;
virtual void execute() = 0;
}
void App::go(int argc, char** argv)
{
parse_options(argc, argv);
validate_options();
if (!OPT_quiet)
{
cout << endl
<< "#---------------------------------#" << endl
<< "#" << endl
<< "# Options:" << endl
<< "#" << endl;
show_options();
cout << "#" << endl
<< "#---------------------------------#" << endl
<< endl;
}
if (!OPT_quiet) cout << "start processing" << endl;
execute();
if (!OPT_quiet) cout << "done" << endl;
}
#define DECL_APP_CLASS(class_name) class class_name\
{\
public:\
static void parse_options(int argc, char** argv);\
static void validate_options();\
static void show_options();\
static void execute();\
}
// App.h
template <typename T>
void go(int argc, char** argv)
{
T::parse_options(argc, argv);
T::validate_options();
T::show_options();
T::run();
}