StormByte C++ Library: Config module 1.0.1.9999
StormByte-Config is the configuration module of the StormByte C++ suite.
Loading...
Searching...
No Matches
type.hxx
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Config.
5 *
6 * StormByte-Config is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Config is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Config. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <StormByte/config/exception.hxx>
23#include <StormByte/config/visibility.h>
24
25#include <concepts>
26#include <cstddef>
27#include <string>
28#include <type_traits>
29#include <vector>
30
39 enum class Type: char {
40 Bool,
41 Comment,
42 Container,
43 Double,
44 Integer,
45 String,
46 Binary
47 };
48
54 static constexpr std::string TypeToString(const Type& t) noexcept {
55 switch(t) {
56 case Type::String: return "String";
57 case Type::Integer: return "Integer";
58 case Type::Double: return "Double";
59 case Type::Comment: return "Comment";
60 case Type::Bool: return "Bool";
61 case Type::Container: return "Container";
62 case Type::Binary: return "Binary";
63 default: return "Unknown";
64 }
65 }
66
71 enum class STORMBYTE_CONFIG_PUBLIC CommentType: char {
72 SingleLineBash = 2,
75 };
76
82 constexpr STORMBYTE_CONFIG_PUBLIC std::string TypeToString(const CommentType& t) noexcept {
83 switch(t) {
84 case CommentType::SingleLineBash: return "Bash like single line comment";
85 case CommentType::SingleLineC: return "C++ like single line comment";
86 case CommentType::MultiLineC: return "C/C++ like multi line comment";
87 default: return "Unknown";
88 }
89 }
90
95 enum class STORMBYTE_CONFIG_PUBLIC ContainerType: char {
96 Group,
98 };
99
105 constexpr STORMBYTE_CONFIG_PUBLIC std::string TypeToString(const ContainerType& t) noexcept {
106 switch(t) {
107 case ContainerType::Group: return "Group";
108 case ContainerType::List: return "List";
109 default: return "Unknown";
110 }
111 }
112
119 constexpr STORMBYTE_CONFIG_PUBLIC ContainerType TypeFromStartCharacter(const char& start) {
120 switch(start) {
121 case '{': return ContainerType::Group;
122 case '[': return ContainerType::List;
123 default: throw Exception("Unknown start character " + std::string(1, start) + " for container");
124 }
125 }
126
130 template<typename T>
132 std::is_same_v<T, int> ||
133 std::is_same_v<T, double> ||
134 std::is_same_v<T, bool> ||
135 std::is_same_v<T, std::string> ||
136 std::is_same_v<T, std::vector<std::byte>>;
137}
Base class for all configuration-related exceptions.
Definition exception.hxx:33
Comment item (#, // or /* *\/).
Definition comment.hxx:36
Holds child items. Group and List derive from this.
Definition container.hxx:38
Named container { … } that can hold items, subgroups and lists.
Definition group.hxx:38
Unnamed-item container [ … ].
Definition list.hxx:38
Value types allowed in Item::Value<T>.
Definition type.hxx:131
Configuration items (values, comments, groups, lists).
Definition alias.hxx:30
enum STORMBYTE_CONFIG_PUBLIC MultiLineC
/* … *&zwj;/
Definition type.hxx:74
enum STORMBYTE_CONFIG_PUBLIC ContainerType
Group of named items.
Definition type.hxx:95
enum STORMBYTE_CONFIG_PUBLIC CommentType
# until end of line
Definition type.hxx:71
Type
Represents the type of a configuration item.
Definition type.hxx:39
@ Binary
Binary data (std::vector<std::byte>; text form is Base64 b"...")
@ Double
Double-precision floating-point item.
constexpr STORMBYTE_CONFIG_PUBLIC ContainerType TypeFromStartCharacter(const char &start)
Resolves a container type from its opening character.
Definition type.hxx:119
enum STORMBYTE_CONFIG_PUBLIC SingleLineC
// until end of line
Definition type.hxx:73