Skip to content

Commit 90e82c1

Browse files
committed
use clang format
1 parent bd7d286 commit 90e82c1

17 files changed

+1536
-1526
lines changed

.clang-format

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveMacros: true
7+
AlignConsecutiveAssignments: true
8+
AlignConsecutiveBitFields: true
9+
AlignConsecutiveDeclarations: true
10+
AlignEscapedNewlines: Right
11+
AlignOperands: Align
12+
AlignTrailingComments: true
13+
AllowAllArgumentsOnNextLine: true
14+
AllowAllConstructorInitializersOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortEnumsOnASingleLine: true
17+
AllowShortBlocksOnASingleLine: Never
18+
AllowShortCaseLabelsOnASingleLine: true
19+
AllowShortFunctionsOnASingleLine: All
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: Never
22+
AllowShortLoopsOnASingleLine: false
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: true
26+
AlwaysBreakTemplateDeclarations: MultiLine
27+
AttributeMacros:
28+
- __capability
29+
BinPackArguments: true
30+
BinPackParameters: true
31+
BraceWrapping:
32+
AfterCaseLabel: true
33+
AfterClass: true
34+
AfterControlStatement: Never
35+
AfterEnum: true
36+
AfterFunction: true
37+
AfterNamespace: true
38+
AfterObjCDeclaration: true
39+
AfterStruct: true
40+
AfterUnion: true
41+
AfterExternBlock: true
42+
BeforeCatch: true
43+
BeforeElse: true
44+
BeforeLambdaBody: true
45+
BeforeWhile: true
46+
IndentBraces: true
47+
SplitEmptyFunction: true
48+
SplitEmptyRecord: true
49+
SplitEmptyNamespace: true
50+
BreakBeforeBinaryOperators: None
51+
BreakBeforeConceptDeclarations: true
52+
BreakBeforeBraces: Attach
53+
BreakBeforeInheritanceComma: false
54+
BreakInheritanceList: BeforeColon
55+
BreakBeforeTernaryOperators: true
56+
BreakConstructorInitializersBeforeComma: false
57+
BreakConstructorInitializers: BeforeColon
58+
BreakAfterJavaFieldAnnotations: false
59+
BreakStringLiterals: true
60+
ColumnLimit: 120
61+
CommentPragmas: '^ IWYU pragma:'
62+
CompactNamespaces: false
63+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
64+
ConstructorInitializerIndentWidth: 4
65+
ContinuationIndentWidth: 4
66+
Cpp11BracedListStyle: true
67+
DeriveLineEnding: true
68+
DerivePointerAlignment: false
69+
DisableFormat: false
70+
EmptyLineBeforeAccessModifier: LogicalBlock
71+
ExperimentalAutoDetectBinPacking: false
72+
FixNamespaceComments: true
73+
ForEachMacros:
74+
- foreach
75+
- Q_FOREACH
76+
- BOOST_FOREACH
77+
StatementAttributeLikeMacros:
78+
- Q_EMIT
79+
IncludeBlocks: Preserve
80+
IncludeCategories:
81+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
82+
Priority: 2
83+
SortPriority: 0
84+
CaseSensitive: false
85+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
86+
Priority: 3
87+
SortPriority: 0
88+
CaseSensitive: false
89+
- Regex: '.*'
90+
Priority: 1
91+
SortPriority: 0
92+
CaseSensitive: false
93+
IncludeIsMainRegex: '(Test)?$'
94+
IncludeIsMainSourceRegex: ''
95+
IndentCaseLabels: true
96+
IndentCaseBlocks: true
97+
IndentGotoLabels: true
98+
IndentPPDirectives: None
99+
IndentExternBlock: AfterExternBlock
100+
IndentRequires: false
101+
IndentWidth: 2
102+
IndentWrappedFunctionNames: true
103+
InsertTrailingCommas: None
104+
JavaScriptQuotes: Leave
105+
JavaScriptWrapImports: true
106+
KeepEmptyLinesAtTheStartOfBlocks: true
107+
MacroBlockBegin: ''
108+
MacroBlockEnd: ''
109+
MaxEmptyLinesToKeep: 1
110+
NamespaceIndentation: None
111+
ObjCBinPackProtocolList: Auto
112+
ObjCBlockIndentWidth: 2
113+
ObjCBreakBeforeNestedBlockParam: true
114+
ObjCSpaceAfterProperty: false
115+
ObjCSpaceBeforeProtocolList: true
116+
PenaltyBreakAssignment: 2
117+
PenaltyBreakBeforeFirstCallParameter: 19
118+
PenaltyBreakComment: 300
119+
PenaltyBreakFirstLessLess: 120
120+
PenaltyBreakString: 1000
121+
PenaltyBreakTemplateDeclaration: 10
122+
PenaltyExcessCharacter: 1000000
123+
PenaltyReturnTypeOnItsOwnLine: 60
124+
PenaltyIndentedWhitespace: 0
125+
PointerAlignment: Right
126+
ReflowComments: true
127+
SortIncludes: false
128+
SortJavaStaticImport: Before
129+
SortUsingDeclarations: true
130+
SpaceAfterCStyleCast: true
131+
SpaceAfterLogicalNot: true
132+
SpaceAfterTemplateKeyword: true
133+
SpaceBeforeAssignmentOperators: true
134+
SpaceBeforeCaseColon: true
135+
SpaceBeforeCpp11BracedList: true
136+
SpaceBeforeCtorInitializerColon: true
137+
SpaceBeforeInheritanceColon: true
138+
SpaceBeforeParens: ControlStatements
139+
SpaceAroundPointerQualifiers: Default
140+
SpaceBeforeRangeBasedForLoopColon: true
141+
SpaceInEmptyBlock: false
142+
SpaceInEmptyParentheses: false
143+
SpacesBeforeTrailingComments: 1
144+
SpacesInAngles: true
145+
SpacesInConditionalStatement: false
146+
SpacesInContainerLiterals: true
147+
SpacesInCStyleCastParentheses: false
148+
SpacesInParentheses: false
149+
SpacesInSquareBrackets: true
150+
SpaceBeforeSquareBrackets: false
151+
BitFieldColonSpacing: Both
152+
Standard: Latest
153+
StatementMacros:
154+
- Q_UNUSED
155+
- QT_REQUIRE_VERSION
156+
TabWidth: 2
157+
UseCRLF: false
158+
UseTab: Never
159+
WhitespaceSensitiveMacros:
160+
- STRINGIZE
161+
- PP_STRINGIZE
162+
- BOOST_PP_STRINGIZE
163+
- NS_SWIFT_NAME
164+
- CF_SWIFT_NAME
165+
...
166+

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ EXTRA_CFLAGS=-std=c++11
3838
#EXTRA_CFLAGS+=-DUSE_SIZE_T
3939

4040
$(OBJDIR)/%.o: %.cpp
41+
$(shell echo clang-format -i $<)
4142
@echo $(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
4243
@$(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
4344

Makefile.base

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ EXTRA_CFLAGS=-std=c++11
2222
#EXTRA_CFLAGS+=-DUSE_SIZE_T
2323

2424
$(OBJDIR)/%.o: %.cpp
25+
$(shell echo clang-format -i $<)
2526
@echo $(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
2627
@$(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
2728

basic_example.cpp

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,81 @@
11
#include "c_plus_plus_serializer.h"
22
#include <limits>
33

4-
static void save_simple (const std::string filename)
5-
{
6-
std::cout << "save to " << filename << std::endl;
7-
std::ofstream out(filename, std::ios::binary );
4+
static void save_simple(const std::string filename) {
5+
std::cout << "save to " << filename << std::endl;
6+
std::ofstream out(filename, std::ios::binary);
87

9-
char a = 42;
10-
unsigned short b = 65535;
11-
int c = 123456;
12-
float d = std::numeric_limits<float>::max();
13-
double e = std::numeric_limits<double>::max();
14-
std::string f("hello");
15-
wchar_t g = L'💩';
16-
std::wstring h(L"wide string 💩");
17-
std::pair<int, std::string> p(42, "life");
8+
char a = 42;
9+
unsigned short b = 65535;
10+
int c = 123456;
11+
float d = std::numeric_limits< float >::max();
12+
double e = std::numeric_limits< double >::max();
13+
std::string f("hello");
14+
wchar_t g = L'💩';
15+
std::wstring h(L"wide string 💩");
16+
std::pair< int, std::string > p(42, "life");
1817

19-
std::cout << std::endl;
20-
std::cout << "write:" << std::endl;
21-
std::cout << " a: char " << a << std::endl;
22-
std::cout << " b: unsigned short " << b << std::endl;
23-
std::cout << " c: int " << c << std::endl;
24-
std::cout << " d: float " << d << std::endl;
25-
std::cout << " e: double " << e << std::endl;
26-
std::cout << " f: std::string " << f << std::endl;
27-
std::wcout << " g: wchar_t " << g << std::endl;
28-
std::wcout << " h: std::wstring " << h << std::endl;
29-
std::cout << " p: std::pair " << p.first << " " << p.second << std::endl;
18+
std::cout << std::endl;
19+
std::cout << "write:" << std::endl;
20+
std::cout << " a: char " << a << std::endl;
21+
std::cout << " b: unsigned short " << b << std::endl;
22+
std::cout << " c: int " << c << std::endl;
23+
std::cout << " d: float " << d << std::endl;
24+
std::cout << " e: double " << e << std::endl;
25+
std::cout << " f: std::string " << f << std::endl;
26+
std::wcout << " g: wchar_t " << g << std::endl;
27+
std::wcout << " h: std::wstring " << h << std::endl;
28+
std::cout << " p: std::pair " << p.first << " " << p.second << std::endl;
3029

31-
std::cout << std::endl;
30+
std::cout << std::endl;
3231

33-
out << bits(a) << bits(b) << bits(c) << bits(d);
34-
out << bits(e) << bits(f) << bits(g) << bits(h);
35-
out << bits(p);
32+
out << bits(a) << bits(b) << bits(c) << bits(d);
33+
out << bits(e) << bits(f) << bits(g) << bits(h);
34+
out << bits(p);
3635
}
3736

38-
static void load_simple (const std::string filename)
39-
{
40-
std::cout << "read from " << filename << std::endl;
41-
std::ifstream in(filename);
37+
static void load_simple(const std::string filename) {
38+
std::cout << "read from " << filename << std::endl;
39+
std::ifstream in(filename);
4240

43-
char a;
44-
unsigned short b;
45-
int c;
46-
float d;
47-
double e;
48-
std::string f;
49-
wchar_t g;
50-
std::wstring h;
51-
std::pair<int, std::string> p;
41+
char a;
42+
unsigned short b;
43+
int c;
44+
float d;
45+
double e;
46+
std::string f;
47+
wchar_t g;
48+
std::wstring h;
49+
std::pair< int, std::string > p;
5250

53-
in >> bits(a) >> bits(b) >> bits(c) >> bits(d);
54-
in >> bits(e) >> bits(f) >> bits(g) >> bits(h);
55-
in >> bits(p);
51+
in >> bits(a) >> bits(b) >> bits(c) >> bits(d);
52+
in >> bits(e) >> bits(f) >> bits(g) >> bits(h);
53+
in >> bits(p);
5654

57-
std::cout << std::endl;
58-
std::cout << "read:" << std::endl;
59-
std::cout << " a: char " << a << std::endl;
60-
std::cout << " b: unsigned short " << b << std::endl;
61-
std::cout << " c: int " << c << std::endl;
62-
std::cout << " d: float " << d << std::endl;
63-
std::cout << " e: double " << e << std::endl;
64-
std::cout << " f: std::string " << f << std::endl;
65-
std::wcout << " g: wchar_t " << g << std::endl;
66-
std::wcout << " h: std::wstring " << h << std::endl;
67-
std::cout << " p: std::pair " << p.first << " " << p.second << std::endl;
68-
std::cout << std::endl;
55+
std::cout << std::endl;
56+
std::cout << "read:" << std::endl;
57+
std::cout << " a: char " << a << std::endl;
58+
std::cout << " b: unsigned short " << b << std::endl;
59+
std::cout << " c: int " << c << std::endl;
60+
std::cout << " d: float " << d << std::endl;
61+
std::cout << " e: double " << e << std::endl;
62+
std::cout << " f: std::string " << f << std::endl;
63+
std::wcout << " g: wchar_t " << g << std::endl;
64+
std::wcout << " h: std::wstring " << h << std::endl;
65+
std::cout << " p: std::pair " << p.first << " " << p.second << std::endl;
66+
std::cout << std::endl;
6967
}
7068

71-
void basic_example (void)
72-
{
73-
//
74-
// Need this to get the poop emoji printed! :)
75-
//
76-
std::locale loc("");
77-
std::ios_base::sync_with_stdio(false);
78-
std::wcout.imbue(loc);
69+
void basic_example(void) {
70+
//
71+
// Need this to get the poop emoji printed! :)
72+
//
73+
std::locale loc("");
74+
std::ios_base::sync_with_stdio(false);
75+
std::wcout.imbue(loc);
7976

80-
std::cout << "basic_example" << std::endl;
81-
std::cout << "=============" << std::endl;
82-
save_simple(std::string("basic_example.bin"));
83-
load_simple(std::string("basic_example.bin"));
77+
std::cout << "basic_example" << std::endl;
78+
std::cout << "=============" << std::endl;
79+
save_simple(std::string("basic_example.bin"));
80+
load_simple(std::string("basic_example.bin"));
8481
}

0 commit comments

Comments
 (0)