# =============================================================================
# PulsimCore C++ Code Formatting Configuration
# =============================================================================
# Used by clang-format for consistent code style
# Run: make format-cpp
# =============================================================================

Language: Cpp
Standard: c++23
BasedOnStyle: LLVM

# Line width
ColumnLimit: 120

# Indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
IndentCaseLabels: true
IndentCaseBlocks: false
IndentPPDirectives: BeforeHash
NamespaceIndentation: None

# Alignment
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true

# Braces
BreakBeforeBraces: Attach
Cpp11BracedListStyle: true
InsertBraces: false

# Short statements
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false

# Line breaks
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true

# Constructor initializers
ConstructorInitializerIndentWidth: 4
PackConstructorInitializers: BinPack

# Function arguments
BinPackArguments: true
BinPackParameters: true

# Access modifiers
AccessModifierOffset: -4
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock

# Include sorting
IncludeBlocks: Regroup
IncludeCategories:
  # Project headers
  - Regex: '^"pulsim/'
    Priority: 1
    SortPriority: 1
  # Local headers
  - Regex: '^"'
    Priority: 2
    SortPriority: 2
  # Third-party headers (Eigen, nlohmann, Catch2, etc.)
  - Regex: '^<(Eigen|nlohmann|catch2|CLI)/'
    Priority: 3
    SortPriority: 3
  # System/STL headers
  - Regex: '^<'
    Priority: 4
    SortPriority: 4
SortIncludes: CaseSensitive

# Pointers and references
DerivePointerAlignment: false
PointerAlignment: Left
ReferenceAlignment: Pointer

# Spaces
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
  Minimum: 1
  Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false

# Lambdas
LambdaBodyIndentation: Signature

# Macros
AttributeMacros: []
ForEachMacros: []
IfMacros: []
StatementAttributeLikeMacros: []
StatementMacros: []
TypenameMacros: []
WhitespaceSensitiveMacros: []

# Penalties (for line breaking decisions)
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60

# Miscellaneous
CompactNamespaces: false
FixNamespaceComments: true
MaxEmptyLinesToKeep: 1
ReflowComments: true
SeparateDefinitionBlocks: Leave
SortUsingDeclarations: true

# Requires clause (C++20/23)
RequiresClausePosition: OwnLine
IndentRequiresClause: true

# Insert trailing commas in container literals (C++11+)
InsertTrailingCommas: None
