Skip to content

Commit 9daaecd

Browse files
committed
update files with new formatting
1 parent 84b8080 commit 9daaecd

17 files changed

Lines changed: 158 additions & 223 deletions

fuzz_test/fuzz_tester.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1+
#include <fmt/format.h>
12
#include <iterator>
23
#include <utility>
3-
#include <fmt/format.h>
44

55
[[nodiscard]] auto sum_values(const uint8_t *Data, size_t Size)
66
{
7-
constexpr auto scale = 1000;
7+
constexpr auto scale = 1000;
88

9-
int value = 0;
10-
for (std::size_t offset = 0; offset < Size; ++offset) {
11-
value += static_cast<int>(*std::next(Data, static_cast<long>(offset))) * scale;
12-
}
13-
return value;
9+
int value = 0;
10+
for (std::size_t offset = 0; offset < Size; ++offset) { value += static_cast<int>(*std::next(Data, static_cast<long>(offset))) * scale; }
11+
return value;
1412
}
1513

1614
// Fuzzer that attempts to invoke undefined behavior for signed integer overflow
1715
// cppcheck-suppress unusedFunction symbolName=LLVMFuzzerTestOneInput
1816
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
1917
{
20-
fmt::print("Value sum: {}, len{}\n", sum_values(Data,Size), Size);
21-
return 0;
18+
fmt::print("Value sum: {}, len{}\n", sum_values(Data, Size), Size);
19+
return 0;
2220
}

src/boost.beast/data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ struct person
88
{
99
std::string name;
1010
std::string address;
11-
int age = {0};
12-
int id = {0};
11+
int age = { 0 };
12+
int id = { 0 };
1313
};
1414

1515
inline void to_json(nlohmann::json &j, const person &p) { j = nlohmann::json{ { "name", p.name }, { "address", p.address }, { "age", p.age }, { "id", p.id } }; }

src/boost.beast/error_handling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
2+
#include <boost/asio/dispatch.hpp>
3+
#include <boost/asio/strand.hpp>
24
#include <boost/beast/core.hpp>
35
#include <boost/beast/http.hpp>
46
#include <boost/beast/version.hpp>
5-
#include <boost/asio/dispatch.hpp>
6-
#include <boost/asio/strand.hpp>
77
#include <fmt/format.h>
88

99
// from <boost/beast.hpp>

src/boost.beast/listener.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2-
#include "error_handling.h"
32
#include "data.h"
3+
#include "error_handling.h"
44
#include "session.h"
55

66
// Accepts incoming connections and launches the sessions
@@ -13,32 +13,28 @@ class Listener : public std::enable_shared_from_this<Listener>
1313

1414
// Open the acceptor
1515
m_acceptor.open(endpoint.protocol(), ec);
16-
if (ec)
17-
{
16+
if (ec) {
1817
fail(ec, "open");
1918
return;
2019
}
2120

2221
// Allow address reuse
2322
m_acceptor.set_option(asio::socket_base::reuse_address(true), ec);
24-
if (ec)
25-
{
23+
if (ec) {
2624
fail(ec, "set_option");
2725
return;
2826
}
2927

3028
// Bind to the server address
3129
m_acceptor.bind(endpoint, ec);
32-
if (ec)
33-
{
30+
if (ec) {
3431
fail(ec, "bind");
3532
return;
3633
}
3734

3835
// Start listening for connections
3936
m_acceptor.listen(asio::socket_base::max_listen_connections, ec);
40-
if (ec)
41-
{
37+
if (ec) {
4238
fail(ec, "listen");
4339
return;
4440
}
@@ -56,12 +52,9 @@ class Listener : public std::enable_shared_from_this<Listener>
5652

5753
void onAccept(beast::error_code ec, tcp::socket socket)
5854
{
59-
if (ec)
60-
{
55+
if (ec) {
6156
fail(ec, "accept");
62-
}
63-
else
64-
{
57+
} else {
6558
// Create the session and run it
6659
std::make_shared<Session>(std::move(socket), m_persons)->run();
6760
}

src/boost.beast/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
#include "listener.h"
12
#include <cstdlib>
23
#include <memory>
34
#include <thread>
45
#include <vector>
5-
#include "listener.h"
66

77

88
int main()
@@ -20,8 +20,7 @@ int main()
2020
// Run the I/O service on the requested number of threads
2121
std::vector<std::thread> v;
2222
v.reserve(threads);
23-
for (auto i = 0; i < threads; i++)
24-
{
23+
for (auto i = 0; i < threads; i++) {
2524
v.emplace_back([&ioc] { ioc.run(); });
2625
}
2726
ioc.run();

src/boost.beast/request.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ template<class Body, class Allocator, class Send> inline void handleRequest(http
2626
};
2727

2828
// Make sure we can handle the method
29-
switch (req.method())
30-
{
29+
switch (req.method()) {
3130
case http::verb::get: {
3231
// Respond to GET request
3332
nlohmann::json j = data;
3433
return send(std::move(createResponse(req, http::status::ok, j)));
3534
}
3635
case http::verb::put: {
37-
try
38-
{
36+
try {
3937
const auto j = nlohmann::json::parse(req.body());
4038
const data::person d = j;
41-
if (d.id > data.size() - 1 || d.id < 0)
42-
{
39+
if (d.id > data.size() - 1 || d.id < 0) {
4340
const nlohmann::json j = R"({"error": "id is larger than data list or negative"})";
4441
return send(std::move(createResponse(req, http::status::internal_server_error, j)));
4542
}
@@ -48,22 +45,17 @@ template<class Body, class Allocator, class Send> inline void handleRequest(http
4845
temp.address = d.address;
4946
temp.age = d.age;
5047
return send(std::move(createResponse(req, http::status::ok, j)));
51-
}
52-
catch (nlohmann::json::exception &e)
53-
{
48+
} catch (nlohmann::json::exception &e) {
5449
return send(std::move(badRequest(e.what())));
5550
}
5651
}
5752
case http::verb::post: {
58-
try
59-
{
53+
try {
6054
const auto j = nlohmann::json::parse(req.body());
6155
data.push_back(j);
6256
data.back().id = static_cast<int>(data.size());
6357
return send(std::move(createResponse(req, http::status::ok, j)));
64-
}
65-
catch (nlohmann::json::exception &e)
66-
{
58+
} catch (nlohmann::json::exception &e) {
6759
return send(std::move(badRequest(e.what())));
6860
}
6961
}

src/boost.beast/session.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,9 @@ class Session : public std::enable_shared_from_this<Session>
3737
boost::ignore_unused(bytes_transferred);
3838

3939
// This means they closed the connection
40-
if (ec == http::error::end_of_stream)
41-
{
42-
return doClose();
43-
}
40+
if (ec == http::error::end_of_stream) { return doClose(); }
4441

45-
if (ec)
46-
{
47-
return fail(ec, "read");
48-
}
42+
if (ec) { return fail(ec, "read"); }
4943

5044
// Send the response
5145
handleRequest(std::move(m_req), m_lambda, m_person);
@@ -55,13 +49,9 @@ class Session : public std::enable_shared_from_this<Session>
5549
{
5650
boost::ignore_unused(bytes_transferred);
5751

58-
if (ec)
59-
{
60-
return fail(ec, "write");
61-
}
52+
if (ec) { return fail(ec, "write"); }
6253

63-
if (close)
64-
{
54+
if (close) {
6555
// This means we should close the connection, usually because
6656
// the response indicated the "Connection: close" semantic.
6757
return doClose();

src/main.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <functional>
22
#include <iostream>
33

4-
#include <spdlog/spdlog.h>
54
#include <docopt/docopt.h>
5+
#include <spdlog/spdlog.h>
66

77
static constexpr auto USAGE =
88
R"(Naval Fate.
@@ -24,18 +24,16 @@ static constexpr auto USAGE =
2424

2525
int main(int argc, const char **argv)
2626
{
27-
std::map<std::string, docopt::value> args = docopt::docopt(USAGE,
28-
{ std::next(argv), std::next(argv, argc) },
29-
true,// show help if requested
30-
"Naval Fate 2.0");// version string
27+
std::map<std::string, docopt::value> args = docopt::docopt(USAGE,
28+
{ std::next(argv), std::next(argv, argc) },
29+
true,// show help if requested
30+
"Naval Fate 2.0");// version string
3131

32-
for (auto const &arg : args) {
33-
std::cout << arg.first << arg.second << std::endl;
34-
}
32+
for (auto const &arg : args) { std::cout << arg.first << arg.second << std::endl; }
3533

3634

37-
//Use the default logger (stdout, multi-threaded, colored)
38-
spdlog::info("Hello, {}!", "World");
35+
// Use the default logger (stdout, multi-threaded, colored)
36+
spdlog::info("Hello, {}!", "World");
3937

40-
fmt::print("Hello, from {}\n", "{fmt}");
38+
fmt::print("Hello, from {}\n", "{fmt}");
4139
}

src/sml/actions.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ std::chrono::time_point<std::chrono::steady_clock> startTime;
44

55
struct turnOffAction
66
{
7-
void operator()() { spdlog::info("turned off"); }
7+
void operator()() { spdlog::info("turned off"); }
88
} turnOffAction;
99

1010
struct startAction
1111
{
12-
void operator()() { startTime = std::chrono::steady_clock::now(); }
12+
void operator()() { startTime = std::chrono::steady_clock::now(); }
1313
} startAction;
1414

1515
struct stopAction
1616
{
17-
void operator()()
18-
{
19-
const auto diff = std::chrono::steady_clock::now() - startTime;
20-
spdlog::info("Elasped time: {}s", std::chrono::duration_cast<std::chrono::seconds>(diff).count());
21-
}
22-
} stopAction;
17+
void operator()()
18+
{
19+
const auto diff = std::chrono::steady_clock::now() - startTime;
20+
spdlog::info("Elasped time: {}s", std::chrono::duration_cast<std::chrono::seconds>(diff).count());
21+
}
22+
} stopAction;

src/sml/logger.h

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,30 @@
22

33
struct CustomLogger
44
{
5-
template<class SM, class TEvent>
6-
void log_process_event(const TEvent &)
7-
{
8-
spdlog::info("[{}][process_event] {}", boost::sml::aux::get_type_name<SM>(), boost::sml::aux::get_type_name<TEvent>());
9-
}
5+
template<class SM, class TEvent> void log_process_event(const TEvent &)
6+
{
7+
spdlog::info("[{}][process_event] {}", boost::sml::aux::get_type_name<SM>(), boost::sml::aux::get_type_name<TEvent>());
8+
}
109

11-
template<class SM, class TGuard, class TEvent>
12-
void log_guard(const TGuard &, const TEvent &, bool result)
13-
{
14-
spdlog::info("[%s][guard] %s %s %s", boost::sml::aux::get_type_name<SM>(), boost::sml::aux::get_type_name<TGuard>(), boost::sml::aux::get_type_name<TEvent>(), (result ? "[OK]" : "[Reject]"));
15-
}
10+
template<class SM, class TGuard, class TEvent> void log_guard(const TGuard &, const TEvent &, bool result)
11+
{
12+
spdlog::info("[%s][guard] %s %s %s",
13+
boost::sml::aux::get_type_name<SM>(),
14+
boost::sml::aux::get_type_name<TGuard>(),
15+
boost::sml::aux::get_type_name<TEvent>(),
16+
(result ? "[OK]" : "[Reject]"));
17+
}
1618

17-
template<class SM, class TAction, class TEvent>
18-
void log_action(const TAction &, const TEvent &)
19-
{
20-
spdlog::info("[{}][action] {} {}", boost::sml::aux::get_type_name<SM>(), boost::sml::aux::get_type_name<TAction>(), boost::sml::aux::get_type_name<TEvent>());
21-
}
19+
template<class SM, class TAction, class TEvent> void log_action(const TAction &, const TEvent &)
20+
{
21+
spdlog::info("[{}][action] {} {}", boost::sml::aux::get_type_name<SM>(), boost::sml::aux::get_type_name<TAction>(), boost::sml::aux::get_type_name<TEvent>());
22+
}
2223

23-
template<class SM, class TSrcState, class TDstState>
24-
void log_state_change(const TSrcState &src, const TDstState &dst)
25-
{
26-
spdlog::info("[{}][transition] {} -> {}", boost::sml::aux::get_type_name<SM>(), src.c_str(), dst.c_str());
27-
}
24+
template<class SM, class TSrcState, class TDstState> void log_state_change(const TSrcState &src, const TDstState &dst)
25+
{
26+
spdlog::info("[{}][transition] {} -> {}", boost::sml::aux::get_type_name<SM>(), src.c_str(), dst.c_str());
27+
}
2828

29-
template<class SM, class _, class TEvent>
30-
void log_process_event(const boost::sml::back::on_entry<_, TEvent> &)
31-
{
32-
spdlog::info("on_entry");
33-
}
34-
template<class SM, class _, class TEvent>
35-
void log_process_event(const boost::sml::back::on_exit<_, TEvent> &)
36-
{
37-
spdlog::info("on_exit");
38-
}
39-
};
29+
template<class SM, class _, class TEvent> void log_process_event(const boost::sml::back::on_entry<_, TEvent> &) { spdlog::info("on_entry"); }
30+
template<class SM, class _, class TEvent> void log_process_event(const boost::sml::back::on_exit<_, TEvent> &) { spdlog::info("on_exit"); }
31+
};

0 commit comments

Comments
 (0)