Skip to content

Commit

Permalink
Removed duplicated sendCommand templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
branoholy committed Jun 10, 2016
1 parent cb8455f commit 1bcee5f
Showing 1 changed file with 9 additions and 40 deletions.
49 changes: 9 additions & 40 deletions include/regilo/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,20 @@ class StreamController : public virtual IController

virtual std::string sendCommand(const std::string& command) final override;

/**
* @brief Send a command to the device and keep the response in the buffer.
* @param command A commmand with all parameters.
*/
template<typename Response = void, typename Command, typename std::enable_if<std::is_void<Response>::value, Response>::type* = nullptr>
void sendCommand(const Command& command);

/**
* @brief Send a command to the device and keep the response in the buffer.
* @param command A commmand without parameters.
* @param params Parameters that will be inserted into the command (separated by space).
*/
template<typename Response = void, typename Command, typename... Args, typename std::enable_if<std::is_void<Response>::value, Response>::type* = nullptr>
void sendCommand(const Command& command, const Args& ... params);

/**
* @brief Send a command to the device.
* @param command A commmand with all parameters.
* @return A response to the command.
*/
template<typename Response, typename Command, typename std::enable_if<!std::is_void<Response>::value, Response>::type* = nullptr>
template<typename Response = void, typename Command>
Response sendCommand(const Command& command);

/**
* @brief Send a command to the device.
* @param command A commmand without parameters.
* @return Parameters that will be inserted into the command (separated by space).
*/
template<typename Response, typename Command, typename... Args, typename std::enable_if<!std::is_void<Response>::value, Response>::type* = nullptr>
template<typename Response = void, typename Command, typename... Args>
Response sendCommand(const Command& command, const Args& ... params);

/**
Expand All @@ -197,8 +182,8 @@ class StreamController : public virtual IController
* @param params Parameters that will be inserted into the command.
* @return A response to the command.
*/
template<typename... Args>
std::string sendFormattedCommand(const std::string& commandFormat, Args... params);
template<typename Response = void, typename... Args>
Response sendFormattedCommand(const std::string& commandFormat, Args... params);

/**
* @brief Create a command with the specified parameters (printf formatting is used).
Expand Down Expand Up @@ -253,42 +238,26 @@ std::string StreamController<StreamT>::sendCommand(const std::string& command)
}

template<typename StreamT>
template<typename Response, typename Command, typename std::enable_if<std::is_void<Response>::value, Response>::type*>
void StreamController<StreamT>::sendCommand(const Command& command)
{
deviceInput << command;
sendCommand();
}

template<typename StreamT>
template<typename Response, typename Command, typename... Args, typename std::enable_if<std::is_void<Response>::value, Response>::type*>
void StreamController<StreamT>::sendCommand(const Command& command, const Args& ... params)
{
deviceInput << command << ' ';
sendCommand(params...);
}

template<typename StreamT>
template<typename Response, typename Command, typename std::enable_if<!std::is_void<Response>::value, Response>::type*>
template<typename Response, typename Command>
Response StreamController<StreamT>::sendCommand(const Command& command)
{
deviceInput << command;
return sendCommand<Response>();
}

template<typename StreamT>
template<typename Response, typename Command, typename... Args, typename std::enable_if<!std::is_void<Response>::value, Response>::type*>
template<typename Response, typename Command, typename... Args>
Response StreamController<StreamT>::sendCommand(const Command& command, const Args& ... params)
{
deviceInput << command << ' ';
return sendCommand<Response>(params...);
}

template<typename StreamT>
template<typename... Args>
std::string StreamController<StreamT>::sendFormattedCommand(const std::string& commandFormat, Args... params)
template<typename Response, typename... Args>
Response StreamController<StreamT>::sendFormattedCommand(const std::string& commandFormat, Args... params)
{
return sendCommand(createFormattedCommand(commandFormat, params...));
return sendCommand<Response>(createFormattedCommand(commandFormat, params...));
}

template<typename StreamT>
Expand Down

0 comments on commit 1bcee5f

Please sign in to comment.