author | mkobetic |
Tue, 31 Jan 2012 03:47:19 +0000 | |
changeset 90 | 59f68d289949 |
parent 67 | a87e5ce04545 |
child 109 | 9587e2df7029 |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/xtreams/substreams' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
WriteSubstream subclass:#TestWriteSubstream |
|
6 |
instanceVariableNames:'substreamAtEnd test inclusive' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
22
e0653bbdbe61
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
4
diff
changeset
|
9 |
category:'Xtreams-Substreams' |
4 | 10 |
! |
11 |
||
12 |
TestWriteSubstream comment:'This is a substream bounded by an element matching the @test criteria. |
|
13 |
||
14 |
Instance Variables |
|
15 |
substreamAtEnd <Boolean> is this substream at end |
|
16 |
test <BlockClosure> the bounding criteria |
|
17 |
inclusive <Boolean> is the boundary part of the substream contents |
|
18 |
||
19 |
' |
|
20 |
! |
|
21 |
||
22 |
||
23 |
!TestWriteSubstream class methodsFor:'instance creation'! |
|
24 |
||
25 |
on: aDestination test: testBlock inclusive: aBoolean |
|
26 |
^self new on: aDestination test: testBlock inclusive: aBoolean |
|
27 |
! ! |
|
28 |
||
29 |
!TestWriteSubstream methodsFor:'accessing'! |
|
30 |
||
31 |
insert: anInteger from: aSequenceableCollection at: startIndex |
|
32 |
^self write: anInteger from: aSequenceableCollection at: startIndex |
|
33 |
! |
|
34 |
||
35 |
put: anObject |
|
36 |
substreamAtEnd ifTrue: [Incomplete zero raise]. |
|
37 |
((substreamAtEnd := test value: anObject) and: [inclusive not]) ifTrue: [Incomplete zero raise]. |
|
38 |
[destination put: anObject] on: Incomplete do: [:incomplete | destinationAtEnd := substreamAtEnd := true. incomplete pass]. |
|
39 |
^anObject |
|
40 |
! |
|
41 |
||
42 |
write: anInteger from: aSequenceableCollection at: startIndex |
|
43 |
| count object | |
|
44 |
substreamAtEnd ifTrue: [Incomplete zero raise]. |
|
45 |
count := 0. |
|
46 |
[[count < anInteger and: [substreamAtEnd not]] whileTrue: |
|
47 |
[object := aSequenceableCollection at: startIndex + count. |
|
48 |
((substreamAtEnd := test value: object) and: [inclusive not]) ifFalse: [destination put: object]. |
|
49 |
count := count + 1]] |
|
50 |
on: Incomplete do: [:incomplete | |
|
51 |
destinationAtEnd := substreamAtEnd := true. |
|
52 |
(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
53 |
count < anInteger ifTrue: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
54 |
^anInteger |
|
55 |
! ! |
|
56 |
||
57 |
!TestWriteSubstream methodsFor:'initialize-release'! |
|
58 |
||
59 |
on: aDestination test: testBlock inclusive: aBoolean |
|
60 |
self on: aDestination. |
|
61 |
test := testBlock. |
|
62 |
inclusive := aBoolean. |
|
63 |
substreamAtEnd := false |
|
64 |
! ! |
|
65 |
||
66 |
!TestWriteSubstream methodsFor:'private'! |
|
67 |
||
68 |
streamingInsert: anInteger from: aReadStream |
|
69 |
self streamingWrite: anInteger from: aReadStream |
|
70 |
! |
|
71 |
||
72 |
streamingInsertFrom: aReadStream |
|
73 |
self streamingWriteFrom: aReadStream |
|
74 |
! |
|
75 |
||
76 |
streamingWrite: anInteger from: aReadStream |
|
77 |
| count object | |
|
78 |
substreamAtEnd ifTrue: [Incomplete zero raise]. |
|
79 |
count := 0. |
|
80 |
[[count < anInteger and: [substreamAtEnd not]] whileTrue: |
|
81 |
[object := aReadStream get. |
|
82 |
((substreamAtEnd := test value: object) and: [inclusive not]) ifFalse: [destination put: object]. |
|
83 |
count := count + 1]] |
|
84 |
on: Incomplete do: [:incomplete | |
|
85 |
destinationAtEnd := substreamAtEnd := true. |
|
86 |
(Incomplete count: count) raise]. |
|
87 |
count < anInteger ifTrue: [(Incomplete count: count) raise]. |
|
88 |
^anInteger |
|
89 |
! |
|
90 |
||
91 |
streamingWriteFrom: aReadStream |
|
92 |
| object count | |
|
93 |
substreamAtEnd ifTrue: [Incomplete zero raise]. |
|
94 |
count := 0. |
|
95 |
^[[substreamAtEnd not] whileTrue: |
|
96 |
[object := aReadStream get. |
|
97 |
((substreamAtEnd := test value: object) and: [inclusive not]) ifFalse: [destination put: object. count := count + 1]]. |
|
98 |
count |
|
99 |
] on: Incomplete do: [:incomplete | destinationAtEnd := substreamAtEnd := true. count ] |
|
100 |
! ! |
|
101 |
||
102 |
!TestWriteSubstream methodsFor:'testing'! |
|
103 |
||
104 |
isPositionable |
|
105 |
^false |
|
106 |
! ! |
|
107 |
||
108 |
!TestWriteSubstream class methodsFor:'documentation'! |
|
109 |
||
110 |
version_SVN |
|
111 |
^ '$Id$' |
|
112 |
! ! |