author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 01 Feb 2012 00:56:17 +0000 | |
changeset 103 | 726bf2ca0b99 |
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:#PositionWriteSubstream |
|
6 |
instanceVariableNames:'position' |
|
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 |
PositionWriteSubstream comment:'This is an abstract substreams that keeps track of its own position and allows positioning if the underlying stream is positionable. |
|
13 |
||
14 |
Instance Variables |
|
15 |
position <Integer> current position within the substream |
|
16 |
||
17 |
' |
|
18 |
! |
|
19 |
||
20 |
||
21 |
!PositionWriteSubstream methodsFor:'accessing'! |
|
22 |
||
23 |
insert: anInteger from: aSequenceableCollection at: startIndex |
|
24 |
[destination insert: anInteger from: aSequenceableCollection at: startIndex] on: Incomplete do: [:incomplete | |
|
25 |
position := position + incomplete count. |
|
26 |
incomplete pass]. |
|
27 |
position := position + anInteger. |
|
28 |
^anInteger |
|
29 |
! |
|
30 |
||
31 |
put: anObject |
|
32 |
| object | |
|
33 |
object := destination put: anObject. |
|
34 |
position := position + 1. |
|
35 |
^object |
|
36 |
! |
|
37 |
||
38 |
write: anInteger from: aSequenceableCollection at: startIndex |
|
39 |
[destination write: anInteger from: aSequenceableCollection at: startIndex] on: Incomplete do: [:incomplete | |
|
40 |
position := position + incomplete count. |
|
41 |
incomplete pass]. |
|
42 |
position := position + anInteger. |
|
43 |
^anInteger |
|
44 |
! ! |
|
45 |
||
46 |
!PositionWriteSubstream methodsFor:'initialize-release'! |
|
47 |
||
48 |
on: aDestination |
|
49 |
super on: aDestination. |
|
50 |
position := 0 |
|
51 |
! ! |
|
52 |
||
53 |
!PositionWriteSubstream methodsFor:'seeking'! |
|
54 |
||
55 |
++ anInteger |
|
56 |
| count | |
|
57 |
anInteger < 0 ifTrue: [ ^self -- anInteger negated ]. |
|
58 |
count := self available min: anInteger. |
|
59 |
count := [destination ++ count. count] on: Incomplete do: [ :ex | ex count ]. |
|
60 |
position := position + count. |
|
61 |
count < anInteger ifTrue: [destinationAtEnd := true. (Incomplete count: count) raise]. |
|
62 |
^anInteger |
|
63 |
! |
|
64 |
||
65 |
-- anInteger |
|
66 |
| count | |
|
67 |
anInteger < 0 ifTrue: [ ^self ++ anInteger negated ]. |
|
68 |
count := anInteger min: position. |
|
69 |
count := [destination -- count. count] on: Incomplete do: [ :ex | ex count ]. |
|
70 |
position := position - count. |
|
71 |
count < anInteger ifTrue: [(Incomplete count: count) raise]. |
|
72 |
anInteger isZero ifFalse: [destinationAtEnd := false]. |
|
73 |
^anInteger |
|
74 |
! |
|
75 |
||
76 |
-= anInteger |
|
77 |
position := self length - anInteger max: 0. |
|
78 |
^destination -= anInteger. |
|
79 |
! |
|
80 |
||
81 |
length |
|
82 |
^destination available + position |
|
83 |
! |
|
84 |
||
85 |
position |
|
86 |
^position |
|
87 |
! |
|
88 |
||
89 |
position: anInteger |
|
90 |
| available adjustment | |
|
91 |
self isPositionable ifFalse: [self error: 'This stream is not positionable.']. |
|
92 |
||
93 |
anInteger < 0 ifTrue: [Incomplete zero raise]. |
|
94 |
available := anInteger min: self length. |
|
95 |
adjustment := available - position. |
|
96 |
adjustment positive |
|
97 |
ifTrue: [ destination ++ adjustment ] |
|
98 |
ifFalse: [ destination -- adjustment negated ]. |
|
99 |
position := available. |
|
100 |
available = anInteger ifTrue: [^anInteger]. |
|
101 |
(Incomplete count: available) raise |
|
102 |
! ! |
|
103 |
||
104 |
!PositionWriteSubstream methodsFor:'testing'! |
|
105 |
||
106 |
isPositionable |
|
107 |
^destination isPositionable |
|
108 |
! ! |
|
109 |
||
110 |
!PositionWriteSubstream class methodsFor:'documentation'! |
|
111 |
||
112 |
version_SVN |
|
113 |
^ '$Id$' |
|
114 |
! ! |