Hi:
I've a model with only one instance in the image and I backup this model with:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. rr nextPut: MyModel someInstance. rr close.
But I can't figure out how to read again inside the image, I've tried, between several attempts,:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. MyModel allInstances do: [:each1 | each1 := rr next]. rr close.
I'm sure that I've only one instance in the model (worked with Seaside and Mewa) but I can't figure out how to recover the data in the file 'MyModel.obj' to rebuild my objects in the image.
The previous MyModel allInstances do: [:each1 | each1 := rr next] fails with 'attempt to index non-existent element in an ordered collection'.
I can't imagine how to replace the "data" of my live instance of MyModel with the data saved in the external file "MyModel.obj".
Any help will be appreciated.
gsa.
On Mon, 2004-08-16 at 08:35, GermXn S. Arduino wrote:
Hi:
I've a model with only one instance in the image and I backup this model with:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. rr nextPut: MyModel someInstance. rr close.
But I can't figure out how to read again inside the image
If memory servers you want to use ReadWriteStream>>fileInObjectAndCode.
Ken
All you need is:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. reconstitutedModel := rr next. rr close.
... whereupon the variable reconsitutedModel will point to your freshly-internalized model.
Cheers,
-- Scott
At 10:35 AM -0300 8/16/04, Germ·n S. Arduino wrote:
Hi:
I've a model with only one instance in the image and I backup this model with:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. rr nextPut: MyModel someInstance. rr close.
But I can't figure out how to read again inside the image, I've tried, between several attempts,:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. MyModel allInstances do: [:each1 | each1 := rr next]. rr close.
I'm sure that I've only one instance in the model (worked with Seaside and Mewa) but I can't figure out how to recover the data in the file 'MyModel.obj' to rebuild my objects in the image.
The previous MyModel allInstances do: [:each1 | each1 := rr next] fails with 'attempt to index non-existent element in an ordered collection'.
I can't imagine how to replace the "data" of my live instance of MyModel with the data saved in the external file "MyModel.obj".
Any help will be appreciated.
gsa.
On Mon, 16 Aug 2004 10:35:29 -0300, "Germán S. Arduino" gsa@softhome.net wrote:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. rr nextPut: MyModel someInstance. rr close.
In general, this is a bad way to handle sole-instance classes. You should have a class variable called 'SoleInstance' or 'Current' or something like that, and write accessor methods on the class side to get and set it:
MyModel class >> #soleInstance
"If you want SoleInstance to self-initialize, un-comment the following expression: SoleInstance isNil ifTrue: [self initializeSoleInstance]."
^SoleInstance
MyModel class >> #soleInstance: aModel
SoleInstance := aModel
That way you always know you have a reference to the instance you want.
Now, when you go to read it in from your file, you can just do this:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. MyModel soleInstance: rr next. rr close.
Now you've got the right instance, and you can reference it from anywhere.
Later, Jon
-------------------------------------------------------------- Jon Hylands Jon@huv.com http://www.huv.com/jon
Project: Micro Seeker (Micro Autonomous Underwater Vehicle) http://www.huv.com
Jon Hylands wrote:
On Mon, 16 Aug 2004 10:35:29 -0300, "Germán S. Arduino" gsa@softhome.net wrote:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. rr nextPut: MyModel someInstance. rr close.
In general, this is a bad way to handle sole-instance classes. You should have a class variable called 'SoleInstance' or 'Current' or something like that, and write accessor methods on the class side to get and set it:
MyModel class >> #soleInstance
"If you want SoleInstance to self-initialize, un-comment the following expression: SoleInstance isNil ifTrue: [self initializeSoleInstance]."
^SoleInstance
MyModel class >> #soleInstance: aModel
SoleInstance := aModel
That way you always know you have a reference to the instance you want.
Now, when you go to read it in from your file, you can just do this:
| rr | rr := SmartRefStream fileNamed: 'MyModel.obj'. MyModel soleInstance: rr next. rr close.
Now you've got the right instance, and you can reference it from anywhere.
Later, Jon
Jon Hylands Jon@huv.com http://www.huv.com/jon
Project: Micro Seeker (Micro Autonomous Underwater Vehicle) http://www.huv.com
Hmmm, the singleton way, ok will try.
Thanks by the response, also thanks to Scott and Ken.
Regards. gsa.
Germán: Del código del TEG (completo está en SqueakRos)
grabaEstado | t1 | t1 _ ReferenceStream fileNamed: 'estado.teg'. t1 nextPut: losJugadores. t1 nextPut: cartasOrden. t1 nextPut: jugadoresVivos. t1 nextPut: playerTurn. t1 nextPut: ronda. t1 nextPut: numCarta. t1 nextPut: cambiosTotales. 1 to: 42 do: [:t2 | t1 nextPut: (submorphs at: t2) ejercitos. t1 nextPut: (submorphs at: t2) deQuienSoy]. t1 close
leerEstado | t1 | t1 _ ReferenceStream fileNamed: 'estado.teg'. losJugadores _ t1 next. cartasOrden _ t1 next. jugadoresVivos _ t1 next. playerTurn _ t1 next. ronda _ t1 next. numCarta _ t1 next. cambiosTotales _ t1 next. 1 to: 42 do: [:t2 | (submorphs at: t2) ejercitos: t1 next. (submorphs at: t2) deQuienSoy: t1 next]. t1 close.
Mismo código para mandar los objetos por red.
askMyData | estadoTEG losPaises losPaisesData elPais soyDe nuevoColor | estadoTEG _ activeSocket getObject. self losJugadores: (estadoTEG at: 1). self cartasOrden: (estadoTEG at: 2). self ronda: (estadoTEG at: 3). self numCarta: (estadoTEG at: 4). self cambiosTotales: (estadoTEG at: 5). losPaises _ estadoTEG at: 6. 1 to: 42 do: [:pais | losPaisesData _ losPaises at: pais. elPais _ self submorphs at: pais. elPais ejercitos: (losPaisesData at: 1). elPais deQuienSoy: (losPaisesData at: 2). soyDe _ elPais deQuienSoy. nuevoColor _ (self losJugadores at: soyDe) miColor. elPais redrawInColor: nuevoColor]. self playerTurn: ( estadoTEG at: 7).
sendMyData | estadoTEG losPaises elPais losPaisesData | serverOrClient = #server ifTrue: [ activeSocket _ socketList at: playerTurn]. (activeSocket isValid and: [activeSocket isConnected]) ifTrue: [estadoTEG _ OrderedCollection new. estadoTEG add: self losJugadores. estadoTEG add: self cartasOrden. estadoTEG add: self ronda. estadoTEG add: self numCarta. estadoTEG add: self cambiosTotales. losPaises _ Array new: 42. 1 to: 42 do: [:pais | elPais _ self submorphs at: pais. losPaisesData _ Array new: 2. losPaisesData at: 1 put: elPais ejercitos. losPaisesData at: 2 put: elPais deQuienSoy. losPaises at: pais put: losPaisesData]. estadoTEG add: losPaises. estadoTEG add: self playerTurn. activeSocket sendObject: estadoTEG]. [activeSocket dataAvailable] whileFalse. self askMyData
Germán: You should receive same in Spanish, but someone could find useful.
From TEG (complete game 3.6Mb and code is in SqueakRos
http://ar.groups.yahoo.com/group/squeakRos/)
grabaEstado | t1 | t1 _ ReferenceStream fileNamed: 'estado.teg'. t1 nextPut: losJugadores. t1 nextPut: cartasOrden. t1 nextPut: jugadoresVivos. t1 nextPut: playerTurn. t1 nextPut: ronda. t1 nextPut: numCarta. t1 nextPut: cambiosTotales. 1 to: 42 do: [:t2 | t1 nextPut: (submorphs at: t2) ejercitos. t1 nextPut: (submorphs at: t2) deQuienSoy]. t1 close
leerEstado | t1 | t1 _ ReferenceStream fileNamed: 'estado.teg'. losJugadores _ t1 next. cartasOrden _ t1 next. jugadoresVivos _ t1 next. playerTurn _ t1 next. ronda _ t1 next. numCarta _ t1 next. cambiosTotales _ t1 next. 1 to: 42 do: [:t2 | (submorphs at: t2) ejercitos: t1 next. (submorphs at: t2) deQuienSoy: t1 next]. t1 close.
Same code for sending objects to other TEG instanc3e in other (or same) computer network connected.
askMyData | estadoTEG losPaises losPaisesData elPais soyDe nuevoColor | estadoTEG _ activeSocket getObject. self losJugadores: (estadoTEG at: 1). self cartasOrden: (estadoTEG at: 2). self ronda: (estadoTEG at: 3). self numCarta: (estadoTEG at: 4). self cambiosTotales: (estadoTEG at: 5). losPaises _ estadoTEG at: 6. 1 to: 42 do: [:pais | losPaisesData _ losPaises at: pais. elPais _ self submorphs at: pais. elPais ejercitos: (losPaisesData at: 1). elPais deQuienSoy: (losPaisesData at: 2). soyDe _ elPais deQuienSoy. nuevoColor _ (self losJugadores at: soyDe) miColor. elPais redrawInColor: nuevoColor]. self playerTurn: ( estadoTEG at: 7).
sendMyData | estadoTEG losPaises elPais losPaisesData | serverOrClient = #server ifTrue: [ activeSocket _ socketList at: playerTurn]. (activeSocket isValid and: [activeSocket isConnected]) ifTrue: [estadoTEG _ OrderedCollection new. estadoTEG add: self losJugadores. estadoTEG add: self cartasOrden. estadoTEG add: self ronda. estadoTEG add: self numCarta. estadoTEG add: self cambiosTotales. losPaises _ Array new: 42. 1 to: 42 do: [:pais | elPais _ self submorphs at: pais. losPaisesData _ Array new: 2. losPaisesData at: 1 put: elPais ejercitos. losPaisesData at: 2 put: elPais deQuienSoy. losPaises at: pais put: losPaisesData]. estadoTEG add: losPaises. estadoTEG add: self playerTurn. activeSocket sendObject: estadoTEG]. [activeSocket dataAvailable] whileFalse. self askMyData
Hi Edgar!
Seems that my news reader has missed your mail until today!!!!
Sorry by the delay and really thanks you very much by your help.
Gracias Edgar!
Lic. Edgar J. De Cleene wrote:
Germán: You should receive same in Spanish, but someone could find useful.
From TEG (complete game 3.6Mb and code is in SqueakRos
http://ar.groups.yahoo.com/group/squeakRos/)
grabaEstado | t1 | t1 _ ReferenceStream fileNamed: 'estado.teg'. t1 nextPut: losJugadores. t1 nextPut: cartasOrden. t1 nextPut: jugadoresVivos. t1 nextPut: playerTurn. t1 nextPut: ronda. t1 nextPut: numCarta. t1 nextPut: cambiosTotales. 1 to: 42 do: [:t2 | t1 nextPut: (submorphs at: t2) ejercitos. t1 nextPut: (submorphs at: t2) deQuienSoy]. t1 close
leerEstado | t1 | t1 _ ReferenceStream fileNamed: 'estado.teg'. losJugadores _ t1 next. cartasOrden _ t1 next. jugadoresVivos _ t1 next. playerTurn _ t1 next. ronda _ t1 next. numCarta _ t1 next. cambiosTotales _ t1 next. 1 to: 42 do: [:t2 | (submorphs at: t2) ejercitos: t1 next. (submorphs at: t2) deQuienSoy: t1 next]. t1 close.
Same code for sending objects to other TEG instanc3e in other (or same) computer network connected.
askMyData | estadoTEG losPaises losPaisesData elPais soyDe nuevoColor | estadoTEG _ activeSocket getObject. self losJugadores: (estadoTEG at: 1). self cartasOrden: (estadoTEG at: 2). self ronda: (estadoTEG at: 3). self numCarta: (estadoTEG at: 4). self cambiosTotales: (estadoTEG at: 5). losPaises _ estadoTEG at: 6. 1 to: 42 do: [:pais | losPaisesData _ losPaises at: pais. elPais _ self submorphs at: pais. elPais ejercitos: (losPaisesData at: 1). elPais deQuienSoy: (losPaisesData at: 2). soyDe _ elPais deQuienSoy. nuevoColor _ (self losJugadores at: soyDe) miColor. elPais redrawInColor: nuevoColor]. self playerTurn: ( estadoTEG at: 7).
sendMyData | estadoTEG losPaises elPais losPaisesData | serverOrClient = #server ifTrue: [ activeSocket _ socketList at: playerTurn]. (activeSocket isValid and: [activeSocket isConnected]) ifTrue: [estadoTEG _ OrderedCollection new. estadoTEG add: self losJugadores. estadoTEG add: self cartasOrden. estadoTEG add: self ronda. estadoTEG add: self numCarta. estadoTEG add: self cambiosTotales. losPaises _ Array new: 42. 1 to: 42 do: [:pais | elPais _ self submorphs at: pais. losPaisesData _ Array new: 2. losPaisesData at: 1 put: elPais ejercitos. losPaisesData at: 2 put: elPais deQuienSoy. losPaises at: pais put: losPaisesData]. estadoTEG add: losPaises. estadoTEG add: self playerTurn. activeSocket sendObject: estadoTEG]. [activeSocket dataAvailable] whileFalse. self askMyData
squeak-dev@lists.squeakfoundation.org