HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
application_metadata.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "semantic_version.hpp"
8#include "../algorithm/module.hpp"
9#include "../macros.hpp"
10#include <string>
11#include <stdexcept>
12#include <filesystem>
13#include <source_location>
14
15hi_export_module(hikogui.metadata.metadata_application);
16
17namespace hi { inline namespace v1 {
18
19inline std::optional<std::string> _application_name = std::nullopt;
20inline std::optional<std::string> _application_slug = std::nullopt;
21inline std::optional<std::string> _application_vendor = std::nullopt;
22inline std::optional<semantic_version> _application_version = std::nullopt;
23
24hi_export [[nodiscard]] inline std::string const& get_application_name()
25{
26 if (_application_name) {
27 return *_application_name;
28 } else {
29 throw std::logic_error("set_application_name() should be called at application startup.");
30 }
31}
32
33hi_export [[nodiscard]] inline std::string const& get_application_slug()
34{
35 if (_application_slug) {
36 return *_application_slug;
37 } else {
38 throw std::logic_error("set_application_name() should be called at application startup.");
39 }
40}
41
42hi_export [[nodiscard]] inline std::string const& get_application_vendor()
43{
44 if (_application_vendor) {
45 return *_application_vendor;
46 } else {
47 throw std::logic_error("set_application_vendor() should be called at application startup.");
48 }
49}
50
51hi_export [[nodiscard]] inline semantic_version const& get_application_version()
52{
53 if (_application_version) {
54 return *_application_version;
55 } else {
56 throw std::logic_error("set_application_version() should be called at application startup.");
57 }
58}
59
60hi_export inline void set_application_name(std::string_view name, std::string_view slug)
61{
62 if (name.empty()) {
63 throw std::invalid_argument("application name must not be empty.");
64 }
65 if (name.contains('/') or name.contains('\\')) {
66 throw std::invalid_argument("application name must not contain a slash or backslash.");
67 }
68 if (slug.empty()) {
69 throw std::invalid_argument("application slug must not be empty.");
70 }
71 if (not is_slug(slug)) {
72 throw std::invalid_argument("application slug must contain only 'a'-'z' '0'-'9' and '-' characters.");
73 }
74
75 _application_name = name;
76 _application_slug = slug;
77}
78
79hi_export inline void set_application_name(std::string_view name)
80{
81 return set_application_name(name, make_slug(name));
82}
83
84hi_export inline void set_application_vendor(std::string_view name)
85{
86 if (name.empty()) {
87 throw std::invalid_argument("vendor name must not be empty.");
88 }
89 if (name.contains('/') or name.contains('\\')) {
90 throw std::invalid_argument("vendor name must not contain a slash or backslash.");
91 }
92
93 _application_vendor = name;
94}
95
96hi_export inline void set_application_version(semantic_version version) noexcept
97{
98 _application_version = version;
99}
100
101hi_export inline void set_application_version(int major, int minor = 0, int patch = 0) noexcept
102{
103 return set_application_version(semantic_version{major, minor, patch});
104}
105
106}} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr std::string make_slug(std::string_view str) noexcept
Create a slug from a string.
Definition strings.hpp:254
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377