blob: 9a7eaf777bed2169d188971d12756c9c3160edbf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*
* 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 <compare>
#include <cstddef>
#include <string>
#include <ucl.h>
export module nihil.ucl:object;
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);
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
|