author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 01 Feb 2012 00:41:14 +0000 | |
changeset 99 | 677c81c943e4 |
parent 67 | a87e5ce04545 |
child 107 | de5fa7bcc01a |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/xtreams/substreams' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
PositionWriteSubstream subclass:#LimitWriteSubstream |
|
6 |
instanceVariableNames:'limit' |
|
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 |
LimitWriteSubstream comment:'Limits the number of elements that can be written into the destination stream. |
|
13 |
||
14 |
Instance Variables |
|
15 |
limit <Integer> maximum number of elements that can be written into this stream |
|
16 |
position <Integer> number of elements already written into the stream |
|
17 |
||
18 |
' |
|
19 |
! |
|
20 |
||
21 |
||
22 |
!LimitWriteSubstream class methodsFor:'instance creation'! |
|
23 |
||
24 |
on: aDestination limit: anInteger |
|
25 |
^self new on: aDestination limit: anInteger |
|
26 |
! ! |
|
27 |
||
28 |
!LimitWriteSubstream methodsFor:'accessing'! |
|
29 |
||
30 |
insert: anInteger from: aSequenceableCollection at: startIndex |
|
31 |
| count | |
|
32 |
count := anInteger min: self available. |
|
33 |
super insert: count from: aSequenceableCollection at: startIndex. |
|
34 |
count < anInteger ifTrue: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
35 |
^anInteger |
|
36 |
! |
|
37 |
||
38 |
put: anObject |
|
39 |
position = limit ifTrue: [Incomplete zero raise]. |
|
40 |
^super put: anObject |
|
41 |
! |
|
42 |
||
43 |
write: anInteger from: aSequenceableCollection at: startIndex |
|
44 |
| count | |
|
45 |
count := anInteger min: self available. |
|
46 |
super write: count from: aSequenceableCollection at: startIndex. |
|
47 |
count < anInteger ifTrue: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
48 |
^anInteger |
|
49 |
! ! |
|
50 |
||
51 |
!LimitWriteSubstream methodsFor:'initialize-release'! |
|
52 |
||
53 |
on: aDestination limit: anInteger |
|
54 |
self on: aDestination. |
|
55 |
limit := anInteger |
|
56 |
! |
|
57 |
||
58 |
subseekend |
|
59 |
self isPositionable ifFalse: [^self]. |
|
60 |
self -= 0 |
|
61 |
! ! |
|
62 |
||
63 |
!LimitWriteSubstream methodsFor:'seeking'! |
|
64 |
||
65 |
-= anInteger |
|
66 |
| available | |
|
67 |
anInteger < 0 ifTrue: [Incomplete zero raise]. |
|
68 |
available := anInteger min: limit. |
|
69 |
destination ++ (limit - position - available). |
|
70 |
position := limit - available. |
|
71 |
available = anInteger ifTrue: [^anInteger]. |
|
72 |
^(Incomplete count: available) raise |
|
73 |
! |
|
74 |
||
75 |
length |
|
76 |
^limit |
|
77 |
! ! |
|
78 |
||
79 |
!LimitWriteSubstream class methodsFor:'documentation'! |
|
80 |
||
81 |
version_SVN |
|
82 |
^ '$Id$' |
|
83 |
! ! |