/////////////////////////////////////////////////////////////////////////////// // transmogrify.hpp // // Copyright 2008 Eric Niebler. 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) #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005 // MS compatible compilers support #pragma once #if defined(_MSC_VER) # pragma once #endif #include // for std::strlen #include #include #include #include #include #include #include #include #include #include namespace boost { namespace xpressive { namespace detail { template struct is_char_literal : mpl::or_, is_same > {}; /////////////////////////////////////////////////////////////////////////////// // transmogrify // template struct default_transmogrify { typedef typename Traits::char_type char_type; typedef typename Traits::string_type string_type; typedef typename mpl::if_c < is_char_literal::value , literal_matcher , string_matcher >::type type; template static type call(Matcher2 const &m, Visitor &visitor) { return default_transmogrify::call_(m, visitor, is_char_literal()); } template static type call_(Matcher2 const &m, Visitor &visitor, mpl::true_) { char_type ch = char_cast(m, visitor.traits()); return type(ch, visitor.traits()); } template static type call_(Matcher2 const &m, Visitor &visitor, mpl::false_) { string_type str = string_cast(m, visitor.traits()); return type(str, visitor.traits()); } }; template struct default_transmogrify { typedef Matcher type; template static Matcher2 const &call(Matcher2 const &m, dont_care) { return m; } }; template struct transmogrify : default_transmogrify {}; template struct transmogrify { typedef assert_bol_matcher type; template static type call(Matcher2, Visitor &visitor) { return type(visitor.traits()); } }; template struct transmogrify { typedef assert_eol_matcher type; template static type call(Matcher2, Visitor &visitor) { return type(visitor.traits()); } }; template struct transmogrify { typedef logical_newline_matcher type; template static type call(Matcher2, Visitor &visitor) { return type(visitor.traits()); } }; template struct transmogrify > { // By design, we don't widen character ranges. typedef typename iterator_value::type char_type; BOOST_MPL_ASSERT((is_same)); typedef range_matcher type; template static type call(Matcher2 const &m, Visitor &visitor) { return type(m.ch_min_, m.ch_max_, m.not_, visitor.traits()); } }; template struct transmogrify { typedef mark_matcher type; template static type call(Matcher2 const &m, Visitor &visitor) { return type(m.mark_number_, visitor.traits()); } }; template struct transmogrify { typedef posix_charset_matcher type; template static type call(Matcher2 const &m, Visitor &visitor) { char const *name_end = m.name_ + std::strlen(m.name_); return type(visitor.traits().lookup_classname(m.name_, name_end, ICase::value), m.not_); } }; template struct transmogrify > { typedef set_matcher type; template static type call(Matcher2 m, Visitor &visitor) { m.nocase(visitor.traits()); return m; } }; template struct transmogrify > { typedef assert_word_matcher type; template static type call(dont_care, Visitor &visitor) { return type(visitor.traits()); } }; template struct transmogrify > > { typedef regex_byref_matcher type; template static type call(Matcher2 const &m, dont_care) { return type(detail::core_access::get_regex_impl(m.get())); } }; template struct transmogrify const> > { typedef regex_byref_matcher type; template static type call(Matcher2 const &m, dont_care) { return type(detail::core_access::get_regex_impl(m.get())); } }; template struct transmogrify > > { typedef regex_matcher type; template static type call(Matcher2 const &m, dont_care) { return type(m.get()); } }; template struct transmogrify { typedef regex_byref_matcher type; template static type call(Matcher2, Visitor &visitor) { return type(visitor.self()); } }; }}} #endif