Blame qtools/qcollection.cpp

Packit 1c1d7e
/****************************************************************************
Packit 1c1d7e
** 
Packit 1c1d7e
**
Packit 1c1d7e
** Implementation of base class for all collection classes
Packit 1c1d7e
**
Packit 1c1d7e
** Created : 920820
Packit 1c1d7e
**
Packit 1c1d7e
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit 1c1d7e
**
Packit 1c1d7e
** This file is part of the tools module of the Qt GUI Toolkit.
Packit 1c1d7e
**
Packit 1c1d7e
** This file may be distributed under the terms of the Q Public License
Packit 1c1d7e
** as defined by Trolltech AS of Norway and appearing in the file
Packit 1c1d7e
** LICENSE.QPL included in the packaging of this file.
Packit 1c1d7e
**
Packit 1c1d7e
** This file may be distributed and/or modified under the terms of the
Packit 1c1d7e
** GNU General Public License version 2 as published by the Free Software
Packit 1c1d7e
** Foundation and appearing in the file LICENSE.GPL included in the
Packit 1c1d7e
** packaging of this file.
Packit 1c1d7e
**
Packit 1c1d7e
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit 1c1d7e
** licenses may use this file in accordance with the Qt Commercial License
Packit 1c1d7e
** Agreement provided with the Software.
Packit 1c1d7e
**
Packit 1c1d7e
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit 1c1d7e
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit 1c1d7e
**
Packit 1c1d7e
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit 1c1d7e
**   information about Qt Commercial License Agreements.
Packit 1c1d7e
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit 1c1d7e
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit 1c1d7e
**
Packit 1c1d7e
** Contact info@trolltech.com if any conditions of this licensing are
Packit 1c1d7e
** not clear to you.
Packit 1c1d7e
**
Packit 1c1d7e
**********************************************************************/
Packit 1c1d7e
Packit 1c1d7e
#include "qcollection.h"
Packit 1c1d7e
Packit 1c1d7e
// NOT REVISED
Packit 1c1d7e
/*!
Packit 1c1d7e
  \class QCollection qcollection.h
Packit 1c1d7e
  \brief The QCollection class is the base class of all Qt collections.
Packit 1c1d7e
Packit 1c1d7e
  \ingroup collection
Packit 1c1d7e
  \ingroup tools
Packit 1c1d7e
Packit 1c1d7e
  The QCollection class is an abstract base class for the Qt \link
Packit 1c1d7e
  collection.html collection classes\endlink QDict, QList etc. via QGDict,
Packit 1c1d7e
  QGList etc.
Packit 1c1d7e
Packit 1c1d7e
  A QCollection knows only about the number of objects in the
Packit 1c1d7e
  collection and the deletion strategy (see setAutoDelete()).
Packit 1c1d7e
Packit 1c1d7e
  A collection is implemented using the \c Item (generic collection
Packit 1c1d7e
  item) type, which is a \c void*.  The template classes that create
Packit 1c1d7e
  the real collections cast the \c Item to the required type.
Packit 1c1d7e
Packit 1c1d7e
  \sa \link collection.html Collection Classes\endlink
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*! \enum QCollection::Item
Packit 1c1d7e
Packit 1c1d7e
  This type is the generic "item" in a QCollection.
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn QCollection::QCollection()
Packit 1c1d7e
Packit 1c1d7e
  Constructs a collection. The constructor is protected because
Packit 1c1d7e
  QCollection is an abstract class.
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn QCollection::QCollection( const QCollection & source )
Packit 1c1d7e
Packit 1c1d7e
  Constructs a copy of \a source with autoDelete() set to FALSE. The
Packit 1c1d7e
  constructor is protected because QCollection is an abstract class.
Packit 1c1d7e
Packit 1c1d7e
  Note that if \a source has autoDelete turned on, copying it is a
Packit 1c1d7e
  good way to get memory leaks, reading freed memory, or both.
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn QCollection::~QCollection()
Packit 1c1d7e
  Destroys the collection. The destructor is protected because QCollection
Packit 1c1d7e
  is an abstract class.
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn bool QCollection::autoDelete() const
Packit 1c1d7e
  Returns the setting of the auto-delete option (default is FALSE).
Packit 1c1d7e
  \sa setAutoDelete()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn void QCollection::setAutoDelete( bool enable )
Packit 1c1d7e
Packit 1c1d7e
  Sets the auto-delete option of the collection.
Packit 1c1d7e
Packit 1c1d7e
  Enabling auto-delete (\e enable is TRUE) will delete objects that
Packit 1c1d7e
  are removed from the collection.  This can be useful if the
Packit 1c1d7e
  collection has the only reference to the objects.  (Note that the
Packit 1c1d7e
  object can still be copied using the copy constructor - copying such
Packit 1c1d7e
  objects is a good way to get memory leaks, reading freed memory or
Packit 1c1d7e
  both.)
Packit 1c1d7e
Packit 1c1d7e
  Disabling auto-delete (\e enable is FALSE) will \e not delete objects
Packit 1c1d7e
  that are removed from the collection.	 This is useful if the objects
Packit 1c1d7e
  are part of many collections.
Packit 1c1d7e
Packit 1c1d7e
  The default setting is FALSE.
Packit 1c1d7e
Packit 1c1d7e
  \sa autoDelete()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn virtual uint QCollection::count() const
Packit 1c1d7e
  Returns the number of objects in the collection.
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn virtual void QCollection::clear()
Packit 1c1d7e
  Removes all objects from the collection.  The objects will be deleted
Packit 1c1d7e
  if auto-delete has been enabled.
Packit 1c1d7e
  \sa setAutoDelete()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Virtual function that creates a copy of an object that is about to
Packit 1c1d7e
  be inserted into the collection.
Packit 1c1d7e
Packit 1c1d7e
  The default implementation returns the \e d pointer, i.e. no copy
Packit 1c1d7e
  is made.
Packit 1c1d7e
Packit 1c1d7e
  This function is seldom reimplemented in the collection template
Packit 1c1d7e
  classes. It is not common practice to make a copy of something
Packit 1c1d7e
  that is being inserted.
Packit 1c1d7e
Packit 1c1d7e
  \sa deleteItem()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QCollection::Item QCollection::newItem( Item d )
Packit 1c1d7e
{
Packit 1c1d7e
    return d;					// just return reference
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Virtual function that deletes an item that is about to be removed from
Packit 1c1d7e
  the collection.
Packit 1c1d7e
Packit 1c1d7e
  The default implementation deletes \e d pointer if and only if
Packit 1c1d7e
  auto-delete has been enabled.
Packit 1c1d7e
Packit 1c1d7e
  This function is always reimplemented in the collection template
Packit 1c1d7e
  classes.
Packit 1c1d7e
Packit 1c1d7e
  \warning If you reimplement this function you must also reimplement
Packit 1c1d7e
  the destructor and call the virtual function clear() from your
Packit 1c1d7e
  destructor.  This is due to the way virtual functions and
Packit 1c1d7e
  destructors work in C++: virtual functions in derived classes cannot
Packit 1c1d7e
  be called from a destructor.  If you do not do this your
Packit 1c1d7e
  deleteItem() function will not be called when the container is
Packit 1c1d7e
  destructed.
Packit 1c1d7e
Packit 1c1d7e
  \sa newItem(), setAutoDelete()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
void QCollection::deleteItem( Item d )
Packit 1c1d7e
{
Packit 1c1d7e
    if ( del_item )
Packit 1c1d7e
#if defined(Q_DELETING_VOID_UNDEFINED)
Packit 1c1d7e
	delete (char *)d;			// default operation
Packit 1c1d7e
#else
Packit 1c1d7e
	delete d;				// default operation
Packit 1c1d7e
#endif
Packit 1c1d7e
}