diff options
Diffstat (limited to 'nihil.ucl/integer.ccm')
| -rw-r--r-- | nihil.ucl/integer.ccm | 24 |
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{}; |
