#define BOOST_SPIRIT_DEBUG #include #include #include namespace myproject { namespace parser { //--------------------------------------------------------------------------- // NAMESPACES //--------------------------------------------------------------------------- namespace qi = boost::spirit::qi; //--------------------------------------------------------------------------- // TYPEDEFS //--------------------------------------------------------------------------- typedef boost::multi_array ReturnT; typedef std::vector ElevationT; //--------------------------------------------------------------------------- // VARIABLES //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // PARSER //--------------------------------------------------------------------------- /*! * \brief DTED Elevation parsing grammar */ template struct dted_elevation_parser : public qi::grammar { /*! * \brief Constructor where the Qi grammar is defined. */ dted_elevation_parser () : dted_elevation_parser::base_type ( elevation ) { using qi::big_word; //--------------------------------------------------- // RULE: DTED Elevation //--------------------------------------------------- elevation = +big_word; //--------------------------------------------------- // Boost Spirit Debugg Information. Only active if // DEBUG_TLE_PARSER is enabled via CMake //--------------------------------------------------- BOOST_SPIRIT_DEBUG_NODE(elevation); } //--------------------------------------------------------------------------- // VARIABLES //--------------------------------------------------------------------------- /*! \brief Top-level grammar rule */ qi::rule elevation; }; } // namespace parser } // namespace myproject int main ( int, char** ) { std::string input = "\x81\x02\x03\x04"; typedef std::string::const_iterator iterator_type; typedef myproject::parser::dted_elevation_parser elevation_parser; elevation_parser parser_obj; iterator_type iter = input.begin(); iterator_type end = input.end(); myproject::parser::ElevationT results; if ( boost::spirit::qi::parse ( iter, end, parser_obj, results ) ) { std::cout << "successfully parsed" << std::endl; myproject::parser::ReturnT data ( boost::extents[2][2] ); std::copy ( results.begin(), results.end(), data.data() ); std::cout << data[0][0] << std::endl; std::cout << data[0][1] << std::endl; } else { std::cout << "failed to parse" << std::endl; } return 0; }