FilteringStream.st
author Claus Gittinger <cg@exept.de>
Sat, 11 Jan 1997 16:51:18 +0100
changeset 474 61cb199537b5
parent 472 33f423823933
child 477 6124ae485dbd
permissions -rw-r--r--
comments & fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     1
"
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     3
              All Rights Reserved
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     4
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     5
 This software is furnished under a license and may be used
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     6
 only in accordance with the terms of that license and with the
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     8
 be provided or otherwise made available to, or used by, any
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
     9
 other person.  No title to or ownership of the software is
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    10
 hereby transferred.
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    11
"
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    12
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    13
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Stream subclass:#FilteringStream
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    15
	instanceVariableNames:'inputStream outputStream filter'
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    18
	category:'Streams-Misc'
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    21
!FilteringStream class methodsFor:'documentation'!
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    22
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    23
copyright
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    24
"
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    25
 COPYRIGHT (c) 1996 by Claus Gittinger
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    26
              All Rights Reserved
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    27
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    28
 This software is furnished under a license and may be used
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    29
 only in accordance with the terms of that license and with the
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    31
 be provided or otherwise made available to, or used by, any
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    32
 other person.  No title to or ownership of the software is
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    33
 hereby transferred.
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    34
"
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    35
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    36
!
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    37
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    38
documentation
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    39
"
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    40
    A FilteringStream can be connected to some input
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    41
    (from which elements are read via the ReadStream protocol),
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    42
    and/or to some output (to which elements are written via
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    43
    the WriteStream protocol.
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    44
    The FilteringStream itself performs some filtering/processing
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    45
    on the elements as they arrive.
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    46
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    47
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    48
    [instance variables:]
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    49
        inputStream     <Stream>  the stream from which elements are read
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    50
        outputStream    <Stream>  the stream to which elements are written
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    51
        filter          <Block>   the filter block;
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    52
        unbound         <Boolean> if true, the stream is unbound.
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    53
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    54
    [author:]
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    55
        Claus Gittinger
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    56
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    57
    [See also:]
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    58
        ReadStream WriteStream
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    59
"
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    60
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    61
!
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
examples
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    65
  pushing the contents of a stream onto another stream
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    66
  (here, the Transcript) without a need to read everyting into a
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    67
  buffer or to reinvent the read-loop:
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    68
  (notice, a FilteringLineStream does this with less overhead)
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    69
                                                                [exBegin]
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    70
    |in pusher|
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    71
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    72
    in := 'Makefile' asFilename readStream.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    73
    pusher := FilteringStream readingFrom:in writingTo:Transcript.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    74
    pusher filterUpToEnd
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    75
                                                                [exEnd]
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    76
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    77
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
  filter random numbers:
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    79
                                                                [exBegin]
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    |in filter|
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    in := Random new.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
    84
    filter := FilteringLineStream readingFrom:in.
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    filter filter:[:num | ((num >= 0.5) and:[num <= 0.6]) ifTrue:[num] ifFalse:[nil]].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    20 timesRepeat:[
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
        Transcript showCR:(filter next printString).
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    ]
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    90
                                                                [exEnd]
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
  filtering prime numbers:
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
    93
                                                                [exBegin]
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    |num generator primeFilter addFilter|
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    num := 1.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    generator := Plug new.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    generator respondTo:#next
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
                   with:[num := num + 1. num].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    generator respondTo:#atEnd
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
                   with:[false].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    addFilter := [:prime | |newFilter|
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
        newFilter := FilteringLineStream basicNew.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
        newFilter filter:[:num | (num \\ prime) == 0 ifTrue:[
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
                                    nil
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
                                 ] ifFalse:[
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
                                    num
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
                                 ]
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
                         ].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
        newFilter inputStream:primeFilter.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
        primeFilter := newFilter
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    ].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    addFilter value:2.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    primeFilter inputStream:generator.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   118
    10000 timesRepeat:[
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
        |nextPrime|
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
        nextPrime := primeFilter next.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
        addFilter value:nextPrime.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
        Transcript showCR:nextPrime.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    ]
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   125
                                                                [exEnd]
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
! !
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   132
!FilteringStream class methodsFor:'instance creation'!
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   133
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   134
new
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   135
    "create and return a new filteringStream.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   136
     The resulting stream must be connected to some other stream,
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   137
     before being used"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   138
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   139
    ^ self basicNew initialize.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   140
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   141
    "Created: 11.1.1997 / 15:31:30 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   142
    "Modified: 11.1.1997 / 15:33:13 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   143
!
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   144
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   145
readingFrom:aReadStream
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   146
    "create and return a new filteringStream, which reads from
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   147
     another stream"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   148
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   149
    ^ self basicNew initialize inputStream:aReadStream.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   150
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   151
    "Created: 11.1.1997 / 15:32:15 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   152
!
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   153
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   154
readingFrom:aReadStream writingTo:aWriteStream
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   155
    "create and return a new filteringStream, which reads from
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   156
     aReadStream and writes to aWriteStream."
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   157
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   158
    |newStream|
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   159
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   160
    newStream := self basicNew initialize.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   161
    newStream inputStream:aReadStream.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   162
    newStream outputStream:aWriteStream.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   163
    ^ newStream
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   164
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   165
    "Created: 11.1.1997 / 15:32:28 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   166
!
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   167
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   168
writingTo:aWriteStream
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   169
    "create and return a new filteringStream, which writes to
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   170
     another stream"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   171
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   172
    ^ self basicNew initialize outputStream:aWriteStream.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   173
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   174
    "Created: 11.1.1997 / 15:32:36 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   175
! !
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   176
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
!FilteringStream methodsFor:'access - pull-reading'!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
filterUpToEnd
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    "pull input from inputStream up to the end,
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   181
     push it filtered into the outputStream."
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    [inputStream atEnd] whileFalse:[
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
        self nextPut:(inputStream next)
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    ].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "Created: 2.7.1996 / 21:06:42 / cg"
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   188
    "Modified: 11.1.1997 / 16:08:35 / cg"
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
next
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
    "pull input from inputStream and
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
     push it filtered into the outputStream"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    |input output|
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    [inputStream atEnd] whileFalse:[
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   198
        "/ get an element
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
        input := inputStream next.
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   200
        filter isNil ifTrue:[
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   201
            ^ input
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   202
        ].
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   203
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   204
        "/ filter it - this may return nil, to eat it
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
        output := filter value:input.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
        output notNil ifTrue:[
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   207
            "/ good - output it
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
            ^ output.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
        ].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    ].
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    ^ nil
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    "Created: 2.7.1996 / 21:09:58 / cg"
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   214
    "Modified: 11.1.1997 / 16:12:22 / cg"
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
! !
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
!FilteringStream methodsFor:'access - push-writing'!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
nextPut:something
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    "push something through the filter"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    |output|
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   224
    "/ filter it
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   225
    filter isNil ifTrue:[
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   226
        outputStream nextPut:something
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   227
    ] ifFalse:[
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   228
        output := filter value:something.
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   229
        output notNil ifTrue:[
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   230
            outputStream nextPut:output
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   231
        ]
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    ]
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   234
    "Modified: 11.1.1997 / 16:12:52 / cg"
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
! !
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
!FilteringStream methodsFor:'accessing'!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
filter
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
    "return the filter"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    ^ filter
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    "Modified: 2.7.1996 / 21:03:36 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    "Created: 2.7.1996 / 21:06:42 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
filter:something
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    "set the filter"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    filter := something.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    "Modified: 2.7.1996 / 21:03:40 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    "Created: 2.7.1996 / 21:06:42 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
inputStream
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    "return the inputStream"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    ^ inputStream
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    "Modified: 2.7.1996 / 21:03:43 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    "Created: 2.7.1996 / 21:06:42 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
inputStream:something
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    "set the inputStream"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    inputStream := something.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    "Modified: 2.7.1996 / 21:03:46 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
    "Created: 2.7.1996 / 21:06:42 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
outputStream
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
    "return the outputStream"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
    ^ outputStream
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    "Modified: 2.7.1996 / 21:03:49 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
    "Created: 2.7.1996 / 21:06:42 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
outputStream:something
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
    "set the outputStream"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
    outputStream := something.
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    "Modified: 2.7.1996 / 21:03:52 / cg"
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
    "Created: 2.7.1996 / 21:06:42 / cg"
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   291
! !
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   293
!FilteringStream methodsFor:'misc'!
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   295
close
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   296
    "when I am closed, close my input - if any"
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   298
    inputStream notNil ifTrue:[
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   299
        inputStream close
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   300
    ]
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   302
    "Created: 11.1.1997 / 15:27:17 / cg"
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
! !
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
!FilteringStream methodsFor:'queries'!
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
atEnd
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   308
    "return true, if the receiver stream is at the end"
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   309
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
    ^ inputStream atEnd
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   312
    "Modified: 11.1.1997 / 16:26:10 / cg"
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   313
!
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   314
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   315
contentsSpecies
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   316
    "return the kind of collection I should return when asked
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   317
     for multiple elements."
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   318
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   319
    ^ inputStream contentsSpecies
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   320
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   321
    "Created: 11.1.1997 / 16:23:22 / cg"
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
! !
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
472
33f423823933 commentary & doc
Claus Gittinger <cg@exept.de>
parents: 401
diff changeset
   324
!FilteringStream class methodsFor:'documentation'!
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
version
474
61cb199537b5 comments & fixes
Claus Gittinger <cg@exept.de>
parents: 472
diff changeset
   327
    ^ '$Header: /cvs/stx/stx/libbasic2/FilteringStream.st,v 1.3 1997-01-11 15:50:52 cg Exp $'
401
f97488701314 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
! !