File indexing completed on 2025-01-18 09:30:27
0001
0002
0003
0004
0005 #ifndef BOOST_CONVERT_SPIRIT_BASED_CONVERTER_HPP
0006 #define BOOST_CONVERT_SPIRIT_BASED_CONVERTER_HPP
0007
0008 #include <boost/convert/base.hpp>
0009 #include <boost/convert/detail/config.hpp>
0010 #include <boost/spirit/include/qi.hpp>
0011 #include <boost/spirit/include/karma.hpp>
0012
0013 namespace boost { namespace cnv { struct spirit; }}
0014
0015 struct boost::cnv::spirit : boost::cnv::cnvbase<boost::cnv::spirit>
0016 {
0017 using this_type = boost::cnv::spirit;
0018 using base_type = boost::cnv::cnvbase<this_type>;
0019
0020 using base_type::operator();
0021
0022 template<typename string_type, typename out_type>
0023 void
0024 str_to(cnv::range<string_type> range, optional<out_type>& result_out) const
0025 {
0026 using parser = typename boost::spirit::traits::create_parser<out_type>::type;
0027
0028 auto beg = range.begin();
0029 auto end = range.end();
0030 auto result = out_type();
0031
0032 if (boost::spirit::qi::parse(beg, end, parser(), result))
0033 if (beg == end)
0034 result_out = result;
0035 }
0036 template<typename in_type, typename char_type>
0037 cnv::range<char_type*>
0038 to_str(in_type value_in, char_type* beg) const
0039 {
0040 using generator = typename boost::spirit::traits::create_generator<in_type>::type;
0041
0042 auto end = beg;
0043 bool good = boost::spirit::karma::generate(end, generator(), value_in);
0044
0045 return cnv::range<char_type*>(beg, good ? end : beg);
0046 }
0047 };
0048
0049 #endif
0050