Celeritas 0.7.0-33+develop.9c828abdd
Loading...
Searching...
No Matches
Macros
SourceFile.hh File Reference
#include <cstddef>
#include <utility>
#include "corecel/Config.hh"
#include "Macros.hh"

Macros

#define CELER_SOURCE_FILE   __FILE__
 Expand to the current source file path relative to the Celeritas source tree, as a null-terminated string that lives for the duration of the program.
 

Macro Definition Documentation

◆ CELER_SOURCE_FILE

#define CELER_SOURCE_FILE   __FILE__

Expand to the current source file path relative to the Celeritas source tree, as a null-terminated string that lives for the duration of the program.

This replaces __FILE__ in log and error provenance so that build directories are not compiled into the binary and so that messages show a short path such as corecel/io/Logger.hh rather than a full one. The trimming is done at compile time (see celeritas::detail::source_file) and requires only C++17. Paths that do not contain a src/, app/, or test/ component are left unchanged, and Windows path separators are replaced with forward slashes.

Each use expands to a lambda holding a local class, which costs the compiler roughly as much as a small function definition. Trimming is therefore enabled only through the CELERITAS_TRIM_SOURCE_FILE configuration option, which is available only when debug assertions are disabled and the compiler is known to handle it. Otherwise, and always in device code (where the trimmed string would be a host address), this macro is simply __FILE__ .