Boost logo

Boost Users :

Subject: Re: [Boost-users] boost-spirit: need help with simple parser
From: Igor R (boost.lists_at_[hidden])
Date: 2012-07-03 08:29:19


> Sorry for not providing the simplest possible code to reproduce my
> problem, but I'm still new to spirit, I think I will miss some details
> in the conversion.
>
> I tried add the inclusion you suggested, but it did not help.

Sorry, although it works for boost::tuple, it won't work for your Ipv4 struct...
But a simple workaround can solve this issue: in Ipv4Address grammar
change attribute to boost::tuple<uint8_t, uint8_t, uint8_t, uint8_t>,
and in your parse() function use tuple type as temporary, then copy it
to Ipv4 argument (you use a temporary anyway). Like this:
bool parse(const const_string& s, Ipv4& i)
{
    boost::tuple<uint8_t, uint8_t, uint8_t, uint8_t> _i;
    const char * iter = s.begin();
    bool r = qi::parse(iter, s.end(), ipv4_address, _i);

    if( !r || iter != s.end() )
        return false;

    i = Ipv4(_i);
    return true;
}


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