---
# As per the style-guide we base our settings on the LLVM style. This is closer
# than any of the other options, but there are more conventions that differ from
# it than the style-guide suggests.
BasedOnStyle: LLVM

# Default LLVM puts access modifiers (public: etc.) at an offset of -2, meaning
# in the middle between the indentation level of the class and the class members.
# A setting of -4 puts them at the same level as class definitions.
AccessModifierOffset: -4

# We don't want to align function parameters or arguments with the open bracket
# but instead always just add a level of indentation.
AlignAfterOpenBracket: BlockIndent

# Mostly relevant for formatting preprocessor macros so that all backslashes align.
AlignEscapedNewlines: LeftWithLastLine

# We try to avoid having all parameters of a function declaration on a single line
# Together with 'BinPackParameters' and 'PenaltyReturnTypeOnItsOwnLine' this leads
# to function signatures being either all on one line, or split by argument like a
# list.
AllowAllParametersOfDeclarationOnNextLine: false

# Put simple getters/setters in class bodies on a single line.
AllowShortFunctionsOnASingleLine: InlineOnly

# If necessary to break function calls, preferably put each argument on its own line.
BinPackArguments: false

# If necessary to break function signatures, preferably put each parameter on its own line.
# This matches the above setting of `BinPackArguments: false` for calls.
BinPackParameters: OnePerLine

# Brace-wrapping settings. Mostly should resemble BreakBeforebraces: Mozilla with a few
# changes, mostly regarding empty classes.
BraceWrapping:
  AfterCaseLabel: false
  AfterClass: true
  AfterControlStatement: Never
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: true
  AfterObjCDeclaration: false
  AfterStruct: false
  AfterUnion: true
  AfterExternBlock: false
  BeforeCatch: false
  BeforeElse: false
  BeforeLambdaBody: false
  BeforeWhile: false
  IndentBraces: false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true

# Sets clang-format up to use the BraceWrapping setting above.
BreakBeforeBraces: Custom

# When template parameter declarations are split into multiple lines this will put
# the closing '>' on its own line, much like the parens for a declaration list.
BreakBeforeTemplateCloser: true

# Template declarations are always on their own line.
BreakTemplateDeclarations: Yes

# Convention
ColumnLimit: 120

# Includes are sorted according to the style guide, with the additional requirement
# from Boost.Test that the header including the test framework must go first.
IncludeCategories:
  - Regex: ^(<|")BoostTestTargetConfig.h
    Priority: 1
    CaseSensitive: false
  - Regex: ^"(base|config|icinga|perfdata|remote|test)/
    Priority: 2
    CaseSensitive: false
  - Regex: ^<boost/
    Priority: 3
    CaseSensitive: false
  - Regex: ^<
    Priority: 4
    CaseSensitive: false

# Convention
IndentCaseLabels: true
IndentWidth: 4

# Adds braces to if/else/while blocks if they don't have one yet.
# This is required by the current version of the style-guide.
InsertBraces: true

# Break Constructor initializers to one per line (if they have to be broken up).
PackConstructorInitializers: CurrentLine

# We really want to avoid breaking assignments if we can avoid it.
# This, together with 'BinPackArguments' leads to clang-format rather breaking at
# constructor calls with each argument on its own line, like we want.
PenaltyBreakAssignment: 2000

# We never want to break up foo::bar.
PenaltyBreakScopeResolution: 100000

# We allow log message shift operators to start on the next line.
PenaltyBreakFirstLessLess: 0

# We usually don't want to go above the 120 column-width limit, but it's ok if the
# alternative is worse. A setting of 500 means in relation to PenaltyIndentedWhitespace
# that two characters over the limit are equal to one level of indentation.
# This takes it into account that it's worse if a function call with many arguments is
# split, than if it's only one argument that's wrapped around to the next line.
PenaltyExcessCharacter: 20

# This is needed together with 'PenaltyBreakFirstLessLess' for our preferred formatting
# of log messages.
PenaltyIndentedWhitespace: 10

# We absolutely never want the return type on its own line.
# Together with 'AllowAllParametersOfDeclarationOnNextLine' and 'BinPackParameters'
# This makes it so that function signatures are always either on one line or split
# line by line per argument.
PenaltyReturnTypeOnItsOwnLine: 50000

# Convention
PointerAlignment: Left
ReferenceAlignment: Left
SpaceAfterTemplateKeyword: false
TabWidth: 4
UseTab: Always

# This only works for matching tokens, as in parsing tokens. Matching any syntactic
# characters is not supported. Currently we use this mostly to circumvent reformatting
# Boost.Test's weird bullet point syntax for unit-test decorators.
OneLineFormatOffRegex: (BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE|BOOST_FIXTURE_TEST_CASE|BOOST_AUTO_TEST_CASE|unit_test|CTestProperties|RequiresCertificate)
