Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Types.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "util/UnsupportedType.hpp"
23
24#include <fmt/core.h>
25
26#include <cstdint>
27#include <expected>
28#include <ostream>
29#include <string>
30#include <variant>
31
32namespace util::config {
33
35enum class ConfigType { Integer, String, Double, Boolean, Null };
36
40struct NullType {
46 [[nodiscard]] bool
47 operator==(NullType const&) const
48 {
49 return true;
50 }
51};
52
60std::ostream&
61operator<<(std::ostream& stream, ConfigType type);
62
64using Value = std::variant<int64_t, std::string, bool, double, NullType>;
65
73std::ostream&
74operator<<(std::ostream& stream, Value value);
75
82template <typename Type>
83constexpr ConfigType
84getType()
85{
86 if constexpr (std::is_same_v<Type, int64_t>) {
87 return ConfigType::Integer;
88 } else if constexpr (std::is_same_v<Type, std::string>) {
89 return ConfigType::String;
90 } else if constexpr (std::is_same_v<Type, double>) {
91 return ConfigType::Double;
92 } else if constexpr (std::is_same_v<Type, bool>) {
93 return ConfigType::Boolean;
94 } else if constexpr (std::is_same_v<Type, NullType>) {
95 return ConfigType::Null;
96 } else {
97 static_assert(util::Unsupported<Type>, "Wrong config type");
98 }
99}
100
101} // namespace util::config
102
104// Doxygen could not parse this
105template <>
106struct fmt::formatter<util::config::NullType> : fmt::formatter<char const*> {
107 [[nodiscard]]
108 auto
109 format(util::config::NullType const&, fmt::format_context& ctx)
110 {
111 return fmt::formatter<char const*>::format("null", ctx);
112 }
113};
This namespace contains various utilities.
Definition AccountUtils.hpp:30
static constexpr bool Unsupported
used for compile time checking of unsupported types
Definition UnsupportedType.hpp:26
std::ostream & operator<<(std::ostream &stream, Severity sev)
Custom labels for Severity in log output.
Definition Logger.cpp:73
A type that represents a null value.
Definition Types.hpp:40
bool operator==(NullType const &) const
Compare two NullType objects.
Definition Types.hpp:47