[libcamera-devel] [PATCH] cam: convert to libfmt
Tomi Valkeinen
tomi.valkeinen at ideasonboard.com
Tue May 10 11:10:21 CEST 2022
On 10/05/2022 10:16, Tomi Valkeinen wrote:
> This is just a conversation starter, not for merging. I really like
> libfmt, and I really hate the C++ stream-based string formatting. libfmt
> is the first library I add to any new C++ project I make.
>
> You can find more information about libfmt from:
>
> https://github.com/fmtlib/fmt
> https://fmt.dev/latest/index.html
>
> This patch is just a crude conversion with ugly macros to showcase what
> the formatting code might look like.
As for the PR and EPR macros, those was just something to get forward
with. I think fmt::print("") is fine, but fmt::print(stderr, "") is a
bit long.
Compared to cout, "fmt::print(" is actually shorter than "std::cout <<
", and without all those << and std::endl the lines are shorter.
Not so with cerr and fmt::print(stderr, (although in many cases the
total length would still be shorter) but I think it makes sense to have
a macro/inline func for error prints, if only to make it more obvious
that it's an error print.
And, of course, libfmt could also be used for logging:
LOG(Camera, Error) << "Camera in " << camera_state_names[currentState]
<< " state trying " << from << "() requiring state "
<< camera_state_names[state];
to
LOG(Camera, Error, "Camera in {} state trying {}() requiring state {}",
camera_state_names[currentState], from, camera_state_names[state]);
Tomi
More information about the libcamera-devel
mailing list