storing non-trivial objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

storing non-trivial objects

Brad Midgley
Hey,

I'm trying to get an object graph that can have cycles saved into
local storage. I've got a stream that saves into local storage but
that's beyond the scope at the moment.

A few questions

* what is the best way to iterate over key & values for a collection?
Could this be a method that is implemented in Object with an empty
result so I don't have special cases around collections?

* isn't storeOn supposed to save to the stream a string expression
that can be run through the interpreter to get an object back? I see
it store stuff like "A Dictionary" where I'd expect "Dictionary new"

A sketch of how this would come together:

Object >> storeBinaryOn: aStream
  "Serialize this object and its references to the stream"
  |objectPositions objectList|
  objectPositions := Dictionary new.
  objectList := OrderedCollection new.
  self flattenWith: objectPositions into: objectList.
  objectList storeOn: aStream

Object >> flattenWith: objectPositions into: objectList
  "serialize to the next slot in objectList, return that index"
  |attrs index|
  (objectPositions includes: self) ifTrue: [^ objectPositions at: self].
  attrs := Dictionary new.
  objectList addLast: (Array with: (self class printString, ' new')
with: attrs).
  index := objectList size.
  objectPositions at: self put: index.
  self class allInstanceVariableNames do: [:name | attrs at: name put:
((self instVarAt: name) flattenWith: objectPositions
  ^ index

--
Brad Midgley

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: storing non-trivial objects

Nicolas Petton
Hi!

On May 6, 2013, at 10:42 PM, Brad Midgley <[hidden email]> wrote:

> Hey,
>
> I'm trying to get an object graph that can have cycles saved into
> local storage. I've got a stream that saves into local storage but
> that's beyond the scope at the moment.
>
> A few questions
>
> * what is the best way to iterate over key & values for a collection?
> Could this be a method that is implemented in Object with an empty
> result so I don't have special cases around collections?

I don't understand :)

>
> * isn't storeOn supposed to save to the stream a string expression
> that can be run through the interpreter to get an object back? I see
> it store stuff like "A Dictionary" where I'd expect "Dictionary new"
>

AFAIK #storeOn: is there but unfinished :) I think that implementing #storeOn: in appropriate places is the way to go though.

Nico

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: storing non-trivial objects

Brad Midgley
Nico

>> * what is the best way to iterate over key & values for a collection?
>> Could this be a method that is implemented in Object with an empty
>> result so I don't have special cases around collections?
>
> I don't understand :)

It looks like "self class allInstanceVariableNames" gives me the ivars
I should persist, but I would like to use smalltalk methods to ask for
all keys and values. Ideally in a generic way that doesn't require
checking first if the object is a collection.

--
Brad Midgley

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: storing non-trivial objects

Nicolas Petton
I would do something like the following (untested):

variables := Dictionary new.

self class allInstanceVariableNames do: [ :each |
        variables at: each put: (self instVarAt: each) ].


Nico

On May 10, 2013, at 5:11 PM, Brad Midgley <[hidden email]> wrote:

> Nico
>
>>> * what is the best way to iterate over key & values for a collection?
>>> Could this be a method that is implemented in Object with an empty
>>> result so I don't have special cases around collections?
>>
>> I don't understand :)
>
> It looks like "self class allInstanceVariableNames" gives me the ivars
> I should persist, but I would like to use smalltalk methods to ask for
> all keys and values. Ideally in a generic way that doesn't require
> checking first if the object is a collection.
>
> --
> Brad Midgley
>
> --
> You received this message because you are subscribed to the Google Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
Nicolas Petton
http://www.nicolas-petton.fr

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.