Source: classlib/include/classlib/shddel.h


Annotated List
Files
Globals
Hierarchy
Index
/***************************************************************************
    shddel.h  -  controllo della cancellazione
                             -------------------
    begin                : ven dic  7 17:40:01 CET 2001
    copyright            : (C) 2001 by Nicola De Nisco
    email                : nicola@winada.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#if !defined( __CLASSLIB_SHDDEL_H )
#define __CLASSLIB_SHDDEL_H

#if !defined( __CLASSLIB_DEFS_H )
#include "classlib/defs.h"
#endif  // __CLASSLIB_DEFS_H

/**
  [INTERNAL USE ONLY]

  This class is included in every indirect container; it control the
  ownership of the elements in the container. All container by default
  turn on the ownership; it means that when the container will be destroyd
  all elements in the container will be destroyed too.
  This behavory can be change calling de OwnsElements() function with the
  value 0; that turn off the ownership of the container. This function will be
  in every indirect container class because every one include TShouldDelete.
*/
class TShouldDelete
{

public:

    enum DeleteType { NoDelete, DefDelete, Delete };

    TShouldDelete( DeleteType dt = Delete )
        {
        OwnsElements( dt );
        }

	/** get information about the ownership of the container
	*/
    int OwnsElements()
        {
        return ShouldDelete == Delete;
        }

	/** set the ownership of the container: OwnsElements(0) turn off the ownership
		OwnsElements(1) turn on the ownership of the container */
    void OwnsElements( int del )
        {
        ShouldDelete = (del == 0) ? NoDelete : Delete;
        }

	/** called internally from the container to determine the behavory
	*/
    int DelObj( DeleteType dt )
        {
        return dt == Delete || (dt==DefDelete && ShouldDelete==Delete);
        }

    int delObj( DeleteType dt ) {return DelObj(dt);}

private:

    DeleteType ShouldDelete;

};

#endif  // __CLASSLIB_SHDDEL_H


Generated by: nicola on gulliver.wadahome.it on Sun May 25 13:54:34 2003, using kdoc 2.0a53.