Blame qtools/qcollection.cpp

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** Implementation of base class for all collection classes
Packit Service 50c9f2
**
Packit Service 50c9f2
** Created : 920820
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 tools module 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
#include "qcollection.h"
Packit Service 50c9f2
Packit Service 50c9f2
// NOT REVISED
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \class QCollection qcollection.h
Packit Service 50c9f2
  \brief The QCollection class is the base class of all Qt collections.
Packit Service 50c9f2
Packit Service 50c9f2
  \ingroup collection
Packit Service 50c9f2
  \ingroup tools
Packit Service 50c9f2
Packit Service 50c9f2
  The QCollection class is an abstract base class for the Qt \link
Packit Service 50c9f2
  collection.html collection classes\endlink QDict, QList etc. via QGDict,
Packit Service 50c9f2
  QGList etc.
Packit Service 50c9f2
Packit Service 50c9f2
  A QCollection knows only about the number of objects in the
Packit Service 50c9f2
  collection and the deletion strategy (see setAutoDelete()).
Packit Service 50c9f2
Packit Service 50c9f2
  A collection is implemented using the \c Item (generic collection
Packit Service 50c9f2
  item) type, which is a \c void*.  The template classes that create
Packit Service 50c9f2
  the real collections cast the \c Item to the required type.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa \link collection.html Collection Classes\endlink
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*! \enum QCollection::Item
Packit Service 50c9f2
Packit Service 50c9f2
  This type is the generic "item" in a QCollection.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QCollection::QCollection()
Packit Service 50c9f2
Packit Service 50c9f2
  Constructs a collection. The constructor is protected because
Packit Service 50c9f2
  QCollection is an abstract class.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QCollection::QCollection( const QCollection & source )
Packit Service 50c9f2
Packit Service 50c9f2
  Constructs a copy of \a source with autoDelete() set to FALSE. The
Packit Service 50c9f2
  constructor is protected because QCollection is an abstract class.
Packit Service 50c9f2
Packit Service 50c9f2
  Note that if \a source has autoDelete turned on, copying it is a
Packit Service 50c9f2
  good way to get memory leaks, reading freed memory, or both.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn QCollection::~QCollection()
Packit Service 50c9f2
  Destroys the collection. The destructor is protected because QCollection
Packit Service 50c9f2
  is an abstract class.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn bool QCollection::autoDelete() const
Packit Service 50c9f2
  Returns the setting of the auto-delete option (default is FALSE).
Packit Service 50c9f2
  \sa setAutoDelete()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn void QCollection::setAutoDelete( bool enable )
Packit Service 50c9f2
Packit Service 50c9f2
  Sets the auto-delete option of the collection.
Packit Service 50c9f2
Packit Service 50c9f2
  Enabling auto-delete (\e enable is TRUE) will delete objects that
Packit Service 50c9f2
  are removed from the collection.  This can be useful if the
Packit Service 50c9f2
  collection has the only reference to the objects.  (Note that the
Packit Service 50c9f2
  object can still be copied using the copy constructor - copying such
Packit Service 50c9f2
  objects is a good way to get memory leaks, reading freed memory or
Packit Service 50c9f2
  both.)
Packit Service 50c9f2
Packit Service 50c9f2
  Disabling auto-delete (\e enable is FALSE) will \e not delete objects
Packit Service 50c9f2
  that are removed from the collection.	 This is useful if the objects
Packit Service 50c9f2
  are part of many collections.
Packit Service 50c9f2
Packit Service 50c9f2
  The default setting is FALSE.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa autoDelete()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn virtual uint QCollection::count() const
Packit Service 50c9f2
  Returns the number of objects in the collection.
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  \fn virtual void QCollection::clear()
Packit Service 50c9f2
  Removes all objects from the collection.  The objects will be deleted
Packit Service 50c9f2
  if auto-delete has been enabled.
Packit Service 50c9f2
  \sa setAutoDelete()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Virtual function that creates a copy of an object that is about to
Packit Service 50c9f2
  be inserted into the collection.
Packit Service 50c9f2
Packit Service 50c9f2
  The default implementation returns the \e d pointer, i.e. no copy
Packit Service 50c9f2
  is made.
Packit Service 50c9f2
Packit Service 50c9f2
  This function is seldom reimplemented in the collection template
Packit Service 50c9f2
  classes. It is not common practice to make a copy of something
Packit Service 50c9f2
  that is being inserted.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa deleteItem()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
QCollection::Item QCollection::newItem( Item d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    return d;					// just return reference
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
/*!
Packit Service 50c9f2
  Virtual function that deletes an item that is about to be removed from
Packit Service 50c9f2
  the collection.
Packit Service 50c9f2
Packit Service 50c9f2
  The default implementation deletes \e d pointer if and only if
Packit Service 50c9f2
  auto-delete has been enabled.
Packit Service 50c9f2
Packit Service 50c9f2
  This function is always reimplemented in the collection template
Packit Service 50c9f2
  classes.
Packit Service 50c9f2
Packit Service 50c9f2
  \warning If you reimplement this function you must also reimplement
Packit Service 50c9f2
  the destructor and call the virtual function clear() from your
Packit Service 50c9f2
  destructor.  This is due to the way virtual functions and
Packit Service 50c9f2
  destructors work in C++: virtual functions in derived classes cannot
Packit Service 50c9f2
  be called from a destructor.  If you do not do this your
Packit Service 50c9f2
  deleteItem() function will not be called when the container is
Packit Service 50c9f2
  destructed.
Packit Service 50c9f2
Packit Service 50c9f2
  \sa newItem(), setAutoDelete()
Packit Service 50c9f2
*/
Packit Service 50c9f2
Packit Service 50c9f2
void QCollection::deleteItem( Item d )
Packit Service 50c9f2
{
Packit Service 50c9f2
    if ( del_item )
Packit Service 50c9f2
#if defined(Q_DELETING_VOID_UNDEFINED)
Packit Service 50c9f2
	delete (char *)d;			// default operation
Packit Service 50c9f2
#else
Packit Service 50c9f2
	delete d;				// default operation
Packit Service 50c9f2
#endif
Packit Service 50c9f2
}