#include "../support/float_qi.hpp" #include "../support/float_karma.hpp" #include #include #include #include #include #include #include #include template struct float_parser: boost::spirit::qi::grammar { float_parser(): float_parser::base_type(start) { using boost::spirit::byte_; using boost::spirit::bin_float; using boost::spirit::big_bin_float; using boost::spirit::little_bin_float; using boost::spirit::bin_double; using boost::spirit::big_bin_double; using boost::spirit::little_bin_double; start = ( bin_float(1.0f) >> big_bin_float(1.0f) >> little_bin_float(1.0f) >> bin_double(1.0) >> big_bin_double(1.0) >> little_bin_double(1.0) ) ; } boost::spirit::qi::rule start; }; template struct float_generator: boost::spirit::karma::grammar { float_generator(): float_generator::base_type(start) { using boost::spirit::byte_; using boost::spirit::bin_float; using boost::spirit::big_bin_float; using boost::spirit::little_bin_float; using boost::spirit::bin_double; using boost::spirit::big_bin_double; using boost::spirit::little_bin_double; start = ( bin_float(1.0f) << big_bin_float(1.0f) << little_bin_float(1.0f) << bin_double(1.0) << big_bin_double(1.0) << little_bin_double(1.0) ) ; } boost::spirit::karma::rule start; }; int main() { std::ofstream out("float.bin", std::ios::binary | std::ios::trunc); if(!out) { std::cerr << "Failed to open output file\n"; return 1; } typedef std::ostream_iterator iterator; typedef float_generator float_generator; float_generator fg; bool result = boost::spirit::karma::generate(iterator(out), fg); out.close(); if(!result) { std::cerr << "Failed to generate\n"; return 1; } std::ifstream in("float.bin", std::ios::binary); if(!in) { std::cerr << "Failed to open input file\n"; return 1; } namespace spirit = boost::spirit; typedef std::istreambuf_iterator base_iterator_type; spirit::multi_pass first = spirit::make_default_multi_pass(base_iterator_type(in)); spirit::multi_pass last = spirit::make_default_multi_pass(base_iterator_type()); typedef float_parser > float_parser; float_parser fp; bool result2 = parse(first, last, fp); in.close(); if(!result2 || first != last) { std::cerr << "Failed to parse\n"; return 1; } return 0; }