ORE Studio 0.0.4
Loading...
Searching...
No Matches
system_flags.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_VARIABILITY_DOMAIN_SYSTEM_FLAGS_HPP
21#define ORES_VARIABILITY_DOMAIN_SYSTEM_FLAGS_HPP
22
23#include <array>
24#include <string>
25#include <ostream>
26#include <optional>
27#include <stdexcept>
28#include <string_view>
29#include <magic_enum/magic_enum.hpp>
30
31namespace ores::variability::domain {
32
44enum class system_flag {
52 bootstrap_mode,
53
61 user_signups,
62
70 disable_password_validation
71};
72
77 system_flag flag;
78 bool default_enabled;
79 std::string_view description;
80};
81
89inline constexpr std::array system_flag_definitions = {
91 .flag = system_flag::bootstrap_mode,
92 .default_enabled = true,
93 .description = "Indicates whether the system is in bootstrap mode "
94 "(waiting for initial admin account)."
95 },
96 system_flag_definition {
97 .flag = system_flag::user_signups,
98 .default_enabled = false,
99 .description = "Controls whether user self-registration is allowed."
100 },
101 system_flag_definition {
102 .flag = system_flag::disable_password_validation,
103 .default_enabled = false,
104 .description = "When enabled, disables strict password validation. "
105 "FOR TESTING/DEVELOPMENT ONLY."
106 }
107};
108
118[[nodiscard]] inline std::string to_flag_name(system_flag flag) {
119 return std::string("system.") + std::string(magic_enum::enum_name(flag));
120}
121
128[[nodiscard]] inline std::optional<system_flag> from_flag_name(std::string_view name) {
129 constexpr std::string_view prefix = "system.";
130 if (!name.starts_with(prefix)) {
131 return std::nullopt;
132 }
133
134 auto enum_name = name.substr(prefix.size());
135 return magic_enum::enum_cast<system_flag>(enum_name);
136}
137
144[[nodiscard]] inline const system_flag_definition&
145get_definition(system_flag flag) {
146 for (const auto& def : system_flag_definitions) {
147 if (def.flag == flag)
148 return def;
149 }
150 // This should never happen for valid enum values.
151 throw std::logic_error("Definition for system_flag not found.");
152}
153
159inline std::ostream& operator<<(std::ostream& os, system_flag flag) {
160 return os << to_flag_name(flag);
161}
162
163}
164
165#endif
Metadata for a system flag including its default state and description.
Definition system_flags.hpp:76