Re: [ROOT] TList Unique entry

From: Jean-Eric Campagne (campagne@lal.in2p3.fr)
Date: Thu Jun 05 2003 - 14:16:45 MEST


Hi Fons,

What do you think of the following routine...

Chers. Jean-Eric

//-------------------------------------------------------------------------
---/
#include <set>
 typedef std::set<void*> AddressBook;


void SecureDelete(TList* aList) {
  AddressBook uniqueInstanceSet; //Address Container with unique instance
  pair<AddressBook::iterator,bool> rc;

  TIter next(aList);
  TObject* aObj;
  //referencer les addresses dans un set (une entree par adresse differente)
  while ( (aObj = next()) ) {
    rc = uniqueInstanceSet.insert((void*)aObj);
    if (rc.second) {// the objet has not been referenced so it can be 
deleted
      delete aObj;
    }
  }//eow
  //Use Clear with nodelete option to reset the List wo deletion of the 
objects
  //as they have been deleted in previous while loop.
  aList->Clear("nodelete");
}

--On mercredi 4 juin 2003 21:33 +0200 Fons Rademakers 
<Fons.Rademakers@cern.ch> wrote:

> Hi Jean-Eric,
>
>   this cannot be done automatically, you have to make some add method
> that first looks if the object is already in the list (like
> list->FindObject(newObj)) and only add the method if FindObject()
> returns 0.
>
> Cheers, Fons.
>
>
> On Wed, 2003-06-04 at 16:05, Jean-Eric Campagne wrote:
>> Hello,
>>
>> If I make add twice  the same instance of an object in a TList, then at
>> the  Delete phase of the TList there is a crash for known reason.
>> How, I can ask the TList to keep Unique Instance of an Object?
>>
>> Regards
>> Jean-Eric Campagne
>>
>> ........................................................................
>> ... .LAL - IN2P3 - CNRS
>> .LAL - B.P 34 - 91898 Orsay Cedex - France
>> .Piece 108
>> .Tel +33 (0)1 64 46 84 29
>> .Fax +33 (0)1 64 46 83 97
>> ........................................................................
>> ...
> --
> Org:    CERN, European Laboratory for Particle Physics.
> Mail:   1211 Geneve 23, Switzerland
> E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
> WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480
>



...........................................................................
.LAL - IN2P3 - CNRS
.LAL - B.P 34 - 91898 Orsay Cedex - France
.Piece 108
.Tel +33 (0)1 64 46 84 29
.Fax +33 (0)1 64 46 83 97
...........................................................................



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET