Xavax C++ Library Class Index   FAQ   Overview

Class xavax::DList<T>

DList<T> is a template class doubly linked lists that store elements of type T by value. To use DList<T>, type T must have a copy constructor and implement operator=. Due to the overhead of storing elements by value, this container is only recommended for storing native types and small objects. For larger objects, consider using PDList<T> which stores pointers to objects.

Constructor Summary
DList()
         Construct an empty list.
DList(const DList<T>& src)
         Construct a new list that is a copy of src.

Operator Summary
DList<T>& operator=(DList<T>& src)
         Remove all elements, then copy the elements of src to this list.

Method Summary
void append(const T& t)
         Append an object of type T to the end of the list.
void clear()
         Remove all elements from the list.
size_t count() const
         Returns the number of elements in the list.
T* first()
         Returns a pointer to the first element in the list.
void insert(const T& t, size_t p= 0)
         Insert object t of type T at position p in the list.
T* last
         Returns a pointer to the last element in the list.
T* locate(size_t p)
         Locate and return a pointer to the element at position p.
T* locate(bool (proc)(T*,void*), void* data)
         Locate and return a pointer to the element selected by proc.
T remove(size_t p)
         Remove and return the element at position p.
void traverse(TraversalOrder order, void (proc)(T*,void*), void* data)
         Traverse the list in the specified order calling proc for each element.

Related Classes
DListConstIterator<T>, DListIterator<T>, PDList<T>

Constructor Detail

DList<T>

DList<T>()
Construct an empty list.

DList<T>

DList<T>(const DList<T>& src)
Construct a new list that is a copy of src. Since elements are stored by value, the depth of the copy depends on type T's copy constructor.
Parameters:
src - the list to be copied.

Operator Detail

operator=

DList<T>& operator=(DList<T>& src)
Remove all elements from this list, then copy each element of src to this list. Since elements are stored by value, the depth of the copy depends on type T's copy constructor.
Parameters:
src - the list to be copied.

Method Detail

append

void append(const T& t)
Append object t of type T to the end of the list.
Parameters:
t - an object of type T to be inserted into the list.

clear

void clear()
Remove all objects from the list.

count

size_t count() const
Return the number of elements in this list.
Returns:
the number of elements in this list.

first

T* first()
Return a pointer to the first element in the list.
Returns:
a pointer to the first element in the list.

insert

void insert(const T& t, size_t p= 0)
Insert object t of type T at position p in the list.
Parameters:
t - the object to be inserted in the list.
p - the position at which the object should be inserted.

last

T* last();
Return the last element in the list.
Returns:
a pointer to the last element in the list.

locate

T* locate(size_t p)
Locate and return a pointer to the element at position p in the list. The first element is at position 0.
Parameters:
p - the position of the object to be retrieved.
Returns:
a pointer to the element at position p if the list contains at least p+1 elements; otherwise, null.

T* locate(bool (proc)(T*,void*), void* data)
Iterate over the list calling proc for each element. If proc returns true, return a pointer to that element.
Parameters:
proc - a function that returns true if an element is selected.
data - can be used to pass client data to proc.
Returns:
a pointer to the first element selected by proc, or null if no element was selected.

remove

T remove(size_t p)
Remove and return the element at position p in the list.
Parameters:
p - the position of the object to be removed.
Returns:
the element at position p if the list contains at least p+1 elements.
Throws:
RangeException - if the list contains fewer than p+1 elements.

traverse

void traverse(TraversalOrder order, void (proc)(T*,void*), void* data);
Traverse the list in the specified order calling proc for each list element.
Parameters:
order - the order of the traversal.
proc - the function to be called for each element.
data - can be used to pass client data to proc.

Example Code

Copyright © 2003 Xavax Inc. -- All Rights Reserved