2785
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2009 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
2786
|
12 |
"{ Package: 'stx:libview2' }"
|
2785
|
13 |
|
|
14 |
ValueHolder subclass:#TypedValueHolder
|
|
15 |
instanceVariableNames:'types'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Support-Models'
|
|
19 |
!
|
|
20 |
|
|
21 |
!TypedValueHolder class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2009 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
this is simply a valueHolder which checks new values against a given type.
|
|
40 |
Useful to debug/trap invalid setters (such as those storing a true into a numeric holder)
|
|
41 |
|
|
42 |
[author:]
|
|
43 |
Claus Gittinger
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
examples
|
|
48 |
"
|
|
49 |
[exBegin]
|
|
50 |
|v|
|
|
51 |
|
|
52 |
v := (TypedValueHolder with:1) type:Number.
|
|
53 |
|
|
54 |
(Delay forSeconds:3) wait.
|
|
55 |
v value:nil.
|
|
56 |
[exEnd]
|
|
57 |
|
|
58 |
[exBegin]
|
|
59 |
|v|
|
|
60 |
|
|
61 |
v := (TypedValueHolder with:1) types:{UndefinedObject. Number}.
|
|
62 |
|
|
63 |
(Delay forSeconds:3) wait.
|
|
64 |
v value:nil.
|
|
65 |
(Delay forSeconds:3) wait.
|
|
66 |
v value:'huh'.
|
|
67 |
[exEnd]
|
|
68 |
"
|
|
69 |
! !
|
|
70 |
|
|
71 |
!TypedValueHolder methodsFor:'accessing'!
|
|
72 |
|
|
73 |
type:aClass
|
|
74 |
self types:(Array with:aClass)
|
|
75 |
!
|
|
76 |
|
|
77 |
types:aCollectionOfTypes
|
|
78 |
types := aCollectionOfTypes.
|
|
79 |
!
|
|
80 |
|
|
81 |
value:newValue
|
|
82 |
types notNil ifTrue:[
|
|
83 |
(types contains:[:type | newValue isKindOf:type]) ifFalse:[
|
|
84 |
self error:'Unvalid value stored in typed valueHolder' mayProceed:true
|
|
85 |
]
|
|
86 |
].
|
|
87 |
^ super value:newValue.
|
|
88 |
! !
|
|
89 |
|
|
90 |
!TypedValueHolder class methodsFor:'documentation'!
|
|
91 |
|
|
92 |
version_CVS
|
2786
|
93 |
^ '$Header: /cvs/stx/stx/libview2/TypedValueHolder.st,v 1.2 2009-11-06 19:24:27 cg Exp $'
|
2785
|
94 |
! !
|