Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) (01/22/91)
a_dent@fennel.cc.uwa.oz.au writes in a message to All
A> One of my classes deletes objects from a CList by (more or less)
A>
while ((myObject = myList->FirstItem()) != NULL) {
myList->Remove(myObject);
myObject->Dispose();
}
Question: the above removes all objects, no? Why not just use myList->DisposeItems();
???
Lawson
--
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English
Internet: Lawson.English@p88.f15.n300.z1.fidonet.org
soudan@iitmax.iit.edu (Bassel Soudan) (01/22/91)
I faced a similar situation where I had to remove all the objects from a list without disposing of them. ( I had two lists sharing some of their objects, and I wanted to remove the objects from one list and still keep them in the other.) What I ended up doing was write a RemoveAll method and add it to the CList class. In this method I saved the number of objects in a local variable and used that as my counter to remove the first item in the list that many times. It works fine. Watch out though because once you make this change, your CList class is no longer the same as the CList that came with TCL. And by the way, when you try to run the project, it will recompile every single file included in the project. I hope this helps. I am sorry but due to Symantec's copyright I can not publish the exact code for this method, but I think that there won't be any problem if someone needed an e-mail copy of it. Bassel soudan@iitmax.iit.edu
Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) (01/23/91)
Bassel Soudan writes in a message to All BS> I faced a similar situation where I had to remove all the objects BS> from a list without disposing of them. ( I had two lists sharing BS> some of their objects, and I wanted to remove the objects from BS> one list and still keep them in the other.) BS> What I ended up doing was write a RemoveAll method and add it BS> to the CList class. In this method I saved the number of objects BS> in a local variable and used that as my counter to remove the BS> first item in the list that many times. It works fine. ??? From the Think C manual, page 272: void Dispose(void); Dispose of a cluster, but not the items in it. ??? Am I missing something? Why not just use the CCluster method? Lawson -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English Internet: Lawson.English@p88.f15.n300.z1.fidonet.org
d88-jwa@dront.nada.kth.se (Jon W{tte) (01/23/91)
In article <> soudan@iitmax.iit.edu (Bassel Soudan) writes: > What I ended up doing was write a RemoveAll method and add it to the >CList class. In this method I saved the number of objects in a local variable What's this ? You needn't fdo that - just subclass the class with your method added - most parts of the TCL can be modified by subclassing and overriding, which is what OOP is all about. One sad omission is the construction of the switchboard (if you for instance want to implement macros...) h+ Jon W{tte, Stockholm, Sweden, h+@nada.kth.se :: This article is fake. If you take it for real, the _REAL_ :: Jon W{tte will sue you for slander. So there ! Nyah ! :-)
minow@bolt.enet.dec.com (Martin Minow) (01/23/91)
During the discussion of removing objects from a TCL list, I wrote that I had used a sequence like: > while ((myObject = myList->FirstItem()) != NULL) { > myList->Remove(myObject); > myObject->Dispose(); >} And a respondant quite naturally asked why I didn't use myList->DisposeItems(); Actually, the real situation was a set of multiply-connected lists that handle open PPC Toolbox sessions. The PPC class contains a list of open PPCPorts, the PPCPort class has a list of open sessions, and the PPCSession class has a list of active (asychronous) I/O buffers. Messages have an instance variable linking them to their Session and sessions have an instance variable pointing to their port. Looking only at the session-port interaction; the application terminates a session by mySession->Dispose(). This does the toolbox stuff, then executes itsPort->itsSessionList->Remove(), then does an inherited::Dispose(). If the application closes the port, it must empty the session list without using DoForEach or any method that uses that technique as the actual removal is done by the list element's Dispose() method. Here's the PPCPort disposal: void PPCPort::Dispose() { PPCSession *aSession; while ((aSession = (PPCSession *) itsSessions->FirstItem()) != NULL) aSession->Dispose(); itsSessions->Dispose(); /* Toolbox stuff deleted */ inherited::Dispose(); } Here's the PPCSession disposal: void PPCSession::Dispose() { /* Toolbox stuff deleted */ itsPort->itsSessions->Remove(this); inherited::Dispose(); } Hope this is clearer. Martin Minow minow@bolt.enet.dec.com
hpoppe@ncar.ucar.edu (Herb Poppe) (01/24/91)
In article <19302@shlump.nac.dec.com> minow@bolt.enet.dec.com (Martin Minow) writes: > Actually, the real situation was a set of multiply-connected lists that > handle open PPC Toolbox sessions. Okay, I'll bite: what is the PPC Toolbox? Herb Poppe hpoppe@ncar.ucar.edu NCAR (303) 497-1296 1850 Table Mesa Dr. Boulder, CO 80307-3000