xtd 0.2.0
__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
10#include "__enum_formatter.hpp"
11#include "../helpers/throw_helper.hpp"
12#include "../iformatable.hpp"
13#include "../istringable.hpp"
14
16namespace xtd {
17 class object;
18}
19
20std::string __to_string_object_to_string(const xtd::object* obj);
21std::string __to_string_istringable_to_string(const xtd::istringable* obj);
22
23template<class value_t>
24static std::string __to_string_polymorphic(const value_t& value, const std::string& fmt, const std::locale& loc, std::true_type) {
25 auto value_ptr = &value;
26 if (dynamic_cast<const xtd::iformatable*>(value_ptr)) return dynamic_cast<const xtd::iformatable&>(value).__opague_internal_formatable__(reinterpret_cast<intptr_t>(&fmt), reinterpret_cast<intptr_t>(&loc), 0, INTPTR_MAX);
27 if (dynamic_cast<const xtd::istringable*>(value_ptr)) return __to_string_istringable_to_string(dynamic_cast<const xtd::istringable*>(&value));
28 if (dynamic_cast<const xtd::object*>(value_ptr)) return __to_string_object_to_string(dynamic_cast<const xtd::object*>(value_ptr));
29 if (dynamic_cast<const std::exception*>(value_ptr)) return std::string {"exception: "} + dynamic_cast<const std::exception&>(value).what();
31}
32
33template<class value_t>
34static std::string __to_string_polymorphic(const value_t& value, const std::string& fmt, const std::locale& loc, std::false_type) {
35 return __to_string_enum(value, fmt, loc, std::is_enum<value_t>());
36}
Contains __enum_formatter method.
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
Provides a way to represent the current object as a string.
Definition istringable.hpp:23
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
@ format_not_iformatable
The object is not iformatable.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10