Refactor command lookup so that generated commands can automatically be added

This commit is contained in:
Joe Ferris 2011-02-24 23:48:18 -05:00
parent d84f5c9a2e
commit 9f41e030f5
4 changed files with 20 additions and 13 deletions

View File

@ -26,6 +26,10 @@ task :generate_command do
project.gsub!(/(SOURCES = .*)/, "\\1 #{name}.cpp")
File.open(project_file_name, "w") { |file| file.write(project) }
end
File.open("src/find_command.h", "a") do |file|
file.write("CHECK_COMMAND(#{name})")
end
end
desc "Generate a Makefile using qmake"

View File

@ -8,15 +8,15 @@ class Capybara::Driver::Webkit
end
def visit(url)
command "visit", url
command "Visit", url
end
def find(query)
command("find", query).split(",")
command("Find", query).split(",")
end
def reset!
command("reset")
command("Reset")
end
private

View File

@ -47,16 +47,10 @@ void Connection::readNext() {
}
Command *Connection::startCommand(const char *name) {
if (strcmp(name, "visit") == 0) {
return new Visit(m_page, this);
} else if (strcmp(name, "find") == 0) {
return new Find(m_page, this);
} else if (strcmp(name, "reset") == 0) {
return new Reset(m_page, this);
} else {
std::cout << ">> Unknown command" << std::endl;
return NULL;
}
#include "find_command.h"
std::cout << ">> Unknown command" << std::endl;
return NULL;
}
void Connection::finishCommand(bool success, QString &response) {

9
src/find_command.h Normal file
View File

@ -0,0 +1,9 @@
#define CHECK_COMMAND(expectedName) \
if (strcmp(#expectedName, name) == 0) { \
return new expectedName(m_page, this); \
}
CHECK_COMMAND(Visit)
CHECK_COMMAND(Find)
CHECK_COMMAND(Reset)