Skip to content

Commit

Permalink
Merge pull request #734 from olekscode/733-Remove-asGetterForEntityClass
Browse files Browse the repository at this point in the history
733 remove as getter for entity class
  • Loading branch information
olekscode committed Sep 18, 2023
2 parents 72c26a7 + 105ef1e commit c49eb28
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 85 deletions.
8 changes: 4 additions & 4 deletions repository/Cormas-Core/CGStCormas.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CGStCormas >> confirmIsAbstractClass: aClass [
<< ' a concret class will have instances and ';
<< self cormasModelClass name;
<< ' will define an attribut called ';
<< aClass asGetterForEntityClass;
<< aClass buildGetterForEntityClass;
<< ').' ]).
]

Expand Down Expand Up @@ -159,7 +159,7 @@ CGStCormas >> createModelAccessorsIn: aClass [
CGStCormas >> createModelInstancesAccessorsIn: aClass [
| pop |

pop := aClass asGetterForEntityClass.
pop := aClass buildGetterForEntityClass.
aClass isAbstract
ifTrue: [
self targetClass
Expand All @@ -185,7 +185,7 @@ Ex: #theXXXs

| pop |

pop := aClass asGetterForEntityClass.
pop := aClass buildGetterForEntityClass.
self targetClass
compile: (self templateForModelReaderAccessor: pop)
classified: 'accessing'
Expand All @@ -201,7 +201,7 @@ aClassName = <String> or <Symbol>.
(aClassName ('XXX') is completed as theXXXs)"

| pop |
pop := aClass asGetterForEntityClass.
pop := aClass buildGetterForEntityClass.
self targetClass
compile: (self templateForModelSetterAccessor: pop)
classified: 'accessing'
Expand Down
79 changes: 37 additions & 42 deletions repository/Cormas-Core/CMAbstractModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Class {
'cormas',
'timeStep',
'channel',
'entityGetters',
'activeInit',
'activeControl',
'spaceModel',
Expand Down Expand Up @@ -464,18 +465,6 @@ CMAbstractModel class >> defaultSteppingBackSetting [
^false
]

{ #category : #compiling }
CMAbstractModel class >> getterForEntityClass: aClass [
"Create the getter selector for the entity class aClass.
Example: self getterForEntityClass: Object -> #theObjects
self basicNew getterForEntityClass: Object
"

self deprecated: 'Use aClass asGetterForEntityClass'.
^ aClass asGetterForEntityClass
]

{ #category : #testing }
CMAbstractModel class >> hasProbes [
" Answer <true> if the receiver's contains any methods to be used as probes "
Expand Down Expand Up @@ -891,17 +880,6 @@ CMAbstractModel class >> setDescriptionFor: method withText: text [
notifying: nil
]

{ #category : #compiling }
CMAbstractModel class >> setterForEntityClass: aClass [
"efficiently create the setter selector for the entity class aClass (avoid concatenation).
ex : Object -> #theObjects:
self setterForEntityClass: CMEntity
"

^ aClass asSetterForEntityClass
]

{ #category : #accessing }
CMAbstractModel class >> shortName [
"Answer the model name as short string (without 'CM' nor 'Model').
Expand Down Expand Up @@ -1337,15 +1315,17 @@ CMAbstractModel >> comment: anObject [
{ #category : #'accessing - entities' }
CMAbstractModel >> compoundSpatialClasses [

| coll |
coll := self class compoundSpatialClasses.
coll size = 0
ifTrue: [^self cormas warn: 'Pas d''entites spatiales composees !'].
coll size > 1
ifTrue:
[^self cormas warn:
'Il y a plusieurs classes d''entites spatiales composees !'].
^self perform: (self getterForEntityClass: coll first)
| classes getter |
classes := self class compoundSpatialClasses.

classes ifEmpty: [
^ self cormas warn: 'There are no compound spatial entity classes!' ].

classes size > 1 ifTrue: [
^ self cormas warn: 'There is more than one compound spatial entity class!'].

getter := self getterForEntityClass: classes first.
^ self perform: getter
]

{ #category : #accessing }
Expand Down Expand Up @@ -2135,14 +2115,9 @@ CMAbstractModel >> getSimDescriptionText [
{ #category : #'accessing - entities' }
CMAbstractModel >> getterForEntityClass: aClass [
"efficiently create the getter selector for the entity class aClass (avoid concatenation).
ex : Object -> #theObjects
self basicNew getterForEntityClass: Object
"
self deprecated: 'Use aClass asGetterForEntityClass'.
^self class getterForEntityClass: aClass
^ entityGetters at: aClass name
ifAbsent: [ self error: 'Getter for class #', aClass name, ' was not found in the dictionary' ].
]
{ #category : #'utilities - population metrics' }
Expand Down Expand Up @@ -2334,6 +2309,8 @@ CMAbstractModel >> initialize [
super initialize.
self projectManager: CMProjectManager new.
self class socialClasses ifNotEmpty: [ self initializeChannel ].
self initializeEntityGetters.
]
Expand Down Expand Up @@ -2371,6 +2348,20 @@ CMAbstractModel >> initializeEntitiesActiveProbes [
put: Dictionary new ] ] ]
]
{ #category : #initialization }
CMAbstractModel >> initializeEntityGetters [
"Create a dictionary of getters for entity classes based on accessors with pragmas"
| pragmas className selector |
pragmas := Pragma allNamed: #getterFor: in: self class.
entityGetters := Dictionary newFrom: (pragmas collect: [ :pragma |
className := pragma arguments first.
selector := pragma method selector.
className -> selector ])
]
{ #category : #initialization }
CMAbstractModel >> initializeProbes [
Expand Down Expand Up @@ -3153,7 +3144,7 @@ CMAbstractModel >> setterForEntityClass: aClass [
self basicNew setterForEntityClass: Object
"
^self class setterForEntityClass: aClass
^ (self getterForEntityClass: aClass) asMutator
]
{ #category : #'utilities - space metrics' }
Expand Down Expand Up @@ -3359,13 +3350,17 @@ CMAbstractModel >> theEntities: aClass [
"Returns a collection of all the instances of aClass"
| collection getter |
aClass isAbstract
ifTrue: [ ^ OrderedCollection new ].
getter := aClass asGetterForEntityClass.
getter := self getterForEntityClass: aClass.
collection := (self perform: getter)
ifNil: [
self class createModelReaderAccessor: aClass.
self perform: getter ].
^ collection
]
Expand Down Expand Up @@ -3483,7 +3478,7 @@ CMAbstractModel >> updateLocalData [
ifTrue: [
(self data at: className) keysAndValuesDo: [ : name : dict |
res := OrderedCollection new.
(self perform: cl asGetterForEntityClass) do: [ : c |
(self perform: (self getterForEntityClass: cl)) do: [ : c |
(aValue := c class perform: name) isSymbol
ifTrue: [
"The local probe is a reference to a global probe"
Expand Down
16 changes: 1 addition & 15 deletions repository/Cormas-Core/CMEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ Class {
'image',
'activeProbes',
'povDict',
'activityDiagrams',
'getter'
'activityDiagrams'
],
#category : #'Cormas-Core-Entities'
}
Expand Down Expand Up @@ -349,19 +348,6 @@ Example: LandCover allTerminalClasses"
^ self withAllSubclasses select: #isTerminal
]

{ #category : #accessing }
CMEntity class >> asGetterForEntityClass [
"Create the getter selector for the entity class aClass.
CMEntity asGetterForEntityClass -> #theEntities"

^ getter ifNil: [ getter := self buildGetterForEntityClass ].
]

{ #category : #accessing }
CMEntity class >> asSetterForEntityClass [
^self asGetterForEntityClass asMutator
]

{ #category : #'accessing - methods & classes' }
CMEntity class >> availableInfo [
"Purpose: returns the list of available info methods
Expand Down
4 changes: 2 additions & 2 deletions repository/Cormas-Core/CMProjectModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ CMProjectModel >> removeEntity: aCMEntityAnnouncement [
| theClass theGetter |

theClass := self classFor: aCMEntityAnnouncement entityName.
theGetter := theClass asGetterForEntityClass.
theGetter := self cormasModel getterForEntityClass: theClass.

self removeEntitySubclasses: aCMEntityAnnouncement.

Expand Down Expand Up @@ -528,7 +528,7 @@ CMProjectModel >> removeEntitySubclasses: aCMEntityAnnouncement [

(OrderedCollection withAll: theClass allSubclasses)
do: [ : cl |
theGetter := cl asGetterForEntityClass.
theGetter := self cormasModel getterForEntityClass: cl.
(self perform: (aCMEntityAnnouncement type asLowercase , 'Classes') asSymbol)
remove: cl
ifAbsent: [ self error ].
Expand Down
52 changes: 33 additions & 19 deletions repository/Cormas-Core/CMSpaceModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,18 @@ CMSpaceModel >> getAggregatesFrom: baseEntity attribute: attributeName [

{ #category : #'private - regular polygons' }
CMSpaceModel >> getAggregatesFrom: baseEntity verifying: aBlock [
| eeInstances set seed neighbours newNeighbours collec |
self isNotTorroidal
ifFalse: [ ^ self warningBoundaries ].
eeInstances := ((self cormasModel
perform: baseEntity asGetterForEntityClass)

| selector eeInstances set seed neighbours newNeighbours collec |

self isNotTorroidal ifFalse: [ ^ self warningBoundaries ].

selector := self cormasModel getterForEntityClass: baseEntity.

eeInstances := ((self cormasModel perform: selector)
select: [ :c | aBlock value: c ]) copy asOrderedCollection.

collec := OrderedCollection new. "collec est une collection de set (composants des agregats)"

[ eeInstances isEmpty ]
whileFalse: [ set := IndexedSet new.
seed := eeInstances first.
Expand All @@ -1188,6 +1193,7 @@ CMSpaceModel >> getAggregatesFrom: baseEntity verifying: aBlock [
neighbours := newNeighbours ].
set do: [ :c | eeInstances remove: c ].
collec add: set ].

^ collec
]

Expand Down Expand Up @@ -1730,15 +1736,16 @@ CMSpaceModel >> lowerRightLocation [

{ #category : #'landscape indices' }
CMSpaceModel >> meanCompactness: aClass [
| sum aggregates |
aggregates := self cormasModel
perform: aClass asGetterForEntityClass.
sum := aggregates
inject: 0
into: [ :cumul :aggreg | cumul + aggreg updateCompactness ].
^ aggregates size = 0
ifTrue: [ 0 ]
ifFalse: [ sum / aggregates size ]

| selector aggregates sum |

selector := self cormasModel getterForEntityClass: aClass.
aggregates := self cormasModel perform: selector.

aggregates ifEmpty: [ ^ 0 ].

sum := aggregates sum: [ :each | each updateCompactness ].
^ sum / aggregates size
]

{ #category : #'landscape indices' }
Expand Down Expand Up @@ -2315,18 +2322,25 @@ CMSpaceModel >> setFragmentedEntities: compoundEntity from: baseEntity verifying
aBlock (example = [:cell | cell isTree] or [:aggregat | aggregat type = #forest] )
compoundEntity = a Class name inheriting from <SpatialEntityNotConnex>"

| fragmentedEntity beInstances |
self isNotTorroidal
ifFalse: [ ^ self warningBoundaries ].
| getter fragmentedEntity beInstances |

self isNotTorroidal ifFalse: [ ^ self warningBoundaries ].

self
resetCompoundSpatialEntity: compoundEntity
andTheirComponents: baseEntity.
beInstances := ((self cormasModel perform: baseEntity asGetterForEntityClass asSymbol)
select: [ :c | aBlock value: c ]) copy asOrderedCollection.

getter := self cormasModel getterForEntityClass: baseEntity.

beInstances := ((self cormasModel perform: getter)
select: [ :c | aBlock value: c ]) copy asOrderedCollection.

fragmentedEntity := compoundEntity new: self.
fragmentedEntity addSilentlyComponents: beInstances.

(self spatialEntitiesAt: compoundEntity name) add: fragmentedEntity.
self dispatchCompoundSpatialEntity: compoundEntity.

^ self spatialEntitiesAt: compoundEntity name
]

Expand Down
7 changes: 5 additions & 2 deletions repository/Cormas-Core/CMSpacePolygonNeighbourhood.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ CMSpacePolygonNeighbourhood >> gridCellShapeType [
{ #category : #'private - irregular polygons creation' }
CMSpacePolygonNeighbourhood >> initializeOrderedNeighbourhood: polygones [

| allPolygones |
| getter allPolygones |

polygones isEmpty ifTrue: [ ^ self ].
allPolygones := self cormasModel perform: (self cormasModel getterForEntityClass: polygones first).

getter := self cormasModel getterForEntityClass: polygones first.
allPolygones := self cormasModel perform: getter.

polygones do: [ : b | self initializePolygone: b in: allPolygones ]
]

Expand Down
5 changes: 4 additions & 1 deletion repository/Cormas-Mocks/CMMockModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,20 @@ CMMockModel >> randomSeed: aNumber [
{ #category : #accessing }
CMMockModel >> theCells [

<getterFor: #CMMockCell>
^ theCells
]

{ #category : #accessing }
CMMockModel >> theCows [

<getterFor: #CMMockCow>
^ theCows
]

{ #category : #accessing }
CMMockModel >> theGoats [


<getterFor: #CMMockGoat>
^ theGoats
]

0 comments on commit c49eb28

Please sign in to comment.