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/boolean.ccm | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'nihil.ucl/boolean.ccm') diff --git a/nihil.ucl/boolean.ccm b/nihil.ucl/boolean.ccm index db6c864..e9c161b 100644 --- a/nihil.ucl/boolean.ccm +++ b/nihil.ucl/boolean.ccm @@ -22,18 +22,30 @@ export struct boolean final : object { inline static constexpr object_type ucl_type = object_type::boolean; - boolean(value_type value) - : object(::ucl_object_frombool(value)) + // Create a new boolean from a UCL object. + boolean(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 boolean(::ucl_object_t *uobj) : object(uobj) + boolean(noref_t, ::ucl_object_t *uobj) + : object(noref, uobj) { - assert(type() == object_type::boolean); + if (type() != ucl_type) + throw type_mismatch(ucl_type, type()); + } + + // Create a new boolean from a value. + explicit boolean(value_type value) + : object(noref, ::ucl_object_frombool(value)) + { + if (_object == nullptr) + throw error("failed to create UCL object"); } + // Return this object's value. auto value(this boolean const &self) -> value_type { auto v = value_type{}; -- cgit v1.2.3