Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
format_stuff.hh
Go to the documentation of this file.
1/*
2 * Scroom - Generic viewer for 2D data
3 * Copyright (C) 2009-2026 Kees-Jan Dijkzeul
4 *
5 * SPDX-License-Identifier: LGPL-2.1
6 */
7
8#pragma once
9
10#include <memory>
11
12#include <fmt/format.h>
13
14#include <scroom/point.hh>
15#include <scroom/rectangle.hh>
16
17template <typename T>
18struct fmt::formatter<Scroom::Utils::Rectangle<T>> : formatter<T>
19{
20 template <typename FormatContext>
21 auto format(const Scroom::Utils::Rectangle<T>& r, FormatContext& ctx) const -> decltype(ctx.out())
22 {
23 format_to(ctx.out(), "<");
24 formatter<T>::format(r.getLeft(), ctx);
25 format_to(ctx.out(), ",");
26 formatter<T>::format(r.getTop(), ctx);
27 format_to(ctx.out(), ",");
28 formatter<T>::format(r.getWidth(), ctx);
29 format_to(ctx.out(), ",");
30 formatter<T>::format(r.getHeight(), ctx);
31 format_to(ctx.out(), ">");
32
33 return ctx.out();
34 }
35};
36
37template <typename T>
38struct fmt::formatter<Scroom::Utils::Point<T>> : formatter<T>
39{
40 template <typename FormatContext>
41 auto format(const Scroom::Utils::Point<T>& p, FormatContext& ctx) const -> decltype(ctx.out())
42 {
43 format_to(ctx.out(), "(");
44 formatter<T>::format(p.x, ctx);
45 format_to(ctx.out(), ",");
46 formatter<T>::format(p.y, ctx);
47 format_to(ctx.out(), ")");
48
49 return ctx.out();
50 }
51};
52
53template <typename T>
54struct fmt::formatter<std::shared_ptr<T>> : formatter<const void*>
55{
56 template <typename FormatContext>
57 auto format(const std::shared_ptr<T>& p, FormatContext& ctx) const -> decltype(ctx.out())
58 {
59 return formatter<const void*>::format(fmt::ptr(p.get()), ctx);
60 }
61};
62
63template <typename T>
64struct fmt::formatter<std::weak_ptr<T>> : formatter<const void*>
65{
66 template <typename FormatContext>
67 auto format(const std::weak_ptr<T>& p, FormatContext& ctx) const -> decltype(ctx.out())
68 {
69 auto locked = p.lock();
70 if(locked)
71 {
72 return formatter<const void*>::format(fmt::ptr(locked.get()), ctx);
73 }
74
75 return format_to(ctx.out(), "[expired]");
76 }
77};
Definition point.hh:28
Definition rectangle.hh:29
value_type getTop() const
Definition rectangle.hh:108
value_type getWidth() const
Definition rectangle.hh:121
value_type getHeight() const
Definition rectangle.hh:123
value_type getLeft() const
Definition rectangle.hh:110
PresentationInterfaceStub::Ptr const p
Definition determine-size-test.cc:172
Definition blockallocator.hh:18
STL namespace.
auto format(const Scroom::Utils::Point< T > &p, FormatContext &ctx) const -> decltype(ctx.out())
Definition format_stuff.hh:41
auto format(const Scroom::Utils::Rectangle< T > &r, FormatContext &ctx) const -> decltype(ctx.out())
Definition format_stuff.hh:21
auto format(const std::shared_ptr< T > &p, FormatContext &ctx) const -> decltype(ctx.out())
Definition format_stuff.hh:57
auto format(const std::weak_ptr< T > &p, FormatContext &ctx) const -> decltype(ctx.out())
Definition format_stuff.hh:67
Scroom::Utils::Rectangle< double > const r
Definition transformpresentation_test.cc:65