'From Squeak 1.31 of Feb 4, 1998 on 8 May 1998 at 12:31:37 pm'! Object subclass: #FileDictionary instanceVariableNames: 'state index file ' classVariableNames: '' poolDictionaries: '' category: 'dbdictionary'! DataStream subclass: #PositionableDataStream instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Object Storage'! !FileDictionary reorganize! ('initialize/creation' checkOpen close initialize open) ('enumeration' do: keysDo:) ('access' at: at:ifAbsent: at:put: file file: index keys state) ! !FileDictionary methodsFor: 'initialize/creation' stamp: 'mjg 3/17/98 16:29'! checkOpen state = 'open' ifFalse: [self error: 'File is not open']. ! ! !FileDictionary methodsFor: 'initialize/creation' stamp: 'mjg 3/17/98 16:38'! close | output | file size > 0 ifFalse: [self error: 'No file specified.']. output _ DataStream fileNamed: file,'.toc'. output nextPut: index. output close. state _ 'closed'.! ! !FileDictionary methodsFor: 'initialize/creation' stamp: 'mjg 3/17/98 15:52'! initialize index _ Dictionary new. state _ 'closed'. file _ ''.! ! !FileDictionary methodsFor: 'initialize/creation' stamp: 'mjg 4/30/98 16:15'! open | input | state = 'open' ifTrue: [self close]. file size > 0 ifFalse: [self error: 'No file specified.']. input _ DataStream fileNamed: file,'.toc'. input size > 0 ifTrue: [index _ input next. input close.] ifFalse: [index _ Dictionary new. input close.]. state _ 'open'.! ! !FileDictionary methodsFor: 'enumeration' stamp: 'mjg 3/17/98 16:41'! do: aBlock | a | index keysDo: [:i | a _ Association new key: i value: (self at: i). aBlock value: a]. ! ! !FileDictionary methodsFor: 'enumeration' stamp: 'mjg 3/23/98 12:53'! keysDo: aBlock index keysDo: [:i | aBlock value: i]. ! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/17/98 16:32'! at: key ^self at: key ifAbsent: [self error: 'key not found']. ! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/25/98 15:22'! at: key ifAbsent: aBlock | data pos obj | self checkOpen. pos _ index at: key ifAbsent: [nil]. pos isNil ifTrue: [^aBlock value]. data _ PositionableDataStream fileNamed: file. data position: pos. obj _ data next. data close. ^ obj ! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/17/98 16:30'! at: key put: value | data pos| self checkOpen. data _ PositionableDataStream fileNamed: file. data setToEnd. pos _ data position. data nextPut: value. index at: key put: pos. data close. ! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/17/98 15:56'! file ^file ! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/17/98 15:56'! file: aFile file _ aFile. ! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/17/98 15:57'! index ^index ! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/25/98 15:26'! keys ^index keys! ! !FileDictionary methodsFor: 'access' stamp: 'mjg 3/17/98 15:57'! state ^state ! ! !FileDictionary class reorganize! ('examples' basicExamples) ('create' fileNamed:) ! !FileDictionary class methodsFor: 'examples' stamp: 'mjg 3/17/98 16:44'! basicExamples "Write stuff out | fd | fd _ FileDictionary fileNamed: 'testfd'. fd open. fd at: 'fred' put: 'ethel'. fd at: 'tim' put: #(0 1 2 3). fd close. Write more complicated stuff out | fd newDict | fd _ FileDictionary fileNamed: 'testfd'. fd open. newDict _ Dictionary new. newDict at: 'mary' put: 'poppins'. newDict at: 'fred' put: 'astaire'. fd at: 'names' put: newDict. fd close Read stuff in |fd| fd _ FileDictionary fileNamed: 'testfd'. fd open. Transcript show: 'Fred: ', (fd at: 'fred') printString ; cr. Transcript show: 'Tim: ', (fd at: 'tim') printString ; cr. Transcript show: 'Fred: ', (fd at: 'fred') printString ; cr. fd do: [:anAssoc | Transcript show: anAssoc printString ; cr]. fd close. "! ! !FileDictionary class methodsFor: 'create' stamp: 'mjg 3/17/98 16:36'! fileNamed: dataFile "dataFile.toc is the index. dataFile is the data source." | newFD | newFD _ super new initialize. newFD file: dataFile. ^newFD ! ! !PositionableDataStream reorganize! ('all' position position: setToEnd) ! !PositionableDataStream methodsFor: 'all' stamp: 'mjg 3/17/98 16:23'! position "Very dangerous. Position must be the start of a new object." ^byteStream position! ! !PositionableDataStream methodsFor: 'all' stamp: 'mjg 3/17/98 16:21'! position: number "Very dangerous. Position must be the start of a new object." byteStream position: number.! ! !PositionableDataStream methodsFor: 'all' stamp: 'mjg 3/17/98 16:26'! setToEnd self position: (self size). ! !