2016-03-16 20:15:24 +00:00
|
|
|
#ifndef COMMAND_H
|
|
|
|
#define COMMAND_H
|
2016-04-16 17:21:39 +00:00
|
|
|
#pragma once
|
2016-03-16 20:15:24 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-04-16 17:21:39 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
extern "C"{
|
|
|
|
#include <popt.h>
|
|
|
|
}
|
2016-03-16 20:15:24 +00:00
|
|
|
#include "commandexecutor.h"
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2016-03-18 17:48:16 +00:00
|
|
|
namespace mshconsole{
|
|
|
|
class Command
|
|
|
|
{
|
|
|
|
const string name;
|
|
|
|
void checkObj();
|
2016-04-16 17:21:39 +00:00
|
|
|
vector<poptOption> opts;
|
|
|
|
static const struct poptOption POPT_TERMINATOR;
|
|
|
|
size_t optionNum;
|
2016-03-16 20:15:24 +00:00
|
|
|
|
2016-03-18 17:48:16 +00:00
|
|
|
public:
|
2016-04-06 19:39:27 +00:00
|
|
|
class Data{
|
2016-04-02 14:28:03 +00:00
|
|
|
public:
|
2016-04-16 17:21:39 +00:00
|
|
|
union Arg{
|
|
|
|
int i;
|
|
|
|
char* s;
|
|
|
|
long l;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
};
|
|
|
|
enum Types{
|
|
|
|
STRING,
|
|
|
|
INT,
|
|
|
|
LONG,
|
|
|
|
FLOAT,
|
|
|
|
DOUBLE
|
2016-04-02 14:28:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2016-04-16 17:21:39 +00:00
|
|
|
union Arg d;
|
|
|
|
poptOption* of;
|
|
|
|
Data(poptOption* o) : of(o), d() {}
|
|
|
|
friend class mshconsole::Command;
|
2016-04-02 14:28:03 +00:00
|
|
|
|
|
|
|
public:
|
2016-04-16 17:21:39 +00:00
|
|
|
const union Arg& getArg() const;
|
|
|
|
enum Types getType() const;
|
|
|
|
int getInt() const;
|
|
|
|
char* getString() const;
|
|
|
|
long getLong() const;
|
|
|
|
float getFloat() const;
|
|
|
|
double getDouble() const;
|
2016-04-02 14:28:03 +00:00
|
|
|
};
|
|
|
|
|
2016-04-06 19:39:27 +00:00
|
|
|
class Datas : public vector<Data*>{
|
|
|
|
public:
|
|
|
|
Data* getOptData(const string& optionName) const;
|
2016-04-16 17:21:39 +00:00
|
|
|
Data* getOptData(char opt) const;
|
|
|
|
Data* operator[](const string& opt) const;
|
2016-04-06 19:39:27 +00:00
|
|
|
};
|
|
|
|
|
2016-04-16 17:21:39 +00:00
|
|
|
class DuplicatedOptionException{};
|
|
|
|
class CommandNameNotValidException{};
|
|
|
|
class InvalidOptionException{};
|
|
|
|
|
|
|
|
Command(const string& n, int (*funcptr)(CommandExecutor* whoExecuted,const Datas& data, const vector<const char*> argv));
|
2016-03-18 17:48:16 +00:00
|
|
|
Command(const Command&);
|
|
|
|
~Command();
|
2016-04-16 17:21:39 +00:00
|
|
|
const string& getName();
|
|
|
|
int execute(const struct Params&, CommandExecutor*);
|
|
|
|
void addOption(const poptOption& option);
|
2016-04-02 14:28:03 +00:00
|
|
|
|
|
|
|
private:
|
2016-04-16 17:21:39 +00:00
|
|
|
int (*funcCommand)(CommandExecutor* whoExecuted,const Datas& data, const vector<const char*> argv);
|
2016-03-18 17:48:16 +00:00
|
|
|
};
|
|
|
|
}
|
2016-04-02 14:28:03 +00:00
|
|
|
|
2016-03-16 20:15:24 +00:00
|
|
|
#endif // COMMAND_H
|