|
Boost Users : |
Subject: Re: [Boost-users] Optional XML serialization
From: Paul (elegant_dice_at_[hidden])
Date: 2010-02-22 20:25:19
Hi Robert,
On 23 February 2010 01:13, Robert Ramey <ramey_at_[hidden]> wrote:
> Paul wrote:
> > Hi,
> >
> > I use xml_woarchive and xml_wiarchive for reading/writing
> > configuration files.
> >
> > It seems work work well for me, but now I'd like to see if I can do
> > more with it... is it possible to load an XML serialized file, but
> > completely IGNORE a subtree of the XML file if desired?
>
> Anything is possible if you're willing to change the code that's in there.
>
I'm concerned about the "class_id" magic that might not be skippable. See
below
> > eg
> > template <class Archive>
> > void load( Archive & ar, MyConfig & c, const unsigned int version )
> > {
> > ar >> make_nvp("standard",c.standard);
> > if (some_global_flag_or_whatever)
> > ar >> make_nvp("advanced", c.advanced);
> > else
> > ar.skip("advanced"); // key bit
> > }
>
> Something like the following might be made to work.
>
> ar >> c.standard
> if(flag)
> ar >> c.advanced
> else{
> Advanced a; // to be thrown away
> ar >> a
> }
>
>
And what if "Advanced" is part of a module that may not be linked into the
app ?
The "lite" version doesn't have "Advanced", but the "full" version does.
The code above doesn't describe how I was going to achieve that, but
basically I was going to delegate the serialization of modules, something
like
void load(ar, modules, version)
{
string module_name;
ar << module_name;
ModuleManager::load_if_possible(config.module, module_name);
}
So if the module isn't available, then its not possible to deserialize the
information, even into a temporary object. The code isn't linked in.
I had another look at the basic_oarchive code and an XML archive. As you
know, the first time a class is serialized, the tag header will also include
a class_id="x" tracking="y" version="z"... but if I need to skip an entire
subtree, it may miss that first visitation.
If EVERY tag included that information, or at least the class_id number,
then I could write a new XML archive that would be able to skip subtrees.
By the way, is there a reason why there is no YAML archive format? Why only
XML as a human-readable option?
Thanks,
Paul
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