StormByte C++ Library: Config module 0.0.9999
StormByte-Config is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
type.hxx
1#pragma once
2
3#include <StormByte/config/exception.hxx>
4#include <StormByte/config/visibility.h>
5
6#include <cstddef>
7#include <concepts>
8#include <string>
9#include <type_traits>
10
15namespace StormByte::Config::Item {
20 enum class Type: char {
21 Bool,
22 Comment,
23 Container,
24 Double,
25 Integer,
26 String
27 };
28
34 static constexpr std::string TypeToString(const Type& t) noexcept {
35 switch(t) {
36 case Type::String: return "String";
37 case Type::Integer: return "Integer";
38 case Type::Double: return "Double";
39 case Type::Comment: return "Comment";
40 case Type::Bool: return "Bool";
41 case Type::Container: return "Container";
42 default: return "Unknown";
43 }
44 }
45
50 enum class STORMBYTE_CONFIG_PUBLIC CommentType: char {
51 SingleLineBash = 2,
52 SingleLineC=5,
53 MultiLineC=8
54 };
55
61 constexpr STORMBYTE_CONFIG_PUBLIC std::string TypeToString(const CommentType& t) noexcept {
62 switch(t) {
63 case CommentType::SingleLineBash: return "Bash like single line comment";
64 case CommentType::SingleLineC: return "C++ like single line comment";
65 case CommentType::MultiLineC: return "C/C++ like multi line comment";
66 default: return "Unknown";
67 }
68 }
69
74 enum class STORMBYTE_CONFIG_PUBLIC ContainerType: char {
75 Group,
76 List
77 };
78
84 constexpr STORMBYTE_CONFIG_PUBLIC std::string TypeToString(const ContainerType& t) noexcept {
85 switch(t) {
86 case ContainerType::Group: return "Group";
87 case ContainerType::List: return "List";
88 default: return "Unknown";
89 }
90 }
91
97 constexpr STORMBYTE_CONFIG_PUBLIC ContainerType TypeFromStartCharacter(const char& start) noexcept {
98 switch(start) {
99 case '{': return ContainerType::Group;
100 case '[': return ContainerType::List;
101 default: throw Exception("Unknown start character " + std::string(1, start) + " for container");
102 }
103 }
104
105 template<typename T>
106 concept AllowedValueType = std::is_same_v<T, int> ||
107 std::is_same_v<T, double> ||
108 std::is_same_v<T, bool> ||
109 std::is_same_v<T, std::string>;
110}