thin-provisioning-tools/base/application.h

73 lines
1.3 KiB
C
Raw Normal View History

2014-08-27 18:31:31 +05:30
#ifndef BASE_APPLICATION_H
#define BASE_APPLICATION_H
#include <boost/shared_ptr.hpp>
2014-08-27 18:31:31 +05:30
#include <iostream>
#include <list>
#include <string>
#include <stdexcept>
#include <stdint.h>
2014-08-27 18:31:31 +05:30
//----------------------------------------------------------------
namespace base {
class command {
public:
typedef boost::shared_ptr<command> ptr;
command(std::string const &name);
virtual ~command() {}
void die(std::string const &msg);
uint64_t parse_uint64(std::string const &str, std::string const &desc);
2014-08-27 18:31:31 +05:30
virtual void usage(std::ostream &out) const = 0;
virtual int run(int argc, char **argv) = 0;
2014-08-27 18:31:31 +05:30
std::string const &get_name() const {
return name_;
}
private:
std::string name_;
};
class command_old : public command {
public:
typedef int (*cmd_fn)(int, char **);
command_old(std::string const &name, cmd_fn fn)
: command(name),
fn_(fn) {
}
2014-08-27 18:31:31 +05:30
int run(int argc, char **argv) const {
return fn_(argc, argv);
}
private:
cmd_fn fn_;
};
class application {
public:
void add_cmd(command::ptr c) {
cmds_.push_back(c);
2014-08-27 18:31:31 +05:30
}
int run(int argc, char **argv);
private:
void usage();
std::string get_basename(std::string const &path) const;
2014-08-27 18:31:31 +05:30
std::list<command::ptr> cmds_;
2014-08-27 18:31:31 +05:30
};
}
//----------------------------------------------------------------
#endif