Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Vladimir Batov (vbatov_at_[hidden])
Date: 2011-05-06 06:45:39

> From: "Jeremy Maitin-Shepard" <jeremy_at_[hidden]>
> ...
>> Say, a Train class is complex as it has a *lot* of
>> stuff. We serialize/unserialize the class to/from XML using 'convert'.
>> Train has
>> op>>() op<<().
> I don't like default_value as a customization point either. However, it
> seems that for a non-default constructable type, operator>> is likely not
> the ideal interface for unserialization.

Agreed. And you nailed it -- for unserialization we've been in fact moving
towards more direct approach. As simple as a class needs to provide a
specific constructor "class::class(xml::element const&)" for that purpose. I
personally like it better. Less overhead; do what you mean; easier to
follow. As with long-running projects is does not happen overnight
especially when the old supporting framework is in place.

> How would you use your unserialization functionality separately from the
> convert library? Presumably you would need some way to obtain a
> constructed instance in a form suitable for invoking operator>>. If the
> non-default-constructable type has any members that aren't default
> constructable, you would have to somehow construct the members as well.

I am not sure I understand. A non-default-constructable object is
constructed in whatever way it can be constructed and then is fed to
convert::from(). Like

// Constructed by whatever means available. Not the def. cntr
direction fallback (direction::up);
convert<direction>::result res = convert<direction>::from(str, fallback);
direction reconstructed_from_str = res.value();

For big classes with value-semantics it might be quite an overhead. However,
our classes are overwhelmingly pointer-semantics pimpl-based classes. That
way we essentially apply something that probably can be called in-place
re-initialization. For me it's somewhat over-engineered and we've been
moving towards "class::class(xml::element const&)" for unserialization.
Still, all the current features of 'convert' are needed. They will be
(hopefully) used on smaller scale though.

Not sure if answered your question to your satisfaction though. :-)


Boost list run by bdawes at, gregod at, cpdaniel at, john at