Skip to content

Commit 93a1bf9

Browse files
committed
feat: support dom::Function
1 parent 3aecfc0 commit 93a1bf9

File tree

22 files changed

+4734
-3443
lines changed

22 files changed

+4734
-3443
lines changed

include/mrdox/Dom/Array.hpp

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,6 @@ class MRDOX_DECL
108108
*/
109109
Array(Array const& other);
110110

111-
/** Assignment.
112-
113-
Ownership of the array is transferred
114-
to this, and ownership of the previous
115-
contents is released. The moved-from
116-
array behaves as if default constructed.
117-
*/
118-
Array& operator=(Array&&);
119-
120-
/** Assignment.
121-
122-
This acquires shared ownership of the copied
123-
array, and ownership of the previous contents
124-
is released.
125-
*/
126-
Array& operator=(Array const&) = default;
127-
128-
//--------------------------------------------
129-
130111
/** Constructor.
131112
132113
This constructs an array from an existing
@@ -150,6 +131,25 @@ class MRDOX_DECL
150131
*/
151132
Array(storage_type elements);
152133

134+
/** Assignment.
135+
136+
Ownership of the array is transferred
137+
to this, and ownership of the previous
138+
contents is released. The moved-from
139+
array behaves as if default constructed.
140+
*/
141+
Array& operator=(Array&&);
142+
143+
/** Assignment.
144+
145+
This acquires shared ownership of the copied
146+
array, and ownership of the previous contents
147+
is released.
148+
*/
149+
Array& operator=(Array const&) = default;
150+
151+
//--------------------------------------------
152+
153153
/** Return the implementation used by this object.
154154
*/
155155
auto impl() const noexcept -> impl_type const&
@@ -175,6 +175,13 @@ class MRDOX_DECL
175175
*/
176176
value_type get(size_type i) const;
177177

178+
/** Set the i-th element, without bounds checking.
179+
180+
@param i The zero-based index of the element.
181+
@param v The value to set.
182+
*/
183+
void set(size_type i, Value v);
184+
178185
/** Return the i-th element, without bounds checking.
179186
*/
180187
value_type operator[](size_type i) const;
@@ -185,6 +192,18 @@ class MRDOX_DECL
185192
*/
186193
value_type at(size_type i) const;
187194

195+
/** Return the first element.
196+
197+
@throw Exception `empty()`
198+
*/
199+
value_type front() const;
200+
201+
/** Return the last element.
202+
203+
@throw Exception `empty()`
204+
*/
205+
value_type back() const;
206+
188207
/** Return an iterator to the beginning of the range of elements.
189208
*/
190209
iterator begin() const;
@@ -200,6 +219,27 @@ class MRDOX_DECL
200219
*/
201220
void emplace_back(value_type value);
202221

222+
/** Concatenate two arrays.
223+
*/
224+
friend Array operator+(Array const& lhs, Array const& rhs);
225+
226+
/// @overload
227+
template <std::convertible_to<Array> S>
228+
friend auto operator+(
229+
S const& lhs, Array const& rhs) noexcept
230+
{
231+
return Array(lhs) + rhs;
232+
}
233+
234+
/// @overload
235+
template <std::convertible_to<Array> S>
236+
friend auto operator+(
237+
Array const& lhs, S const& rhs) noexcept
238+
{
239+
return lhs + Array(rhs);
240+
}
241+
242+
203243
/** Swap two arrays.
204244
*/
205245
void swap(Array& other) noexcept
@@ -214,6 +254,18 @@ class MRDOX_DECL
214254
lhs.swap(rhs);
215255
}
216256

257+
/** Compare two arrays for equality.
258+
*/
259+
friend
260+
bool
261+
operator==(Array const&, Array const&) noexcept;
262+
263+
/** Compare two arrays for precedence.
264+
*/
265+
friend
266+
std::strong_ordering
267+
operator<=>(Array const&, Array const&) noexcept;
268+
217269
/** Return a diagnostic string.
218270
*/
219271
friend
@@ -261,6 +313,10 @@ class MRDOX_DECL
261313
*/
262314
virtual value_type get(size_type i) const = 0;
263315

316+
/** Set the i-th element, without bounds checking.
317+
*/
318+
virtual void set(size_type, Value);
319+
264320
/** Append an element to the end of the array.
265321
266322
The default implementation throws an exception,
@@ -298,6 +354,7 @@ class MRDOX_DECL
298354
storage_type elements) noexcept;
299355
size_type size() const override;
300356
value_type get(size_type i) const override;
357+
void set(size_type i, Value v) override;
301358
void emplace_back(value_type value) override;
302359

303360
private:

include/mrdox/Dom/Array.ipp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ inline auto Array::get(std::size_t i) const -> value_type
170170
return impl_->get(i);
171171
}
172172

173+
inline void Array::set(std::size_t i, Value v)
174+
{
175+
impl_->set(i, std::move(v));
176+
}
177+
173178
inline auto Array::operator[](std::size_t i) const -> value_type
174179
{
175180
return get(i);
@@ -179,7 +184,17 @@ inline auto Array::at(std::size_t i) const -> value_type
179184
{
180185
if(i < size())
181186
return get(i);
182-
Error("out of range").Throw();
187+
return {};
188+
}
189+
190+
inline auto Array::front() const -> value_type
191+
{
192+
return at(0);
193+
}
194+
195+
inline auto Array::back() const -> value_type
196+
{
197+
return at(size() - 1);
183198
}
184199

185200
inline auto Array::begin() const -> iterator
@@ -197,6 +212,17 @@ inline void Array::emplace_back(value_type value)
197212
impl_->emplace_back(std::move(value));
198213
}
199214

215+
inline
216+
Array operator+(Array const& lhs, Array const& rhs)
217+
{
218+
Array buf;
219+
for (auto e: lhs)
220+
buf.emplace_back(e);
221+
for (auto e: rhs)
222+
buf.emplace_back(e);
223+
return buf;
224+
}
225+
200226
} // dom
201227
} // mrdox
202228
} // clang

0 commit comments

Comments
 (0)