Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:51

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // transmogrify.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <cstring> // for std::strlen
0017 #include <boost/mpl/if.hpp>
0018 #include <boost/mpl/or.hpp>
0019 #include <boost/mpl/bool.hpp>
0020 #include <boost/mpl/assert.hpp>
0021 #include <boost/type_traits/is_same.hpp>
0022 #include <boost/xpressive/detail/detail_fwd.hpp>
0023 #include <boost/xpressive/detail/core/matchers.hpp>
0024 #include <boost/xpressive/detail/static/placeholders.hpp>
0025 #include <boost/xpressive/detail/utility/dont_care.hpp>
0026 #include <boost/xpressive/detail/utility/traits_utils.hpp>
0027 
0028 namespace boost { namespace xpressive { namespace detail
0029 {
0030     template<typename T, typename Char>
0031     struct is_char_literal
0032       : mpl::or_<is_same<T, Char>, is_same<T, char> >
0033     {};
0034 
0035     ///////////////////////////////////////////////////////////////////////////////
0036     // transmogrify
0037     //
0038     template<typename BidiIter, typename ICase, typename Traits, typename Matcher, typename EnableIf = void>
0039     struct default_transmogrify
0040     {
0041         typedef typename Traits::char_type char_type;
0042         typedef typename Traits::string_type string_type;
0043 
0044         typedef typename mpl::if_c
0045         <
0046             is_char_literal<Matcher, char_type>::value
0047           , literal_matcher<Traits, ICase, mpl::false_>
0048           , string_matcher<Traits, ICase>
0049         >::type type;
0050 
0051         template<typename Matcher2, typename Visitor>
0052         static type call(Matcher2 const &m, Visitor &visitor)
0053         {
0054             return default_transmogrify::call_(m, visitor, is_char_literal<Matcher2, char_type>());
0055         }
0056 
0057         template<typename Matcher2, typename Visitor>
0058         static type call_(Matcher2 const &m, Visitor &visitor, mpl::true_)
0059         {
0060             char_type ch = char_cast<char_type>(m, visitor.traits());
0061             return type(ch, visitor.traits());
0062         }
0063 
0064         template<typename Matcher2, typename Visitor>
0065         static type call_(Matcher2 const &m, Visitor &visitor, mpl::false_)
0066         {
0067             string_type str = string_cast<string_type>(m, visitor.traits());
0068             return type(str, visitor.traits());
0069         }
0070     };
0071 
0072     template<typename BidiIter, typename ICase, typename Traits, typename Matcher>
0073     struct default_transmogrify<BidiIter, ICase, Traits, Matcher, typename Matcher::is_boost_xpressive_xpression_>
0074     {
0075         typedef Matcher type;
0076 
0077         template<typename Matcher2>
0078         static Matcher2 const &call(Matcher2 const &m, dont_care)
0079         {
0080             return m;
0081         }
0082     };
0083 
0084     template<typename BidiIter, typename ICase, typename Traits, typename Matcher>
0085     struct transmogrify
0086       : default_transmogrify<BidiIter, ICase, Traits, Matcher>
0087     {};
0088 
0089     template<typename BidiIter, typename ICase, typename Traits>
0090     struct transmogrify<BidiIter, ICase, Traits, assert_bol_placeholder >
0091     {
0092         typedef assert_bol_matcher<Traits> type;
0093 
0094         template<typename Matcher2, typename Visitor>
0095         static type call(Matcher2, Visitor &visitor)
0096         {
0097             return type(visitor.traits());
0098         }
0099     };
0100 
0101     template<typename BidiIter, typename ICase, typename Traits>
0102     struct transmogrify<BidiIter, ICase, Traits, assert_eol_placeholder >
0103     {
0104         typedef assert_eol_matcher<Traits> type;
0105 
0106         template<typename Matcher2, typename Visitor>
0107         static type call(Matcher2, Visitor &visitor)
0108         {
0109             return type(visitor.traits());
0110         }
0111     };
0112 
0113     template<typename BidiIter, typename ICase, typename Traits>
0114     struct transmogrify<BidiIter, ICase, Traits, logical_newline_placeholder >
0115     {
0116         typedef logical_newline_matcher<Traits> type;
0117 
0118         template<typename Matcher2, typename Visitor>
0119         static type call(Matcher2, Visitor &visitor)
0120         {
0121             return type(visitor.traits());
0122         }
0123     };
0124 
0125     template<typename BidiIter, typename ICase, typename Traits, typename Char>
0126     struct transmogrify<BidiIter, ICase, Traits, range_placeholder<Char> >
0127     {
0128         // By design, we don't widen character ranges.
0129         typedef typename iterator_value<BidiIter>::type char_type;
0130         BOOST_MPL_ASSERT((is_same<Char, char_type>));
0131         typedef range_matcher<Traits, ICase> type;
0132 
0133         template<typename Matcher2, typename Visitor>
0134         static type call(Matcher2 const &m, Visitor &visitor)
0135         {
0136             return type(m.ch_min_, m.ch_max_, m.not_, visitor.traits());
0137         }
0138     };
0139 
0140     template<typename BidiIter, typename ICase, typename Traits>
0141     struct transmogrify<BidiIter, ICase, Traits, mark_placeholder >
0142     {
0143         typedef mark_matcher<Traits, ICase> type;
0144 
0145         template<typename Matcher2, typename Visitor>
0146         static type call(Matcher2 const &m, Visitor &visitor)
0147         {
0148             return type(m.mark_number_, visitor.traits());
0149         }
0150     };
0151 
0152     template<typename BidiIter, typename ICase, typename Traits>
0153     struct transmogrify<BidiIter, ICase, Traits, posix_charset_placeholder >
0154     {
0155         typedef posix_charset_matcher<Traits> type;
0156 
0157         template<typename Matcher2, typename Visitor>
0158         static type call(Matcher2 const &m, Visitor &visitor)
0159         {
0160             char const *name_end = m.name_ + std::strlen(m.name_);
0161             return type(visitor.traits().lookup_classname(m.name_, name_end, ICase::value), m.not_);
0162         }
0163     };
0164 
0165     template<typename BidiIter, typename Traits, typename Size>
0166     struct transmogrify<BidiIter, mpl::true_, Traits, set_matcher<Traits, Size> >
0167     {
0168         typedef set_matcher<Traits, Size> type;
0169 
0170         template<typename Matcher2, typename Visitor>
0171         static type call(Matcher2 m, Visitor &visitor)
0172         {
0173             m.nocase(visitor.traits());
0174             return m;
0175         }
0176     };
0177 
0178     template<typename BidiIter, typename ICase, typename Traits, typename Cond>
0179     struct transmogrify<BidiIter, ICase, Traits, assert_word_placeholder<Cond> >
0180     {
0181         typedef assert_word_matcher<Cond, Traits> type;
0182 
0183         template<typename Visitor>
0184         static type call(dont_care, Visitor &visitor)
0185         {
0186             return type(visitor.traits());
0187         }
0188     };
0189 
0190     template<typename BidiIter, typename ICase, typename Traits>
0191     struct transmogrify<BidiIter, ICase, Traits, reference_wrapper<basic_regex<BidiIter> > >
0192     {
0193         typedef regex_byref_matcher<BidiIter> type;
0194 
0195         template<typename Matcher2>
0196         static type call(Matcher2 const &m, dont_care)
0197         {
0198             return type(detail::core_access<BidiIter>::get_regex_impl(m.get()));
0199         }
0200     };
0201 
0202     template<typename BidiIter, typename ICase, typename Traits>
0203     struct transmogrify<BidiIter, ICase, Traits, reference_wrapper<basic_regex<BidiIter> const> >
0204     {
0205         typedef regex_byref_matcher<BidiIter> type;
0206 
0207         template<typename Matcher2>
0208         static type call(Matcher2 const &m, dont_care)
0209         {
0210             return type(detail::core_access<BidiIter>::get_regex_impl(m.get()));
0211         }
0212     };
0213 
0214     template<typename BidiIter, typename ICase, typename Traits>
0215     struct transmogrify<BidiIter, ICase, Traits, tracking_ptr<regex_impl<BidiIter> > >
0216     {
0217         typedef regex_matcher<BidiIter> type;
0218 
0219         template<typename Matcher2>
0220         static type call(Matcher2 const &m, dont_care)
0221         {
0222             return type(m.get());
0223         }
0224     };
0225 
0226     template<typename BidiIter, typename ICase, typename Traits>
0227     struct transmogrify<BidiIter, ICase, Traits, self_placeholder >
0228     {
0229         typedef regex_byref_matcher<BidiIter> type;
0230 
0231         template<typename Matcher2, typename Visitor>
0232         static type call(Matcher2, Visitor &visitor)
0233         {
0234             return type(visitor.self());
0235         }
0236     };
0237 
0238 }}}
0239 
0240 #endif