diff options
Diffstat (limited to 'include/cru/platform')
23 files changed, 181 insertions, 307 deletions
diff --git a/include/cru/platform/check.hpp b/include/cru/platform/check.hpp new file mode 100644 index 00000000..8e60e848 --- /dev/null +++ b/include/cru/platform/check.hpp @@ -0,0 +1,41 @@ +#pragma once +#include "cru/common/format.hpp" +#include "exception.hpp" +#include "resource.hpp" + +#include <cassert> +#include <memory> +#include <type_traits> + +namespace cru::platform { +template <typename TTarget> +TTarget* CheckPlatform(INativeResource* resource, + const std::string_view& target_platform) { + assert(resource); + const auto result = dynamic_cast<TTarget*>(resource); + if (result == nullptr) { + throw UnsupportPlatformException(util::Format( + "Try to convert resource to target platform failed. Platform id of " + "resource to convert: {} . Target platform id: {} .", + resource->GetPlatformId(), target_platform)); + } + return result; +} + +template <typename TTarget, typename TSource> +std::shared_ptr<TTarget> CheckPlatform( + const std::shared_ptr<TSource>& resource, + const std::string_view& target_platform) { + static_assert(std::is_base_of_v<INativeResource, TSource>, + "TSource must be a subclass of INativeResource."); + assert(resource); + const auto result = std::dynamic_pointer_cast<TTarget>(resource); + if (result == nullptr) { + throw UnsupportPlatformException(util::Format( + "Try to convert resource to target platform failed. Platform id of " + "resource to convert: {} . Target platform id: {} .", + resource->GetPlatformId(), target_platform)); + } + return result; +} +} // namespace cru::platform diff --git a/include/cru/platform/exception.hpp b/include/cru/platform/exception.hpp index ad6827c0..1774b12c 100644 --- a/include/cru/platform/exception.hpp +++ b/include/cru/platform/exception.hpp @@ -9,10 +9,18 @@ class PlatformException : public std::runtime_error { using runtime_error::runtime_error; // inherit constructors }; -// This exception is throwed when a resource has been disposed and not usable +// This exception is thrown when a resource is used on another platform. +// Of course, you can't mix resources of two different platform. +// For example, Win32 Brush (may add in the future) with Direct Painter. +class UnsupportPlatformException : public std::runtime_error { + public: + using runtime_error::runtime_error; // inherit constructors +}; + +// This exception is thrown when a resource has been disposed and not usable // again. -// For example, calling Build twice on a GeometryBuilder::Build will lead to this -// exception. +// For example, calling Build twice on a GeometryBuilder::Build will lead to +// this exception. class ReuseException : public std::runtime_error { public: using runtime_error::runtime_error; // inherit constructors diff --git a/include/cru/platform/graph/base.hpp b/include/cru/platform/graph/base.hpp new file mode 100644 index 00000000..8c2a2d2f --- /dev/null +++ b/include/cru/platform/graph/base.hpp @@ -0,0 +1,4 @@ +#pragma once +#include "../graph_base.hpp" +#include "../matrix.hpp" +#include "../resource.hpp" diff --git a/include/cru/platform/graph/brush.hpp b/include/cru/platform/graph/brush.hpp index d292ae82..af7a1dec 100644 --- a/include/cru/platform/graph/brush.hpp +++ b/include/cru/platform/graph/brush.hpp @@ -1,46 +1,11 @@ #pragma once -#include "../graphic_base.hpp" -#include "../native_resource.hpp" +#include "resource.hpp" namespace cru::platform::graph { -class Brush : public NativeResource { - protected: - Brush() = default; +struct IBrush : virtual IGraphResource {}; - public: - Brush(const Brush& other) = delete; - Brush& operator=(const Brush& other) = delete; - - Brush(Brush&& other) = delete; - Brush& operator=(Brush&& other) = delete; - - ~Brush() override = default; -}; - -class SolidColorBrush : public Brush { - protected: - SolidColorBrush() = default; - - public: - SolidColorBrush(const SolidColorBrush& other) = delete; - SolidColorBrush& operator=(const SolidColorBrush& other) = delete; - - SolidColorBrush(SolidColorBrush&& other) = delete; - SolidColorBrush& operator=(SolidColorBrush&& other) = delete; - - ~SolidColorBrush() = default; - - public: - Color GetColor() { return color_; } - void SetColor(const Color& color) { - color_ = color; - OnSetColor(color); - } - - protected: - virtual void OnSetColor(const Color& color) = 0; - - protected: - Color color_ = colors::black; +struct ISolidColorBrush : virtual IBrush { + virtual Color GetColor() = 0; + virtual void SetColor(const Color& color) = 0; }; } // namespace cru::platform::graph diff --git a/include/cru/platform/graph/factory.hpp b/include/cru/platform/graph/factory.hpp new file mode 100644 index 00000000..2c52cbb8 --- /dev/null +++ b/include/cru/platform/graph/factory.hpp @@ -0,0 +1,27 @@ +#pragma once +#include "base.hpp" + +#include "brush.hpp" +#include "font.hpp" +#include "geometry.hpp" +#include "text_layout.hpp" + +#include <memory> +#include <string> +#include <string_view> +#include <utility> + +namespace cru::platform::graph { +// Entry point of the graph module. +struct IGraphFactory : virtual INativeResource { + virtual std::unique_ptr<ISolidColorBrush> CreateSolidColorBrush() = 0; + + virtual std::unique_ptr<IGeometryBuilder> CreateGeometryBuilder() = 0; + + virtual std::unique_ptr<IFont> CreateFont(const std::string_view& font_family, + float font_size) = 0; + + virtual std::unique_ptr<ITextLayout> CreateTextLayout( + std::shared_ptr<IFont> font, std::string text) = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/font.hpp b/include/cru/platform/graph/font.hpp index bd470256..98ce80e7 100644 --- a/include/cru/platform/graph/font.hpp +++ b/include/cru/platform/graph/font.hpp @@ -1,18 +1,6 @@ #pragma once -#include "../native_resource.hpp" +#include "resource.hpp" namespace cru::platform::graph { -class Font : public NativeResource { - protected: - Font() = default; - - public: - Font(const Font& other) = delete; - Font& operator=(const Font& other) = delete; - - Font(Font&& other) = delete; - Font& operator=(Font&& other) = delete; - - ~Font() override = default; -}; +struct IFont : virtual IGraphResource {}; } // namespace cru::platform::graph diff --git a/include/cru/platform/graph/geometry.hpp b/include/cru/platform/graph/geometry.hpp index d31b3b27..689b2ab9 100644 --- a/include/cru/platform/graph/geometry.hpp +++ b/include/cru/platform/graph/geometry.hpp @@ -1,45 +1,22 @@ #pragma once -#include "../graphic_base.hpp" -#include "../native_resource.hpp" +#include "resource.hpp" -namespace cru::platform::graph { -class Geometry : public NativeResource { - protected: - Geometry() = default; - - public: - Geometry(const Geometry& other) = delete; - Geometry& operator=(const Geometry& other) = delete; - - Geometry(Geometry&& other) = delete; - Geometry& operator=(Geometry&& other) = delete; - - ~Geometry() override = default; +#include <memory> - public: +namespace cru::platform::graph { +struct IGeometry : virtual IGraphResource { virtual bool FillContains(const Point& point) = 0; }; -class GeometryBuilder : public NativeResource { - protected: - GeometryBuilder() = default; - - public: - GeometryBuilder(const GeometryBuilder& other) = delete; - GeometryBuilder& operator=(const GeometryBuilder& other) = delete; - - GeometryBuilder(GeometryBuilder&& other) = delete; - GeometryBuilder& operator=(GeometryBuilder&& other) = delete; - - ~GeometryBuilder() override = default; +// After called Build, calling every method will throw a - public: +class IGeometryBuilder : virtual IGraphResource { virtual void BeginFigure(const Point& point) = 0; virtual void LineTo(const Point& point) = 0; virtual void QuadraticBezierTo(const Point& control_point, const Point& end_point) = 0; virtual void CloseFigure(bool close) = 0; - virtual Geometry* Build() = 0; + virtual std::unique_ptr<IGeometry> Build() = 0; }; } // namespace cru::platform::graph diff --git a/include/cru/platform/graph/graph_factory.hpp b/include/cru/platform/graph/graph_factory.hpp deleted file mode 100644 index 0b1034cc..00000000 --- a/include/cru/platform/graph/graph_factory.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once -#include "../graphic_base.hpp" -#include "../native_resource.hpp" - -#include "brush.hpp" -#include "font.hpp" -#include "geometry.hpp" -#include "text_layout.hpp" - -#include <memory> -#include <string> -#include <string_view> - -namespace cru::platform::graph { -// Entry point of the graph module. -// If you create a IUiApplication instance, then you should not create -// IGraphFactory manually. IUiApplication will call -// IGraphFactory::CreateInstance and set auto-delete to true. -// The manual creation method of IGraphFactory provides a you a way to use graph -// related tools without interact with actual ui like window system. -class GraphFactory : public NativeResource { - public: - // Create a platform-specific instance and save it as the global instance. - // Do not create the instance twice. Implements should assert for that. - // After creating, get the instance by GetInstance. - static GraphFactory* CreateInstance(); - - // Get the global instance. If it is not created, then return nullptr. - static GraphFactory* GetInstance(); - - protected: - GraphFactory() = default; - - public: - GraphFactory(const GraphFactory& other) = delete; - GraphFactory& operator=(const GraphFactory& other) = delete; - - GraphFactory(GraphFactory&& other) = delete; - GraphFactory& operator=(GraphFactory&& other) = delete; - - ~GraphFactory() override = default; - - public: - virtual SolidColorBrush* CreateSolidColorBrush() = 0; - SolidColorBrush* CreateSolidColorBrush(const Color& color) { - const auto brush = CreateSolidColorBrush(); - brush->SetColor(color); - return brush; - } - - virtual GeometryBuilder* CreateGeometryBuilder() = 0; - - virtual Font* CreateFont(const std::wstring_view& font_family, - float font_size) = 0; - - virtual TextLayout* CreateTextLayout(std::shared_ptr<Font> font, - std::wstring text) = 0; - - virtual bool IsAutoDelete() const = 0; - virtual void SetAutoDelete(bool value) = 0; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/painter.hpp b/include/cru/platform/graph/painter.hpp index 97d4b4cf..3ae9cf1c 100644 --- a/include/cru/platform/graph/painter.hpp +++ b/include/cru/platform/graph/painter.hpp @@ -1,42 +1,27 @@ #pragma once -#include "../graphic_base.hpp" -#include "../matrix.hpp" -#include "../native_resource.hpp" +#include "base.hpp" namespace cru::platform::graph { -class Brush; -class Geometry; -class TextLayout; +struct IBrush; +struct IGeometry; +struct ITextLayout; -class Painter : public NativeResource { - protected: - Painter() = default; - - public: - Painter(const Painter& other) = delete; - Painter& operator=(const Painter& other) = delete; - - Painter(Painter&& other) = delete; - Painter& operator=(Painter&& other) = delete; - - ~Painter() override = default; - - public: +struct IPainter : virtual INativeResource { virtual Matrix GetTransform() = 0; virtual void SetTransform(const Matrix& matrix) = 0; virtual void Clear(const Color& color) = 0; - virtual void StrokeRectangle(const Rect& rectangle, Brush* brush, + virtual void StrokeRectangle(const Rect& rectangle, IBrush* brush, float width) = 0; - virtual void FillRectangle(const Rect& rectangle, Brush* brush) = 0; + virtual void FillRectangle(const Rect& rectangle, IBrush* brush) = 0; - virtual void StrokeGeometry(Geometry* geometry, Brush* brush, + virtual void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) = 0; - virtual void FillGeometry(Geometry* geometry, Brush* brush) = 0; + virtual void FillGeometry(IGeometry* geometry, IBrush* brush) = 0; - virtual void DrawText(const Point& offset, TextLayout* text_layout, - Brush* brush) = 0; + virtual void DrawText(const Point& offset, ITextLayout* text_layout, + IBrush* brush) = 0; virtual void EndDraw() = 0; }; diff --git a/include/cru/platform/graph/resource.hpp b/include/cru/platform/graph/resource.hpp new file mode 100644 index 00000000..255865eb --- /dev/null +++ b/include/cru/platform/graph/resource.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "base.hpp" + +namespace cru::platform::graph { +struct IGraphFactory; + +struct IGraphResource : virtual INativeResource { + virtual IGraphFactory* GetGraphFactory() = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/text_layout.hpp b/include/cru/platform/graph/text_layout.hpp index 56943098..4f6e81e1 100644 --- a/include/cru/platform/graph/text_layout.hpp +++ b/include/cru/platform/graph/text_layout.hpp @@ -1,33 +1,19 @@ #pragma once -#include "../graphic_base.hpp" -#include "../native_resource.hpp" +#include "resource.hpp" #include <memory> #include <string> #include <vector> namespace cru::platform::graph { -class Font; +struct IFont; -class TextLayout : public NativeResource { - protected: - TextLayout() = default; +struct ITextLayout : virtual IGraphResource { + virtual std::string GetText() = 0; + virtual void SetText(std::string new_text) = 0; - public: - TextLayout(const TextLayout& other) = delete; - TextLayout& operator=(const TextLayout& other) = delete; - - TextLayout(TextLayout&& other) = delete; - TextLayout& operator=(TextLayout&& other) = delete; - - ~TextLayout() override = default; - - public: - virtual std::wstring GetText() = 0; - virtual void SetText(std::wstring new_text) = 0; - - virtual std::shared_ptr<Font> GetFont() = 0; - virtual void SetFont(std::shared_ptr<Font> font) = 0; + virtual std::shared_ptr<IFont> GetFont() = 0; + virtual void SetFont(std::shared_ptr<IFont> font) = 0; virtual void SetMaxWidth(float max_width) = 0; virtual void SetMaxHeight(float max_height) = 0; diff --git a/include/cru/platform/graph/util/painter_util.hpp b/include/cru/platform/graph/util/painter.hpp index 7a655a34..72d96bc1 100644 --- a/include/cru/platform/graph/util/painter_util.hpp +++ b/include/cru/platform/graph/util/painter.hpp @@ -6,13 +6,12 @@ namespace cru::platform::graph::util { template <typename Fn> -inline void WithTransform(Painter* painter, const Matrix& matrix, - const Fn& action) { - static_assert(std::is_invocable_v<decltype(action), Painter*>, +void WithTransform(IPainter* painter, const Matrix& matrix, const Fn& action) { + static_assert(std::is_invocable_v<decltype(action), IPainter*>, "Action must can be be invoked with painter."); const auto old = painter->GetTransform(); painter->SetTransform(old * matrix); action(painter); painter->SetTransform(old); } -} // namespace cru::platform::util +} // namespace cru::platform::graph::util diff --git a/include/cru/platform/graphic_base.hpp b/include/cru/platform/graph_base.hpp index c9c4f629..c9c4f629 100644 --- a/include/cru/platform/graphic_base.hpp +++ b/include/cru/platform/graph_base.hpp diff --git a/include/cru/platform/heap_debug.hpp b/include/cru/platform/heap_debug.hpp index e305be31..9e3ae368 100644 --- a/include/cru/platform/heap_debug.hpp +++ b/include/cru/platform/heap_debug.hpp @@ -2,5 +2,6 @@ #include "cru/common/pre_config.hpp" namespace cru::platform { +// Setup the heap debug function. Currently I only use this on Windows... void SetupHeapDebug(); -} +} // namespace cru::platform diff --git a/include/cru/platform/matrix.hpp b/include/cru/platform/matrix.hpp index cbb55c78..030e1378 100644 --- a/include/cru/platform/matrix.hpp +++ b/include/cru/platform/matrix.hpp @@ -1,5 +1,5 @@ #pragma once -#include "graphic_base.hpp" +#include "graph_base.hpp" #include <cmath> @@ -39,7 +39,7 @@ struct Matrix { Point TransformPoint(const Point& point) const { return Point{point.x * m11 + point.y * m21 + m31, - point.x * m12 + point.y * m22 + m32}; + point.x * m12 + point.y * m22 + m32}; } static Matrix Identity() { @@ -50,10 +50,8 @@ struct Matrix { return Matrix{1.0f, 0.0f, 0.0f, 1.0f, x, y}; } - static Matrix Scale(float sx, float sy) { return Scale(sx, sy, 0.0f, 0.0f); } - - static Matrix Scale(float sx, float sy, float cx, float cy) { - return Matrix{sx, 0.0f, 0.0f, sy, cx - sx * cx, cy - sy * cy}; + static Matrix Scale(float sx, float sy) { + return Matrix{sx, 0.0f, 0.0f, sy, 0.0f, 0.0f}; } static Matrix Rotation(float angle) { diff --git a/include/cru/platform/native/basic_types.hpp b/include/cru/platform/native/basic_types.hpp index 5a7155ee..a53fa671 100644 --- a/include/cru/platform/native/basic_types.hpp +++ b/include/cru/platform/native/basic_types.hpp @@ -7,5 +7,5 @@ struct Dpi { float y; }; -enum MouseButton : unsigned { Left = 1, Right = 2, Middle = 4 }; +enum MouseButton : unsigned { Left = 0b1, Right = 0b10, Middle = 0b100 }; } // namespace cru::platform::native diff --git a/include/cru/platform/native/cursor.hpp b/include/cru/platform/native/cursor.hpp index b8604ecb..961dff34 100644 --- a/include/cru/platform/native/cursor.hpp +++ b/include/cru/platform/native/cursor.hpp @@ -5,35 +5,16 @@ #include <memory> namespace cru::platform::native { -class Cursor : public NativeResource { - public: - Cursor() = default; +struct ICursor : public virtual INativeResource {}; - CRU_DELETE_COPY(Cursor) - CRU_DELETE_MOVE(Cursor) - - ~Cursor() override = default; -}; - -enum class SystemCursor { +enum class SystemCursorType { Arrow, Hand, }; -class CursorManager : public NativeResource { - public: - CursorManager() = default; - - CRU_DELETE_COPY(CursorManager) - CRU_DELETE_MOVE(CursorManager) +struct ICursorManager : public virtual INativeResource { + virtual std::shared_ptr<ICursor> GetSystemCursor(SystemCursorType type) = 0; - ~CursorManager() override = default; - - public: - virtual std::shared_ptr<Cursor> GetSystemCursor(SystemCursor type) = 0; - - //TODO: Add method to create cursor. + // TODO: Add method to create cursor. }; - -std::shared_ptr<Cursor> GetSystemCursor(SystemCursor type); } // namespace cru::platform::native diff --git a/include/cru/platform/native/native_event.hpp b/include/cru/platform/native/native_event.hpp index 54bab00c..dcd7a336 100644 --- a/include/cru/platform/native/native_event.hpp +++ b/include/cru/platform/native/native_event.hpp @@ -8,4 +8,9 @@ struct NativeMouseButtonEventArgs { MouseButton button; Point point; }; + +enum class FocusChangeType { Gain, Lost }; + +enum class MouseEnterLeaveType { Enter, Leave }; + } // namespace cru::platform::native diff --git a/include/cru/platform/native/native_window.hpp b/include/cru/platform/native/native_window.hpp index 8a067a4c..cd2459e0 100644 --- a/include/cru/platform/native/native_window.hpp +++ b/include/cru/platform/native/native_window.hpp @@ -9,7 +9,7 @@ #include "native_event.hpp" namespace cru::platform::graph { -class Painter; +struct IPainter; } namespace cru::platform::native { @@ -21,28 +21,18 @@ namespace cru::platform::native { // Close or closed by the user, which leads to an invalid instance. You can // check the validity by IsValid. When you call perform native operations on the // invalid instance, there is no effect. -class NativeWindow : public NativeResource { - protected: - NativeWindow() = default; - - public: - NativeWindow(const NativeWindow& other) = delete; - NativeWindow& operator=(const NativeWindow& other) = delete; - - NativeWindow(NativeWindow&& other) = delete; - NativeWindow& operator=(NativeWindow&& other) = delete; - - ~NativeWindow() override = default; - - public: +struct INativeWindow : public virtual INativeResource { // Return if the window is still valid, that is, hasn't been closed or // destroyed. virtual bool IsValid() = 0; + + // Set if the instance is deleted automatically when the window is destroyed + // by other ways. Default is true. virtual void SetDeleteThisOnDestroy(bool value) = 0; virtual void Close() = 0; - virtual NativeWindow* GetParent() = 0; + virtual INativeWindow* GetParent() = 0; virtual bool IsVisible() = 0; virtual void SetVisible(bool is_visible) = 0; @@ -64,16 +54,18 @@ class NativeWindow : public NativeResource { virtual bool CaptureMouse() = 0; virtual bool ReleaseMouse() = 0; - virtual void SetCursor(std::shared_ptr<Cursor> cursor) = 0; + virtual void SetCursor(std::shared_ptr<ICursor> cursor) = 0; + + virtual void RequestRepaint() = 0; - virtual void Repaint() = 0; - virtual graph::Painter* BeginPaint() = 0; + // Remember to call EndDraw on return value and destroy it. + virtual std::unique_ptr<graph::IPainter> BeginPaint() = 0; virtual IEvent<std::nullptr_t>* DestroyEvent() = 0; virtual IEvent<std::nullptr_t>* PaintEvent() = 0; virtual IEvent<Size>* ResizeEvent() = 0; - virtual IEvent<bool>* FocusEvent() = 0; - virtual IEvent<bool>* MouseEnterLeaveEvent() = 0; + virtual IEvent<FocusChangeType>* FocusEvent() = 0; + virtual IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() = 0; virtual IEvent<Point>* MouseMoveEvent() = 0; virtual IEvent<NativeMouseButtonEventArgs>* MouseDownEvent() = 0; virtual IEvent<NativeMouseButtonEventArgs>* MouseUpEvent() = 0; diff --git a/include/cru/platform/native/ui_application.hpp b/include/cru/platform/native/ui_application.hpp index 923fbaf7..6d2ab659 100644 --- a/include/cru/platform/native/ui_application.hpp +++ b/include/cru/platform/native/ui_application.hpp @@ -1,45 +1,36 @@ #pragma once #include "../native_resource.hpp" -#include "cursor.hpp" - #include <chrono> #include <functional> #include <vector> namespace cru::platform::native { -class NativeWindow; +struct INativeWindow; +struct ICursorManager; // The entry point of a ui application. // It will call IGraphFactory::CreateInstance during its creation // and set graph factory to be auto deleted. If you want to keep // the graph factory then you should manually set it to false after // creating the ui application. -class UiApplication : public NativeResource { +struct IUiApplication : public virtual INativeResource { public: // Create a platform-specific instance and save it as the global instance. // Do not create the instance twice. Implements should assert for that. // After creating, get the instance by GetInstance. - static UiApplication* CreateInstance(); + static IUiApplication* CreateInstance(); // Get the global instance. If it is not created, then return nullptr. - static UiApplication* GetInstance(); - - protected: - UiApplication() = default; - - public: - UiApplication(const UiApplication& other) = delete; - UiApplication& operator=(const UiApplication& other) = delete; - - UiApplication(UiApplication&& other) = delete; - UiApplication& operator=(UiApplication&& other) = delete; - - ~UiApplication() override = default; + static IUiApplication* GetInstance(); public: + // Block current thread and run the message loop. Return the exit code when + // message loop gets a quit message (possibly posted by method RequestQuit). virtual int Run() = 0; - virtual void Quit(int quite_code) = 0; + + // Post a quit message with given quit code. + virtual void RequestQuit(int quit_code) = 0; virtual void AddOnQuitHandler(const std::function<void()>& handler) = 0; @@ -50,9 +41,9 @@ class UiApplication : public NativeResource { const std::function<void()>& action) = 0; virtual void CancelTimer(unsigned long id) = 0; - virtual std::vector<NativeWindow*> GetAllWindow() = 0; - virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0; + virtual std::vector<INativeWindow*> GetAllWindow() = 0; + virtual INativeWindow* CreateWindow(INativeWindow* parent) = 0; - virtual CursorManager* GetCursorManager() = 0; + virtual ICursorManager* GetCursorManager() = 0; }; } // namespace cru::platform::native diff --git a/include/cru/platform/native_resource.hpp b/include/cru/platform/native_resource.hpp deleted file mode 100644 index ec7f01b6..00000000 --- a/include/cru/platform/native_resource.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "cru/common/base.hpp" - -#include <string_view> - -namespace cru::platform { -class NativeResource : public Object { - protected: - NativeResource() = default; - - public: - NativeResource(const NativeResource& other) = delete; - NativeResource& operator=(const NativeResource& other) = delete; - - - NativeResource(NativeResource&& other) = delete; - NativeResource& operator=(NativeResource&& other) = delete; - ~NativeResource() override = default; - - public: - virtual std::wstring_view GetPlatformId() const = 0; -}; -} // namespace cru::platform diff --git a/include/cru/platform/resource.hpp b/include/cru/platform/resource.hpp new file mode 100644 index 00000000..6b315527 --- /dev/null +++ b/include/cru/platform/resource.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "cru/common/base.hpp" + +#include <string_view> + +namespace cru::platform { +struct INativeResource : virtual Interface { + virtual std::string_view GetPlatformId() const = 0; +}; +} // namespace cru::platform diff --git a/include/cru/platform/string_util.hpp b/include/cru/platform/string_util.hpp deleted file mode 100644 index 822c0c95..00000000 --- a/include/cru/platform/string_util.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "cru/common/pre_config.hpp" - -#include <string> -#include <string_view> - -namespace cru::platform { -std::string ToUtf8String(const std::wstring_view& string); -} |