Boost logo

Boost Users :

Subject: [Boost-users] Parsing statements from ascii files in arbitrary order into hierarchies of structs using boost spirit
From: Stefan Zellmann (zellmans_at_[hidden])
Date: 2011-12-15 06:28:14


Hello!

I'd like to parse one-line statements from an ascii file using boost spirit
into structs. Statements may be quite different and may occur in
arbitrary order. I'm wondering how I can achieve something like the
following:

/qi::rule<T, Statement(), Skipper> r_statement;
qi::rule<T, DerivedStatement0(), Skipper> r_derivedStatement0;
qi::rule<T, DerivedStatement1(), Skipper> r_derivedStatement1;/

With:

/struct Statement
{
     // empty
};

struct DerivedStatement0 : public Statement
{
     // members
};

struct DerivedStatement1 : public Statement
{
     // members
};/

First thing I'm not sure about is how to adapt (using
/BOOST_FUSION_ADAPT_STRUCT/)
this hierarchy, since /Statement/ has no members. I've seen some
snippets on the internet
where inherited members (data members are good for me, no member
functions) were
adapted using /BOOST_FUSION_ADAPT_STRUCT/, so I'm right to believe that
inheritance
in my case shell pose no problem?

Well, I'm actually not sure if the idea I came up with is the right way
to accomplish this
in the first place, so I'm grateful for any suggestions on how to do
this more appropriately.

Thanks in advance!

Cheers,

Stefan

-- 
Stefan Zellmann
Dipl.-Wirt.-Inf.
Universität zu Köln
RRZK
Phone: +49 221 478 86578
Mail: zellmans_at_[hidden]


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