// 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_INT_FEB_23_2007_0840PM) #define BOOST_SPIRIT_KARMA_INT_FEB_23_2007_0840PM #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 #include namespace boost { namespace spirit { namespace karma { /////////////////////////////////////////////////////////////////////////// // This specialization is used for int generators not having a direct // initializer: int_, long_ etc. These generators must be used in // conjunction with a parameter. /////////////////////////////////////////////////////////////////////////// template struct int_generator { template struct attribute { typedef T type; }; // check template parameter 'Radix' for validity BOOST_MPL_ASSERT_MSG( Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16, not_supported_radix, ()); BOOST_MPL_ASSERT_MSG(std::numeric_limits::is_signed, signed_unsigned_mismatch, ()); // int has a parameter attached template static bool generate(Component const& /*component*/, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& param) { sign_inserter::call(sink, detail::is_zero(param), detail::is_negative(param)); bool result = int_inserter::call(sink, detail::absolute_value(param)); karma::delimit(sink, d); // always do post-delimiting return result; } // this int 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, int__not_usable_without_parameter, ()); return false; } template static std::string what(Component const& component, Context const& ctx) { return "integer"; } }; /////////////////////////////////////////////////////////////////////////// // This specialization is used for int generators having a direct // initializer: int_(10), long_(20) etc. /////////////////////////////////////////////////////////////////////////// template struct int_generator { template struct attribute { typedef unused_type type; }; // check template parameter 'Radix' for validity BOOST_MPL_ASSERT_MSG( Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16, not_supported_radix, ()); BOOST_MPL_ASSERT_MSG(std::numeric_limits::is_signed, signed_unsigned_mismatch, ()); template static bool generate(Component const& component, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& /*param*/) { T n = fusion::at_c<0>(component.elements); sign_inserter::call(sink, detail::is_zero(n), detail::is_negative(n)); bool result = int_inserter::call(sink, detail::absolute_value(n)); karma::delimit(sink, d); // always do post-delimiting return result; } template static std::string what(Component const& component, Context const& ctx) { return "integer"; } }; }}} namespace boost { namespace spirit { namespace traits { /////////////////////////////////////////////////////////////////////////// // lower_case int_generator generator /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::int_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 karma::int_generator int_type; typedef component type; static type call(Elements const&) { return type(fusion::nil()); } }; template struct make_modified_component< Domain, karma::int_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 int_data_type; typedef fusion::vector vector_type; typedef karma::int_generator int_type; typedef component type; static type call(Elements const& elements) { return type(elements); } }; /////////////////////////////////////////////////////////////////////////// // upper_case int_generator generator /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::int_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 karma::int_generator int_type; typedef component type; static type call(Elements const&) { return type(fusion::nil()); } }; template struct make_modified_component< Domain, karma::int_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 int_data_type; typedef fusion::vector vector_type; typedef karma::int_generator int_type; typedef component type; static type call(Elements const& elements) { return type(elements); } }; }}} // namespace boost::spirit::traits #endif