aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/client
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-01-13 08:39:02 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-01-13 08:42:08 +0300
commit6913c6d965d64481ed09fc06a43154f35e8bd914 (patch)
treefa8d3f360a651a31fba4b91a09a5bba505a904c4 /client
parentTravis: only run clang-format on master (diff)
downloadmath-server-6913c6d965d64481ed09fc06a43154f35e8bd914.tar.gz
math-server-6913c6d965d64481ed09fc06a43154f35e8bd914.zip
clang-format all the code
Diffstat (limited to 'client')
-rw-r--r--client/client.hpp16
-rw-r--r--client/error.hpp6
-rw-r--r--client/input.hpp28
-rw-r--r--client/settings.hpp53
-rw-r--r--client/transport.hpp20
5 files changed, 43 insertions, 80 deletions
diff --git a/client/client.hpp b/client/client.hpp
index 2f917c1..3d68157 100644
--- a/client/client.hpp
+++ b/client/client.hpp
@@ -18,19 +18,15 @@ namespace math::client {
class Client {
public:
explicit Client(const Settings& settings)
- : Client{make_input_reader(settings), make_transport(settings)}
- { }
+ : Client{make_input_reader(settings), make_transport(settings)} {}
Client(input::ReaderPtr&& input_reader, TransportPtr&& transport)
- : m_input_reader{std::move(input_reader)}
- , m_transport{std::move(transport)}
- { }
+ : m_input_reader{std::move(input_reader)}, m_transport{std::move(transport)} {}
void run() {
- m_input_reader->for_each_input([this] (const std::string& input) {
- m_transport->send_query(input, [] (const std::string& reply) {
- std::cout << reply << '\n';
- });
+ m_input_reader->for_each_input([this](const std::string& input) {
+ m_transport->send_query(input,
+ [](const std::string& reply) { std::cout << reply << '\n'; });
return true;
});
}
@@ -54,4 +50,4 @@ private:
TransportPtr m_transport;
};
-}
+} // namespace math::client
diff --git a/client/error.hpp b/client/error.hpp
index 2ae0075..b8a7b35 100644
--- a/client/error.hpp
+++ b/client/error.hpp
@@ -12,9 +12,7 @@ namespace math::client {
class Error : public std::runtime_error {
public:
- explicit Error(const std::string& what)
- : std::runtime_error{"client error: " + what}
- { }
+ explicit Error(const std::string& what) : std::runtime_error{"client error: " + what} {}
};
-}
+} // namespace math::client
diff --git a/client/input.hpp b/client/input.hpp
index 9c22b03..0295f3b 100644
--- a/client/input.hpp
+++ b/client/input.hpp
@@ -19,14 +19,12 @@ namespace math::client::input {
class Error : public client::Error {
public:
- explicit Error(const std::string& what)
- : client::Error{"input error: " + what} {
- }
+ explicit Error(const std::string& what) : client::Error{"input error: " + what} {}
};
class Reader {
public:
- using InputHandler = std::function<bool (const std::string&)>;
+ using InputHandler = std::function<bool(const std::string&)>;
virtual ~Reader() = default;
@@ -37,13 +35,9 @@ using ReaderPtr = std::unique_ptr<input::Reader>;
class FileReader : public Reader {
public:
- explicit FileReader(const std::string& path)
- : m_path{path}
- { }
+ explicit FileReader(const std::string& path) : m_path{path} {}
- bool for_each_input(const InputHandler& process) const override {
- return enum_lines(process);
- }
+ bool for_each_input(const InputHandler& process) const override { return enum_lines(process); }
private:
bool enum_lines(const InputHandler& process) const {
@@ -73,9 +67,7 @@ private:
class MultiFileReader : public Reader {
public:
- explicit MultiFileReader(const std::vector<std::string>& paths)
- : m_paths{paths}
- { }
+ explicit MultiFileReader(const std::vector<std::string>& paths) : m_paths{paths} {}
bool for_each_input(const InputHandler& process) const override {
for (const auto& path : m_paths) {
@@ -101,13 +93,9 @@ inline input::ReaderPtr make_file_reader(const std::vector<std::string>& paths)
class StringReader : public Reader {
public:
- explicit StringReader(const std::string& input)
- : m_input{input}
- { }
+ explicit StringReader(const std::string& input) : m_input{input} {}
- bool for_each_input(const InputHandler& process) const override {
- return process(m_input);
- }
+ bool for_each_input(const InputHandler& process) const override { return process(m_input); }
private:
const std::string m_input;
@@ -141,4 +129,4 @@ inline input::ReaderPtr make_console_reader() {
return std::make_unique<input::ConsoleReader>();
}
-}
+} // namespace math::client::input
diff --git a/client/settings.hpp b/client/settings.hpp
index 2e72dba..8c26a56 100644
--- a/client/settings.hpp
+++ b/client/settings.hpp
@@ -25,42 +25,30 @@ struct Settings {
bool exit_with_usage() const { return m_vm.count("help"); }
- bool input_from_string() const {
- return m_vm.count("command");
- }
+ bool input_from_string() const { return m_vm.count("command"); }
- bool input_from_files() const {
- return !input_from_string() && !m_files.empty();
- }
+ bool input_from_files() const { return !input_from_string() && !m_files.empty(); }
- bool input_from_console() const {
- return !input_from_string() && !input_from_files();
- }
+ bool input_from_console() const { return !input_from_string() && !input_from_files(); }
boost::program_options::variables_map m_vm;
};
class SettingsParser {
public:
- explicit SettingsParser(const std::string& argv0)
- : m_prog_name{extract_filename(argv0)}
- {
+ explicit SettingsParser(const std::string& argv0) : m_prog_name{extract_filename(argv0)} {
m_visible.add_options()("help,h", "show this message and exit");
+ m_visible.add_options()("command,c", boost::program_options::value(&m_settings.m_input),
+ "evaluate the argument expression and exit");
m_visible.add_options()(
- "command,c",
- boost::program_options::value(&m_settings.m_input),
- "evaluate the argument expression and exit");
- m_visible.add_options()(
- "host,H",
- boost::program_options::value(&m_settings.m_host)->default_value("localhost"),
+ "host,H", boost::program_options::value(&m_settings.m_host)->default_value("localhost"),
"server host address");
- m_visible.add_options()(
- "port,p",
- boost::program_options::value(&m_settings.m_port)->default_value(NetworkTransport::DEFAULT_PORT),
- "server port number");
+ m_visible.add_options()("port,p",
+ boost::program_options::value(&m_settings.m_port)
+ ->default_value(NetworkTransport::DEFAULT_PORT),
+ "server port number");
m_hidden.add_options()(
- "files",
- boost::program_options::value<std::vector<std::string>>(&m_settings.m_files),
+ "files", boost::program_options::value<std::vector<std::string>>(&m_settings.m_files),
"shouldn't be visible");
m_positional.add("files", -1);
}
@@ -72,12 +60,11 @@ public:
Settings parse(int argc, char* argv[]) {
boost::program_options::options_description all;
all.add(m_hidden).add(m_visible);
- boost::program_options::store(
- boost::program_options::command_line_parser{argc, argv}
- .options(all)
- .positional(m_positional)
- .run(),
- m_settings.m_vm);
+ boost::program_options::store(boost::program_options::command_line_parser{argc, argv}
+ .options(all)
+ .positional(m_positional)
+ .run(),
+ m_settings.m_vm);
if (m_settings.exit_with_usage()) {
return m_settings;
}
@@ -85,9 +72,7 @@ public:
return m_settings;
}
- void usage() const {
- std::cout << *this;
- }
+ void usage() const { std::cout << *this; }
void usage_error(const std::exception& e) const {
std::cerr << "usage error: " << e.what() << '\n';
@@ -114,4 +99,4 @@ private:
}
};
-}
+} // namespace math::client
diff --git a/client/transport.hpp b/client/transport.hpp
index 04e6c4b..dbb142f 100644
--- a/client/transport.hpp
+++ b/client/transport.hpp
@@ -19,18 +19,16 @@ namespace transport {
class Error : public client::Error {
public:
- explicit Error(const std::string& msg)
- : client::Error{"transport error: " + msg}
- { }
+ explicit Error(const std::string& msg) : client::Error{"transport error: " + msg} {}
};
-}
+} // namespace transport
class Transport {
public:
virtual ~Transport() = default;
- using ProcessResult = std::function<void (const std::string&)>;
+ using ProcessResult = std::function<void(const std::string&)>;
virtual void send_query(const std::string&, const ProcessResult&) = 0;
};
@@ -42,8 +40,7 @@ public:
static constexpr auto DEFAULT_PORT = "18000";
NetworkTransport(const std::string& host, const std::string& port)
- : m_host{host}, m_port{port}
- { }
+ : m_host{host}, m_port{port} {}
protected:
const std::string m_host;
@@ -52,7 +49,7 @@ protected:
class BlockingNetworkTransport : public NetworkTransport {
public:
- BlockingNetworkTransport(const std::string &host, const std::string& port)
+ BlockingNetworkTransport(const std::string& host, const std::string& port)
: NetworkTransport{host, port}, m_socket{m_io_context} {
try {
connect();
@@ -100,10 +97,9 @@ private:
boost::asio::streambuf m_buffer;
};
-inline TransportPtr make_blocking_network_transport(
- const std::string& host, const std::string& port) {
-
+inline TransportPtr make_blocking_network_transport(const std::string& host,
+ const std::string& port) {
return std::make_unique<BlockingNetworkTransport>(host, port);
}
-}
+} // namespace math::client