aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/integer.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-22 17:39:27 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-22 17:39:27 +0100
commit09b7a494bd5de24f380095003fb7da4939de43e5 (patch)
tree125ba6cc66370399c578d81f98d1eeef14f85686 /nihil.ucl/integer.ccm
parentd6c3858418c4c00adb18d927135f73ed5a54564a (diff)
downloadnihil-09b7a494bd5de24f380095003fb7da4939de43e5.tar.gz
nihil-09b7a494bd5de24f380095003fb7da4939de43e5.tar.bz2
nihil.ucl: improve reference management
Diffstat (limited to 'nihil.ucl/integer.ccm')
-rw-r--r--nihil.ucl/integer.ccm24
1 files changed, 18 insertions, 6 deletions
diff --git a/nihil.ucl/integer.ccm b/nihil.ucl/integer.ccm
index d3009a1..18f0049 100644
--- a/nihil.ucl/integer.ccm
+++ b/nihil.ucl/integer.ccm
@@ -22,18 +22,30 @@ export struct integer final : object {
inline static constexpr object_type ucl_type = object_type::integer;
- integer(value_type value)
- : object(::ucl_object_fromint(value))
+ // Create a new integer from a UCL object.
+ integer(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 integer(::ucl_object_t *uobj) : object(uobj)
+ integer(noref_t, ::ucl_object_t *uobj)
+ : object(noref, uobj)
{
- assert(type() == object_type::integer);
+ if (type() != ucl_type)
+ throw type_mismatch(ucl_type, type());
+ }
+
+ // Create a new integer from a value.
+ integer(value_type value)
+ : object(noref, ::ucl_object_fromint(value))
+ {
+ if (_object == nullptr)
+ throw error("failed to create UCL object");
}
+ // Return the value of this object.
auto value(this integer const &self) -> value_type
{
auto v = value_type{};