Read Strategies

Keith Hodges keith_hodges at yahoo.co.uk
Tue Sep 19 11:56:08 UTC 2006


I had a look at tweaking MaReadStrategy with the idea of being able to 
specify a default depth for attributes that do not have explicitly 
defined depths since it is currently 0.

This is what I came up with:

Store the default depth in the depthSpecifications as an association 
with with no value.


 >onAny: aClass readToDepth: anInteger
 >
 >   ^depthSpecifications at: aClass ifAbsentPut: [ Association key: 
anInteger value: nil ].

Store the specific depths for attributes in a dictionary in the 
Association value.

 >forVariableNamed: aString onAny: aClass readToDepth: anInteger
 >
 >| specs |
 >
 >    (aClass allInstVarNames includes: aString)
 >        ifFalse:
 >            [ MagmaUserError signal: aString , ' is not an attribute 
of ' , aClass name ].
 >  
 >specs := depthSpecifications at: aClass ifAbsent: [ self onAny: aClass 
readToDepth: 0 ].
 >
 >specs value ifNil: [ specs value: (self depthDictionaryOfSize: aClass 
instSize) ].
 >          
 >specs value at: aString
 >            put: anInteger

Update the code that uses this datastructure.

 >instVarMapFor: aMaClassDefinition
 >    "Answer an Array with an instVarMap of aMaClassDefinition 
according to
 >user-declared read depths."
 >
 >    | specifiedDepths answer |
 >    (aMaClassDefinition isDefined
 >    and: [ depthSpecifications includesKey: aMaClassDefinition 
classObject ])
 >        ifTrue:
 >            [ specifiedDepths _ depthSpecifications at: 
aMaClassDefinition classObject.
 >            specifiedDepths value
 >                ifNil: [ answer _ specifiedDepths key ]
 >                ifNotNil:
 >                    [ answer _ self depthArrayOfSize: 
aMaClassDefinition namedInstSize >default: specifiedDepths key.
 >                    specifiedDepths value keysAndValuesDo:
 >                        [ : eachInstVarName : eachDepth |
 >                        answer
 >                            at: (aMaClassDefinition allInstVarNames 
indexOf: eachInstVarName)
 >                            put: eachDepth ] ] ].
 >    ^ answer

I dont know whether this scheme is as efficient as it could be, but it 
seemed to me that filling the depthArray with the given default value 
would be the best answer here.

any thoughts?

Keith

		
___________________________________________________________ 
Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html


More information about the Magma mailing list