Skip to content

Commit 328ad97

Browse files
authored
Adds automatic formatting with clang-format
1 parent 1060733 commit 328ad97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1745
-1598
lines changed

.clang-format

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
Language: Cpp
3+
ColumnLimit: 100
4+
IndentWidth: 3
5+
BreakBeforeBraces: Custom
6+
BraceWrapping:
7+
AfterCaseLabel: true
8+
AfterClass: false
9+
AfterControlStatement: false
10+
AfterEnum: true
11+
AfterFunction: true
12+
AfterNamespace: false
13+
AfterStruct: false
14+
AfterUnion: false
15+
AfterExternBlock: false
16+
BeforeCatch: false
17+
BeforeElse: false
18+
IndentBraces: false
19+
SplitEmptyFunction: false
20+
SplitEmptyRecord: false
21+
SplitEmptyNamespace: true
22+
AccessModifierOffset: -3
23+
BinPackArguments: false
24+
BinPackParameters: false
25+
AlignAfterOpenBracket: AlwaysBreak
26+
PointerAlignment: Left
27+
IncludeBlocks: Regroup
28+
IncludeCategories:
29+
- Regex: '^<boost/redis.*>|<boost/redis/.*>'
30+
Priority: -10
31+
SortPriority: 1
32+
- Regex: '^<boost/.*>'
33+
Priority: -8
34+
SortPriority: 3
35+
- Regex: "^<.*"
36+
Priority: -6
37+
SortPriority: 5
38+
- Regex: ".*"
39+
Priority: -5
40+
SortPriority: 4
41+
IndentCaseLabels: true
42+
AllowShortCaseLabelsOnASingleLine: true
43+
AllowAllArgumentsOnNextLine: false
44+
AllowAllParametersOfDeclarationOnNextLine: false
45+
AllowShortIfStatementsOnASingleLine: Never
46+
AllowShortLoopsOnASingleLine: false
47+
AlignArrayOfStructures: Left
48+
DerivePointerAlignment: false
49+
PenaltyBreakAssignment: 2000000
50+
PenaltyBreakBeforeFirstCallParameter: 0
51+
PenaltyBreakOpenParenthesis: 0
52+
PenaltyBreakComment: 300
53+
PenaltyBreakFirstLessLess: 120
54+
PenaltyBreakString: 1000
55+
PenaltyBreakTemplateDeclaration: 10
56+
PenaltyExcessCharacter: 1000000
57+
PenaltyBreakScopeResolution: 1000000
58+
PenaltyReturnTypeOnItsOwnLine: 200000000
59+
60+
# Defaults (based on Google)
61+
AlignConsecutiveMacros: false
62+
AlignConsecutiveAssignments: false
63+
AlignConsecutiveDeclarations: false
64+
AlignEscapedNewlines: Left
65+
AlignOperands: true
66+
AlignTrailingComments: true
67+
AllowAllConstructorInitializersOnNextLine: true
68+
AllowShortBlocksOnASingleLine: Never
69+
AllowShortFunctionsOnASingleLine: All
70+
AllowShortLambdasOnASingleLine: Empty
71+
AlwaysBreakAfterDefinitionReturnType: None
72+
AlwaysBreakAfterReturnType: ExceptShortType
73+
AlwaysBreakBeforeMultilineStrings: true
74+
AlwaysBreakTemplateDeclarations: Yes
75+
BreakTemplateDeclarations: Leave
76+
BreakBeforeBinaryOperators: None
77+
BreakBeforeInheritanceComma: false
78+
BreakInheritanceList: BeforeColon
79+
BreakBeforeTernaryOperators: true
80+
BreakConstructorInitializersBeforeComma: true
81+
BreakConstructorInitializers: BeforeColon
82+
BreakAfterJavaFieldAnnotations: false
83+
BreakStringLiterals: true
84+
CommentPragmas: '(^ IWYU pragma:)|(^\\copydoc )|(^ ?\\n)'
85+
CompactNamespaces: false
86+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
87+
ConstructorInitializerIndentWidth: 0
88+
ContinuationIndentWidth: 3
89+
Cpp11BracedListStyle: true
90+
DeriveLineEnding: true
91+
DisableFormat: false
92+
ExperimentalAutoDetectBinPacking: false
93+
FixNamespaceComments: true
94+
ForEachMacros:
95+
- foreach
96+
- Q_FOREACH
97+
- BOOST_FOREACH
98+
IncludeIsMainRegex: null
99+
IncludeIsMainSourceRegex: ""
100+
IndentGotoLabels: false
101+
IndentPPDirectives: None
102+
IndentWrappedFunctionNames: false
103+
JavaScriptQuotes: Leave
104+
JavaScriptWrapImports: true
105+
KeepEmptyLinesAtTheStartOfBlocks: false
106+
MacroBlockBegin: ""
107+
MacroBlockEnd: ""
108+
MaxEmptyLinesToKeep: 1
109+
NamespaceIndentation: None
110+
ObjCBinPackProtocolList: Never
111+
ObjCBlockIndentWidth: 2
112+
ObjCSpaceAfterProperty: false
113+
ObjCSpaceBeforeProtocolList: true
114+
RawStringFormats:
115+
- Language: Cpp
116+
Delimiters:
117+
- cc
118+
- CC
119+
- cpp
120+
- Cpp
121+
- CPP
122+
- "c++"
123+
- "C++"
124+
CanonicalDelimiter: ""
125+
BasedOnStyle: google
126+
- Language: TextProto
127+
Delimiters:
128+
- pb
129+
- PB
130+
- proto
131+
- PROTO
132+
EnclosingFunctions:
133+
- EqualsProto
134+
- EquivToProto
135+
- PARSE_PARTIAL_TEXT_PROTO
136+
- PARSE_TEST_PROTO
137+
- PARSE_TEXT_PROTO
138+
- ParseTextOrDie
139+
- ParseTextProtoOrDie
140+
CanonicalDelimiter: ""
141+
BasedOnStyle: google
142+
ReflowComments: false
143+
SortIncludes: true
144+
SortUsingDeclarations: false
145+
SpaceAfterCStyleCast: false
146+
SpaceAfterLogicalNot: false
147+
SpaceAfterTemplateKeyword: true
148+
SpaceBeforeAssignmentOperators: true
149+
SpaceBeforeCtorInitializerColon: true
150+
SpaceBeforeInheritanceColon: true
151+
SpaceBeforeParens: ControlStatements
152+
SpaceBeforeRangeBasedForLoopColon: true
153+
SpaceInEmptyBlock: true
154+
SpaceInEmptyParentheses: false
155+
SpacesBeforeTrailingComments: 2
156+
SpacesInAngles: false
157+
SpacesInConditionalStatement: false
158+
SpacesInContainerLiterals: true
159+
SpacesInCStyleCastParentheses: false
160+
SpacesInParentheses: false
161+
SpacesInSquareBrackets: false
162+
SpaceBeforeSquareBrackets: false
163+
Standard: Auto
164+
StatementMacros:
165+
- Q_UNUSED
166+
- QT_REQUIRE_VERSION
167+
TabWidth: 8
168+
UseCRLF: false
169+
UseTab: Never
170+
AlignConsecutiveShortCaseStatements:
171+
Enabled: true
172+
AcrossEmptyLines: false
173+
AcrossComments: true
174+
AlignCaseColons: false
175+
---
176+

benchmarks/cpp/asio/echo_server_client.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* accompanying file LICENSE.txt)
55
*/
66

7-
#include <iostream>
87
#include <boost/asio.hpp>
8+
9+
#include <iostream>
910
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1011

1112
namespace net = boost::asio;
@@ -62,6 +63,10 @@ int main(int argc, char* argv[])
6263
std::cerr << e.what() << std::endl;
6364
}
6465
}
65-
#else // defined(BOOST_ASIO_HAS_CO_AWAIT)
66-
auto main() -> int {std::cout << "Requires coroutine support." << std::endl; return 1;}
67-
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
66+
#else // defined(BOOST_ASIO_HAS_CO_AWAIT)
67+
auto main() -> int
68+
{
69+
std::cout << "Requires coroutine support." << std::endl;
70+
return 1;
71+
}
72+
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)

benchmarks/cpp/asio/echo_server_direct.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
99
//
1010

11+
#include <boost/asio.hpp>
12+
1113
#include <cstdio>
1214
#include <iostream>
13-
#include <boost/asio.hpp>
1415
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1516

1617
namespace net = boost::asio;
@@ -27,37 +28,41 @@ constexpr net::use_awaitable_t<executor_type> use_awaitable;
2728

2829
awaitable_type echo(tcp_socket socket)
2930
{
30-
try {
31-
char data[1024];
32-
for (;;) {
33-
std::size_t n = co_await socket.async_read_some(net::buffer(data), use_awaitable);
34-
co_await async_write(socket, net::buffer(data, n), use_awaitable);
35-
}
36-
} catch (std::exception const&) {
37-
//std::printf("echo Exception: %s\n", e.what());
38-
}
31+
try {
32+
char data[1024];
33+
for (;;) {
34+
std::size_t n = co_await socket.async_read_some(net::buffer(data), use_awaitable);
35+
co_await async_write(socket, net::buffer(data, n), use_awaitable);
36+
}
37+
} catch (std::exception const&) {
38+
//std::printf("echo Exception: %s\n", e.what());
39+
}
3940
}
4041

4142
awaitable_type listener()
4243
{
43-
auto ex = co_await this_coro::executor;
44-
tcp_acceptor acceptor(ex, {tcp::v4(), 55555});
45-
for (;;) {
46-
tcp_socket socket = co_await acceptor.async_accept(use_awaitable);
47-
co_spawn(ex, echo(std::move(socket)), detached);
48-
}
44+
auto ex = co_await this_coro::executor;
45+
tcp_acceptor acceptor(ex, {tcp::v4(), 55555});
46+
for (;;) {
47+
tcp_socket socket = co_await acceptor.async_accept(use_awaitable);
48+
co_spawn(ex, echo(std::move(socket)), detached);
49+
}
4950
}
5051

5152
int main()
5253
{
53-
try {
54-
net::io_context io_context{BOOST_ASIO_CONCURRENCY_HINT_UNSAFE_IO};
55-
co_spawn(io_context, listener(), detached);
56-
io_context.run();
57-
} catch (std::exception const& e) {
58-
std::printf("Exception: %s\n", e.what());
59-
}
54+
try {
55+
net::io_context io_context{BOOST_ASIO_CONCURRENCY_HINT_UNSAFE_IO};
56+
co_spawn(io_context, listener(), detached);
57+
io_context.run();
58+
} catch (std::exception const& e) {
59+
std::printf("Exception: %s\n", e.what());
60+
}
61+
}
62+
#else // defined(BOOST_ASIO_HAS_CO_AWAIT)
63+
auto main() -> int
64+
{
65+
std::cout << "Requires coroutine support." << std::endl;
66+
return 1;
6067
}
61-
#else // defined(BOOST_ASIO_HAS_CO_AWAIT)
62-
auto main() -> int {std::cout << "Requires coroutine support." << std::endl; return 1;}
63-
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
68+
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)

example/cpp17_intro.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66

77
#include <boost/redis/connection.hpp>
8+
89
#include <boost/asio/detached.hpp>
10+
911
#include <iostream>
1012

1113
namespace asio = boost::asio;
@@ -14,7 +16,7 @@ using boost::redis::request;
1416
using boost::redis::response;
1517
using boost::redis::config;
1618

17-
auto main(int argc, char * argv[]) -> int
19+
auto main(int argc, char* argv[]) -> int
1820
{
1921
try {
2022
config cfg;
@@ -47,4 +49,3 @@ auto main(int argc, char * argv[]) -> int
4749
return 1;
4850
}
4951
}
50-

example/cpp17_intro_sync.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
#include "sync_connection.hpp"
88

9-
#include <string>
109
#include <iostream>
10+
#include <string>
1111

1212
using boost::redis::sync_connection;
1313
using boost::redis::request;
1414
using boost::redis::response;
1515
using boost::redis::config;
1616

17-
auto main(int argc, char * argv[]) -> int
17+
auto main(int argc, char* argv[]) -> int
1818
{
1919
try {
2020
config cfg;

example/cpp20_chat_room.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
*/
66

77
#include <boost/redis/connection.hpp>
8-
#include <boost/asio/signal_set.hpp>
8+
99
#include <boost/asio/co_spawn.hpp>
1010
#include <boost/asio/detached.hpp>
11-
#include <boost/asio/redirect_error.hpp>
1211
#include <boost/asio/posix/stream_descriptor.hpp>
13-
#include <unistd.h>
12+
#include <boost/asio/redirect_error.hpp>
13+
#include <boost/asio/signal_set.hpp>
14+
1415
#include <iostream>
16+
#include <unistd.h>
1517

1618
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1719
#if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
@@ -38,8 +40,7 @@ using namespace std::chrono_literals;
3840
// Chat over Redis pubsub. To test, run this program from multiple
3941
// terminals and type messages to stdin.
4042

41-
auto
42-
receiver(std::shared_ptr<connection> conn) -> awaitable<void>
43+
auto receiver(std::shared_ptr<connection> conn) -> awaitable<void>
4344
{
4445
request req;
4546
req.push("SUBSCRIBE", "channel");
@@ -48,27 +49,24 @@ receiver(std::shared_ptr<connection> conn) -> awaitable<void>
4849
conn->set_receive_response(resp);
4950

5051
while (conn->will_reconnect()) {
51-
5252
// Subscribe to channels.
5353
co_await conn->async_exec(req, ignore);
5454

5555
// Loop reading Redis push messages.
5656
for (error_code ec;;) {
5757
co_await conn->async_receive(redirect_error(use_awaitable, ec));
5858
if (ec)
59-
break; // Connection lost, break so we can reconnect to channels.
60-
std::cout
61-
<< resp.value().at(1).value
62-
<< " " << resp.value().at(2).value
63-
<< " " << resp.value().at(3).value
64-
<< std::endl;
59+
break; // Connection lost, break so we can reconnect to channels.
60+
std::cout << resp.value().at(1).value << " " << resp.value().at(2).value << " "
61+
<< resp.value().at(3).value << std::endl;
6562
resp.value().clear();
6663
}
6764
}
6865
}
6966

7067
// Publishes stdin messages to a Redis channel.
71-
auto publisher(std::shared_ptr<stream_descriptor> in, std::shared_ptr<connection> conn) -> awaitable<void>
68+
auto publisher(std::shared_ptr<stream_descriptor> in, std::shared_ptr<connection> conn)
69+
-> awaitable<void>
7270
{
7371
for (std::string msg;;) {
7472
auto n = co_await async_read_until(*in, dynamic_buffer(msg, 1024), "\n");
@@ -96,11 +94,11 @@ auto co_main(config cfg) -> awaitable<void>
9694
stream->cancel();
9795
}
9896

99-
#else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
97+
#else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
10098
auto co_main(config const&) -> awaitable<void>
10199
{
102100
std::cout << "Requires support for posix streams." << std::endl;
103101
co_return;
104102
}
105-
#endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
106-
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
103+
#endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
104+
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)

0 commit comments

Comments
 (0)