SYNOPSIS

#include <Inventor/lists/SbList.h>

Public Member Functions

SbList (const int sizehint=DEFAULTSIZE)

SbList (const SbList< Type > &l)

~SbList ()

void copy (const SbList< Type > &l)

SbList< Type > & operator= (const SbList< Type > &l)

void fit (void)

void append (const Type item)

int find (const Type item) const

void insert (const Type item, const int insertbefore)

void removeItem (const Type item)

void remove (const int index)

void removeFast (const int index)

int getLength (void) const

void truncate (const int length, const int dofit=0)

void push (const Type item)

Type pop (void)

const Type * getArrayPtr (const int start=0) const

Type operator[] (const int index) const

Type & operator[] (const int index)

int operator== (const SbList< Type > &l) const

int operator!= (const SbList< Type > &l) const

void ensureCapacity (const int size)

Protected Member Functions

void expand (const int size)

int getArraySize (void) const

Detailed Description

template<class Type>class SbList< Type >

The SbList class is a template container class for lists.

SbList is an extension of the Coin library versus the original Open Inventor API. Open Inventor handles most list classes by inheriting the SbPList class, which contains an array of generic void* pointers. By using this template-based class instead, we can share more code and make the list handling code more typesafe.

Care has been taken to make sure the list classes which are part of the Open Inventor API to still be compatible with their original interfaces, as derived from the SbPList base class. But if you still bump into any problems when porting your Open Inventor applications, let us know and we'll do our best to sort them out.

A feature with this class is that the list object arrays grow dynamically as you append() more items to the list. The actual growing technique used is to double the list size when it becomes too small.

There are also other array-related convenience methods; e.g. finding item indices, inserting items at any position, removing items (and shrink the array), copying of arrays, etc.

See also:

SbPList

Constructor & Destructor Documentation

template<class Type> \fBSbList\fP< Type >::\fBSbList\fP (const intsizehint = \fCDEFAULTSIZE\fP)\fC [inline]\fP

Default constructor.

The sizehint argument hints about how many elements the list will contain, so memory allocation can be done efficiently.

Important note: explicitly specifying an sizehint value does not mean that the list will initially contain this number of values. After construction, the list will contain zero items, just as for the default constructor. Here's a good example on how to give yourself hard to find bugs:

SbList<SbBool> flags(2); // Assume we need only 2 elements. Note
                         // that the list is still 0 elements long.
flags[0] = TRUE;         // Ouch. List is still 0 elements long.

Since this conceptual misunderstanding is so easy to make, you're probably better (or at least safer) off leaving the sizehint argument to its default value by not explicitly specifying it.

It improves performance if you know the approximate total size of the list in advance before adding list elements, as the number of reallocations will be minimized.

template<class Type> \fBSbList\fP< Type >::\fBSbList\fP (const \fBSbList\fP< Type > &l)\fC [inline]\fP

Copy constructor. Creates a complete copy of the given list.

template<class Type> \fBSbList\fP< Type >::~\fBSbList\fP ()\fC [inline]\fP

Destructor, frees all internal resources used by the list container.

Member Function Documentation

template<class Type> void \fBSbList\fP< Type >::copy (const \fBSbList\fP< Type > &l)\fC [inline]\fP

Make this list a copy of l.

template<class Type> \fBSbList\fP< Type > & \fBSbList\fP< Type >::operator= (const \fBSbList\fP< Type > &l)\fC [inline]\fP

Make this list a copy of l.

template<class Type> void \fBSbList\fP< Type >::fit (void)\fC [inline]\fP

Fit the allocated array exactly around the length of the list, descarding memory spent on unused pre-allocated array cells.

You should normally not need or want to call this method, and it is only available for the sake of having the option to optimize memory usage for the unlikely event that you should throw around huge SbList objects within your application.

template<class Type> void \fBSbList\fP< Type >::append (const Typeitem)\fC [inline]\fP

Append the item at the end of list, expanding the list array by one.

template<class Type> int \fBSbList\fP< Type >::find (const Typeitem) const\fC [inline]\fP

Return index of first occurrence of item in the list, or -1 if item is not present.

template<class Type> void \fBSbList\fP< Type >::insert (const Typeitem, const intinsertbefore)\fC [inline]\fP

Insert item at index insertbefore.

insertbefore should not be larger than the current number of items in the list.

template<class Type> void \fBSbList\fP< Type >::removeItem (const Typeitem)\fC [inline]\fP

Removes an item from the list. If there are several items with the same value, removes the item with the lowest index.

template<class Type> void \fBSbList\fP< Type >::remove (const intindex)\fC [inline]\fP

Remove the item at index, moving all subsequent items downwards one place in the list.

template<class Type> void \fBSbList\fP< Type >::removeFast (const intindex)\fC [inline]\fP

Remove the item at index, moving the last item into its place and truncating the list.

template<class Type> int \fBSbList\fP< Type >::getLength (void) const\fC [inline]\fP

Returns number of items in the list.

template<class Type> void \fBSbList\fP< Type >::truncate (const intlength, const intfit = \fC0\fP)\fC [inline]\fP

Shorten the list to contain length elements, removing items from index length and onwards.

If fit is non-zero, will also shrink the internal size of the allocated array. Note that this is much less efficient than not re-fitting the array size.

template<class Type> void \fBSbList\fP< Type >::push (const Typeitem)\fC [inline]\fP

This appends item at the end of the list in the same fashion as append() does. Provided as an abstraction for using the list class as a stack.

template<class Type> Type \fBSbList\fP< Type >::pop (void)\fC [inline]\fP

Pops off the last element of the list and returns it.

template<class Type> const Type * \fBSbList\fP< Type >::getArrayPtr (const intstart = \fC0\fP) const\fC [inline]\fP

Returns pointer to a non-modifiable array of the lists elements. start specifies an index into the array.

The caller is not responsible for freeing up the array, as it is just a pointer into the internal array used by the list.

template<class Type> Type \fBSbList\fP< Type >::operator[] (const intindex) const\fC [inline]\fP

Returns a copy of item at index.

template<class Type> Type & \fBSbList\fP< Type >::operator[] (const intindex)\fC [inline]\fP

Returns a reference to item at index.

template<class Type> SbBool \fBSbList\fP< Type >::operator== (const \fBSbList\fP< Type > &l) const\fC [inline]\fP

Equality operator. Returns TRUE if this list and l are identical, containing the exact same set of elements.

template<class Type> SbBool \fBSbList\fP< Type >::operator!= (const \fBSbList\fP< Type > &l) const\fC [inline]\fP

Inequality operator. Returns TRUE if this list and l are not equal.

template<class Type> void \fBSbList\fP< Type >::ensureCapacity (const intsize)\fC [inline]\fP

Ensure that the internal buffer can hold at least size elements. SbList will automatically resize itself to make room for new elements, but this method can be used to improve performance (and avoid memory fragmentation) if you know approximately the number of elements that is going to be added to the list.

Since:

Coin 2.5

template<class Type> void \fBSbList\fP< Type >::expand (const intsize)\fC [inline]\fP, \fC [protected]\fP

Expand the list to contain size items. The new items added at the end have undefined value.

template<class Type> int \fBSbList\fP< Type >::getArraySize (void) const\fC [inline]\fP, \fC [protected]\fP

Return number of items there's allocated space for in the array.

See also:

getLength()

Author

Generated automatically by Doxygen for Coin from the source code.