xtd 1.0.0
Loading...
Searching...
No Matches
__iformatable_formatter.hpp
Go to the documentation of this file.
1
3#pragma once
5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
7#endif
9
11#include "../iformatable.hpp"
12#include "../istringable.hpp"
13#include "../textual.hpp"
14#include "../raw_type.hpp"
15#include <type_traits>
16
18namespace xtd {
19 class object;
20}
21
22[[nodiscard]] auto __to_string_iformatable_to_string(const xtd::iformatable* obj, const std::string& fmt, const std::locale& loc) -> std::string;
23template<typename type_t>
24[[nodiscard]] auto __to_string_istringable_to_string(const xtd::istringable<type_t>* obj) -> std::string;
25[[nodiscard]] auto __to_string_object_to_string(const xtd::object* obj) -> std::string;
26
27template<typename value_t>
28[[nodiscard]] inline static auto __to_string_polymorphic(const value_t& value, const std::string& fmt, const std::locale& loc) -> std::string {
29 if constexpr(std::derived_from<xtd::raw_type<value_t>, xtd::iformatable>) return __to_string_iformatable_to_string(static_cast<const xtd::iformatable*>(&value), fmt, loc);
30 else if constexpr(std::derived_from<xtd::raw_type<value_t>, xtd::istringable<xtd::raw_type<value_t>>>) return __to_string_istringable_to_string(static_cast<const xtd::istringable<value_t>*>(&value));
31 else if constexpr(std::derived_from<xtd::raw_type<value_t>, xtd::object>) return __to_string_object_to_string(static_cast<const xtd::object*>(&value));
32 else if constexpr(std::derived_from<xtd::raw_type<value_t>, std::exception>) return std::string {"exception: "} + static_cast<const std::exception&>(value).what();
33 else if constexpr(requires(const xtd::raw_type<value_t>& value, const xtd::string& _fmt) {{value.to_string(_fmt)} -> xtd::textual;}) return value.to_string(fmt);
34 else if constexpr(requires(const xtd::raw_type<value_t>& value) {{value.to_string()} -> xtd::textual;}) return value.to_string();
36}
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:42
Provides a way to represent the current object as a string.
Definition istringable.hpp:26
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:40
Definition textual.hpp:16
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
@ format_not_iformatable
The object is not iformatable.
Definition exception_case.hpp:59
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::remove_cvref_t< value_t > raw_type
Represents a raw type alias equivalent to std::remove_cvref_t<value_t>.
Definition raw_type.hpp:25
Contains xtd::iformatable interface.
Contains xtd::istringable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::raw_type alias.
Contains xtd::textual concept.
Contains xtd::helpers::throw_helper class.