Plug.st
author Claus Gittinger <cg@exept.de>
Wed, 09 Apr 2003 12:49:21 +0200
changeset 1743 2f206c9f1319
parent 1554 d01ffa42ca7a
child 1760 48478a48da82
permissions -rw-r--r--
replace $. in c-variables name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
claus
parents: 82
diff changeset
     1
"
claus
parents: 82
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
114
e577a2f332d0 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
     3
	      All Rights Reserved
88
claus
parents: 82
diff changeset
     4
claus
parents: 82
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 82
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 82
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 82
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 82
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 82
diff changeset
    10
 hereby transferred.
claus
parents: 82
diff changeset
    11
"
claus
parents: 82
diff changeset
    12
1554
d01ffa42ca7a implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    13
"{ Package: 'stx:libview2' }"
d01ffa42ca7a implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    14
55
409211feffa2 *** empty log message ***
claus
parents: 54
diff changeset
    15
Model subclass:#Plug
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    16
	instanceVariableNames:'simulatedProtocol'
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    17
	classVariableNames:''
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    18
	poolDictionaries:''
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    19
	category:'Kernel-Objects'
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    20
!
f8592e95890f Initial revision
claus
parents:
diff changeset
    21
f8592e95890f Initial revision
claus
parents:
diff changeset
    22
!Plug class methodsFor:'documentation'!
f8592e95890f Initial revision
claus
parents:
diff changeset
    23
88
claus
parents: 82
diff changeset
    24
copyright
claus
parents: 82
diff changeset
    25
"
claus
parents: 82
diff changeset
    26
 COPYRIGHT (c) 1995 by Claus Gittinger
114
e577a2f332d0 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    27
	      All Rights Reserved
88
claus
parents: 82
diff changeset
    28
claus
parents: 82
diff changeset
    29
 This software is furnished under a license and may be used
claus
parents: 82
diff changeset
    30
 only in accordance with the terms of that license and with the
claus
parents: 82
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
claus
parents: 82
diff changeset
    32
 be provided or otherwise made available to, or used by, any
claus
parents: 82
diff changeset
    33
 other person.  No title to or ownership of the software is
claus
parents: 82
diff changeset
    34
 hereby transferred.
claus
parents: 82
diff changeset
    35
"
claus
parents: 82
diff changeset
    36
!
claus
parents: 82
diff changeset
    37
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    38
documentation
f8592e95890f Initial revision
claus
parents:
diff changeset
    39
"
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    40
    A Plug is an object which simulates a protocol and evaluates
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    41
    a corresponding block when receiving messages.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    42
    A plugs interface can be changed dynamically.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    43
226
c5a265ceddd1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
    44
    Its main use is for the demo doIts, to play the role of a model,
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    45
    when no actual modelClass is available for the demonstration.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    46
    However, it can be used wherever some object is needed which responds to
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    47
    some protocol AND you do not want to add a class for it
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    48
    (lightWeight objects).
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    49
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    50
    There is a slight performance penalty - compared to `normal' objects,
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    51
    getting `normal' messages, though.
224
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    52
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    53
    [author:]
fe3164373601 documentation
Claus Gittinger <cg@exept.de>
parents: 162
diff changeset
    54
        Claus Gittinger
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    55
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    56
    [see also:]
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    57
        Model
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    58
"
f8592e95890f Initial revision
claus
parents:
diff changeset
    59
!
f8592e95890f Initial revision
claus
parents:
diff changeset
    60
f8592e95890f Initial revision
claus
parents:
diff changeset
    61
examples
f8592e95890f Initial revision
claus
parents:
diff changeset
    62
"
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    63
                                                                        [exBegin]
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    64
    |plug|
f8592e95890f Initial revision
claus
parents:
diff changeset
    65
f8592e95890f Initial revision
claus
parents:
diff changeset
    66
    plug := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
    67
    plug respondTo:#foo  with:[Transcript showCR:'received foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
    68
    plug respondTo:#foo: with:[:arg | Transcript showCR:'received foo: ', arg printString].
54
f8592e95890f Initial revision
claus
parents:
diff changeset
    69
f8592e95890f Initial revision
claus
parents:
diff changeset
    70
    plug foo.
f8592e95890f Initial revision
claus
parents:
diff changeset
    71
    plug foo:'some argument'
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    72
                                                                        [exEnd]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    73
360
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    74
  using a plug as a generator (simulates a readStream):
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    75
                                                                        [exBegin]
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    76
    |generator num|
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    77
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    78
    num := 0.
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    79
    generator := Plug new.
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    80
    generator respondTo:#next
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    81
                   with:[num := num + 1. num].
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    82
    generator respondTo:#atEnd
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    83
                   with:[false].
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    84
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    85
    10 timesRepeat:[
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    86
        Transcript showCR:(generator next)
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    87
    ]
c5e6039033e7 another example
Claus Gittinger <cg@exept.de>
parents: 268
diff changeset
    88
                                                                        [exEnd]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    89
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    90
  simulating ``instance variables'':
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    91
  (actually, this is somewhat expensive - the contexts locals are used for them ...)
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    92
  be careful with unintended variable sharing (if plugs are created in a loop ..)
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
    93
                                                                        [exBegin]
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    94
    |plug1 plug2 local1 local2|
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    95
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    96
    plug1 := Plug new.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    97
    plug1 respondTo:#get  with:[local1].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    98
    plug1 respondTo:#set: with:[:arg | local1 := arg].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
    99
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   100
    plug2 := Plug new.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   101
    plug2 respondTo:#get  with:[local2].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   102
    plug2 respondTo:#set: with:[:arg | local2 := arg].
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   103
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   104
    Transcript show:'plug1''s value: '; showCR:plug1 get.
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   105
    Transcript show:'plug2''s value: '; showCR:plug2 get.
162
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   106
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   107
    plug1 set:5.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   108
    plug2 set:17.
cbbd2f3422a3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 137
diff changeset
   109
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   110
    Transcript show:'plug1''s value: '; showCR:plug1 get.
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   111
    Transcript show:'plug2''s value: '; showCR:plug2 get.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   112
                                                                        [exEnd]
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   113
"
f8592e95890f Initial revision
claus
parents:
diff changeset
   114
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   115
f8592e95890f Initial revision
claus
parents:
diff changeset
   116
!Plug class methodsFor:'instance creation'!
f8592e95890f Initial revision
claus
parents:
diff changeset
   117
f8592e95890f Initial revision
claus
parents:
diff changeset
   118
new
232
b898f5762952 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
   119
    ^ super basicNew privateInitialize
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   120
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   121
    "Modified: 27.4.1996 / 16:16:59 / cg"
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   122
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   123
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   124
!Plug methodsFor:'initialization'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   125
232
b898f5762952 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 228
diff changeset
   126
privateInitialize
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   127
    "this method is NOT called `#initialize' to allow plugging that
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   128
     selector ..."
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   129
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   130
    simulatedProtocol := IdentityDictionary new.
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   131
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   132
    "Modified: 27.4.1996 / 16:15:45 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   133
    "Created: 27.4.1996 / 16:17:07 / cg"
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   134
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   135
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   136
!Plug methodsFor:'message sending'!
f8592e95890f Initial revision
claus
parents:
diff changeset
   137
f8592e95890f Initial revision
claus
parents:
diff changeset
   138
doesNotUnderstand:aMessage
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   139
    "catch unhandled messages by looking in my simulated protocol
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   140
     definition; if there is some block for it, return its value.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   141
     Otherwise, fall into the real doesNotUnderstand error."
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   142
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   143
    |block|
f8592e95890f Initial revision
claus
parents:
diff changeset
   144
f8592e95890f Initial revision
claus
parents:
diff changeset
   145
    block := simulatedProtocol at:aMessage selector ifAbsent:[].
f8592e95890f Initial revision
claus
parents:
diff changeset
   146
    block isNil ifTrue:[
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   147
        ^ super doesNotUnderstand:aMessage
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   148
    ].
f8592e95890f Initial revision
claus
parents:
diff changeset
   149
    ^ block valueWithArguments:(aMessage arguments)
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   150
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   151
    "Modified: 27.4.1996 / 16:15:34 / cg"
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   152
!
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   153
1317
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   154
update:something with:aParameter from:changedObject
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   155
    "catch unhandled messages by looking in my simulated protocol
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   156
     definition; if there is some block for it, return its value.
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   157
     Otherwise, fall into the real update."
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   158
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   159
    |block|
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   160
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   161
    block := simulatedProtocol at:#'update:with:from:' ifAbsent:[].
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   162
    block isNil ifTrue:[
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   163
        ^ super update:something with:aParameter from:changedObject
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   164
    ].
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   165
    ^ block valueWithArguments:(Array with:something with:aParameter with:changedObject)
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   166
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   167
!
18aabf275ec2 allow #update:with:from:
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
   168
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   169
value
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   170
    "catch this one - its so common"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   171
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   172
    ^ self doesNotUnderstand:(Message selector:#value arguments:#())
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   173
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   174
    "Created: 21.1.1997 / 15:21:24 / cg"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   175
!
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   176
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   177
value:arg
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   178
    "catch this one - its so common"
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   179
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   180
    ^ self doesNotUnderstand:(Message selector:#value: argument:arg)
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   181
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   182
    "Created: 21.1.1997 / 15:21:36 / cg"
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   183
! !
f8592e95890f Initial revision
claus
parents:
diff changeset
   184
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   185
!Plug methodsFor:'protocol definition'!
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   186
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   187
forgetAbout:aSelector
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   188
    "tell the receiver to forget about how to respond to the given by selector"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   189
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   190
    simulatedProtocol removeKey:aSelector ifAbsent:nil
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   191
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   192
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   193
     |p|
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   194
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   195
     p := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   196
     p respondTo:#foo  with:[Transcript showCR:'foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   197
     p respondTo:#foo: with:[:arg | Transcript show:'foo:'; showCR:arg].
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   198
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   199
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   200
     p foo:'hello'.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   201
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   202
     p forgetAbout:#foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   203
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   204
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   205
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   206
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   207
    "Modified: 27.4.1996 / 16:14:19 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   208
    "Created: 27.4.1996 / 16:19:08 / cg"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   209
!
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   210
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   211
respondTo:aSelector with:aBlock
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   212
    "tell the receiver to respond to a message given by selector,
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   213
     with evaluating aBlock. The number of arguments as defined by the 
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   214
     selector must match the number of blockArsg expected by the block.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   215
     The value returned from aBlock will be the value returned from the
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   216
     message."
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   217
1554
d01ffa42ca7a implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   218
    (self class includesSelector:aSelector) ifFalse:[
444
4ad5cc26ad6a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   219
        (self class superclass canUnderstand:aSelector) ifTrue:[
377
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   220
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   221
            "/ sorry - this implementation is too quick of a hack.
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   222
            "/ (must be rewritten to inherit from nil, in order 
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   223
            "/  to be able to catch more ...)
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   224
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   225
            self error:'inherited message cannot be redefined: ' , aSelector.
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   226
        ]
afe504923e5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 360
diff changeset
   227
    ].
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   228
    simulatedProtocol at:aSelector put:aBlock
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   229
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   230
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   231
     |p|
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   232
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   233
     p := Plug new.
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   234
     p respondTo:#foo  with:[Transcript showCR:'foo'].
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 232
diff changeset
   235
     p respondTo:#foo: with:[:arg | Transcript show:'foo:'; showCR:arg].
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   236
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   237
     p foo.
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   238
     p foo:'hello'
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   239
    "
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   240
444
4ad5cc26ad6a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   241
    "Modified: 21.2.1997 / 18:35:07 / cg"
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   242
! !
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   243
82
claus
parents: 55
diff changeset
   244
!Plug methodsFor:'queries'!
claus
parents: 55
diff changeset
   245
claus
parents: 55
diff changeset
   246
respondsTo:aSelector
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   247
    "return true, if the receiver responds to a message"
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   248
82
claus
parents: 55
diff changeset
   249
    (simulatedProtocol includesKey:aSelector) ifTrue:[^ true].
claus
parents: 55
diff changeset
   250
    ^ super respondsTo:aSelector
228
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   251
8f73cdf66b60 commentary
Claus Gittinger <cg@exept.de>
parents: 226
diff changeset
   252
    "Modified: 27.4.1996 / 16:14:41 / cg"
82
claus
parents: 55
diff changeset
   253
! !
claus
parents: 55
diff changeset
   254
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   255
!Plug class methodsFor:'documentation'!
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   256
137
449db28201ec checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   257
version
1554
d01ffa42ca7a implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   258
    ^ '$Header: /cvs/stx/stx/libview2/Plug.st,v 1.18 2002-02-25 19:59:46 cg Exp $'
54
f8592e95890f Initial revision
claus
parents:
diff changeset
   259
! !