Code of conduct
This section details the coding style and formatting conventions used in the COMFOR project. These guidelines ensure consistency, readability, and long-term maintainability of the codebase.
Key Conventions#
COMFOR follows an adapted version of the LLVM coding style.
| Aspect | Standard |
|---|---|
| Indentation | 4 spaces (no tabs) |
| Max line length | 80 characters |
| Brace style | K&R / 1TBS |
| Pointer alignment | Left (int* ptr;) |
| Namespace indentation | None |
switch / case |
case aligned with switch |
| File header | Fixed format (see below) |
| Enum declaration | enum class |
| Type aliases | using (avoid typedef) |
| Function/method names | camelCase |
| Class names | PascalCase |
| Private members | snake_case_ |
| File extensions | .h and .cpp (no .hpp) |
| Doxygen comments | /// @ syntax only |
| Required tools | clang-format ≥ 15 |
For full details, refer to the .clang-format file in the project root.
File Header Template#
Every .h or .cpp file must start with the following header:
//------------------------------------------------------------------------------
// COMFOR - Simulation Framework for Composite Forming and Processing
//------------------------------------------------------------------------------
//
// @file file_name.ext
// @brief Description of the file content.
// @author Your Name <your@email.com>
// @date YYYY-MM-DD
// @copyright (C) 20XX-20YY Your Name/University/Company
//
// For licensing terms, see the LICENSE file in the root directory.
//------------------------------------------------------------------------------
Code Separators#
Long separator (80 characters)#
Section separator#
VSCode Snippets#
Predefined snippets are available in .vscode/comfor.code-snippets to quickly insert headers and separators.
How to use:
- Press Ctrl+Space to trigger snippets.
- Type the snippet name (e.g.,
comfor_hppfor a header file). - Update placeholders (author, copyright,
@brief).
Available snippets:
comfor_hpp→ Header file template.comfor_cpp→ Source file template.comfor_sep_long→ Long separator.comfor_sep_short→ Section separator.comfor_cmake_header→ CMakeLists.txt header.
CLion Live Templates#
CLion automatically inserts COMFOR-style headers when creating new files (.cpp, .h, CMakeLists.txt). Templates are defined in .idea/fileTemplates.
Post-insertion steps:
- Update author/contact information.
- Adjust copyright years.
- Complete Doxygen tags (e.g.,
@brief).
Include What You Use (IWYU)#
IWYU is integrated into COMFOR to optimize #include directives by:
- Removing unused includes.
- Adding missing includes.
- Replacing internal Eigen includes with
ComforMath.h. - Reducing build times and dependencies.
Installation#
IWYU is not officially supported on Windows. Manual setup requires a full LLVM/Clang toolchain and building IWYU from source.
Debian/Ubuntu
Fedora
Arch
Enable IWYU in CMake#
Add the following to your CMakeLists.txt:
option(USE_IWYU "Enable include-what-you-use analysis" ON)
if(USE_IWYU)
find_program(IWYU_PATH NAMES include-what-you-use iwyu REQUIRED)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${IWYU_PATH}
-Xiwyu --comment_style=long
-Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/.iwyu-imp)
endif()
Manual Usage#
Run IWYU manually with:
Apply fixes with:Final Notes#
- Format your code with
.clang-formatbefore committing. - Use official templates for headers and source files.
- Keep includes minimal with IWYU.
- Stay consistent with the project’s coding standards.