Boost logo

Boost Users :

From: Johan Franzén (johan_at_[hidden])
Date: 2007-06-18 14:41:40


> I still got some starting problems with the boost::serialization library.
> I want to serialize a shared_ptr to my own polymorphic class.
> I'm building my own networkprotocol and the basic idea is a kind
> of "header"-class which with a shared_ptr<data_base> which can point to a
> lot of different data structs, which are polymorphic children of data_base.
>
> This "header"-class is then serialized and send to another peer. But how
> should this peer get the real type from the shared_ptr<data_base>? Which
> child is it pointing to? I can get the name with "typeid()", but i cannot
> get the type through that way. I would like to get the type from it
> automaticly without using some case-conditions, so i only have to add a new
> child of data_base and can use it, without changing any networkprotocol
> related code.
>
> Kind Regards
> Manuel Jung

This isn't really related to Boost.Serialization, but I think You might get
what You want using the visitor pattern. That's how I manage the different
message bodies in my latest project at work. (See
http://en.wikipedia.org/wiki/Visitor_pattern).

HTH,
Johan Franzén


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net