Skip to content

Commit

Permalink
feature:format code (#34)
Browse files Browse the repository at this point in the history
* format

* add format.sh and format codes

1.添加了format.sh ,因为发现在cmake文件中直接写命令会存在\反邪杆转义的问题,直接写在sh文件中了
2.在cmake中添加了相关的命令

---------

Co-authored-by: siwuxie <[email protected]>
  • Loading branch information
578223592 and example authored Feb 20, 2024
1 parent 1d796aa commit ecd134b
Show file tree
Hide file tree
Showing 38 changed files with 3,246 additions and 3,160 deletions.
198 changes: 198 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@

# from https://github.com/OpenAtomFoundation/pikiwidb/blob/5ea7bc0949cbd49122633cf086322143121c5985/.clang-format
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
StatementAttributeLikeMacros:
- Q_EMIT
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentExternBlock: AfterExternBlock
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
cmake_minimum_required(VERSION 3.22)
project(KVRaftCpp)






set(CMAKE_CXX_STANDARD 20)
# 生成debug版本,可以进行gdb调试
set(CMAKE_BUILD_TYPE "Debug")
Expand Down Expand Up @@ -33,4 +38,18 @@ add_subdirectory(example)

add_library(skip_list_on_raft STATIC ${src_rpc} ${rpc_example} ${raftsource} ${src_raftCore} ${src_raftRpcPro})

target_link_libraries(skip_list_on_raft muduo_net muduo_base pthread )
target_link_libraries(skip_list_on_raft muduo_net muduo_base pthread )


# 添加格式化目标 start
# from : https://blog.csdn.net/guotianqing/article/details/121661067

add_custom_target(format
COMMAND bash ${PROJECT_SOURCE_DIR}/format.sh
COMMAND echo "format done!"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)


# 添加格式化目标 end

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
- muduo
- boost
- protoc
- clang-format(可选)

**安装说明**

- clang-format,如果你不设计提交pr,那么不用安装,这里也给出安装命令:`sudo apt-get install clang-format`
- protoc,本地版本为3.12.4,ubuntu22使用`sudo apt-get install protobuf-compiler libprotobuf-dev`安装默认就是这个版本
- boost,`sudo apt-get install libboost-dev libboost-test-dev libboost-all-dev`
- muduo,https://blog.csdn.net/QIANGWEIYUAN/article/details/89023980
> 如果库安装编译本仓库的时候有错误或者需要确认版本信息,可以在issue页面查看其他人遇到的问题和分享: [链接](https://github.com/youngyangyang04/KVstorageBaseRaft-cpp/issues)
### 2.编译启动
Expand Down
26 changes: 13 additions & 13 deletions example/raftCoreExample/caller.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//
// Created by swx on 23-6-4.
//
#include "clerk.h"
#include <iostream>
#include "clerk.h"
#include "util.h"
int main(){
Clerk client;
client.Init("test.conf");
auto start = now();
int count = 500;
int tmp = count;
while (tmp --){
client.Put("x",std::to_string(tmp));
int main() {
Clerk client;
client.Init("test.conf");
auto start = now();
int count = 500;
int tmp = count;
while (tmp--) {
client.Put("x", std::to_string(tmp));

std::string get1 = client.Get("x");
std::printf("get return :{%s}\r\n",get1.c_str());
}
return 0;
std::string get1 = client.Get("x");
std::printf("get return :{%s}\r\n", get1.c_str());
}
return 0;
}
Loading

0 comments on commit ecd134b

Please sign in to comment.