From: stephan b. <st...@wa...> - 2003-10-07 00:13:41
|
Executive summary: We can now load data trees from containing an arbitrary number of differe= nt=20 Serializable-like interfaces. Consider this tree: theroot=3D(fake::FakeRoot (bar two) (foo one) othertype=3D(AltSerializable (got_milk 1)) ) where FakeRoot extends Serializable and AltSerializable is a Serializable= =20 work-alike (different function names, same conventions), but not related = to=20 Serializable. In FakeRoot's deser we can now deserialize an AltSerializable object from= our=20 data tree: The long way: typedef s11n::basic_node<AltSerializable> ALTNode; ALTNode * theother =3D 0; AltSerializable * foo =3D 0; theother =3D node.cast_serializable_type<AltSerializable>("othertype"); if( theother ) { foo =3D theother->deserialize(); if( ! foo ) { ... pain ... } else ... it worked ... delete( foo ); } or the short way: foo =3D node.deserializeAs<AltSerializable>("othertype"); if( foo ) { foo->bogo_method(); delete( foo ); } Doing this is remarkably inefficient, however, because we actually have t= o=20 copy all children (that is, an arbitrary amount of string data) as part o= f=20 the not-quite-really-a-conversion that goes on behind the scenes. There's= =20 gotta be a more efficient way to do it, but i haven't thought of one yet.= =20 It's only copying properties, after all, but that easily gets expensive f= or=20 big trees, because you have the big original plus your=20 copy-made-only-for-a-silly-quasi-cast. Then again, i guess std::string us= es=20 copy-on-write(?) or something similar. My next Quest, as it were, is to figure out a way to dynamically load for= mat=20 parsers (i.e., Serializers). --=20 ----- st...@wa... http://qub.sourceforge.net http://libfunutil.sourceforge.net =20 http://toc.sourceforge.net http://countermoves.sourceforge.net http://stephan.rootonfire.org et al. |