Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarFormat.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-28 00:20:22 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-28 00:20:22 +1000
commit152af876550ec63bac9d7aa27b1994268c80f878 (patch)
treeec1ca9b7f013252505ad719990900a64cc3afc35 /source/core/StarFormat.hpp
parent2496789ea7632556486560f80590d5ba7f8da0f5 (diff)
Fix broken regex, make game timestep non-const
Diffstat (limited to 'source/core/StarFormat.hpp')
-rw-r--r--source/core/StarFormat.hpp79
1 files changed, 8 insertions, 71 deletions
diff --git a/source/core/StarFormat.hpp b/source/core/StarFormat.hpp
index ccfb80c..c31697f 100644
--- a/source/core/StarFormat.hpp
+++ b/source/core/StarFormat.hpp
@@ -2,6 +2,7 @@
#define STAR_FORMAT_HPP
#include "StarMemory.hpp"
+#include "StarException.hpp"
#include "fmt/core.h"
#include "fmt/ostream.h"
@@ -10,23 +11,19 @@
namespace Star {
-struct FormatException : public std::exception {
- FormatException(std::string what) : whatmsg(move(what)) {}
+STAR_EXCEPTION(FormatException, StarException);
- char const* what() const noexcept override {
- return whatmsg.c_str();
+template <typename... T>
+std::string strf(fmt::format_string<T...> fmt, T&&... args) {
+ try { return fmt::format(fmt, args...); }
+ catch (std::exception const& e) {
+ throw FormatException(strf("Exception thrown during string format: {}", e.what()));
}
-
- std::string whatmsg;
-};
-
}
-namespace Star {
-
template <typename... T>
void format(std::ostream& out, fmt::format_string<T...> fmt, T&&... args) {
- out << fmt::format(fmt, args...);
+ out << strf(fmt, args...);
}
// Automatically flushes, use format to avoid flushing.
@@ -43,66 +40,6 @@ void cerrf(char const* fmt, Args const&... args) {
std::cerr.flush();
}
-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 << string<T, CharT, Traits>(t);
- }
-
- namespace Operator {
- template<typename T, typename CharT, typename Traits>
- std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, T const& t) {
- return output(os, t);
- }
- }
-
- template <typename T>
- struct Wrapper {
- T const& wrapped;
- };
-
- template <typename T>
- std::ostream& operator<<(std::ostream& os, Wrapper<T> const& wrapper) {
- using namespace Operator;
- return os << wrapper.wrapped;
- }
-}
-
-// Wraps a type so that is printable no matter what.. If no operator<< is
-// defined for a type, then will print <type [typeid] at address: [address]>
-template <typename T>
-OutputAnyDetail::Wrapper<T> outputAny(T const& t) {
- return OutputAnyDetail::Wrapper<T>{t};
-}
-
-struct OutputProxy {
- typedef function<void(std::ostream&)> PrintFunction;
-
- OutputProxy(PrintFunction p)
- : print(move(p)) {}
-
- PrintFunction print;
-};
-
-inline std::ostream& operator<<(std::ostream& os, OutputProxy const& p) {
- p.print(os);
- return os;
}
-}
-
-template <typename T>
-struct fmt::formatter<Star::OutputAnyDetail::Wrapper<T>> : ostream_formatter {};
-template <> struct fmt::formatter<Star::OutputProxy> : ostream_formatter {};
-
#endif