LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
app_formatters.hpp
1#pragma once
2
3#include <litefx/app_api.hpp>
4
5template <>
6struct LITEFX_APPMODEL_API std::formatter<LiteFX::Platform> : std::formatter<std::string_view> {
7 auto format(LiteFX::Platform t, std::format_context& ctx) const {
8 string_view name = "Invalid";
9 switch (t) {
10 case LiteFX::Platform::Win32: name = "Win32"; break;
11 case LiteFX::Platform::Other: name = "Other"; break;
12 case LiteFX::Platform::None: name = "None"; break;
13 }
14 return formatter<string_view>::format(name, ctx);
15 }
16};
17
18template <>
19struct LITEFX_APPMODEL_API std::formatter<LiteFX::BackendType> : std::formatter<std::string_view> {
20 auto format(LiteFX::BackendType t, std::format_context& ctx) const {
21 string_view name = "Invalid";
22 switch (t) {
23 case LiteFX::BackendType::Rendering: name = "Rendering"; break;
24 //case LiteFX::BackendType::Physics: name = "Physics"; break;
25 case LiteFX::BackendType::Other: name = "Other"; break;
26 }
27 return formatter<string_view>::format(name, ctx);
28 }
29};
30
31template <>
32struct std::formatter<LiteFX::AppVersion> {
33 bool engineVersion = false;
34
35 constexpr auto parse(format_parse_context& ctx) {
36 auto it = ctx.begin(), end = ctx.end();
37
38 if (it != end && (*it == 'e'))
39 {
40 engineVersion = true;
41 it++;
42 }
43
44 if (it != end && *it != '}')
45 throw format_error("Invalid version format: expected: `}`.");
46
47 return it;
48 }
49
50 auto format(const LiteFX::AppVersion& app, std::format_context& ctx) const {
51 return engineVersion ?
52 std::format_to(ctx.out(), "{} Version {}", app.engineIdentifier(), app.engineVersion()) :
53 std::format_to(ctx.out(), "{}.{}.{}.{}", app.major(), app.minor(), app.patch(), app.revision());
54 }
55};
Contains the version of an App.
Definition app_api.hpp:50
StringView engineVersion() const noexcept
Gets the version string of the engine build.
Definition appversion.cpp:85
int major() const noexcept
Gets the major version of the app.
Definition appversion.cpp:40
int patch() const noexcept
Gets the patch number of the app.
Definition appversion.cpp:50
int revision() const noexcept
Gets the revision of the app.
Definition appversion.cpp:55
int minor() const noexcept
Gets the minor version of the app.
Definition appversion.cpp:45
StringView engineIdentifier() const noexcept
Gets the identifier of the engine build.
Definition appversion.cpp:80
Definition app.hpp:6
BackendType
Definition app_api.hpp:35
Platform
Definition app_api.hpp:29
auto format(const LiteFX::AppVersion &app, std::format_context &ctx) const
Definition app_formatters.hpp:50
constexpr auto parse(format_parse_context &ctx)
Definition app_formatters.hpp:35
auto format(LiteFX::BackendType t, std::format_context &ctx) const
Definition app_formatters.hpp:20
auto format(LiteFX::Platform t, std::format_context &ctx) const
Definition app_formatters.hpp:7