How bernedom/si works
Project Type and Purpose
• This is a header‐only C++17 library (“SI”) that provides compile‐time, type‐safe representations of physical quantities in the International System of Units.
• It offers a set of unit_t templates (in include/SI), specialized typedefs and user-defined literals, plus detail helpers for compile‐time parsing, arithmetic and casting.
• It includes a comprehensive test suite (Catch2‐based), CI pipelines, documentation generation, and packaging via CMake/Conan.
High‐Level Architecture and Components
a. Core Library (Compile‐Time Engine)
• Directory: include/SI
• unit_t template struct
• Unit headers (e.g. length, mass, time, derived units)
• detail sub-folder: parser, operator helpers, conversion logic
• Responsibility: define units, ratios, execute arithmetic and conversions at compile time.
b. Build & Packaging Infrastructure
• Root CMakeLists.txt + CMakePresets.json + cmake/SIConfig.cmake.in
• Conan integration via conanfile.txt and CMakeDeps
• Packaging targets: install rules, cpack (optional), Conan center
c. Continuous Integration & Documentation
• .github/workflows/ci.yml – builds/tests on multiple compilers
• .github/workflows/api-doc.yml – triggers Doxygen or Sphinx API docs
• .github/workflows/codeql.yml – security/code analysis
• doc/ – installation guide, implementation details, code‐quality tools
d. Test Suite
• test/src – unit tests (base, derived, detail), compilation‐only tests, benchmarks
• Catch2 is vendored under test/include/catch2
• Installation tests under test/installation-tests
e. Consumer Integration (User Code)
• CMake FetchContent snippet shown in README
• Conan package usage
Relationships & Interactions
• The Core Library headers have an internal dependency on detail helpers, then expose public typedefs/literals to user code.
• Build system (CMake + Conan) reads conanfile.txt → generates CMakeDeps → drives header installation and test targets.
• CI pipelines invoke CMake builds, run tests (including compilation‐only tests), generate API docs into si.dominikberner.ch/doc/.
• Users consume the library via target_link_libraries(MyApp PUBLIC SI::SI) or FetchContent/Conan.
Architectural Patterns and Principles
• Header‐Only “Library as Code” pattern: no runtime binaries, only templates and inline functions.
• Single Responsibility: each unit (e.g. length.h, mass.h) encapsulates one physical quantity.
• CRTP/Type Traits: ratio and unit relationships encoded as type traits in detail/*.
• Zero‐Overhead Abstraction: same‐ratio operations compile to no runtime overhead.
• Extensive Test‐Driven Development: compilation‐failure tests ensure type safety at compile time.