DlangUI

Cross Platform GUI for D programming language

Home API Docs Screenshots Download .zip View on GitHub

dlangui.core.collections

This module implements array based collection.

Synopsis:
import dlangui.core.collections;

// add
Collection!Widget widgets;
widgets ~= new Widget("id1");
widgets ~= new Widget("id2");
Widget w3 = new Widget("id3");
widgets ~= w3;

// remove by index
widgets.remove(1);

// foreach
foreach(w; widgets)
    writeln("widget: ", w.id);

// remove by value
widgets -= w3;
writeln(widgets[0].id);




License:
Boost License 1.0

Authors:
Vadim Lopatin, coolreader.org@gmail.com

struct Collection(T, bool ownItems = false);
array based collection of items

retains item order when during add/remove operations

@property bool empty();
returns true if there are no items in collection

@property size_t length();
returns number of items in collection

@property size_t size();
returns currently allocated capacity (may be more than length)

@property void size(size_t newSize);
change capacity (e.g. to reserve big space to avoid multiple reallocations)

@property void length(size_t newSize);
returns number of items in collection

ref T opIndex(size_t index);
access item by index

void add(T item, size_t index = size_t.max);
insert new item in specified position

void addAll(ref Collection!(T, ownItems) v);
add all items from other collection

ref Collection opOpAssign(string op)(T item);
support for appending (~=, +=) and removing by value (-=)

size_t indexOf(T item);
returns index of first occurence of item, size_t.max if not found

T remove(size_t index);
remove single item, returning removed item

bool removeValue(T value);
remove single item by value - if present in collection, returning true if item was found and removed

int opApply(int delegate(ref T param) op);
support of foreach with reference

void clear();
remove all items

@property T popFront();
remove first item

void pushFront(T item);
insert item at beginning of collection

@property T popBack();
remove last item

void pushBack(T item);
insert item at end of collection

@property T front();
peek first item

@property T back();
peek last item