2014-08-27 18:31:31 +05:30
|
|
|
#ifndef BASE_APPLICATION_H
|
|
|
|
#define BASE_APPLICATION_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class command {
|
|
|
|
public:
|
|
|
|
typedef int (*cmd_fn)(int, char **);
|
|
|
|
|
|
|
|
command(std::string const &name, cmd_fn fn)
|
|
|
|
: name_(name),
|
|
|
|
fn_(fn) {
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string const &get_name() const {
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int run(int argc, char **argv) const {
|
|
|
|
return fn_(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string name_;
|
|
|
|
cmd_fn fn_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class application {
|
|
|
|
public:
|
|
|
|
void add_cmd(command const &c) {
|
|
|
|
cmds_.push_back(&c);
|
|
|
|
}
|
|
|
|
|
|
|
|
int run(int argc, char **argv);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void usage();
|
2015-01-16 16:18:19 +05:30
|
|
|
std::string get_basename(std::string const &path) const;
|
2014-08-27 18:31:31 +05:30
|
|
|
|
|
|
|
std::list<command const *> cmds_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|