Skip to content

Commit

Permalink
butano: intrusive_list and intrusive_forward_list iterator constructo…
Browse files Browse the repository at this point in the history
…rs are now public
  • Loading branch information
GValiente committed Oct 25, 2024
1 parent 019548b commit e975ace
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 39 deletions.
49 changes: 29 additions & 20 deletions butano/include/bn_intrusive_forward_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ class intrusive_forward_list
using const_pointer = intrusive_forward_list::const_pointer; //!< Const pointer alias.
using iterator_category = forward_iterator_tag; //!< Iterator category alias.

/**
* @brief Default class constructor.
*/
iterator() = default;

/**
* @brief Class constructor.
* @param node Intrusive forward list node.
*/
explicit iterator(node_type* node) :
_node(node)
{
}

/**
* @brief Increments the position.
* @return Reference to this.
Expand Down Expand Up @@ -124,13 +138,6 @@ class intrusive_forward_list
friend class const_iterator;

node_type* _node = nullptr;

iterator() = default;

explicit iterator(node_type* node) :
_node(node)
{
}
};

/**
Expand All @@ -149,6 +156,20 @@ class intrusive_forward_list
using const_pointer = intrusive_forward_list::const_pointer; //!< Const pointer alias.
using iterator_category = forward_iterator_tag; //!< Iterator category alias.

/**
* @brief Default class constructor.
*/
const_iterator() = default;

/**
* @brief Class constructor.
* @param node Intrusive forward list node.
*/
explicit const_iterator(const node_type* node) :
_node(node)
{
}

/**
* @brief Public constructor.
* @param it Non const iterator.
Expand Down Expand Up @@ -193,13 +214,6 @@ class intrusive_forward_list
friend class intrusive_forward_list;

const node_type* _node = nullptr;

const_iterator() = default;

explicit const_iterator(const node_type* node) :
_node(node)
{
}
};

/**
Expand Down Expand Up @@ -419,12 +433,7 @@ class intrusive_forward_list
*/
iterator erase_after(reference value)
{
BN_BASIC_ASSERT(! empty(), "List is empty");

iterator position(&value);
_erase_after(position);
++position;
return position;
return erase_after(const_iterator(&value));
}

/**
Expand Down
46 changes: 29 additions & 17 deletions butano/include/bn_intrusive_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ class intrusive_list
using const_pointer = intrusive_list::const_pointer; //!< Const pointer alias.
using iterator_category = bidirectional_iterator_tag; //!< Iterator category alias.

/**
* @brief Default class constructor.
*/
iterator() = default;

/**
* @brief Class constructor.
* @param node Intrusive list node.
*/
explicit iterator(node_type* node) :
_node(node)
{
}

/**
* @brief Increments the position.
* @return Reference to this.
Expand Down Expand Up @@ -136,11 +150,6 @@ class intrusive_list
friend class const_iterator;

node_type* _node = nullptr;

explicit iterator(node_type* node) :
_node(node)
{
}
};

/**
Expand All @@ -159,6 +168,20 @@ class intrusive_list
using const_pointer = intrusive_list::const_pointer; //!< Const pointer alias.
using iterator_category = bidirectional_iterator_tag; //!< Iterator category alias.

/**
* @brief Default class constructor.
*/
const_iterator() = default;

/**
* @brief Class constructor.
* @param node Intrusive list node.
*/
explicit const_iterator(const node_type* node) :
_node(node)
{
}

/**
* @brief Public constructor.
* @param it Non const iterator.
Expand Down Expand Up @@ -213,11 +236,6 @@ class intrusive_list
friend class intrusive_list;

const node_type* _node = nullptr;

explicit const_iterator(const node_type* node) :
_node(node)
{
}
};

using reverse_iterator = bn::reverse_iterator<iterator>; //!< Reverse iterator alias.
Expand Down Expand Up @@ -509,13 +527,7 @@ class intrusive_list
*/
iterator erase(reference value)
{
BN_BASIC_ASSERT(! empty(), "List is empty");

iterator position(&value);
iterator next = position;
++next;
_erase(position);
return next;
return erase(const_iterator(&value));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* bn::sprite_affine_mat_ptr::set_rotation_angle_safe, bn::sprite_builder::set_rotation_angle_safe
* and bn::sprite_ptr::set_rotation_angle_safe added.
* * Position in `create` methods is now optional.
* * bn::intrusive_list and bn::intrusive_forward_list iterator constructors are now public.
* * Real time clock (RTC) string added.
* * SRAM string with link-time optimization fixed.
* * @ref faq_bg_top_left and @ref faq_sprites_top_left questions added to the @ref faq page.
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.html

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions docs/classbn_1_1intrusive__forward__list_1_1const__iterator.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ <h2><a href="#pub-types">Public types</a></h2>
<section id="typeless-methods">
<h2><a href="#typeless-methods">Constructors, destructors, conversion operators</a></h2>
<dl class="m-doc">
<dt id="ab49e97d816b626a74491eb2ce3932edb">
<span class="m-doc-wrap-bumper"><a href="#ab49e97d816b626a74491eb2ce3932edb" class="m-doc-self">const_iterator</a>(</span><span class="m-doc-wrap">) <span class="m-label m-flat m-info">defaulted</span></span>
</dt>
<dd>Default class constructor.</dd>
<dt>
<span class="m-doc-wrap-bumper"><a href="#aff0768bd66d9bd6c77b8e4b10a7ce943" class="m-doc">const_iterator</a>(</span><span class="m-doc-wrap">const <a href="classbn_1_1intrusive__forward__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-flat m-info">explicit</span> </span>
</dt>
<dd>Class constructor.</dd>
<dt>
<span class="m-doc-wrap-bumper"><a href="#ac44fbb32f1bac282af642c996c1bfdc4" class="m-doc">const_iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__forward__list_1_1iterator.html" class="m-doc">iterator</a> it)</span>
</dt>
Expand Down Expand Up @@ -140,6 +148,23 @@ <h2><a href="#friends">Friends</a></h2>
</section>
<section>
<h2>Function documentation</h2>
<section class="m-doc-details" id="aff0768bd66d9bd6c77b8e4b10a7ce943"><div>
<h3>
<span class="m-doc-wrap-bumper"> bn::<wbr />intrusive_forward_list::<wbr />const_iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#aff0768bd66d9bd6c77b8e4b10a7ce943" class="m-doc-self">const_iterator</a>(</span><span class="m-doc-wrap">const <a href="classbn_1_1intrusive__forward__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-info">explicit</span> </span></span>
</h3>
<p>Class constructor.</p>
<table class="m-table m-fullwidth m-flat">
<thead>
<tr><th colspan="2">Parameters</th></tr>
</thead>
<tbody>
<tr>
<td style="width: 1%">node</td>
<td>Intrusive forward list node.</td>
</tr>
</tbody>
</table>
</div></section>
<section class="m-doc-details" id="ac44fbb32f1bac282af642c996c1bfdc4"><div>
<h3>
<span class="m-doc-wrap-bumper"> bn::<wbr />intrusive_forward_list::<wbr />const_iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#ac44fbb32f1bac282af642c996c1bfdc4" class="m-doc-self">const_iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__forward__list_1_1iterator.html" class="m-doc">iterator</a> it)</span></span>
Expand Down
31 changes: 31 additions & 0 deletions docs/classbn_1_1intrusive__forward__list_1_1iterator.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ <h3>Contents</h3>
Reference
<ul>
<li><a href="#pub-types">Public types</a></li>
<li><a href="#typeless-methods">Constructors, destructors, conversion operators</a></li>
<li><a href="#pub-methods">Public functions</a></li>
<li><a href="#friends">Friends</a></li>
</ul>
Expand Down Expand Up @@ -101,6 +102,19 @@ <h2><a href="#pub-types">Public types</a></h2>
<dd>Iterator category alias.</dd>
</dl>
</section>
<section id="typeless-methods">
<h2><a href="#typeless-methods">Constructors, destructors, conversion operators</a></h2>
<dl class="m-doc">
<dt id="a38f0feed219981f976cac4ed9d483576">
<span class="m-doc-wrap-bumper"><a href="#a38f0feed219981f976cac4ed9d483576" class="m-doc-self">iterator</a>(</span><span class="m-doc-wrap">) <span class="m-label m-flat m-info">defaulted</span></span>
</dt>
<dd>Default class constructor.</dd>
<dt>
<span class="m-doc-wrap-bumper"><a href="#ae5f0ba90475b3009153a8fd5185b085c" class="m-doc">iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__forward__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-flat m-info">explicit</span> </span>
</dt>
<dd>Class constructor.</dd>
</dl>
</section>
<section id="pub-methods">
<h2><a href="#pub-methods">Public functions</a></h2>
<dl class="m-doc">
Expand Down Expand Up @@ -138,6 +152,23 @@ <h2><a href="#friends">Friends</a></h2>
</section>
<section>
<h2>Function documentation</h2>
<section class="m-doc-details" id="ae5f0ba90475b3009153a8fd5185b085c"><div>
<h3>
<span class="m-doc-wrap-bumper"> bn::<wbr />intrusive_forward_list::<wbr />iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#ae5f0ba90475b3009153a8fd5185b085c" class="m-doc-self">iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__forward__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-info">explicit</span> </span></span>
</h3>
<p>Class constructor.</p>
<table class="m-table m-fullwidth m-flat">
<thead>
<tr><th colspan="2">Parameters</th></tr>
</thead>
<tbody>
<tr>
<td style="width: 1%">node</td>
<td>Intrusive forward list node.</td>
</tr>
</tbody>
</table>
</div></section>
<section class="m-doc-details" id="addf930ad9d3a445ea0be7f645b656439"><div>
<h3>
<span class="m-doc-wrap-bumper"><a href="classbn_1_1intrusive__forward__list_1_1iterator.html" class="m-doc">iterator</a>&amp; bn::<wbr />intrusive_forward_list::<wbr />iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#addf930ad9d3a445ea0be7f645b656439" class="m-doc-self">operator++</a>(</span><span class="m-doc-wrap">)</span></span>
Expand Down
25 changes: 25 additions & 0 deletions docs/classbn_1_1intrusive__list_1_1const__iterator.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ <h2><a href="#pub-types">Public types</a></h2>
<section id="typeless-methods">
<h2><a href="#typeless-methods">Constructors, destructors, conversion operators</a></h2>
<dl class="m-doc">
<dt id="a3cfbe8474089afe371a1f959d8410ab1">
<span class="m-doc-wrap-bumper"><a href="#a3cfbe8474089afe371a1f959d8410ab1" class="m-doc-self">const_iterator</a>(</span><span class="m-doc-wrap">) <span class="m-label m-flat m-info">defaulted</span></span>
</dt>
<dd>Default class constructor.</dd>
<dt>
<span class="m-doc-wrap-bumper"><a href="#aeeaef21a8a4749e40ffd74d73c396ba7" class="m-doc">const_iterator</a>(</span><span class="m-doc-wrap">const <a href="classbn_1_1intrusive__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-flat m-info">explicit</span> </span>
</dt>
<dd>Class constructor.</dd>
<dt>
<span class="m-doc-wrap-bumper"><a href="#a2ab00422329705eedaca3c8993fac15b" class="m-doc">const_iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__list_1_1iterator.html" class="m-doc">iterator</a> it)</span>
</dt>
Expand Down Expand Up @@ -144,6 +152,23 @@ <h2><a href="#friends">Friends</a></h2>
</section>
<section>
<h2>Function documentation</h2>
<section class="m-doc-details" id="aeeaef21a8a4749e40ffd74d73c396ba7"><div>
<h3>
<span class="m-doc-wrap-bumper"> bn::<wbr />intrusive_list::<wbr />const_iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#aeeaef21a8a4749e40ffd74d73c396ba7" class="m-doc-self">const_iterator</a>(</span><span class="m-doc-wrap">const <a href="classbn_1_1intrusive__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-info">explicit</span> </span></span>
</h3>
<p>Class constructor.</p>
<table class="m-table m-fullwidth m-flat">
<thead>
<tr><th colspan="2">Parameters</th></tr>
</thead>
<tbody>
<tr>
<td style="width: 1%">node</td>
<td>Intrusive list node.</td>
</tr>
</tbody>
</table>
</div></section>
<section class="m-doc-details" id="a2ab00422329705eedaca3c8993fac15b"><div>
<h3>
<span class="m-doc-wrap-bumper"> bn::<wbr />intrusive_list::<wbr />const_iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a2ab00422329705eedaca3c8993fac15b" class="m-doc-self">const_iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__list_1_1iterator.html" class="m-doc">iterator</a> it)</span></span>
Expand Down
31 changes: 31 additions & 0 deletions docs/classbn_1_1intrusive__list_1_1iterator.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ <h3>Contents</h3>
Reference
<ul>
<li><a href="#pub-types">Public types</a></li>
<li><a href="#typeless-methods">Constructors, destructors, conversion operators</a></li>
<li><a href="#pub-methods">Public functions</a></li>
<li><a href="#friends">Friends</a></li>
</ul>
Expand Down Expand Up @@ -101,6 +102,19 @@ <h2><a href="#pub-types">Public types</a></h2>
<dd>Iterator category alias.</dd>
</dl>
</section>
<section id="typeless-methods">
<h2><a href="#typeless-methods">Constructors, destructors, conversion operators</a></h2>
<dl class="m-doc">
<dt id="a188af1921a5c4e59058ce141def4001b">
<span class="m-doc-wrap-bumper"><a href="#a188af1921a5c4e59058ce141def4001b" class="m-doc-self">iterator</a>(</span><span class="m-doc-wrap">) <span class="m-label m-flat m-info">defaulted</span></span>
</dt>
<dd>Default class constructor.</dd>
<dt>
<span class="m-doc-wrap-bumper"><a href="#a46378e6da70638ce55cf00a7e1e3fad2" class="m-doc">iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-flat m-info">explicit</span> </span>
</dt>
<dd>Class constructor.</dd>
</dl>
</section>
<section id="pub-methods">
<h2><a href="#pub-methods">Public functions</a></h2>
<dl class="m-doc">
Expand Down Expand Up @@ -142,6 +156,23 @@ <h2><a href="#friends">Friends</a></h2>
</section>
<section>
<h2>Function documentation</h2>
<section class="m-doc-details" id="a46378e6da70638ce55cf00a7e1e3fad2"><div>
<h3>
<span class="m-doc-wrap-bumper"> bn::<wbr />intrusive_list::<wbr />iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a46378e6da70638ce55cf00a7e1e3fad2" class="m-doc-self">iterator</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1intrusive__list__node__type.html" class="m-doc">node_<wbr />type</a>* node) <span class="m-label m-info">explicit</span> </span></span>
</h3>
<p>Class constructor.</p>
<table class="m-table m-fullwidth m-flat">
<thead>
<tr><th colspan="2">Parameters</th></tr>
</thead>
<tbody>
<tr>
<td style="width: 1%">node</td>
<td>Intrusive list node.</td>
</tr>
</tbody>
</table>
</div></section>
<section class="m-doc-details" id="a9c779e3f5ed35d716ef80710808233f6"><div>
<h3>
<span class="m-doc-wrap-bumper"><a href="classbn_1_1intrusive__list_1_1iterator.html" class="m-doc">iterator</a>&amp; bn::<wbr />intrusive_list::<wbr />iterator::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a9c779e3f5ed35d716ef80710808233f6" class="m-doc-self">operator++</a>(</span><span class="m-doc-wrap">)</span></span>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchdata-v2.js

Large diffs are not rendered by default.

0 comments on commit e975ace

Please sign in to comment.