Google style guide
This commit is contained in:
151
.clang-format
Normal file
151
.clang-format
Normal file
@@ -0,0 +1,151 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: true
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^<ext/.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 1
|
||||
- Regex: '^<.*'
|
||||
Priority: 2
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
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
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
37
buffer.cc
37
buffer.cc
@@ -3,12 +3,9 @@
|
||||
namespace firebuf {
|
||||
|
||||
ConstBuffer::ConstBuffer(const char *buf, size_t len)
|
||||
: const_buf_(buf),
|
||||
len_(len) {}
|
||||
: const_buf_(buf), len_(len) {}
|
||||
|
||||
size_t ConstBuffer::ReadMaxLen() const {
|
||||
return len_ - start_;
|
||||
}
|
||||
size_t ConstBuffer::ReadMaxLen() const { return len_ - start_; }
|
||||
|
||||
const char *ConstBuffer::Read(size_t len) {
|
||||
if (ReadMaxLen() < len) {
|
||||
@@ -27,40 +24,26 @@ bool ConstBuffer::Discard(size_t len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConstBuffer::ResetRead() {
|
||||
start_ = commit_;
|
||||
}
|
||||
void ConstBuffer::ResetRead() { start_ = commit_; }
|
||||
|
||||
void ConstBuffer::Commit() {
|
||||
commit_ = start_;
|
||||
}
|
||||
|
||||
void ConstBuffer::Reset() {
|
||||
commit_ = start_ = 0;
|
||||
}
|
||||
void ConstBuffer::Commit() { commit_ = start_; }
|
||||
|
||||
void ConstBuffer::Reset() { commit_ = start_ = 0; }
|
||||
|
||||
Buffer::Buffer(char *buf, size_t size, size_t len)
|
||||
: ConstBuffer(buf, size),
|
||||
buf_(buf),
|
||||
size_(size) {
|
||||
: ConstBuffer(buf, size), buf_(buf), size_(size) {
|
||||
len_ = len;
|
||||
}
|
||||
|
||||
Buffer::Buffer(size_t size)
|
||||
: Buffer(new char[size], size, 0) {
|
||||
Buffer::Buffer(size_t size) : Buffer(new char[size], size, 0) {
|
||||
own_buf_.reset(buf_);
|
||||
}
|
||||
|
||||
char *Buffer::WritePtr() {
|
||||
return &buf_[len_];
|
||||
}
|
||||
char *Buffer::WritePtr() { return &buf_[len_]; }
|
||||
|
||||
size_t Buffer::WriteMaxLen() const {
|
||||
return size_ - len_;
|
||||
}
|
||||
size_t Buffer::WriteMaxLen() const { return size_ - len_; }
|
||||
|
||||
bool Buffer::Write(const std::string_view& str) {
|
||||
bool Buffer::Write(const std::string_view &str) {
|
||||
if (WriteMaxLen() < str.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
10
buffer.h
10
buffer.h
@@ -12,7 +12,8 @@ class ConstBuffer {
|
||||
|
||||
[[nodiscard]] size_t ReadMaxLen() const;
|
||||
[[nodiscard]] virtual const char *Read(size_t len);
|
||||
template<class T> [[nodiscard]] const T *ReadObj();
|
||||
template <class T>
|
||||
[[nodiscard]] const T *ReadObj();
|
||||
|
||||
bool Discard(size_t len); // like Read() but don't use the result
|
||||
void ResetRead(); // next read from last commit
|
||||
@@ -34,7 +35,7 @@ class Buffer : public ConstBuffer {
|
||||
|
||||
[[nodiscard]] char *WritePtr();
|
||||
[[nodiscard]] size_t WriteMaxLen() const;
|
||||
bool Write(const std::string_view& str);
|
||||
bool Write(const std::string_view &str);
|
||||
void Wrote(ssize_t len);
|
||||
|
||||
void Consume(); // discard up to last commit
|
||||
@@ -47,11 +48,12 @@ class Buffer : public ConstBuffer {
|
||||
const size_t size_;
|
||||
};
|
||||
|
||||
template<class T> const T *ConstBuffer::ReadObj() {
|
||||
template <class T>
|
||||
const T *ConstBuffer::ReadObj() {
|
||||
if (ReadMaxLen() < sizeof(T)) {
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<const T*>(Read(sizeof(T)));
|
||||
return reinterpret_cast<const T *>(Read(sizeof(T)));
|
||||
}
|
||||
|
||||
} // namespace firebuf
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace firebuf {
|
||||
|
||||
StreamBuffer::StreamBuffer(int sock, size_t size)
|
||||
: Buffer(size),
|
||||
sock_(sock) {}
|
||||
StreamBuffer::StreamBuffer(int sock, size_t size) : Buffer(size), sock_(sock) {}
|
||||
|
||||
bool StreamBuffer::Refill() {
|
||||
if (WriteMaxLen() == 0) {
|
||||
|
||||
Reference in New Issue
Block a user