/* * This source code is released into the public domain. */ module; /* * A UCL object. The object is immutable and internally refcounted, so it * may be copied as needed. * */ #include #include #include #include export module nihil.ucl:object; import nihil; import :type; namespace nihil::ucl { /*********************************************************************** * The basic object type. */ // Ref the UCL object when creating an object. export inline constexpr struct ref_t {} ref; // Don't ref the UCL object. export inline constexpr struct noref_t {} noref; export struct object { inline static constexpr object_type ucl_type = object_type::object; // Create an object from an existing ucl_object_t. The first argument // determines whether we ref the object or not. object(ref_t, ::ucl_object_t const *object); object(noref_t, ::ucl_object_t *object); // Free our object on destruction. virtual ~object(); // Movable. object(object &&other) noexcept; auto operator=(this object &self, object &&other) noexcept -> object&; // Copyable. // Note that this copies the entire UCL object. object(object const &other) noexcept; auto operator=(this object &self, object const &other) -> object &; // Increase the refcount of this object. [[nodiscard]] auto ref(this object const &self) -> object; // Return the type of this object. [[nodiscard]] auto type(this object const &self) -> object_type; // Return the underlying object. [[nodiscard]] auto get_ucl_object(this object &self) -> ::ucl_object_t *; [[nodiscard]] auto get_ucl_object(this object const &self) -> ::ucl_object_t const *; // Return the key of this object. [[nodiscard]] auto key(this object const &self) -> std::string_view; protected: // The object we're wrapping. ::ucl_object_t *m_object = nullptr; friend auto swap(object &a, object &b) -> void; }; /*********************************************************************** * Object comparison. */ export [[nodiscard]] auto operator==(object const &lhs, object const &rhs) -> bool; export [[nodiscard]] auto operator<=>(object const &lhs, object const &rhs) -> std::strong_ordering; } // namespace nihil::ucl