From d868d7b0d463ede80b761f87f10d4e25f52989c3 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Sun, 15 Jun 2025 01:02:30 +0800 Subject: Remove some files of OSX. Symbol Point is conflict and needs to be fixed. --- include/cru/base/Osx.h | 26 ++++++++++++++++++++++++++ include/cru/base/Range.h | 12 ++++++++++++ include/cru/base/String.h | 14 ++++++++++++++ include/cru/base/platform/osx/Convert.h | 17 ----------------- include/cru/base/platform/osx/Exception.h | 14 -------------- 5 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 include/cru/base/Osx.h delete mode 100644 include/cru/base/platform/osx/Convert.h delete mode 100644 include/cru/base/platform/osx/Exception.h (limited to 'include/cru/base') diff --git a/include/cru/base/Osx.h b/include/cru/base/Osx.h new file mode 100644 index 00000000..711da9a3 --- /dev/null +++ b/include/cru/base/Osx.h @@ -0,0 +1,26 @@ +#pragma once + +#ifndef CRU_PLATFORM_OSX +#error "This header can only be included on OSX." +#endif + +#include + +namespace cru { +template +class CFWrapper { + public: + CFClassRef ref; + + explicit CFWrapper(CFClassRef ref) { this->ref = ref; } + ~CFWrapper() { + if (this->ref) CFRelease(this->ref); + } + + CFClassRef* release() { + auto ref = this->ref; + this->ref = nullptr; + return ref; + } +}; +} // namespace cru diff --git a/include/cru/base/Range.h b/include/cru/base/Range.h index edc2ec55..ade1979a 100644 --- a/include/cru/base/Range.h +++ b/include/cru/base/Range.h @@ -1,6 +1,10 @@ #pragma once #include "Base.h" +#ifdef CRU_PLATFORM_OSX +#include +#endif + namespace cru { struct Range final { constexpr static Range FromTwoSides(Index start, Index end) { @@ -36,6 +40,14 @@ struct Range final { return Range::FromTwoSides(coerce(GetStart()), coerce(GetEnd())); } +#ifdef CRU_PLATFORM_OSX + CFRange ToCFRange() const { return CFRangeMake(this->position, this->count); } + + static Range FromCFRange(const CFRange& range) { + return Range(range.location, range.length); + } +#endif + Index position = 0; Index count = 0; }; diff --git a/include/cru/base/String.h b/include/cru/base/String.h index 21a3db51..49c96c4a 100644 --- a/include/cru/base/String.h +++ b/include/cru/base/String.h @@ -14,6 +14,11 @@ #include #include +#ifdef CRU_PLATFORM_OSX +#include +#include +#endif + namespace cru { class StringView; @@ -237,6 +242,11 @@ class CRU_BASE_API String { } #endif +#ifdef CRU_PLATFORM_OSX + CFWrapper ToCFStringRef() const; + static String FromCFStringRef(CFStringRef string); +#endif + template String Format(T&&... args) const; @@ -380,6 +390,10 @@ class CRU_BASE_API StringView { std::string ToUtf8() const; Buffer ToUtf8Buffer(bool end_zero = true) const; +#ifdef CRU_PLATFORM_OSX + CFWrapper ToCFStringRef() const; +#endif + private: const char16_t* ptr_; Index size_; diff --git a/include/cru/base/platform/osx/Convert.h b/include/cru/base/platform/osx/Convert.h deleted file mode 100644 index 6250190e..00000000 --- a/include/cru/base/platform/osx/Convert.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#ifndef CRU_PLATFORM_OSX -#error "This file can only be included on osx." -#endif - -#include "../../String.h" - -#include - -namespace cru::platform::osx { -CFStringRef Convert(const String& string); -String Convert(CFStringRef string); - -CFRange Convert(const Range& range); -Range Convert(const CFRange& range); -} // namespace cru::platform::osx diff --git a/include/cru/base/platform/osx/Exception.h b/include/cru/base/platform/osx/Exception.h deleted file mode 100644 index c1037cc6..00000000 --- a/include/cru/base/platform/osx/Exception.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#ifndef CRU_PLATFORM_OSX -#error "This file can only be included on osx." -#endif - -#include "../Exception.h" - -namespace cru::platform::osx { -class OsxException : public PlatformException { - public: - using PlatformException::PlatformException; -}; -} // namespace cru::platform::osx -- cgit v1.2.3