12 const std::unordered_map<std::string,
13 std::shared_ptr<CommandOptions>>&
options)
24 for (std::pair<std::string, std::string> param : cmdParams.
params)
35 std::vector<std::string> split;
36 boost::split(split, cmdParams.
cmd, boost::is_any_of(
" "));
37 int keyWordCounter = 0;
39 for (std::string s : split)
41 if (s.find(
'$') != std::string::npos)
45 std::string param = s.substr(1, std::string::npos);
46 cmdParameter.push_back(param);
47 cmdParameterSet.insert(param);
54 cmdKeyWords.push_back(s);
68 std::vector<std::string> split2;
69 boost::split(split2, cmdParams.
response, boost::is_any_of(
" "));
72 for (std::string s : split2)
74 if (s.find(
'$') != std::string::npos)
76 std::string param = s.substr(1, std::string::npos);
91 std::stringstream ss = std::stringstream();
96 (this->*component.second)(component.first, inputParams, s);
99 out = ss.str().substr(1, std::string::npos);
103 const std::vector<std::string>& optionsList,
106 std::string cmd =
"";
108 std::stringstream ss = std::stringstream();
110 for (std::string s : optionsList)
113 if(cmdopt.
opt.size()<1)
break;
114 std::vector<std::string> split;
115 boost::split(split, cmdopt.
opt, boost::is_any_of(
" ="));
116 for (std::string s1 : split)
120 std::string value =
"";
127 ss <<
" " <<
syntax->optionsPrefix << s1;
135 const std::string& responseOrig,
139 std::string response = responseOrig;
140 response.erase(boost::remove_if(response, boost::is_any_of(
syntax->answerOnCmdPrefix +
143 boost::trim(response);
155 std::vector<std::string> split;
156 boost::split(split, response, boost::is_any_of(
" ="));
161 for (
int i = 0; i < split.size(); i++)
173 std::string expectedValue =
"";
176 if (split[i].compare(expectedValue) != 0)
184 std::stringstream ss = std::stringstream();
185 for(
int n = i; n<split.size(); n++){
188 std::string out = ss.str().substr(1,std::string::npos);
200 if (split[i].compare(param) != 0)
209 const std::vector<std::string>&
options,
210 const std::string& responseOrig,
214 std::string response = responseOrig;
216 boost::remove_if(response, boost::is_any_of(
syntax->answerOnCmdPrefix)),
218 boost::trim(response);
225 std::vector<std::shared_ptr<CommandOptions>> optWithResponse = std::vector<std::shared_ptr<CommandOptions>>();
226 for (std::string opt : options)
228 if (this->options[opt]->optReturnsParams)
231 optWithResponse.push_back(this->options[opt]);
234 std::vector<std::string> split;
243 std::string restResponse =
245 boost::split(split, restResponse, boost::is_any_of(
" "));
251 boost::split(split, response, boost::is_any_of(
" "));
252 for (
int i = 0; i < split.size(); i++)
267 std::string expectedValue =
"";
270 if (split[i].compare(expectedValue) != 0)
282 if (split[i].compare(param) != 0)
288 for (std::shared_ptr<CommandOptions> opt : optWithResponse)
291 if (splitIndex >= split.size())
294 std::vector<std::string> optionSplit;
295 boost::split(optionSplit, opt->response, boost::is_any_of(
" "));
296 for (std::string s : optionSplit)
299 if (splitIndex >= split.size())
302 int dollarIdx = s.find(
'$');
303 int assignIdx = s.find(
'=');
304 if (dollarIdx != std::string::npos && dollarIdx == 0)
307 std::string param = s.substr(1, std::string::npos);
309 std::string paramType =
"";
310 for(
auto params : opt->params){
311 if(params.first.compare(param)==0){
312 paramType = params.second;
316 if(paramType.size()<1)
return false;
317 if(paramType.compare(
"string_t")==0){
318 std::stringstream ss = std::stringstream();
319 for(
int n = splitIndex; n<split.size(); n++){
322 std::string out = ss.str().substr(1,std::string::npos);
329 std::string paramValue =
"";
331 if (split[splitIndex].compare(paramValue) != 0)
340 else if(dollarIdx!=std::string::npos && assignIdx!=std::string::npos){
341 std::vector<std::string> asignSplit;
342 boost::split(asignSplit, s, boost::is_any_of(
"="));
343 if(split[splitIndex].find(
'=')==std::string::npos)
return false;
344 std::vector<std::string> responseSplit;
345 boost::split(responseSplit, split[splitIndex], boost::is_any_of(
"="));
347 if(asignSplit.size()!=2)
return false;
348 if(responseSplit.size()!=2)
return false;
349 std::string optParam = asignSplit[1].substr(1, std::string::npos);
350 std::string optKey = asignSplit[0].substr(0, std::string::npos);
351 std::string respParam = responseSplit[1].substr(0, std::string::npos);
352 std::string respKey = responseSplit[0].substr(0, std::string::npos);
353 if(optKey.compare(respKey)!=0)
return false;
354 std::string optParamValue;
357 if(respParam.compare(optParamValue)!=0)
return false;
363 if (s.compare(split[splitIndex]) != 0)
380 throw std::out_of_range(
"Command keyword index out of bounds! Size: " +
382 std::to_string(index));
391 throw std::out_of_range(
"Command parameter index out of bounds! Size: " +
393 std::to_string(index));
396 throw std::out_of_range(
"Command parameter" + param +
"not in map.");
std::vector< std::string > cmdKeyWords
std::vector< std::string > cmdParameter
Header file for the Command class.
Command()
Command default constructor.
std::unordered_set< std::string > cmdParameterSet
void getParameterValueAsString(const std::string &name, std::string &out) const
Get the string representation of a value from a parameter in this map with the given name...
The Parameter::ParameterMap class provides a map functionality for Parameter::Parameter objects conta...
const bool isParamInMap(const std::string &name) const
Is a parameter with the given name contained within this map?.
void insertCmdKeyword(const int &index, const Parameter::ParameterMap &input, std::string &out)
Command template building function for a keyword token.
const bool verifyResponse(const Parameter::ParameterMap &inputParams, const std::string &responseOrig, Parameter::ParameterMap &outputParams)
Verifies a given response based on the internal template given all necessary input parameter values...
The CommandOptions class serves as a data struct to inform Command objects about all modifiers that c...
std::string simpleResponse
std::unordered_map< std::string, std::string > parameterTypes
std::unordered_map< std::string, std::shared_ptr< CommandOptions > > options
std::vector< std::pair< int, insertInstruction > > commandTemplate
void insertParameter(const std::string &name, const std::string &type, const T &value, const bool isValid=true)
Insert a new parameter in this map, with the given name, type and value.
std::vector< std::pair< std::string, bool > > responseTemplate
std::shared_ptr< Syntax > syntax
std::vector< std::pair< std::string, std::string > > params
void setParameterValueAsString(const std::string &name, const std::string &input, const bool isValid=true)
Set the value of a parameter in this map with the given name from a string.
The CommandParams class serves as a data struct to configure Command objects.
void insertCmdParameter(const int &index, const Parameter::ParameterMap &input, std::string &out)
Command template building function for a parameter token.
const std::string & getName() const
Getter for the unique name attribute.
void generateCommand(const Parameter::ParameterMap &inputParams, std::string &out)
Generates a command string from the internal template given all necessary parameter values...