Atlas Game Manager
A game manager for f95 and dlsite written in c++
Loading...
Searching...
No Matches
formatters.hpp
Go to the documentation of this file.
1//
2// Created by kj16609 on 9/11/23.
3//
4
5#pragma once
6#ifndef ATLASGAMEMANAGER_FORMATTERS_HPP
7#define ATLASGAMEMANAGER_FORMATTERS_HPP
8
9#include <QString>
10
11// clang-format:off
12
13#ifdef HAVE_STD_FORMAT
14#include <format>
15namespace format_ns = std;
16
17#else
18#ifdef __GNUC__
19#pragma GCC diagnostic push
20#pragma GCC diagnostic ignored "-Weffc++"
21#pragma GCC diagnostic ignored "-Wswitch-default"
22#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
23#endif
24
25#include <fmt/format.h>
26namespace format_ns = fmt;
27
28#ifdef __GNUC__
29#pragma GCC diagnostic pop
30#endif
31
32#endif
33
34// clang-format:on
35
37template <>
38struct format_ns::formatter< QString >
39{
40 constexpr auto parse( format_ns::format_parse_context& ctx ) -> decltype( ctx.begin() ) { return ctx.begin(); }
41
42 template < typename FormatContext >
43 auto format( const QString& my, FormatContext& ctx ) const -> decltype( ctx.out() )
44 {
45 return format_ns::format_to( ctx.out(), "{}", my.toStdString() );
46 }
47};
48
49template <>
50struct format_ns::formatter< std::filesystem::path >
51{
52 bool print_canonical { false };
53 bool print_exists { false };
54
55 constexpr format_parse_context::iterator parse( format_parse_context& ctx )
56 {
57 //Check if ctx has 'c' 'ce' or 'e' and return the itterator after it
58 auto idx { ctx.begin() };
59 const auto end { ctx.end() };
60
61 if ( idx != end && *idx == 'c' )
62 {
63 print_canonical = true;
64 ++idx;
65 }
66
67 if ( idx != end && *idx == 'e' )
68 {
69 print_exists = true;
70 ++idx;
71 }
72
73 return idx;
74 }
75
76 format_context::iterator format( const std::filesystem::path& path, format_context& ctx ) const;
77};
78
79template <>
80struct format_ns::formatter< std::source_location >
81{
82 constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
83
84 format_context::iterator format( const std::source_location& loc, format_context& ctx ) const;
85};
86
87template <>
88struct format_ns::formatter< format_ns::format_string<> >
89{
90 constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
91
92 format_context::iterator format( const format_ns::format_string<>& str, format_context& ctx ) const;
93};
94
95template <>
96struct format_ns::formatter< QSize >
97{
98 constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
99
100 format_context::iterator format( const QSize size, format_context& ctx ) const;
101};
102
103template <>
104struct format_ns::formatter< QUrl >
105{
106 constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
107
108 format_context::iterator format( const QUrl& url, format_context& ctx ) const;
109};
110
111#endif //ATLASGAMEMANAGER_FORMATTERS_HPP
constexpr format_parse_context::iterator parse(format_parse_context &ctx)
Definition formatters.hpp:98
constexpr auto parse(format_ns::format_parse_context &ctx) -> decltype(ctx.begin())
Definition formatters.hpp:40
auto format(const QString &my, FormatContext &ctx) const -> decltype(ctx.out())
Definition formatters.hpp:43
constexpr format_parse_context::iterator parse(format_parse_context &ctx)
Definition formatters.hpp:106
constexpr format_parse_context::iterator parse(format_parse_context &ctx)
Definition formatters.hpp:90
constexpr format_parse_context::iterator parse(format_parse_context &ctx)
Definition formatters.hpp:55
bool print_canonical
Definition formatters.hpp:52
bool print_exists
Definition formatters.hpp:53
constexpr format_parse_context::iterator parse(format_parse_context &ctx)
Definition formatters.hpp:82