Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Command Class Reference

The Command class builds the syntactic template for a specific command defined in a CommandParams struct. More...

#include <command.h>

Public Member Functions

 Command ()
 Command default constructor. More...
 
 Command (const CommandParams &cmdParams, const std::shared_ptr< Syntax > syntax, const std::unordered_map< std::string, std::shared_ptr< CommandOptions >> &options)
 Command constructor. More...
 
void generateCommand (const Parameter::ParameterMap &inputParams, std::string &out)
 Generates a command string from the internal template given all necessary parameter values. More...
 
void generateCommand (const Parameter::ParameterMap &inputParams, const std::vector< std::string > &options, std::string &out)
 Generates a command string from the internal template given all necessary parameter values and options. This method is able to take an options list as an additional argument to modify its internal command template. More...
 
const std::string & getName () const
 Getter for the unique name attribute. More...
 
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. More...
 
const bool verifyResponse (const Parameter::ParameterMap &inputParams, const std::vector< std::string > &options, const std::string &responseOrig, Parameter::ParameterMap &outputParams)
 Verifies a given response based on the internal template given all necessary input parameter values and options. This method is able to take an options list as an additional argument to verify a modified command template. More...
 

Private Types

typedef void(Command::* insertInstruction) (const int &, const Parameter::ParameterMap &, std::string &out)
 Command template building function pointer type. More...
 

Private Member Functions

void insertCmdKeyword (const int &index, const Parameter::ParameterMap &input, std::string &out)
 Command template building function for a keyword token. More...
 
void insertCmdParameter (const int &index, const Parameter::ParameterMap &input, std::string &out)
 Command template building function for a parameter token. More...
 

Private Attributes

bool cmdHasParams
 
bool cmdHasResponse
 
std::vector< std::string > cmdKeyWords
 
std::vector< std::string > cmdParameter
 
std::unordered_set< std::string > cmdParameterSet
 
std::vector< std::pair< int, insertInstruction > > commandTemplate
 
std::string name
 
std::unordered_map< std::string, std::shared_ptr< CommandOptions > > options
 
std::unordered_map< std::string, std::string > parameterTypes
 
bool respHasParams
 
std::vector< std::pair< std::string, bool > > responseTemplate
 
std::string simpleResponse
 
std::shared_ptr< Syntaxsyntax
 

Detailed Description

The Command class builds the syntactic template for a specific command defined in a CommandParams struct.

A Command object builds its command message given the required parameter values. It can also verfy if a given response is valid, given the input parameters of the previously sent command.

If a non empty CommandOptions list was given on initilization, a command object can change its command template based on required options.

Definition at line 90 of file command.h.

Member Typedef Documentation

void(Command::* Command::insertInstruction)(const int &, const Parameter::ParameterMap &, std::string &out)
private

Command template building function pointer type.

Parameters
[in]indexIndex of the token in a cmdToken list.
[in]inputPointer to a ParameterMap object.
[out]outOutput string, containing the requested token.

Definition at line 101 of file command.h.

Constructor & Destructor Documentation

Command::Command ( )

Command default constructor.

Definition at line 9 of file command.cpp.

Command::Command ( const CommandParams cmdParams,
const std::shared_ptr< Syntax syntax,
const std::unordered_map< std::string, std::shared_ptr< CommandOptions >> &  options 
)

Command constructor.

Parameters
[in]cmdParamsCommandParams struct that is used to configure a Command object.
[in]cmdResponsePrefixMarks the beginning of a response.
[in]optionsMap of possible options, that may modify this command. (first: name, second: CommandOptions)
[in]optionsPrefixMarks the appearance of an option within a command template.
Exceptions
std::exception

Definition at line 11 of file command.cpp.

Member Function Documentation

void Command::generateCommand ( const Parameter::ParameterMap inputParams,
std::string &  out 
)

Generates a command string from the internal template given all necessary parameter values.

Parameters
[in]inputParamsInput parameter map, containing all necessary parameter values and types to create a command.
[out]outGenerated command string.
Exceptions
std::exception

Definition at line 88 of file command.cpp.

void Command::generateCommand ( const Parameter::ParameterMap inputParams,
const std::vector< std::string > &  options,
std::string &  out 
)

Generates a command string from the internal template given all necessary parameter values and options. This method is able to take an options list as an additional argument to modify its internal command template.

Parameters
[in]inputParamsInput parameter map, containing all necessary parameter values and types to create a command, including parameter values required by given options.
[in]optionsList of options, to be applied to a command.
[out]outGenerated command string.
Exceptions
std::exception

Definition at line 102 of file command.cpp.

const std::string & Command::getName ( ) const

Getter for the unique name attribute.

Returns
name attribute value

Definition at line 373 of file command.cpp.

void Command::insertCmdKeyword ( const int &  index,
const Parameter::ParameterMap input,
std::string &  out 
)
private

Command template building function for a keyword token.

Parameters
[in]indexIndex of the keyword in the cmdKeyWords list.
[in]inputPointer to a ParameterMap object, unused in this function.
[out]outOutput string, containing the keyword.

Definition at line 375 of file command.cpp.

void Command::insertCmdParameter ( const int &  index,
const Parameter::ParameterMap input,
std::string &  out 
)
private

Command template building function for a parameter token.

Parameters
[in]indexIndex of the parameter in the cmdParameter list.
[in]inputPointer to a ParameterMap object, used to get the required parameter value.
[out]outOutput string, containing the parameter value as string.

Definition at line 386 of file command.cpp.

const bool Command::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.

Parameters
[in]inputParamsInput parameter map, containing all necessary parameter values and types to verify a response.
[in]responseOrigResponse on command to be verified.
[out]outputParamsIf the command requested returned parameters, those will be put here.
Returns
true if response is valid, else false.
Exceptions
std::exception

Definition at line 134 of file command.cpp.

const bool Command::verifyResponse ( const Parameter::ParameterMap inputParams,
const std::vector< std::string > &  options,
const std::string &  responseOrig,
Parameter::ParameterMap outputParams 
)

Verifies a given response based on the internal template given all necessary input parameter values and options. This method is able to take an options list as an additional argument to verify a modified command template.

Parameters
[in]inputParamsInput parameter map, containing all necessary parameter values and types to verify a response, including parameter values required by given options.
[in]optionsList of options, which have been applied to a command.
[in]responseOrigResponse on command to be verified.
[out]outputParamsIf the command or command options requested returned parameters, those will be put here.
Returns
true if response is valid, else false.
Exceptions
std::exception

Definition at line 208 of file command.cpp.

Member Data Documentation

bool Command::cmdHasParams
private

Does this Command have dynamic parameters?

Definition at line 193 of file command.h.

bool Command::cmdHasResponse
private

Does this Command trigger a response?

Definition at line 194 of file command.h.

std::vector<std::string> Command::cmdKeyWords
private

List of command key words, ordered by appearance in the template.)

Definition at line 206 of file command.h.

std::vector<std::string> Command::cmdParameter
private

List of command parameters, ordered by appearance in the template.)

Definition at line 208 of file command.h.

std::unordered_set<std::string> Command::cmdParameterSet
private

Set of possible command parameters)

Definition at line 204 of file command.h.

std::vector<std::pair<int, insertInstruction> > Command::commandTemplate
private

Command building template (first: appearance index, second: building function))

Definition at line 212 of file command.h.

std::string Command::name
private

Unique identifier of a Command object.

Definition at line 192 of file command.h.

std::unordered_map<std::string, std::shared_ptr<CommandOptions> > Command::options
private

Map of possible options, that may modify this command. (first: name, second: CommandOptions)

Definition at line 197 of file command.h.

std::unordered_map<std::string, std::string> Command::parameterTypes
private

Map of possible parameters, that may appear in this command. (first: name, second: type)

Definition at line 200 of file command.h.

bool Command::respHasParams
private

Does the response have dynamic parameters?

Definition at line 195 of file command.h.

std::vector<std::pair<std::string, bool> > Command::responseTemplate
private

Response validation template: first: contains a keyWord if second:=false, else first contains paramName

Definition at line 220 of file command.h.

std::string Command::simpleResponse
private

Static part of the response.

Definition at line 217 of file command.h.

std::shared_ptr<Syntax> Command::syntax
private

Pointer to a Syntax object

Definition at line 196 of file command.h.


The documentation for this class was generated from the following files:


pses_ucbridge
Author(s): Sebastian Ehmes
autogenerated on Sat Oct 28 2017 19:16:13