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/algorithm.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
17hi_export namespace 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 initialize();
27
28 if (_application_name) {
29 return *_application_name;
30 } else {
31 throw std::logic_error("set_application_name() should be called at application startup.");
32 }
33}
34
35hi_export [[nodiscard]] inline std::string const& get_application_slug()
36{
37 initialize();
38
39 if (_application_slug) {
40 return *_application_slug;
41 } else {
42 throw std::logic_error("set_application_name() should be called at application startup.");
43 }
44}
45
46hi_export [[nodiscard]] inline std::string const& get_application_vendor()
47{
48 initialize();
49
50 if (_application_vendor) {
51 return *_application_vendor;
52 } else {
53 throw std::logic_error("set_application_vendor() should be called at application startup.");
54 }
55}
56
57hi_export [[nodiscard]] inline semantic_version const& get_application_version()
58{
59 initialize();
60
61 if (_application_version) {
62 return *_application_version;
63 } else {
64 throw std::logic_error("set_application_version() should be called at application startup.");
65 }
66}
67
68hi_export inline void set_application_name(std::string_view name, std::string_view slug)
69{
70 initialize();
71
72 if (name.empty()) {
73 throw std::invalid_argument("application name must not be empty.");
74 }
75 if (name.contains('/') or name.contains('\\')) {
76 throw std::invalid_argument("application name must not contain a slash or backslash.");
77 }
78 if (slug.empty()) {
79 throw std::invalid_argument("application slug must not be empty.");
80 }
81 if (not is_slug(slug)) {
82 throw std::invalid_argument("application slug must contain only 'a'-'z' '0'-'9' and '-' characters.");
83 }
84
85 _application_name = name;
86 _application_slug = slug;
87}
88
89hi_export inline void set_application_name(std::string_view name)
90{
91 initialize();
92
93 return set_application_name(name, make_slug(name));
94}
95
96hi_export inline void set_application_vendor(std::string_view name)
97{
98 initialize();
99
100 if (name.empty()) {
101 throw std::invalid_argument("vendor name must not be empty.");
102 }
103 if (name.contains('/') or name.contains('\\')) {
104 throw std::invalid_argument("vendor name must not contain a slash or backslash.");
105 }
106
107 _application_vendor = name;
108}
109
110hi_export inline void set_application_version(semantic_version version) noexcept
111{
112 initialize();
113
114 _application_version = version;
115}
116
117hi_export inline void set_application_version(int major, int minor = 0, int patch = 0) noexcept
118{
119 initialize();
120
121 return set_application_version(semantic_version{major, minor, patch});
122}
123
124}} // namespace hi::inline v1
The HikoGUI namespace.
Definition array_generic.hpp:20
void initialize() noexcept
Initialize base functionality of HikoGUI.
Definition initialize.hpp:56
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
constexpr std::string make_slug(std::string_view str) noexcept
Create a slug from a string.
Definition strings.hpp:254