/** This file is a part of rexy's general purpose library Copyright (C) 2022 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef REXY_DETAIL_FORMAT_STORAGE_TPP #define REXY_DETAIL_FORMAT_STORAGE_TPP #include "storage.hpp" #include "named_args.hpp" #include //is_pointer, remove_cvref, remove_pointer, is_same, is_arithmetic #include //unsigned_integral, signed_integral, floating_point #include //nullptr_t namespace rexy::fmt::detail{ ///////////////////////storage type mapping//////////////////////// template consteval storage_type map_to_storage_enum(void){ using type = std::remove_cvref_t; if constexpr(std::is_pointer_v){ if constexpr(std::is_same_v>,Char>){ return storage_type::char_ptr_t; }else{ return storage_type::ptr_t; } }else if constexpr(std::is_same_v>){ return storage_type::string_t; }else if constexpr(std::is_same_v){ return storage_type::char_t; }else if constexpr(std::is_same_v){ return storage_type::none_t; }else if constexpr(std::is_same_v){ return storage_type::bool_t; }else if constexpr(std::is_same_v){ return storage_type::int_t; }else if constexpr(std::is_same_v){ return storage_type::uint_t; }else if constexpr(std::is_same_v){ return storage_type::long_long_t; }else if constexpr(std::is_same_v){ return storage_type::ulong_long_t; }else if constexpr(std::is_same_v){ return storage_type::float_t; }else if constexpr(std::is_same_v){ return storage_type::double_t; }else if constexpr(std::is_same_v){ return storage_type::long_double_t; }else{ return storage_type::custom_t; } } template struct map_to_stored_type_helper{ using char_type = typename Context::char_type; template requires (!std::is_arithmetic_v && !std::is_pointer_v && !NamedArg) constexpr auto operator()(T) -> typename basic_format_arg::handle; constexpr auto operator()(std::unsigned_integral auto i){ if constexpr(sizeof(i) <= sizeof(unsigned int)){ return (unsigned int)(0); }else{ return (unsigned long long)(0); } } constexpr auto operator()(std::signed_integral auto i){ if constexpr(sizeof(i) <= sizeof(int)){ return int(0); }else{ return (long long)(0); } } template constexpr auto operator()(T) -> std::remove_cvref_t; constexpr auto operator()(char_type) -> char_type; constexpr auto operator()(bool) -> bool; constexpr auto operator()(float) -> float; constexpr auto operator()(double) -> double; constexpr auto operator()(long double) -> long double; constexpr auto operator()(const char_type*) -> const char_type*; constexpr auto operator()(basic_string_view) -> basic_string_view; constexpr auto operator()(basic_string) -> basic_string_view; template requires (!std::is_same_v,char_type>) constexpr auto operator()(T*) -> const void*; constexpr auto operator()(std::nullptr_t) -> const void*; template constexpr auto operator()(T t) -> decltype((*this)(t.value)); }; } #endif