boost::spirit::qi and out-of-sequence variables

假装没事ソ 提交于 2019-12-03 14:52:16

You have several possibilities. The easiest is to adapt your struct into a Fusion sequence in the required order:

BOOST_FUSION_ADAPT_STRUCT(
    LatLongDegrees,
    (std::string, dirLong_)
    (double, degLong_)
    (std::string, dirLat_)
    (double, degLat_)
);

(yes, the order of adaptation does not have to match the order of the members in the original struct, you can even leave out members or duplicate them). This works fine if you have one particular order you want to parse your members in.

If you need different orderings in the same program, you might want to utilize a similar adaptation mechanism, but which additionally allows to give a name to the adapted struct:

BOOST_FUSION_ADAPT_STRUCT_NAME(
    LatLongDegrees, reversed_LatLongDegrees,
    (std::string, dirLong_)
    (double, degLong_)
    (std::string, dirLat_)
    (double, degLat_)
);

where reversed_LatLongDegrees is the data type used as the attribute in your Spirit grammar:

rule <Iterator, reversed_LatLongDegrees()> reversed;
reversed = longitude  >> ' ' >> double_ >> ' ' >> latitude >> double_;

LatLongDegrees data;
parse(begin, end, reversed, data);

This allows to create several adaptations for the same struct at the same time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!