Blame qtools/qvector.doc

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** QVector class documentation
Packit Service 50c9f2
**
Packit Service 50c9f2
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is part of the Qt GUI Toolkit.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed under the terms of the Q Public License
Packit Service 50c9f2
** as defined by Trolltech AS of Norway and appearing in the file
Packit Service 50c9f2
** LICENSE.QPL included in the packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed and/or modified under the terms of the
Packit Service 50c9f2
** GNU General Public License version 2 as published by the Free Software
Packit Service 50c9f2
** Foundation and appearing in the file LICENSE.GPL included in the
Packit Service 50c9f2
** packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit Service 50c9f2
** licenses may use this file in accordance with the Qt Commercial License
Packit Service 50c9f2
** Agreement provided with the Software.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit Service 50c9f2
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 50c9f2
**
Packit Service 50c9f2
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit Service 50c9f2
**   information about Qt Commercial License Agreements.
Packit Service 50c9f2
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit Service 50c9f2
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Contact info@trolltech.com if any conditions of this licensing are
Packit Service 50c9f2
** not clear to you.
Packit Service 50c9f2
**
Packit Service 50c9f2
**********************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QVector documentation
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
// BEING REVISED: ettrich
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QVector qvector.h
Packit Service 50c9f2
Packit Service 50c9f2
  \brief The QVector class is a template collection class that
Packit Service 50c9f2
  provides a vector (array).
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup tools
Packit Service 50c9f2
Packit Service 50c9f2
  QVector is implemented as a template class. Define a template
Packit Service 50c9f2
  instance QVector\<X\> to create a vector that contains pointers to
Packit Service 50c9f2
  X, or X*.
Packit Service 50c9f2
Packit Service 50c9f2
  A vector is the same as an array. The main difference between
Packit Service 50c9f2
  QVector and QArray is that QVector stores pointers to the elements,
Packit Service 50c9f2
  while QArray stores the elements themselves (i.e. QArray is
Packit Service 50c9f2
  value-based).
Packit Service 50c9f2
Packit Service 50c9f2
  Unless where otherwise stated, all functions that remove items from
Packit Service 50c9f2
  the vector will also delete the element pointed to if auto-deletion
Packit Service 50c9f2
  is enabled - see setAutoDelete(). By default, auto-deletion is
Packit Service 50c9f2
  disabled. This behaviour can be changed in a subclass by
Packit Service 50c9f2
  reimplementing the virtual method deleteItem().
Packit Service 50c9f2
Packit Service 50c9f2
  Functions that compares items, e.g. find() and sort(), will do so
Packit Service 50c9f2
  using the virtual function compareItems(). The default
Packit Service 50c9f2
  implementation of this function will only compare the absolute
Packit Service 50c9f2
  pointer values. Reimplement compareItems() in a subclass to get
Packit Service 50c9f2
  searching and sorting based on the item contents.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link collection.html Collection Classes\endlink, QArray
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QVector::QVector()
Packit Service 50c9f2
Packit Service 50c9f2
  Constructs a null vector.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QVector::QVector( uint size )
Packit Service 50c9f2
Packit Service 50c9f2
  Constructs an vector with room for \a size items.  Makes a null
Packit Service 50c9f2
  vector if \a size == 0.
Packit Service 50c9f2
Packit Service 50c9f2
  All \a size positions in the vector are initialized to 0.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa size(), resize(), isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QVector::QVector( const QVector<type> &v )
Packit Service 50c9f2
Packit Service 50c9f2
  Constructs a copy of \a v. Only the pointers are copied (i.e. shallow copy).
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QVector::~QVector()
Packit Service 50c9f2
Packit Service 50c9f2
  Removes all items from the vector, and destroys the vector itself.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa clear()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QVector<type> &QVector::operator=( const QVector<type> &v )
Packit Service 50c9f2
Packit Service 50c9f2
  Assigns \a v to this vector and returns a reference to this vector.
Packit Service 50c9f2
Packit Service 50c9f2
  This vector is first cleared, then all the items from \a v is copied
Packit Service 50c9f2
  into this vector. Only the pointers are copied (i.e. shallow copy).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa clear()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn type **QVector::data() const
Packit Service 50c9f2
  Returns a pointer to the actual vector data, which is an array of type*.
Packit Service 50c9f2
Packit Service 50c9f2
  The vector is a null vector if data() == 0 (null pointer).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn uint QVector::size() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the size of the vector, i.e. the number of vector
Packit Service 50c9f2
  positions. This is also the maximum number of items the vector can
Packit Service 50c9f2
  hold.
Packit Service 50c9f2
Packit Service 50c9f2
  The vector is a null vector if size() == 0.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull(), resize(), count()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn uint QVector::count() const 
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the number of items in the vector. The vector is empty if
Packit Service 50c9f2
  count() == 0.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isEmpty(), size()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QVector::isEmpty() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if the vector is empty, i.e. count() == 0, otherwise FALSE.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa count()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QVector::isNull() const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if the vector is null, otherwise FALSE.
Packit Service 50c9f2
Packit Service 50c9f2
  A null vector has size() == 0 and data() == 0.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa size()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QVector::resize( uint size )
Packit Service 50c9f2
  Resizes (expands or shrinks) the vector to \a size elements. The array
Packit Service 50c9f2
  becomes a null array if \a size == 0.
Packit Service 50c9f2
Packit Service 50c9f2
  Any items in position \a size or beyond in the vector are removed.
Packit Service 50c9f2
  New positions are initialized 0.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if successful, or FALSE if the memory cannot be allocated.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa size(), isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QVector::insert( uint i, const type *d )
Packit Service 50c9f2
Packit Service 50c9f2
  Sets position \a i in the vector to contain the item \a d. \a i must
Packit Service 50c9f2
  be less than size(). Any previous element in position \a i is removed.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa at()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QVector::remove( uint i )
Packit Service 50c9f2
Packit Service 50c9f2
  Removes the item at position \a i in the vector, if there is one.
Packit Service 50c9f2
  \a i must be less than size().
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE unless \a i is out of range.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa take(), at()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn type* QVector::take( uint i )
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the item at position \a i in the vector, and removes that
Packit Service 50c9f2
  item from the vector. \a i must be less than size(). If there is no
Packit Service 50c9f2
  item at position \a i, 0 is returned.
Packit Service 50c9f2
Packit Service 50c9f2
  In contrast to remove(), this function does \e not call deleteItem()
Packit Service 50c9f2
  for the removed item.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa remove(), at()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QVector::clear()
Packit Service 50c9f2
Packit Service 50c9f2
  Removes all items from the vector, and destroys the vector
Packit Service 50c9f2
  itself.
Packit Service 50c9f2
Packit Service 50c9f2
  The vector becomes a null vector.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa isNull()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QVector::fill( const type *d, int size )
Packit Service 50c9f2
Packit Service 50c9f2
  Inserts item \a d in all positions in the vector. Any existing items
Packit Service 50c9f2
  are removed. If \a d is 0, the vector becomes empty.
Packit Service 50c9f2
Packit Service 50c9f2
  If \a size >= 0, the vector is first resized to \a size. By default,
Packit Service 50c9f2
  \a size is -1.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns TRUE if successful, or FALSE if the memory cannot be allocated
Packit Service 50c9f2
  (only if a resize has been requested).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa resize(), insert(), isEmpty()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QVector::sort()
Packit Service 50c9f2
Packit Service 50c9f2
  Sorts the items in ascending order. Any empty positions will be put
Packit Service 50c9f2
  last.
Packit Service 50c9f2
Packit Service 50c9f2
  Compares items using the virtual function compareItems().
Packit Service 50c9f2
Packit Service 50c9f2
  \sa bsearch()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn int QVector::bsearch( const type* d ) const
Packit Service 50c9f2
Packit Service 50c9f2
  In a sorted array, finds the first occurrence of \a d using binary
Packit Service 50c9f2
  search. For a sorted array, this is generally much faster than
Packit Service 50c9f2
  find(), which does a linear search.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the position of \a d, or -1 if \a d could not be found. \a d
Packit Service 50c9f2
  may not be 0.
Packit Service 50c9f2
Packit Service 50c9f2
  Compares items using the virtual function compareItems().
Packit Service 50c9f2
Packit Service 50c9f2
  \sa sort(), find()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn int QVector::findRef( const type *d, uint i ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Finds the first occurrence of the item pointer \a d in the vector,
Packit Service 50c9f2
  using linear search. The search starts at position \a i, which must
Packit Service 50c9f2
  be less than size(). \a i is by default 0; i.e. the search starts at
Packit Service 50c9f2
  the start of the vector.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the position of \a d, or -1 if \a d could not be found.
Packit Service 50c9f2
Packit Service 50c9f2
  This function does \e not use compareItems() to compare items.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa find(), bsearch()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn int QVector::find( const type *d, uint i ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Finds the first occurrence of item \a d in the vector, using linear
Packit Service 50c9f2
  search. The search starts at position \a i, which must be less than
Packit Service 50c9f2
  size(). \a i is by default 0; i.e. the search starts at the start of
Packit Service 50c9f2
  the vector.
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the position of \e v, or -1 if \e v could not be found.
Packit Service 50c9f2
Packit Service 50c9f2
  Compares items using the virtual function compareItems().
Packit Service 50c9f2
Packit Service 50c9f2
  \sa findRef(), bsearch()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn uint QVector::containsRef( const type *d ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the number of occurrences of the item pointer \a d in the
Packit Service 50c9f2
  vector.
Packit Service 50c9f2
Packit Service 50c9f2
  This function does \e not use compareItems() to compare items.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa findRef()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn uint QVector::contains( const type *d ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the number of occurrences of item \a d in the vector.
Packit Service 50c9f2
Packit Service 50c9f2
  Compares items using the virtual function compareItems().
Packit Service 50c9f2
Packit Service 50c9f2
  \sa containsRef()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn type *QVector::operator[]( int i ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the item at position \a i, or 0 if there is no item at
Packit Service 50c9f2
  that position. \a i must be less than size().
Packit Service 50c9f2
Packit Service 50c9f2
  Equivalent to at( \a i ).
Packit Service 50c9f2
Packit Service 50c9f2
  \sa at()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn type *QVector::at( uint i ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Returns the item at position \a i, or 0 if there is no item at
Packit Service 50c9f2
  that position. \a i must be less than size().
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QVector::toList( QGList *list ) const
Packit Service 50c9f2
Packit Service 50c9f2
  Copies all items in this vector to the list \a list. First, \a list
Packit Service 50c9f2
  is cleared, then all items are appended to \a list.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa QList, QStack, QQueue
Packit Service 50c9f2
*/
Packit Service 50c9f2