AutoDeletedFilename.st
changeset 10761 6a63674a5cb1
child 10847 2f39b0b6f4e6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AutoDeletedFilename.st	Thu Oct 25 11:40:08 2007 +0200
@@ -0,0 +1,60 @@
+"{ Package: 'stx:libbasic' }"
+
+Filename subclass:#AutoDeletedFilename
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'System-Support'
+!
+
+!AutoDeletedFilename class methodsFor:'documentation'!
+
+documentation
+"
+    Used with temporary files - these will automatically delete themself,
+    when no longer referenced.
+    See -> Filename asAutoDeletedFilename
+"
+!
+
+examples
+"
+    the following file will be automatically deleted after some time:
+
+    |f p|
+
+    f := Filename newTemporary.
+    f writeStream
+        nextPutLine:'hello';
+        close.
+    p := f pathName.
+    Transcript showCR:p.
+    f := f asAutoDeletedFilename.
+    self assert:(p asFilename exists).
+    ObjectMemory collectGarbage.
+    Delay waitForSeconds:2.
+    self assert:(p asFilename exists).
+    f := nil.
+    ObjectMemory collectGarbage.
+    Delay waitForSeconds:2.
+    self assert:(p asFilename exists not).
+"
+! !
+
+!AutoDeletedFilename methodsFor:'accessing'!
+
+finalize
+    Transcript showCR:'deleting ',self pathName.
+    self delete
+!
+
+setName:aString
+    super setName:aString.
+    self registerForFinalization    
+! !
+
+!AutoDeletedFilename class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libbasic/AutoDeletedFilename.st,v 1.1 2007-10-25 09:40:08 cg Exp $'
+! !