From 09b7a494bd5de24f380095003fb7da4939de43e5 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sun, 22 Jun 2025 17:39:27 +0100 Subject: nihil.ucl: improve reference management --- nihil.ucl/real.ccm | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'nihil.ucl/real.ccm') diff --git a/nihil.ucl/real.ccm b/nihil.ucl/real.ccm index 4639109..d968667 100644 --- a/nihil.ucl/real.ccm +++ b/nihil.ucl/real.ccm @@ -21,16 +21,27 @@ export struct real final : object { inline static constexpr object_type ucl_type = object_type::real; - real(value_type value) - : object(::ucl_object_fromdouble(value)) + // Create a new real from a UCL object. + real(ref_t, ::ucl_object_t const *uobj) + : object(nihil::ucl::ref, uobj) { - if (_object == nullptr) - throw error("failed to create UCL object"); + if (type() != ucl_type) + throw type_mismatch(ucl_type, type()); } - explicit real(::ucl_object_t *uobj) : object(uobj) + real(noref_t, ::ucl_object_t *uobj) + : object(noref, uobj) { - assert(type() == object_type::real); + if (type() != ucl_type) + throw type_mismatch(ucl_type, type()); + } + + // Create a new real from a value. + real(value_type value) + : object(noref, ::ucl_object_fromdouble(value)) + { + if (_object == nullptr) + throw error("failed to create UCL object"); } auto value(this real const &self) -> value_type -- cgit v1.2.3