parse string into struct with boost spirit -


i have following code need parse string , move struct defined follows:

#include "boost\spirit\include\classic.hpp" #include "boost\spirit\include\qi.hpp" #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> #include <boost/filesystem.hpp> #include <boost/format.hpp> #include <regex> #include <string> #include <boost\chrono.hpp> #include <ctype.h> #include <iostream>  struct my_struct {    std::string s1;    std::string s2;    std::string s3;    std::string s4;    std::string s5;    std::string s6;    std::string s7;    std::string s8;    std::string s9;    std::string s10;    std::string s11; };  boost_fusion_adapt_struct(     my_struct,     (std::string, s1 )     (std::string, s2 )     (std::string, s3 )     (std::string, s4 )     (std::string, s5 )     (std::string, s6 )     (std::string, s7 )     (std::string, s8 )     (std::string, s9 )     (std::string, s10)     (std::string, s11)  ) 

an grammar this:

template <typename iterator> struct my_struct_parser : qi::grammar<iterator, my_struct(), ascii::space_type> {     my_struct_parser() : my_struct_parser::base_type(start)     {         using ascii::char_;         using qi::digit;         using qi::alpha;          start %=             qi::alpha>>"-"             >>qi::repeat(9)[digit]>>"-"             >>+(digit)>>"-"             >>+(digit)>>"-"             >>+(digit)>>"-"             >>qi::repeat(5)[digit]>>"-"             >>+char_("a-za-z")>>"-"             >>qi::repeat(2)[digit]>>"-"             >>+(digit)>>"-"             >>+(digit)>>"-"            >>+(qi::alpha)             >>-('-'>>+(char_("a-za-z0-9@$")));     }     qi::rule<iterator, my_struct(), ascii::space_type> start; }; 

and parse strings using these lines of code:

       my_struct & emp;//this passed argument function        typedef my_struct_parser<iterator_type> my_struct_parser_type;        my_struct_parser_type parser;        std::string::const_iterator iter = filename.begin();        std::string::const_iterator end = filename.end();        bool r =        boost::spirit::qi::phrase_parse(iter, end,parser,boost::spirit::ascii::space ,emp); 

ok,the problem code compiles fine when struct has 10 fields or less give errors when have more fields in struct , guessed because of parameter spirit_arguments_limit because default value 10.

i tried defining parameter size desire before include spirit header files still compile errors

how should solve problem?

if check compiler complains about, see this:

.... /usr/include/boost/fusion/container/vector/convert.hpp:26:13: error: invalid use of incomplete type ‘struct boost::fusion::detail::as_vector<12>’ .... /usr/include/boost/fusion/container/vector/detail/as_vector.hpp:26:12: error: declaration of ‘struct boost::fusion::detail::as_vector<12>’ 

i ran problem time ago well. if struct contains more 10 fields need redefine fusion_max_vector_size since fusion container(s) aggregates matched attributes.

http://www.boost.org/doc/libs/1_52_0/libs/fusion/doc/html/fusion/container/vector.html http://www.boost.org/doc/libs/1_52_0/libs/spirit/doc/html/spirit/qi/quick_reference/compound_attribute_rules.html

i use these 2 defines before other include files override default values:

#define fusion_max_vector_size      20 #define spirit_arguments_limit      20 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -