Переглянути джерело

LibCore: Add formatter for Object.

asynts 4 роки тому
батько
коміт
56cf272ed5
2 змінених файлів з 16 додано та 0 видалено
  1. 9 0
      Libraries/LibCore/Object.cpp
  2. 7 0
      Libraries/LibCore/Object.h

+ 9 - 0
Libraries/LibCore/Object.cpp

@@ -264,3 +264,12 @@ const LogStream& operator<<(const LogStream& stream, const Object& object)
 }
 
 }
+
+namespace AK {
+
+void Formatter<Core::Object>::format(TypeErasedFormatParams& params, FormatBuilder& builder, const Core::Object& value)
+{
+    Formatter<StringView>::format(params, builder, String::formatted("{}({})", value.class_name(), &value));
+}
+
+}

+ 7 - 0
Libraries/LibCore/Object.h

@@ -170,6 +170,13 @@ private:
 
 }
 
+namespace AK {
+template<>
+struct Formatter<Core::Object> : Formatter<StringView> {
+    void format(TypeErasedFormatParams&, FormatBuilder&, const Core::Object&);
+};
+}
+
 namespace Core {
 template<typename T, typename Callback>
 inline void Object::for_each_child_of_type(Callback callback)