Xavax C++ Library Class Index   FAQ   Overview

Class xavax::PSList<T>

PSList<T> is a template class for non-intrusive, singly linked lists that stores pointers to elements of type T. PSList<T> is implemented using private inheritance of PSListBase. Each PSList<T> can be managed or unmanaged. A managed list assumes the responsibility of deleting the objects pointed to by the list elements when the list is destroyed or when all elements are removed using the clear method.

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

Operator Summary
PSList<T>& operator=(PSList<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.
void managed(bool flag)
         Set the state of the managed flag.
bool managed()
         Return the state of the managed flag.
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
SList<T>, PSListConstIterator<T>. PSListIterator<T>.

Constructor Detail

PSList<T>

PSList<T>()
Construct an empty list.

PSList<T>

PSList<T>(const PSList<T>& src)
Construct a new list that is a shallow copy of src.
Parameters:
src - the list to be copied.

Operator Detail

operator=

PSList<T>& operator=(PSList<T>& src)
Remove all elements from this list, then copy each element of src to this list.
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 elements from the list. If the list is managed, destroy the objects pointed to by the list elements.

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.

locate

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.

managed

void managed(bool flag)
Set the managed state of this list. If flag is true, objects pointed to by list elements will be destroyed when the list is destroyed or when all elements are removed using the clear method.
Parameters:
flag - the new state of the managed flag.

managed

bool managed() const
Return the state of the managed flag.
Returns:
true if the list is managed; otherwise, false.

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