2016-03-12 17:58:01 +00:00
|
|
|
#include "shell.h"
|
2016-03-11 14:49:24 +00:00
|
|
|
|
2016-03-13 16:16:34 +00:00
|
|
|
Command::Command(const string& n, int (*funcptr)(const vector<string>* args, CommandExecutor*)) : name(n) , funcCommand(funcptr){
|
2016-03-11 14:49:24 +00:00
|
|
|
checkObj();
|
|
|
|
numCom++;
|
|
|
|
}
|
|
|
|
|
2016-03-13 16:16:34 +00:00
|
|
|
int Command::execute(const vector<string>* args, CommandExecutor* ciao){
|
|
|
|
if(args==nullptr) return -1;
|
|
|
|
return (*funcCommand)(args, ciao);
|
2016-03-11 14:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string Command::getName(){
|
|
|
|
return this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command::Command(const Command& old) : name(old.name) , funcCommand(old.funcCommand){
|
|
|
|
checkObj();
|
|
|
|
numCom++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::checkObj(){
|
|
|
|
for(unsigned int i=0; i<name.length(); i++){
|
|
|
|
if(!((name[i]>'a'&&name[i]<'z')||(name[i]>'A'&&name[i]<'Z'))){
|
|
|
|
throw CommandNameNotValidException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command::~Command(){
|
|
|
|
numCom--;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Command::numCom = 0;
|