Index: home/qi/binary/binary.hpp =================================================================== --- home/qi/binary/binary.hpp (revision 72619) +++ home/qi/binary/binary.hpp (working copy) @@ -25,6 +25,7 @@ #include #include #include +#include #include #define BOOST_SPIRIT_ENABLE_BINARY(name) \ @@ -42,6 +43,19 @@ \ /***/ +#define BOOST_SPIRIT_ENABLE_BINARY_IEEE754(name) \ + template<> \ + struct use_terminal: mpl::true_ {}; \ + \ + template \ + struct use_terminal > >: is_floating_point {}; \ + \ + template<> \ + struct use_lazy_terminal: mpl::true_ {}; \ + \ +/***/ + namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// @@ -59,9 +73,16 @@ BOOST_SPIRIT_ENABLE_BINARY(big_qword) // enables big_qword BOOST_SPIRIT_ENABLE_BINARY(little_qword) // enables little_qword #endif + BOOST_SPIRIT_ENABLE_BINARY_IEEE754(bin_float) + BOOST_SPIRIT_ENABLE_BINARY_IEEE754(big_bin_float) + BOOST_SPIRIT_ENABLE_BINARY_IEEE754(little_bin_float) + BOOST_SPIRIT_ENABLE_BINARY_IEEE754(bin_double) + BOOST_SPIRIT_ENABLE_BINARY_IEEE754(big_bin_double) + BOOST_SPIRIT_ENABLE_BINARY_IEEE754(little_bin_double) }} #undef BOOST_SPIRIT_ENABLE_BINARY +#undef BOOST_SPIRIT_ENABLE_BINARY_IEEE754 namespace boost { namespace spirit { namespace qi { @@ -92,6 +113,12 @@ using boost::spirit::big_qword_type; using boost::spirit::little_qword_type; #endif + using boost::spirit::bin_float_type; + using boost::spirit::big_bin_float_type; + using boost::spirit::little_bin_float_type; + using boost::spirit::bin_double_type; + using boost::spirit::big_bin_double_type; + using boost::spirit::little_bin_double_type; namespace detail { @@ -135,6 +162,26 @@ }; #endif + template + struct floating_point + { + BOOST_SPIRIT_ASSERT_MSG( + bits == 32 || bits == 64, + not_supported_binary_size, ()); + }; + + template <> + struct floating_point<32> + { + typedef float type; + }; + + template <> + struct floating_point<64> + { + typedef double type; + }; + /////////////////////////////////////////////////////////////////////// template struct what; @@ -168,14 +215,14 @@ } /////////////////////////////////////////////////////////////////////////// - template - struct any_binary_parser : primitive_parser > + template + struct any_binary_parser : primitive_parser > { template struct attribute { typedef boost::integer::endian< - endian, typename qi::detail::integer::type, bits + endian, typename T::type, bits > type; }; @@ -211,10 +258,10 @@ }; /////////////////////////////////////////////////////////////////////////// - template struct binary_lit_parser - : primitive_parser > + : primitive_parser > { template struct attribute @@ -222,7 +269,7 @@ typedef unused_type type; }; - binary_lit_parser(Int n) + binary_lit_parser(V n) : n(n) {} template ::type, bits> attr_; + boost::integer::endian attr_; #if defined(BOOST_MSVC) // warning C4244: 'argument' : conversion from 'const int' to 'foo', possible loss of data @@ -270,27 +316,27 @@ return info(qi::detail::what::is()); } - Int n; + V n; }; /////////////////////////////////////////////////////////////////////////// // Parser generators: make_xxx function (objects) /////////////////////////////////////////////////////////////////////////// - template + template struct make_binary_parser { - typedef any_binary_parser result_type; + typedef any_binary_parser result_type; result_type operator()(unused_type, unused_type) const { return result_type(); } }; - template struct make_binary_lit_parser { - typedef binary_lit_parser result_type; + typedef binary_lit_parser result_type; template result_type operator()(Terminal const& term, unused_type) const { @@ -298,16 +344,18 @@ } }; -#define BOOST_SPIRIT_MAKE_BINARY_PRIMITIVE(name, endian, bits) \ - template \ - struct make_primitive \ - : make_binary_parser {}; \ - \ - template \ - struct make_primitive< \ - terminal_ex > , Modifiers> \ - : make_binary_lit_parser {};\ - \ +#define BOOST_SPIRIT_MAKE_BINARY_PRIMITIVE(name, endian, bits) \ + template \ + struct make_primitive \ + : make_binary_parser, \ + boost::integer::endianness::endian, bits> {}; \ + \ + template \ + struct make_primitive< \ + terminal_ex > , Modifiers> \ + : make_binary_lit_parser, \ + boost::integer::endianness::endian, bits> {}; \ + \ /***/ BOOST_SPIRIT_MAKE_BINARY_PRIMITIVE(byte_, native, 8) @@ -325,6 +373,30 @@ #undef BOOST_SPIRIT_MAKE_BINARY_PRIMITIVE +#define BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE(name, endian, bits) \ + template \ + struct make_primitive \ + : make_binary_parser, \ + boost::integer::endianness::endian, bits> {}; \ + \ + template \ + struct make_primitive< \ + terminal_ex >, Modifiers> \ + : make_binary_lit_parser, \ + boost::integer::endianness::endian, \ + bits> {}; \ + \ + /***/ + + BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE(bin_float, native, 32) + BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE(big_bin_float, big, 32) + BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE(little_bin_float, little, 32) + BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE(bin_double, native, 64) + BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE(big_bin_double, big, 64) + BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE(little_bin_double, little, 64) + +#undef BOOST_SPIRIT_MAKE_BINARY_IEEE754_PRIMITIVE + }}} #endif