// Copyright (c) 2001-2008 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #if !defined(BOOST_SPIRIT_KARMA_REAL_FEB_26_2007_0512PM) #define BOOST_SPIRIT_KARMA_REAL_FEB_26_2007_0512PM #if defined(_MSC_VER) && (_MSC_VER >= 1020) #pragma once // MS compatible compilers support #pragma once #endif #include #include #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace karma { namespace detail { template struct real_policy; } /////////////////////////////////////////////////////////////////////////// // This specialization is used for real generators not having a direct // initializer: float_, double_ etc. These generators must be used in // conjunction with a parameter. /////////////////////////////////////////////////////////////////////////// template struct real_generator { template struct attribute { typedef T type; }; // double_/float_/etc. has a parameter attached template static bool generate(Component const& component, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& param) { RealPolicies const& p = detail::real_policy::get( fusion::at_c<0>(component.elements)); bool result = real_inserter:: call(sink, param, p); karma::delimit(sink, d); // always do post-delimiting return result; } // this double_/float_/etc. has no parameter attached, it needs to have // been initialized from a direct literal template static bool generate(Component const&, OutputIterator&, Context&, Delimiter const&, unused_type) { BOOST_MPL_ASSERT_MSG(false, real_not_usable_without_parameter, (Component, Context)); return false; } template static std::string what(Component const& component, Context const& ctx) { return "real number"; } }; /////////////////////////////////////////////////////////////////////////// // This specialization is used for real generators having a direct // initializer: float_(10.), double_(20.) etc. /////////////////////////////////////////////////////////////////////////// template struct real_generator { template struct attribute { typedef unused_type type; }; template static bool generate(Component const& component, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& /*param*/) { RealPolicies const& p = detail::real_policy::get( fusion::at_c<0>(component.elements)); T n = fusion::at_c<1>(component.elements); bool result = real_inserter::call(sink, n, p); karma::delimit(sink, d); // always do post-delimiting return result; } template static std::string what(Component const& component, Context const& ctx) { return "real number"; } }; }}} namespace boost { namespace spirit { namespace traits { /////////////////////////////////////////////////////////////////////////// // lower_case real generator /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::real_generator, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename Modifier::char_set char_set; typedef spirit::char_class::tag::lower char_class_; typedef spirit::char_class::key key_tag; typedef typename fusion::result_of::value_at_c::type real_policy_type; typedef fusion::vector vector_type; typedef karma::real_generator real_type; typedef component type; static type call(Elements const& elements) { return type(elements); } }; template struct make_modified_component< Domain, karma::real_generator, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename Modifier::char_set char_set; typedef spirit::char_class::tag::lower char_class_; typedef spirit::char_class::key key_tag; typedef typename fusion::result_of::value_at_c::type real_policy_type; typedef typename fusion::result_of::value_at_c::type real_data_type; typedef fusion::vector vector_type; typedef karma::real_generator real_type; typedef component type; static type call(Elements const& elements) { return type(elements); } }; /////////////////////////////////////////////////////////////////////////// // lower_case real generator /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::real_generator, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename Modifier::char_set char_set; typedef spirit::char_class::tag::upper char_class_; typedef spirit::char_class::key key_tag; typedef typename fusion::result_of::value_at_c::type real_policy_type; typedef fusion::vector vector_type; typedef karma::real_generator real_type; typedef component type; static type call(Elements const& elements) { return type(elements); } }; template struct make_modified_component< Domain, karma::real_generator, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename Modifier::char_set char_set; typedef spirit::char_class::tag::upper char_class_; typedef spirit::char_class::key key_tag; typedef typename fusion::result_of::value_at_c::type real_policy_type; typedef typename fusion::result_of::value_at_c::type real_data_type; typedef fusion::vector vector_type; typedef karma::real_generator real_type; typedef component type; static type call(Elements const& elements) { return type(elements); } }; }}} // namespace boost::spirit::traits #endif // defined(BOOST_SPIRIT_KARMA_REAL_FEB_26_2007_0512PM)