82 lines
2 KiB
C++
82 lines
2 KiB
C++
#ifndef COMMAND_H
|
|
#define COMMAND_H
|
|
#include <string>
|
|
#include <vector>
|
|
//#include "shell.h"
|
|
#include "option.h"
|
|
#include "commandexecutor.h"
|
|
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
namespace mshconsole{
|
|
class Command
|
|
{
|
|
class OptionNotParsedCorrectlyException {
|
|
string optarg;
|
|
public:
|
|
OptionNotParsedCorrectlyException(const string& s) : optarg(s) {}
|
|
string getOptarg(){
|
|
return optarg;
|
|
}
|
|
};
|
|
|
|
class CommandNameNotValidException {};
|
|
class NotRightArgException {};
|
|
const string name;
|
|
void checkObj();
|
|
vector<Option*> longOpts;
|
|
vector<Option*> shortOpts;
|
|
|
|
public:
|
|
class Data{
|
|
public:
|
|
enum States{
|
|
STRING=4,
|
|
TRUE=2,
|
|
FALSE=1
|
|
};
|
|
class MultipleDefinitionException{};
|
|
|
|
private:
|
|
string sData;
|
|
const Option* of;
|
|
enum States state;
|
|
static const string EMPTY;
|
|
bool isSDataValorized;
|
|
Data(const Option* o) : sData(), state(Data::FALSE), isSDataValorized(false), of(o) {}
|
|
|
|
public:
|
|
void set(bool b);
|
|
void set(const string& s);
|
|
enum States getState() const;
|
|
const string& getData() const;
|
|
bool getBoolState() const;
|
|
friend class Command;
|
|
friend class Datas;
|
|
};
|
|
|
|
class Datas : public vector<Data*>{
|
|
public:
|
|
Data* getOptData(const string& optionName) const;
|
|
};
|
|
|
|
Command(const string& n, int (*funcptr)(CommandExecutor* whoExecuted,const Datas& data, const vector<char*> argv));
|
|
Command(const Command&);
|
|
~Command();
|
|
string getName();
|
|
int execute(const vector<string>*, CommandExecutor*);
|
|
void addOption(Option* a);
|
|
|
|
private:
|
|
int (*funcCommand)(CommandExecutor* whoExecuted,const Datas& data, const vector<char*> argv);
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // COMMAND_H
|