Code refactored to use Magritte to meta-describe GDB objects.
This should give greate flexibility without reinventing the wheel.
"{ Package: 'jv:libgdbs' }"
Object subclass:#GDBObject
instanceVariableNames:'properties'
classVariableNames:''
poolDictionaries:''
category:'GDB-Core'
!
!GDBObject class methodsFor:'accessing-magritte'!
descriptionContainer
^ GDBMAContainer forClass: self.
"Created: / 23-09-2014 / 23:26:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GDBObject class methodsFor:'utilities - properties'!
getPropertiesOf: object
| names index properties |
names := object class allInstVarNames.
index := names indexOf: #properties.
index ~~ 0 ifTrue:[
properties := object instVarAt: index.
properties isNil ifTrue:[
properties := Dictionary new.
object instVarAt: index put: properties.
^ properties
].
].
^ nil
"Created: / 20-06-2014 / 09:03:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
getProperty: nm of: object
| nmXlated names index properties |
nmXlated := (nm includes: $-) ifTrue:[ nm copyReplaceAll: $- with: $_] ifFalse:[ nm ].
index := (names := object class allInstVarNames) indexOf: nmXlated.
index ~~ 0 ifTrue:[
^ object instVarAt: index.
].
index := names indexOf: #properties.
index ~~ 0 ifTrue:[
properties := object instVarAt: index.
properties notNil ifTrue:[
^ properties at: nm ifAbsent:[ nil ]
].
].
^ nil
"Created: / 20-06-2014 / 08:59:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 06-09-2014 / 02:05:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
setProperty: nm of: object to: value
| nmXlated names index properties |
nmXlated := (nm includes: $-) ifTrue:[ nm copyReplaceAll: $- with: $_] ifFalse:[ nm ].
index := (names := object class allInstVarNames) indexOf: nmXlated.
index ~~ 0 ifTrue:[
object instVarAt: index put: value.
] ifFalse:[
index := names indexOf: #properties.
index ~~ 0 ifTrue:[
properties := object instVarAt: index.
properties isNil ifTrue:[
properties := Dictionary new.
object instVarAt: index put: properties.
].
properties at: nm put: value.
].
].
"Created: / 20-06-2014 / 09:01:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (format): / 06-09-2014 / 02:05:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GDBObject methodsFor:'accessing-properties'!
properties
^ self class getPropertiesOf: self.
"Modified: / 06-09-2014 / 01:49:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
propertyAt: name
^ self class getProperty: name of: self
"Created: / 31-05-2014 / 00:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 06-09-2014 / 01:49:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
propertyAt: name put: value
^ self class setProperty: name of: self to: value
"Created: / 31-05-2014 / 00:01:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 06-09-2014 / 01:49:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GDBObject methodsFor:'attributes access'!
objectAttributes
^ properties
"Created: / 18-06-2014 / 07:56:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
objectAttributes: aDictionary
properties := aDictionary
"Created: / 18-06-2014 / 07:57:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !