On 8 aug 2010, at 21:35, Andrei Alexandrescu wrote: > On 08/08/2010 01:39 PM, Jacob wrote: >> On 8 aug 2010, at 17:27, Andrei Alexandrescu wrote: >>> Deserialize into Object and then cast the Object to Shape. >> >> To be able to cast it to a Shape you need to know the type at compile >> time when you deserialize it. Or you have to register a method that >> deserializes the object, which is exactly how it works now when you >> deserialize through a base class reference. > > You only need to know the _base_ type statically. > >>>> Or would Variant be useful here? I have not used Variant. >>> >>> Probably Variant would play a role when e.g. one wants to >>> deserialize "the next primitive type" without needing to know >>> exactly what type that is (e.g. different integer widths). >>> >>> >>> Andrei _______________________________________________ phobos >>> mailing list [email protected] >>> http://lists.puremagic.com/mailman/listinfo/phobos >> >> I'm not sure if we understand each other correctly. > > Most likely - sorry about that. Don't forget that all I'm going by is the > tutorial, which is very brief. > >> If you >> deserialize into Object you eventually need to cast it to something >> more useful and then you probably could have deserialized to that >> type in the first place. The library can deserialize through base >> class references (by register a deserialize method) but you would >> have to start with a static type somewhere, not just Object. Do you >> have a simple (code) example describing what you want to do? > > I think the Shape example is simple enough to serve as a good baseline. Say > you have a hierarchy rooted in Shape including e.g. Triangle, Circle, and > Rectangle. Now say you have a drawing represented as a Shape[]. What steps do > you need to take to save the drawing to disk and restore it later? >
The code example is now available at: http://dsource.org/projects/orange/wiki/Tutorials/SerializeBase > Andrei > _______________________________________________ > phobos mailing list > [email protected] > http://lists.puremagic.com/mailman/listinfo/phobos _______________________________________________ phobos mailing list [email protected] http://lists.puremagic.com/mailman/listinfo/phobos
