BlockValue.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 18:32:07 +0200
changeset 221 ea942fe5dc04
parent 158 16f2237474fe
child 223 b65dc250db8d
permissions -rw-r--r--
documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
     3
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
ValueModel subclass:#BlockValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'cachedValue arguments block'
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
    16
	classVariableNames:'NeverComputed'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Interface-Support-Models'
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 1995 by Claus Gittinger
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    26
	      All Rights Reserved
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    BlockValues depend on multiple other objects (typically valueHolders)
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    and recompute a value whenever one of them changes.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    If the new value is different, it triggers itself a change to its dependents.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    Example use is to base an enableChannels value on multiple other boolean values.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    (See example for how this is done)
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
examples
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
"
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    52
    checkToggle 3 shows the value of toggle1 AND toggle2
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    53
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    54
	|val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    55
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    56
	val1 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    57
	val2 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    58
	both := BlockValue 
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    59
		    with:[:v1 :v2 | 
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    60
			    Transcript showCr:'evaluating ...'.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    61
			    v1 value and:[v2 value]
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    62
			 ] 
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    63
		    arguments:(Array with:val1 with:val2).
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    64
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    65
	box := Dialog new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    66
	box addCheckBox:'one' on:val1.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    67
	box addCheckBox:'two' on:val2.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    68
	box addHorizontalLine.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    69
	box addCheckBox:'both' on:both.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    70
	box open
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    71
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    72
    the same, using a convenient instance creation message:
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    73
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    74
	|val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    75
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    76
	val1 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    77
	val2 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    78
	both := BlockValue forLogical:val1 and:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    80
	box := Dialog new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    81
	box addCheckBox:'one' on:val1.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    82
	box addCheckBox:'two' on:val2.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    83
	box addHorizontalLine.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    84
	box addCheckBox:'both' on:both.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    85
	box open
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    86
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    87
    logical or:
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    88
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    89
	|val1 val2 both box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
    90
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    91
	val1 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    92
	val2 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    93
	both := BlockValue forLogical:val1 or:val2.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    95
	box := Dialog new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    96
	box addCheckBox:'one' on:val1.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    97
	box addCheckBox:'two' on:val2.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    98
	box addHorizontalLine.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    99
	box addCheckBox:'both' on:both.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   100
	box open
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   101
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   102
    example use: enabling an element depending on two others:
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   103
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   104
	|val1 val2 enabler val3 box|
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   105
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   106
	val1 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   107
	val2 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   108
	val3 := false asValue.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   109
	enabler := BlockValue forLogical:val1 and:val2.
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   110
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   111
	box := Dialog new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   112
	box addCheckBox:'one' on:val1.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   113
	box addCheckBox:'two' on:val2.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   114
	box addHorizontalLine.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   115
	(box addCheckBox:'three' on:val3) enableChannel:enabler.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   116
	box open
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   120
!BlockValue class methodsFor:'initialization'!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   121
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   122
initialize
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   123
    NeverComputed isNil ifTrue:[
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   124
	NeverComputed := Object new.
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   125
    ]
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   126
! !
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   127
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
!BlockValue class methodsFor:'instance creation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   130
forLogical:arg1 and:arg2
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   131
    "return a new BlockValue computing the logical AND of its args"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   132
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   133
    ^ (super new) 
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   134
	setBlock:[:a :b | a value and:[b value]]
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   135
	arguments:(Array with:arg1 with:arg2) 
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   136
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   137
    "Created: 16.12.1995 / 19:20:14 / cg"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   138
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   139
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   140
forLogical:arg1 or:arg2
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   141
    "return a new BlockValue computing the logical OR of its args"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   142
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   143
    ^ (super new) 
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   144
	setBlock:[:a :b | a value or:[b value]]
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   145
	arguments:(Array with:arg1 with:arg2) 
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   146
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   147
    "Created: 16.12.1995 / 19:20:14 / cg"
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   148
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   149
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
with:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    ^ (super new) setBlock:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "Created: 16.12.1995 / 19:16:33 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   158
with:aBlock argument:anArgument
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   159
    "return a new BlockValue computing aBlock"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   160
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   161
    ^ (super new) setBlock:aBlock arguments:(Array with:anArgument)
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   162
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   163
    "Created: 16.12.1995 / 19:20:14 / cg"
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   164
!
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   165
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
with:aBlock arguments:aCollectionOfArguments
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    "return a new BlockValue computing aBlock"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    ^ (super new) setBlock:aBlock arguments:aCollectionOfArguments
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    "Created: 16.12.1995 / 19:20:14 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
!BlockValue methodsFor:'accessing'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
dependOn:someObject
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    arguments isNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   178
	arguments := Array with:someObject
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    ] ifFalse:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   180
	arguments := arguments copyWith:someObject
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
    someObject addDependent:self
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
    "Modified: 16.12.1995 / 19:18:31 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
evaluate
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    arguments isNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   189
	^ block value
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    ^ block valueWithArguments:(arguments asArray)
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    "Created: 16.12.1995 / 19:27:40 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
setBlock:aBlock
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    arguments notNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   199
	self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    arguments := nil.
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   202
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    "Created: 16.12.1995 / 19:16:59 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   205
    "Modified: 16.12.1995 / 19:51:23 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
setBlock:aBlock arguments:aCollectionOfArguments
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    block := aBlock.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    arguments notNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   211
	self release
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    arguments := aCollectionOfArguments.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    arguments do:[:arg |
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   215
	arg addDependent:self
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    ].
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   217
    cachedValue := NeverComputed.
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    "Created: 16.12.1995 / 19:21:41 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   220
    "Modified: 16.12.1995 / 19:51:28 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
155
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   223
setValue:newValue 
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   224
    "physically set my value, without change notifications.
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   225
     This is a noop here, since my value is computed."
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   226
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   227
    ^ self
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   228
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   229
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   230
!
7b88cc365866 ignore setValue: / another comment
ah
parents: 146
diff changeset
   231
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
value
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   233
    cachedValue == NeverComputed ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   234
	cachedValue := self evaluate
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   235
    ].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    ^ cachedValue
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    "Created: 16.12.1995 / 19:23:26 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   239
    "Modified: 17.12.1995 / 15:59:16 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
!BlockValue methodsFor:'change and update'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
update:something with:aParameter from:someone
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    |oldValue|
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
    oldValue := cachedValue.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    cachedValue := self evaluate.
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    oldValue ~~ cachedValue ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   250
	self changed:#value
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    "Created: 16.12.1995 / 19:22:54 / cg"
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   254
    "Modified: 17.12.1995 / 15:58:56 / cg"
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
!BlockValue methodsFor:'release'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
release
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    arguments notNil ifTrue:[
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   261
	arguments do:[:arg | arg removeDependent:self].
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    ].
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
    "Modified: 16.12.1995 / 19:21:11 / cg"
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
! !
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
!BlockValue class methodsFor:'documentation'!
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
version
158
16f2237474fe only init once
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   270
    ^ '$Header: /cvs/stx/stx/libview2/BlockValue.st,v 1.4 1996-01-27 18:36:36 cg Exp $'
145
cb162538d41a intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
! !
146
9603cec98ac2 oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents: 145
diff changeset
   272
BlockValue initialize!