// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_CORE_TOSTRING_HPP #define NAZARA_CORE_TOSTRING_HPP #include #include #include #include #include namespace Nz { template std::string Format(std::string_view str, Args&&... args); template decltype(auto) ToString(T&& value); template struct ToStringFormatter { static_assert(AlwaysFalse(), "ToStringFormatter is not implemented for this type"); }; template<> struct NAZARA_CORE_API ToStringFormatter { static std::string Format(const std::filesystem::path& path); }; template<> struct ToStringFormatter { static const std::string& Format(const std::string& value); static std::string Format(std::string&& value); }; template<> struct ToStringFormatter { static std::string Format(std::string_view value); }; template<> struct ToStringFormatter { static std::string_view Format(const char* value); template static std::string_view Format(const char(&str)[N]); }; // Specializations declared in .inl #define NAZARA_TO_STRING_INLINE_SPEC(Type) \ template<> \ struct ToStringFormatter \ { \ static std::string Format(Type value); \ } NAZARA_TO_STRING_INLINE_SPEC(short); NAZARA_TO_STRING_INLINE_SPEC(int); NAZARA_TO_STRING_INLINE_SPEC(long); NAZARA_TO_STRING_INLINE_SPEC(long long); NAZARA_TO_STRING_INLINE_SPEC(unsigned short); NAZARA_TO_STRING_INLINE_SPEC(unsigned int); NAZARA_TO_STRING_INLINE_SPEC(unsigned long); NAZARA_TO_STRING_INLINE_SPEC(unsigned long long); #undef NAZARA_TO_STRING_INLINE_SPEC // Specializations declared in .cpp #define NAZARA_TO_STRING_CPP_SPEC(Type) \ template<> \ struct NAZARA_CORE_API ToStringFormatter \ { \ static std::string Format(Type value); \ } NAZARA_TO_STRING_CPP_SPEC(float); NAZARA_TO_STRING_CPP_SPEC(double); NAZARA_TO_STRING_CPP_SPEC(long double); #undef NAZARA_TO_STRING_CPP_SPEC } #include #endif // NAZARA_CORE_TOSTRING_HPP