dlangui/docs/collections.html

155 lines
4.4 KiB
HTML

<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>dlangui.core.collections</title>
</head><body>
<h1>dlangui.core.collections</h1>
<!-- Generated by Ddoc from src/dlangui/core/collections.d -->
DLANGUI library.
<br><br>
This module implements array based collection.
<br><br>
<b>Synopsis:</b><br>
<pre class="d_code"><font color=blue>import</font> dlangui.core.<u>collections</u>;
<font color=green>// add
</font>Collection!Widget widgets;
widgets ~= <font color=blue>new</font> Widget(<font color=red>"id1"</font>);
widgets ~= <font color=blue>new</font> Widget(<font color=red>"id2"</font>);
Widget w3 = <font color=blue>new</font> Widget(<font color=red>"id3"</font>);
widgets ~= w3;
<font color=green>// remove by index
</font>widgets.remove(1);
<font color=green>// foreach
</font><font color=blue>foreach</font>(w; widgets)
writeln(<font color=red>"widget: "</font>, w.id);
<font color=green>// remove by value
</font>widgets -= w3;
writeln(widgets[0].id);
</pre>
<br><br>
<b>License:</b><br>
Boost License 1.0
<br><br>
<b>Authors:</b><br>
Vadim Lopatin, coolreader.org@gmail.com<br><br>
<dl><dt><big><a name="Collection"></a>struct <u>Collection</u>(T, bool ownItems = false);
</big></dt>
<dd>array based collection of items
retains item order when during add/remove operations<br><br>
<dl><dt><big><a name="empty"></a>bool <u>empty</u>();
</big></dt>
<dd>returns <b>true</b> if there are no items in collection<br><br>
</dd>
<dt><big><a name="length"></a>size_t <u>length</u>();
</big></dt>
<dd>returns number of items in collection<br><br>
</dd>
<dt><big><a name="size"></a>size_t <u>size</u>();
</big></dt>
<dd>returns currently allocated capacity (may be more than length)<br><br>
</dd>
<dt><big><a name="size"></a>void <u>size</u>(size_t <i>newSize</i>);
</big></dt>
<dd>change capacity (e.g. to reserve big space to avoid multiple reallocations)<br><br>
</dd>
<dt><big><a name="length"></a>void <u>length</u>(size_t <i>newSize</i>);
</big></dt>
<dd>returns number of items in collection<br><br>
</dd>
<dt><big><a name="opIndex"></a>T <u>opIndex</u>(size_t <i>index</i>);
</big></dt>
<dd>access item by <i>index</i><br><br>
</dd>
<dt><big><a name="add"></a>void <u>add</u>(T <i>item</i>, size_t <i>index</i> = size_t.max);
</big></dt>
<dd>insert new <i>item</i> in specified position<br><br>
</dd>
<dt><big><a name="addAll"></a>void <u>addAll</u>(ref Collection!(T, ownItems) <i>v</i>);
</big></dt>
<dd>add all items from other collection<br><br>
</dd>
<dt><big><a name="opOpAssign"></a>Collection <u>opOpAssign</u>(string op)(T <i>item</i>);
</big></dt>
<dd>support for appending (~=, +=) and removing by value (-=)<br><br>
</dd>
<dt><big><a name="indexOf"></a>size_t <u>indexOf</u>(T <i>item</i>);
</big></dt>
<dd>returns index of first occurence of <i>item</i>, size_t.max if not found<br><br>
</dd>
<dt><big><a name="remove"></a>T <u>remove</u>(size_t <i>index</i>);
</big></dt>
<dd><u>remove</u> single item, returning removed item<br><br>
</dd>
<dt><big><a name="removeValue"></a>bool <u>removeValue</u>(T <i>value</i>);
</big></dt>
<dd>remove single item by <i>value</i> - if present in collection, returning <b>true</b> if item was found and removed<br><br>
</dd>
<dt><big><a name="opApply"></a>int <u>opApply</u>(int delegate(ref T param) <i>op</i>);
</big></dt>
<dd>support of foreach with reference<br><br>
</dd>
<dt><big><a name="clear"></a>void <u>clear</u>();
</big></dt>
<dd>remove all items<br><br>
</dd>
<dt><big><a name="popFront"></a>T <u>popFront</u>();
</big></dt>
<dd>remove first item<br><br>
</dd>
<dt><big><a name="pushFront"></a>void <u>pushFront</u>(T <i>item</i>);
</big></dt>
<dd>insert <i>item</i> at beginning of collection<br><br>
</dd>
<dt><big><a name="popBack"></a>T <u>popBack</u>();
</big></dt>
<dd>remove last item<br><br>
</dd>
<dt><big><a name="pushBack"></a>void <u>pushBack</u>(T <i>item</i>);
</big></dt>
<dd>insert <i>item</i> at end of collection<br><br>
</dd>
<dt><big><a name="front"></a>T <u>front</u>();
</big></dt>
<dd>peek first item<br><br>
</dd>
<dt><big><a name="back"></a>T <u>back</u>();
</big></dt>
<dd>peek last item<br><br>
</dd>
</dl>
</dd>
</dl>
<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. Vadim Lopatin, 2014
</small>
</body></html>