// 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_CHAR_FEB_21_2007_0543PM) #define BOOST_SPIRIT_KARMA_CHAR_FEB_21_2007_0543PM #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 #include #include #include namespace boost { namespace spirit { namespace karma { /////////////////////////////////////////////////////////////////////////// // // any_char // generates a single character from the associated parameter // // Note: this generator has to have an associated parameter // /////////////////////////////////////////////////////////////////////////// template struct any_char { template struct attribute { typedef Char type; }; // any_char has a parameter attached template static bool generate(Component const&, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& param) { detail::generate_to(sink, param); karma::delimit(sink, d); // always do post-delimiting return true; } // this any_char 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, char__not_usable_without_parameter, ()); return false; } template static std::string what(Component const& component, Context const& ctx) { return "any-char"; } }; /////////////////////////////////////////////////////////////////////////// // // literal_char // generates a single character given by a literal it was initialized // from // /////////////////////////////////////////////////////////////////////////// template struct literal_char { template struct attribute { typedef unused_type type; }; // any_char has a parameter attached template static bool generate(Component const& component, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& /*param*/) { detail::generate_to(sink, fusion::at_c<0>(component.elements)); karma::delimit(sink, d); // always do post-delimiting return true; } template static std::string what(Component const& component, Context const& ctx) { return std::string("'") + spirit::detail::to_narrow_char( fusion::at_c<0>(component.elements)) + '\''; } }; /////////////////////////////////////////////////////////////////////////// // // lazy_char // generates a single character given by a functor it was initialized // from // /////////////////////////////////////////////////////////////////////////// struct lazy_char { template struct attribute { typedef unused_type type; }; // any_char has a parameter attached template static bool generate(Component const& component, OutputIterator& sink, Context& ctx, Delimiter const& d, Parameter const& /*param*/) { detail::generate_to(sink, fusion::at_c<0>(component.elements)(unused, ctx)); karma::delimit(sink, d); // always do post-delimiting return true; } template static std::string what(Component const& component, Context const& ctx) { return "char"; } }; /////////////////////////////////////////////////////////////////////////// // // lower and upper case variants of any_char with an associated parameter // note: this generator has to have a parameter associated // /////////////////////////////////////////////////////////////////////////// template struct case_any_char { template struct attribute { typedef Char type; }; typedef typename Tag::char_set char_set; typedef typename Tag::char_class char_class_; // case_any_char has a parameter attached template static bool generate(Component const& /*component*/, OutputIterator& sink, Context& /*ctx*/, Delimiter const& d, Parameter const& param) { using spirit::char_class::convert; Char p = convert::to(char_class_(), param); detail::generate_to(sink, p); karma::delimit(sink, d); // always do post-delimiting return true; } // this case_any_char 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, char__not_usable_without_parameter, ()); return false; } template static std::string what(Component const& component, Context const& ctx) { std::string result; result = std::string("any-") + spirit::char_class::what::is(char_class_()) + "case-char"; return result; } }; }}} // namespace boost::spirit::karma namespace boost { namespace spirit { namespace traits { /////////////////////////////////////////////////////////////////////////// // lower_case and upper_case any_char and literal_char generators /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::literal_char, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename fusion::result_of::value_at_c::type char_type; typedef fusion::vector vector_type; typedef component< karma::domain, karma::literal_char, vector_type> type; static type call(Elements const& elements) { typedef typename Modifier::char_set char_set; char_type ch = fusion::at_c<0>(elements); vector_type v(char_set::tolower(ch)); return type(v); } }; template struct make_modified_component< Domain, karma::literal_char, Elements, Modifier, typename enable_if< is_member_of_modifier >::type > { typedef typename fusion::result_of::value_at_c::type char_type; typedef fusion::vector vector_type; typedef component, vector_type> type; static type call(Elements const& elements) { typedef typename Modifier::char_set char_set; char_type ch = fusion::at_c<0>(elements); vector_type v(char_set::toupper(ch)); return type(v); } }; /////////////////////////////////////////////////////////////////////////// // lower_case and upper case_any_char conversions /////////////////////////////////////////////////////////////////////////// template struct make_modified_component< Domain, karma::any_char, 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 component< karma::domain, karma::case_any_char, fusion::nil> type; static type call(Elements const&) { return type(fusion::nil()); } }; template struct make_modified_component< Domain, karma::any_char, 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 component< karma::domain, karma::case_any_char, fusion::nil> type; static type call(Elements const&) { return type(fusion::nil()); } }; }}} // namespace boost::spirit::traits #endif // !defined(BOOST_SPIRIT_KARMA_CHAR_FEB_21_2007_0543PM)