From ead116d198c36f7b7ab7b49316239bf809388f81 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 23 Jun 2025 18:50:49 +0200 Subject: [PATCH] CoreFoundation: add cfnumber Signed-off-by: Simon Rozman --- include/MacStd/CoreFoundation.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/MacStd/CoreFoundation.hpp b/include/MacStd/CoreFoundation.hpp index ffb830d..c51737e 100644 --- a/include/MacStd/CoreFoundation.hpp +++ b/include/MacStd/CoreFoundation.hpp @@ -92,6 +92,27 @@ namespace macstd { cfstring(const std::basic_string &s) : cfstring(s.c_str()) {} }; + /// + /// Core Foundation number + /// + class cfnumber : public cfobject + { + public: + cfnumber(CFNumberRef h) : cfobject(h) {} + + cfnumber(float n) : cfobject(CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &n)) + { + if (!valid()) [[unlikely]] + throw std::bad_alloc(); + } + + cfnumber(double n) : cfobject(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &n)) + { + if (!valid()) [[unlikely]] + throw std::bad_alloc(); + } + }; + /// /// Core Foundation runtime error ///