|
Boost : |
From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-09-29 05:33:24
"Vladimir Prus" <ghost_at_[hidden]> wrote in message
news:cjdkpt$bgp$1_at_sea.gmane.org...
> Jonathan Turkanis wrote:
> >
> > I can imagine wanting to generate a report in xml which involves
> > enumerating the employees working on a project. The employees may be
> > represented by complex objects containing extraneous information such as
> > work history, and only the employee name may be needed. In that case,
> > using a serialize method would be wasteful.
>
> Yes, a bit. OTOH, it would be possible to use the same serialize method to
> build, once, and member name -> offset map, which can be then used. For a
> name case you can do:
>
> template<class>
> figure_out_name_offset
> {
> figure_out_name_offset operator&(nvp& p)
> {
> if (p.name() == "name")
> {
> m_address = &p.value()
> }
> }
> std::string* m_address;
> };
> Person p;
> figure_out_name_offset f;
> p.serialize(f);
> unsigned offset = (int)f.m_address - (int)&p;
Does this force the class to represent it's fields as strings? If so, it's
contrary to my understanding of output formatting, according to which types
simply advertise their structure and the end user has complete control over how
subobjects are formatted.
Jonathan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk