diff options
Diffstat (limited to 'include')
26 files changed, 51 insertions, 69 deletions
diff --git a/include/cru/base/Base.h b/include/cru/base/Base.h index f8f8c8c0..bd889645 100644 --- a/include/cru/base/Base.h +++ b/include/cru/base/Base.h @@ -117,5 +117,5 @@ inline void hash_combine(std::size_t& s, const T& v) { #define CRU_DEFINE_CLASS_LOG_TAG(tag) \ private: \ - constexpr static const char16_t* kLogTag = tag; + constexpr static const char* kLogTag = tag; } // namespace cru diff --git a/include/cru/base/SubProcess.h b/include/cru/base/SubProcess.h index fbe8ad2b..482edb6e 100644 --- a/include/cru/base/SubProcess.h +++ b/include/cru/base/SubProcess.h @@ -134,7 +134,7 @@ struct IPlatformSubProcessImpl : virtual Interface { * leak. */ class PlatformSubProcess : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"PlatformSubProcess") + CRU_DEFINE_CLASS_LOG_TAG("PlatformSubProcess") private: struct State { @@ -212,7 +212,7 @@ class PlatformSubProcess : public Object { }; class CRU_BASE_API SubProcess : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"SubProcess") + CRU_DEFINE_CLASS_LOG_TAG("SubProcess") public: static SubProcess Create( diff --git a/include/cru/base/log/Logger.h b/include/cru/base/log/Logger.h index f77296e1..68352ffd 100644 --- a/include/cru/base/log/Logger.h +++ b/include/cru/base/log/Logger.h @@ -5,6 +5,7 @@ #include "../String.h" #include "../concurrent/ConcurrentQueue.h" +#include <format> #include <memory> #include <mutex> #include <thread> @@ -15,35 +16,26 @@ namespace cru::log { enum class LogLevel { Debug, Info, Warn, Error }; struct CRU_BASE_API LogInfo { - LogInfo(LogLevel level, String tag, String message) + LogInfo(LogLevel level, std::string tag, std::string message) : level(level), tag(std::move(tag)), message(std::move(message)) {} - CRU_DEFAULT_COPY(LogInfo) - CRU_DEFAULT_MOVE(LogInfo) - - ~LogInfo() = default; - LogLevel level; - String tag; - String message; + std::string tag; + std::string message; }; struct CRU_BASE_API ILogTarget : virtual Interface { // Write the string s. LogLevel is just a helper. It has no effect on the // content to write. - virtual void Write(LogLevel level, StringView s) = 0; + virtual void Write(LogLevel level, std::string s) = 0; }; -class CRU_BASE_API Logger : public Object { +class CRU_BASE_API Logger : public Object2 { public: static Logger* GetInstance(); public: Logger(); - - CRU_DELETE_COPY(Logger) - CRU_DELETE_MOVE(Logger) - ~Logger() override; public: @@ -51,17 +43,11 @@ class CRU_BASE_API Logger : public Object { void RemoveLogTarget(ILogTarget* source); public: - void Log(LogLevel level, String tag, String message) { + void Log(LogLevel level, std::string tag, std::string message) { Log(LogInfo(level, std::move(tag), std::move(message))); } void Log(LogInfo log_info); - template <typename... Args> - void FormatLog(LogLevel level, String tag, StringView format, - Args&&... args) { - Log(level, std::move(tag), Format(format, std::forward<Args>(args)...)); - } - private: concurrent::ConcurrentQueue<LogInfo> log_queue_; @@ -73,17 +59,17 @@ class CRU_BASE_API Logger : public Object { class CRU_BASE_API LoggerCppStream : public Object2 { public: - explicit LoggerCppStream(Logger* logger, LogLevel level, String tag); + explicit LoggerCppStream(Logger* logger, LogLevel level, std::string tag); ~LoggerCppStream() override = default; LoggerCppStream WithLevel(LogLevel level) const; - LoggerCppStream WithTag(String tag) const; + LoggerCppStream WithTag(std::string tag) const; private: - void Consume(StringView str); + void Consume(std::string_view str); public: - LoggerCppStream& operator<<(StringView str) { + LoggerCppStream& operator<<(std::string_view str) { this->Consume(str); return *this; } @@ -97,23 +83,23 @@ class CRU_BASE_API LoggerCppStream : public Object2 { private: Logger* logger_; LogLevel level_; - String tag_; + std::string tag_; }; } // namespace cru::log -#define CRU_LOG_TAG_DEBUG(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Debug, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_DEBUG(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Debug, kLogTag, \ + std::format(__VA_ARGS__)) -#define CRU_LOG_TAG_INFO(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Info, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_INFO(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Info, kLogTag, \ + std::format(__VA_ARGS__)) -#define CRU_LOG_TAG_WARN(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Warn, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_WARN(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Warn, kLogTag, \ + std::format(__VA_ARGS__)) -#define CRU_LOG_TAG_ERROR(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Error, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_ERROR(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Error, kLogTag, \ + std::format(__VA_ARGS__)) diff --git a/include/cru/base/log/StdioLogTarget.h b/include/cru/base/log/StdioLogTarget.h index 4123766b..8f0180ad 100644 --- a/include/cru/base/log/StdioLogTarget.h +++ b/include/cru/base/log/StdioLogTarget.h @@ -5,13 +5,9 @@ namespace cru::log { class StdioLogTarget : public Object, public virtual log::ILogTarget { public: explicit StdioLogTarget(); - - CRU_DELETE_COPY(StdioLogTarget) - CRU_DELETE_MOVE(StdioLogTarget) - ~StdioLogTarget() override; public: - void Write(log::LogLevel level, StringView s) override; + void Write(log::LogLevel level, std::string message) override; }; } // namespace cru::log diff --git a/include/cru/base/platform/unix/PosixSpawnSubProcess.h b/include/cru/base/platform/unix/PosixSpawnSubProcess.h index 8f4bb795..11aa7372 100644 --- a/include/cru/base/platform/unix/PosixSpawnSubProcess.h +++ b/include/cru/base/platform/unix/PosixSpawnSubProcess.h @@ -16,7 +16,7 @@ namespace cru::platform::unix { class PosixSpawnSubProcessImpl : public Object, public virtual IPlatformSubProcessImpl { - CRU_DEFINE_CLASS_LOG_TAG(u"PosixSpawnSubProcess") + CRU_DEFINE_CLASS_LOG_TAG("PosixSpawnSubProcess") public: explicit PosixSpawnSubProcessImpl(); diff --git a/include/cru/platform/graphics/direct2d/Painter.h b/include/cru/platform/graphics/direct2d/Painter.h index 5e0fc92f..c5d5e86a 100644 --- a/include/cru/platform/graphics/direct2d/Painter.h +++ b/include/cru/platform/graphics/direct2d/Painter.h @@ -12,7 +12,7 @@ class CRU_WIN_GRAPHICS_DIRECT_API D2DDeviceContextPainter : public DirectResource, public virtual IPainter, public virtual IComResource<ID2D1DeviceContext1> { - CRU_DEFINE_CLASS_LOG_TAG(u"D2DDeviceContextPainter") + CRU_DEFINE_CLASS_LOG_TAG("D2DDeviceContextPainter") public: explicit D2DDeviceContextPainter(ID2D1DeviceContext1* device_context, bool release = false); diff --git a/include/cru/platform/graphics/quartz/Painter.h b/include/cru/platform/graphics/quartz/Painter.h index 9e21904d..ec0e57af 100644 --- a/include/cru/platform/graphics/quartz/Painter.h +++ b/include/cru/platform/graphics/quartz/Painter.h @@ -11,7 +11,7 @@ namespace cru::platform::graphics::quartz { class QuartzCGContextPainter : public OsxQuartzResource, public virtual IPainter { - CRU_DEFINE_CLASS_LOG_TAG(u"QuartzCGContextPainter") + CRU_DEFINE_CLASS_LOG_TAG("QuartzCGContextPainter") public: explicit QuartzCGContextPainter( diff --git a/include/cru/platform/gui/win/Clipboard.h b/include/cru/platform/gui/win/Clipboard.h index a322d520..ebaa3f4f 100644 --- a/include/cru/platform/gui/win/Clipboard.h +++ b/include/cru/platform/gui/win/Clipboard.h @@ -6,7 +6,7 @@ namespace cru::platform::gui::win { class WinClipboard : public WinNativeResource, public virtual IClipboard { - CRU_DEFINE_CLASS_LOG_TAG(u"WinClipboard") + CRU_DEFINE_CLASS_LOG_TAG("WinClipboard") public: explicit WinClipboard(WinUiApplication* application); diff --git a/include/cru/platform/gui/win/Cursor.h b/include/cru/platform/gui/win/Cursor.h index f9cb0a09..66b0f657 100644 --- a/include/cru/platform/gui/win/Cursor.h +++ b/include/cru/platform/gui/win/Cursor.h @@ -8,7 +8,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API WinCursor : public WinNativeResource, public virtual ICursor { - CRU_DEFINE_CLASS_LOG_TAG(u"WinCursor") + CRU_DEFINE_CLASS_LOG_TAG("WinCursor") public: WinCursor(HCURSOR handle, bool auto_destroy); diff --git a/include/cru/platform/gui/win/GodWindow.h b/include/cru/platform/gui/win/GodWindow.h index 84fdfcea..05f9a13d 100644 --- a/include/cru/platform/gui/win/GodWindow.h +++ b/include/cru/platform/gui/win/GodWindow.h @@ -9,7 +9,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API GodWindow : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"GodWindow") + CRU_DEFINE_CLASS_LOG_TAG("GodWindow") public: explicit GodWindow(WinUiApplication* application); diff --git a/include/cru/platform/gui/win/InputMethod.h b/include/cru/platform/gui/win/InputMethod.h index 3a9faeaa..565a4cd0 100644 --- a/include/cru/platform/gui/win/InputMethod.h +++ b/include/cru/platform/gui/win/InputMethod.h @@ -12,7 +12,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API AutoHIMC : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"AutoHIMC") + CRU_DEFINE_CLASS_LOG_TAG("AutoHIMC") public: explicit AutoHIMC(HWND hwnd); @@ -36,7 +36,7 @@ class CRU_WIN_GUI_API AutoHIMC : public Object { class CRU_WIN_GUI_API WinInputMethodContext : public WinNativeResource, public virtual IInputMethodContext { - CRU_DEFINE_CLASS_LOG_TAG(u"WinInputMethodContext") + CRU_DEFINE_CLASS_LOG_TAG("WinInputMethodContext") public: WinInputMethodContext(WinNativeWindow* window); diff --git a/include/cru/platform/gui/win/Window.h b/include/cru/platform/gui/win/Window.h index 292bdee2..74d58228 100644 --- a/include/cru/platform/gui/win/Window.h +++ b/include/cru/platform/gui/win/Window.h @@ -11,7 +11,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API WinNativeWindow : public WinNativeResource, public virtual INativeWindow { - CRU_DEFINE_CLASS_LOG_TAG(u"WinNativeWindow") + CRU_DEFINE_CLASS_LOG_TAG("WinNativeWindow") public: explicit WinNativeWindow(WinUiApplication* application); diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h index c3fcfde2..2ddb4a90 100644 --- a/include/cru/ui/ThemeResourceDictionary.h +++ b/include/cru/ui/ThemeResourceDictionary.h @@ -24,7 +24,7 @@ class CRU_UI_API BadThemeResourceException : public Exception { }; class CRU_UI_API ThemeResourceDictionary : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"ThemeResources"); + CRU_DEFINE_CLASS_LOG_TAG("ThemeResources"); public: static std::unique_ptr<ThemeResourceDictionary> FromFile( diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h index 790f4a3a..f6603bbc 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -23,7 +23,7 @@ class CRU_UI_API Control : public Object, public DeleteLaterImpl { friend class RootControl; - CRU_DEFINE_CLASS_LOG_TAG(u"Control") + CRU_DEFINE_CLASS_LOG_TAG("Control") protected: Control(); diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h index 7efd7760..95f7a067 100644 --- a/include/cru/ui/controls/TextHostControlService.h +++ b/include/cru/ui/controls/TextHostControlService.h @@ -77,7 +77,7 @@ class TextControlMovePattern : public Object { }; class CRU_UI_API TextHostControlService : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"TextControlService") + CRU_DEFINE_CLASS_LOG_TAG("TextControlService") public: TextHostControlService(Control* control); diff --git a/include/cru/ui/helper/ClickDetector.h b/include/cru/ui/helper/ClickDetector.h index 5e30d9c3..ec63b92a 100644 --- a/include/cru/ui/helper/ClickDetector.h +++ b/include/cru/ui/helper/ClickDetector.h @@ -41,7 +41,7 @@ enum class ClickState { }; class ClickDetector : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"ClickDetector") + CRU_DEFINE_CLASS_LOG_TAG("ClickDetector") public: explicit ClickDetector(controls::Control* control); diff --git a/include/cru/ui/helper/ShortcutHub.h b/include/cru/ui/helper/ShortcutHub.h index 341e76da..19d8c8c9 100644 --- a/include/cru/ui/helper/ShortcutHub.h +++ b/include/cru/ui/helper/ShortcutHub.h @@ -94,7 +94,7 @@ struct ShortcutInfo { }; class CRU_UI_API ShortcutHub : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"ShortcutHub") + CRU_DEFINE_CLASS_LOG_TAG("ShortcutHub") public: ShortcutHub() = default; diff --git a/include/cru/ui/host/WindowHost.h b/include/cru/ui/host/WindowHost.h index 23229036..e2391125 100644 --- a/include/cru/ui/host/WindowHost.h +++ b/include/cru/ui/host/WindowHost.h @@ -19,7 +19,7 @@ struct AfterLayoutEventArgs {}; // The bridge between control tree and native window. class CRU_UI_API WindowHost : public Object, public SelfResolvable<WindowHost> { friend controls::Control; - CRU_DEFINE_CLASS_LOG_TAG(u"WindowHost") + CRU_DEFINE_CLASS_LOG_TAG("WindowHost") private: static int event_handling_depth_; diff --git a/include/cru/ui/mapper/style/StyleRuleMapper.h b/include/cru/ui/mapper/style/StyleRuleMapper.h index 7430274c..12fcb85b 100644 --- a/include/cru/ui/mapper/style/StyleRuleMapper.h +++ b/include/cru/ui/mapper/style/StyleRuleMapper.h @@ -7,7 +7,7 @@ namespace cru::ui::mapper::style { class CRU_UI_API StyleRuleMapper : public BasicClonablePtrMapper<ui::style::StyleRule> { - CRU_DEFINE_CLASS_LOG_TAG(u"StyleRuleMapper") + CRU_DEFINE_CLASS_LOG_TAG("StyleRuleMapper") public: CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(StyleRuleMapper) diff --git a/include/cru/ui/render/BorderRenderObject.h b/include/cru/ui/render/BorderRenderObject.h index 9f3cff4a..7bfa4290 100644 --- a/include/cru/ui/render/BorderRenderObject.h +++ b/include/cru/ui/render/BorderRenderObject.h @@ -6,7 +6,7 @@ namespace cru::ui::render { class CRU_UI_API BorderRenderObject : public SingleChildRenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"BorderRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("BorderRenderObject") public: BorderRenderObject(); diff --git a/include/cru/ui/render/FlexLayoutRenderObject.h b/include/cru/ui/render/FlexLayoutRenderObject.h index 4effacb1..6c65ace3 100644 --- a/include/cru/ui/render/FlexLayoutRenderObject.h +++ b/include/cru/ui/render/FlexLayoutRenderObject.h @@ -93,7 +93,7 @@ struct FlexChildLayoutData { // class CRU_UI_API FlexLayoutRenderObject : public LayoutRenderObject<FlexChildLayoutData> { - CRU_DEFINE_CLASS_LOG_TAG(u"FlexLayoutRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("FlexLayoutRenderObject") public: FlexLayoutRenderObject() = default; diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h index 7ab62446..80fa2e10 100644 --- a/include/cru/ui/render/RenderObject.h +++ b/include/cru/ui/render/RenderObject.h @@ -59,7 +59,7 @@ struct BoxConstraint { * content_rect) override; */ class CRU_UI_API RenderObject : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"RenderObject") + CRU_DEFINE_CLASS_LOG_TAG("RenderObject") protected: RenderObject() = default; diff --git a/include/cru/ui/render/SingleChildRenderObject.h b/include/cru/ui/render/SingleChildRenderObject.h index a98465f0..85442eda 100644 --- a/include/cru/ui/render/SingleChildRenderObject.h +++ b/include/cru/ui/render/SingleChildRenderObject.h @@ -3,7 +3,7 @@ namespace cru::ui::render { class CRU_UI_API SingleChildRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"SingleChildRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("SingleChildRenderObject") public: SingleChildRenderObject() = default; diff --git a/include/cru/ui/render/StackLayoutRenderObject.h b/include/cru/ui/render/StackLayoutRenderObject.h index 4da63ea2..515e8f43 100644 --- a/include/cru/ui/render/StackLayoutRenderObject.h +++ b/include/cru/ui/render/StackLayoutRenderObject.h @@ -28,7 +28,7 @@ struct StackChildLayoutData { // to min size. class CRU_UI_API StackLayoutRenderObject : public LayoutRenderObject<StackChildLayoutData> { - CRU_DEFINE_CLASS_LOG_TAG(u"StackLayoutRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("StackLayoutRenderObject") public: StackLayoutRenderObject() = default; diff --git a/include/cru/ui/render/TextRenderObject.h b/include/cru/ui/render/TextRenderObject.h index 0cb3623d..72958f6f 100644 --- a/include/cru/ui/render/TextRenderObject.h +++ b/include/cru/ui/render/TextRenderObject.h @@ -19,7 +19,7 @@ namespace cru::ui::render { // If the result layout box is bigger than actual text box, then text is center // aligned. class CRU_UI_API TextRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"TextRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("TextRenderObject") public: constexpr static float default_caret_width = 2; diff --git a/include/cru/ui/render/TreeRenderObject.h b/include/cru/ui/render/TreeRenderObject.h index 8c589d7a..ef40f4d0 100644 --- a/include/cru/ui/render/TreeRenderObject.h +++ b/include/cru/ui/render/TreeRenderObject.h @@ -49,7 +49,7 @@ class CRU_UI_API TreeRenderObjectItem : public Object { }; class CRU_UI_API TreeRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"TreeRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("TreeRenderObject") public: TreeRenderObject(); |