diff options
Diffstat (limited to 'source/core')
30 files changed, 104 insertions, 27 deletions
diff --git a/source/core/StarAssetPath.hpp b/source/core/StarAssetPath.hpp index 93fa8eb..3fc7849 100644 --- a/source/core/StarAssetPath.hpp +++ b/source/core/StarAssetPath.hpp @@ -77,4 +77,6 @@ struct hash<AssetPath> { } +template <> struct fmt::formatter<Star::AssetPath> : ostream_formatter {}; + #endif
\ No newline at end of file diff --git a/source/core/StarBuffer.cpp b/source/core/StarBuffer.cpp index fbed59a..e99615c 100644 --- a/source/core/StarBuffer.cpp +++ b/source/core/StarBuffer.cpp @@ -90,7 +90,7 @@ void Buffer::open(IOMode mode) { } String Buffer::deviceName() const { - return strf("Buffer <%s>", this); + return strf("Buffer <%s>", (void*)this); } StreamOffset Buffer::size() { @@ -244,7 +244,7 @@ size_t ExternalBuffer::writeAbsolute(StreamOffset, char const*, size_t) { } String ExternalBuffer::deviceName() const { - return strf("ExternalBuffer <%s>", this); + return strf("ExternalBuffer <%s>", (void*)this); } StreamOffset ExternalBuffer::size() { diff --git a/source/core/StarByteArray.hpp b/source/core/StarByteArray.hpp index 051895f..9f63643 100644 --- a/source/core/StarByteArray.hpp +++ b/source/core/StarByteArray.hpp @@ -256,4 +256,6 @@ inline size_t hash<ByteArray>::operator()(ByteArray const& b) const { } +template <> struct fmt::formatter<Star::ByteArray> : ostream_formatter {}; + #endif diff --git a/source/core/StarColor.hpp b/source/core/StarColor.hpp index d50d694..08b7e35 100644 --- a/source/core/StarColor.hpp +++ b/source/core/StarColor.hpp @@ -3,6 +3,7 @@ #include "StarStringView.hpp" #include "StarVector.hpp" +#include "StarFormat.hpp" namespace Star { @@ -103,6 +104,8 @@ public: Vec4F toRgbaF() const; Vec3F toRgbF() const; + Vec4F const& data() const; + Vec4F toHsva() const; String toHex() const; @@ -167,4 +170,6 @@ inline Vec4B Color::v4fToByte(Vec4F const& f, bool doClamp) { } +template <> struct fmt::formatter<Star::Color> : ostream_formatter {}; + #endif diff --git a/source/core/StarDirectives.cpp b/source/core/StarDirectives.cpp index dc1765c..bf3dcc1 100644 --- a/source/core/StarDirectives.cpp +++ b/source/core/StarDirectives.cpp @@ -101,6 +101,10 @@ void Directives::parse(String&& directives) { return; shared = std::make_shared<Shared const>(move(newList), move(directives), prefix); + if (view.size() < 1000) { // Pre-load short enough directives + for (auto& entry : shared->entries) + entry.loadOperation(*shared); + } } String Directives::string() const { diff --git a/source/core/StarException.hpp b/source/core/StarException.hpp index 7e6fe3e..4774dd2 100644 --- a/source/core/StarException.hpp +++ b/source/core/StarException.hpp @@ -8,7 +8,7 @@ namespace Star { class StarException : public std::exception { public: template <typename... Args> - static StarException format(char const* fmt, Args const&... args); + static StarException format(fmt::format_string<Args...> fmt, Args const&... args); StarException() noexcept; virtual ~StarException() noexcept; @@ -72,7 +72,7 @@ void fatalException(std::exception const& e, bool showStackTrace); class ClassName : public BaseName { \ public: \ template <typename... Args> \ - static ClassName format(char const* fmt, Args const&... args) { \ + static ClassName format(fmt::format_string<Args...> fmt, Args const&... args) { \ return ClassName(strf(fmt, args...)); \ } \ ClassName() : BaseName(#ClassName, std::string()) {} \ @@ -91,7 +91,7 @@ STAR_EXCEPTION(IOException, StarException); STAR_EXCEPTION(MemoryException, StarException); template <typename... Args> -StarException StarException::format(char const* fmt, Args const&... args) { +StarException StarException::format(fmt::format_string<Args...> fmt, Args const&... args) { return StarException(strf(fmt, args...)); } diff --git a/source/core/StarException_windows.cpp b/source/core/StarException_windows.cpp index ca81332..7fd386c 100644 --- a/source/core/StarException_windows.cpp +++ b/source/core/StarException_windows.cpp @@ -4,6 +4,7 @@ #include "StarString_windows.hpp" #include <DbgHelp.h> +#include <sstream> namespace Star { diff --git a/source/core/StarFormat.hpp b/source/core/StarFormat.hpp index bb0327e..ccfb80c 100644 --- a/source/core/StarFormat.hpp +++ b/source/core/StarFormat.hpp @@ -3,6 +3,11 @@ #include "StarMemory.hpp" +#include "fmt/core.h" +#include "fmt/ostream.h" +#include "fmt/format.h" +#include "fmt/ranges.h" + namespace Star { struct FormatException : public std::exception { @@ -17,15 +22,11 @@ struct FormatException : public std::exception { } -#define TINYFORMAT_ERROR(reason) throw Star::FormatException(reason) - -#include "tinyformat.h" - namespace Star { -template <typename... Args> -void format(std::ostream& out, char const* fmt, Args const&... args) { - tinyformat::format(out, fmt, args...); +template <typename... T> +void format(std::ostream& out, fmt::format_string<T...> fmt, T&&... args) { + out << fmt::format(fmt, args...); } // Automatically flushes, use format to avoid flushing. @@ -42,17 +43,20 @@ void cerrf(char const* fmt, Args const&... args) { std::cerr.flush(); } -template <typename... Args> -std::string strf(char const* fmt, Args const&... args) { - std::ostringstream os; - format(os, fmt, args...); - return os.str(); +template <typename... T> +std::string strf(fmt::format_string<T...> fmt, T&&... args) { + return fmt::format(fmt, args...); } namespace OutputAnyDetail { template<typename T, typename CharT, typename Traits> + std::basic_string<CharT, Traits> string(T const& t) { + return fmt::format("<type {} at address: {}>", typeid(T).name(), (void*)&t); + } + + template<typename T, typename CharT, typename Traits> std::basic_ostream<CharT, Traits>& output(std::basic_ostream<CharT, Traits>& os, T const& t) { - return os << "<type " << typeid(T).name() << " at address: " << &t << ">"; + return os << string<T, CharT, Traits>(t); } namespace Operator { @@ -97,4 +101,8 @@ inline std::ostream& operator<<(std::ostream& os, OutputProxy const& p) { } +template <typename T> +struct fmt::formatter<Star::OutputAnyDetail::Wrapper<T>> : ostream_formatter {}; +template <> struct fmt::formatter<Star::OutputProxy> : ostream_formatter {}; + #endif diff --git a/source/core/StarFormattedJson.hpp b/source/core/StarFormattedJson.hpp index 555d436..df94523 100644 --- a/source/core/StarFormattedJson.hpp +++ b/source/core/StarFormattedJson.hpp @@ -130,4 +130,6 @@ std::ostream& operator<<(std::ostream& os, FormattedJson const& json); } +template <> struct fmt::formatter<Star::FormattedJson> : ostream_formatter {}; + #endif diff --git a/source/core/StarHostAddress.hpp b/source/core/StarHostAddress.hpp index 2f5a128..6948b0e 100644 --- a/source/core/StarHostAddress.hpp +++ b/source/core/StarHostAddress.hpp @@ -86,4 +86,7 @@ struct hash<HostAddressWithPort> { } +template <> struct fmt::formatter<Star::HostAddress> : ostream_formatter {}; +template <> struct fmt::formatter<Star::HostAddressWithPort> : ostream_formatter {}; + #endif diff --git a/source/core/StarIODevice.cpp b/source/core/StarIODevice.cpp index d87d33f..1274e89 100644 --- a/source/core/StarIODevice.cpp +++ b/source/core/StarIODevice.cpp @@ -52,7 +52,7 @@ void IODevice::close() { void IODevice::sync() {} String IODevice::deviceName() const { - return strf("IODevice <%s>", this); + return strf("IODevice <%s>", (void*)this); } bool IODevice::atEnd() { diff --git a/source/core/StarJson.cpp b/source/core/StarJson.cpp index 54d3fe7..9639ce4 100644 --- a/source/core/StarJson.cpp +++ b/source/core/StarJson.cpp @@ -1035,4 +1035,4 @@ Json jsonMerge(Json const& base, Json const& merger) { } } -} +}
\ No newline at end of file diff --git a/source/core/StarJson.hpp b/source/core/StarJson.hpp index 8c256f4..19f390e 100644 --- a/source/core/StarJson.hpp +++ b/source/core/StarJson.hpp @@ -358,4 +358,7 @@ Json jsonMergeQueryDef(String const& key, Json def, Json const& first, T const&. } +template <> struct fmt::formatter<Star::Json> : ostream_formatter {}; +template <> struct fmt::formatter<Star::JsonObject> : ostream_formatter {}; + #endif diff --git a/source/core/StarLexicalCast.hpp b/source/core/StarLexicalCast.hpp index 2831f95..6359591 100644 --- a/source/core/StarLexicalCast.hpp +++ b/source/core/StarLexicalCast.hpp @@ -1,6 +1,7 @@ #ifndef STAR_LEXICAL_CAST_HPP #define STAR_LEXICAL_CAST_HPP +#include "StarFormat.hpp" #include "StarString.hpp" #include "StarStringView.hpp" #include "StarMaybe.hpp" @@ -42,12 +43,8 @@ Type lexicalCast(StringView s, std::ios_base::fmtflags flags = std::ios_base::bo } template <class Type> -std::string toString(Type const& t, std::ios_base::fmtflags flags = std::ios_base::boolalpha) { - std::stringstream ss; - ss.flags(flags); - ss.imbue(std::locale::classic()); - ss << t; - return ss.str(); +std::string toString(Type const& t) { + return fmt::to_string(t); } } diff --git a/source/core/StarLine.hpp b/source/core/StarLine.hpp index ccb3e26..2ca8cdd 100644 --- a/source/core/StarLine.hpp +++ b/source/core/StarLine.hpp @@ -286,4 +286,7 @@ struct hash<Line<T, N>> { } +template <typename T, size_t N> +struct fmt::formatter<Star::Line<T, N>> : ostream_formatter {}; + #endif diff --git a/source/core/StarList.hpp b/source/core/StarList.hpp index bfedf54..e097721 100644 --- a/source/core/StarList.hpp +++ b/source/core/StarList.hpp @@ -1135,4 +1135,7 @@ typename ListEnumerateTypes<Container>::Result enumerate(Container&& container) } +template <typename BaseList> +struct fmt::formatter<Star::ListMixin<BaseList>> : ostream_formatter {}; + #endif diff --git a/source/core/StarLua.hpp b/source/core/StarLua.hpp index d82f906..95b4499 100644 --- a/source/core/StarLua.hpp +++ b/source/core/StarLua.hpp @@ -2160,4 +2160,6 @@ size_t LuaEngine::pushArguments(lua_State* state, Args const&... args) { } +template <> struct fmt::formatter<Star::LuaValue> : ostream_formatter {}; + #endif diff --git a/source/core/StarMap.hpp b/source/core/StarMap.hpp index 45dd219..e4941f3 100644 --- a/source/core/StarMap.hpp +++ b/source/core/StarMap.hpp @@ -315,4 +315,7 @@ std::ostream& operator<<(std::ostream& os, MapMixin<BaseMap> const& m) { } +template <typename BaseMap> +struct fmt::formatter<Star::MapMixin<BaseMap>> : ostream_formatter {}; + #endif diff --git a/source/core/StarMatrix3.hpp b/source/core/StarMatrix3.hpp index 6c688c8..3fb8162 100644 --- a/source/core/StarMatrix3.hpp +++ b/source/core/StarMatrix3.hpp @@ -453,4 +453,7 @@ std::ostream& operator<<(std::ostream& os, Matrix3<T> m) { } +template <typename T> +struct fmt::formatter<Star::Matrix3<T>> : ostream_formatter {}; + #endif diff --git a/source/core/StarMaybe.hpp b/source/core/StarMaybe.hpp index f0e7904..2b2b70d 100644 --- a/source/core/StarMaybe.hpp +++ b/source/core/StarMaybe.hpp @@ -397,4 +397,7 @@ size_t hash<Maybe<T>>::operator()(Maybe<T> const& m) const { } +template <typename T> +struct fmt::formatter<Star::Maybe<T>> : ostream_formatter {}; + #endif diff --git a/source/core/StarMultiArray.hpp b/source/core/StarMultiArray.hpp index ffd432d..f2cf155 100644 --- a/source/core/StarMultiArray.hpp +++ b/source/core/StarMultiArray.hpp @@ -507,4 +507,7 @@ std::ostream& operator<<(std::ostream& os, MultiArray<Element, Rank> const& arra } +template <typename Element, size_t Rank> +struct fmt::formatter<Star::MultiArray<Element, Rank>> : ostream_formatter {}; + #endif diff --git a/source/core/StarOrderedMap.hpp b/source/core/StarOrderedMap.hpp index 61f4c58..71fe816 100644 --- a/source/core/StarOrderedMap.hpp +++ b/source/core/StarOrderedMap.hpp @@ -654,4 +654,7 @@ std::ostream& operator<<(std::ostream& os, OrderedMapWrapper<Map, Key, Value, Al } +template <template <typename...> class Map, typename Key, typename Value, typename Allocator, typename... MapArgs> +struct fmt::formatter<Star::OrderedMapWrapper<Map, Key, Value, Allocator, MapArgs...>> : ostream_formatter {}; + #endif diff --git a/source/core/StarOrderedSet.hpp b/source/core/StarOrderedSet.hpp index 319db79..1f42132 100644 --- a/source/core/StarOrderedSet.hpp +++ b/source/core/StarOrderedSet.hpp @@ -427,4 +427,7 @@ std::ostream& operator<<(std::ostream& os, OrderedSetWrapper<Map, Value, Allocat } +template <template <typename...> class Map, typename Value, typename Allocator, typename... Args> +struct fmt::formatter<Star::OrderedSetWrapper<Map, Value, Allocator, Args...>> : ostream_formatter {}; + #endif diff --git a/source/core/StarPch.hpp b/source/core/StarPch.hpp index 809156c..7757a41 100644 --- a/source/core/StarPch.hpp +++ b/source/core/StarPch.hpp @@ -5,6 +5,7 @@ #include <cstdlib> #include <cstddef> #include <cstring> +#include <cassert> #include <cmath> #include <tuple> #include <memory> diff --git a/source/core/StarRect.hpp b/source/core/StarRect.hpp index 0e2ba90..3525204 100644 --- a/source/core/StarRect.hpp +++ b/source/core/StarRect.hpp @@ -1073,4 +1073,7 @@ auto Box<T, N>::nearestCoordTo(Coord const& c) const -> Coord { } +template <typename T, size_t N> +struct fmt::formatter<Star::Box<T, N>> : ostream_formatter {}; + #endif diff --git a/source/core/StarString.cpp b/source/core/StarString.cpp index 9394e23..aae3410 100644 --- a/source/core/StarString.cpp +++ b/source/core/StarString.cpp @@ -1136,3 +1136,7 @@ size_t hash<StringList>::operator()(StringList const& sl) const { } } + +fmt::v10::appender fmt::formatter<Star::String>::format(Star::String const& s, format_context& ctx) const { + return formatter<std::string>::format(s.utf8(), ctx); +}; diff --git a/source/core/StarString.hpp b/source/core/StarString.hpp index 1fe1aaa..7bca996 100644 --- a/source/core/StarString.hpp +++ b/source/core/StarString.hpp @@ -7,6 +7,7 @@ #include "StarList.hpp" #include "StarMap.hpp" #include "StarSet.hpp" +#include "StarFormat.hpp" namespace Star { @@ -518,4 +519,8 @@ StringList StringList::sorted(Comparator&& comparator) const { } +template <> struct fmt::formatter<Star::String> : formatter<std::string> { + fmt::v10::appender format(Star::String const& s, format_context& ctx) const; +}; + #endif diff --git a/source/core/StarStringView.cpp b/source/core/StarStringView.cpp index d1c9ae3..7580bf6 100644 --- a/source/core/StarStringView.cpp +++ b/source/core/StarStringView.cpp @@ -430,4 +430,8 @@ std::ostream& operator<<(std::ostream& os, StringView const& s) { return os; } -}
\ No newline at end of file +} + +fmt::v10::appender fmt::formatter<Star::StringView>::format(Star::StringView const& s, format_context& ctx) const { + return formatter<std::string_view>::format(s.utf8(), ctx); +};
\ No newline at end of file diff --git a/source/core/StarStringView.hpp b/source/core/StarStringView.hpp index ab40936..67d654e 100644 --- a/source/core/StarStringView.hpp +++ b/source/core/StarStringView.hpp @@ -115,4 +115,8 @@ private: } +template <> struct fmt::formatter<Star::StringView> : formatter<std::string_view> { + fmt::v10::appender format(Star::StringView const& s, format_context& ctx) const; +}; + #endif
\ No newline at end of file diff --git a/source/core/StarVariant.hpp b/source/core/StarVariant.hpp index fe45a6d..043cd1d 100644 --- a/source/core/StarVariant.hpp +++ b/source/core/StarVariant.hpp @@ -924,4 +924,7 @@ void MVariant<Types...>::ConstRefCaller<Function>::operator()(T const& t) { } +template <typename FirstType, typename... RestTypes> +struct fmt::formatter<Star::Variant<FirstType, RestTypes...>> : ostream_formatter {}; + #endif |