Back to home page

EIC code displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // as_inverse.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_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <boost/mpl/sizeof.hpp>
0017 #include <boost/mpl/not.hpp>
0018 #include <boost/xpressive/detail/detail_fwd.hpp>
0019 #include <boost/xpressive/detail/static/static.hpp>
0020 #include <boost/proto/core.hpp>
0021 
0022 #define UNCV(x) typename remove_const<x>::type
0023 #define UNREF(x) typename remove_reference<x>::type
0024 #define UNCVREF(x) UNCV(UNREF(x))
0025 
0026 namespace boost { namespace xpressive { namespace grammar_detail
0027 {
0028 
0029     template<typename T>
0030     struct inverter
0031     {
0032         typedef T type;
0033         static T call(T t)
0034         {
0035             t.inverse();
0036             return t;
0037         }
0038     };
0039 
0040     template<typename Traits, typename ICase, typename Not>
0041     struct inverter<detail::literal_matcher<Traits, ICase, Not> >
0042     {
0043         typedef detail::literal_matcher<Traits, ICase, typename mpl::not_<Not>::type> type;
0044         static type call(detail::literal_matcher<Traits, ICase, Not> t)
0045         {
0046             return type(t.ch_);
0047         }
0048     };
0049 
0050     template<typename Traits>
0051     struct inverter<detail::logical_newline_matcher<Traits> >
0052     {
0053         // ~_ln matches any one character that is not in the "newline" character class
0054         typedef detail::posix_charset_matcher<Traits> type;
0055         static type call(detail::logical_newline_matcher<Traits> t)
0056         {
0057             return type(t.newline(), true);
0058         }
0059     };
0060 
0061     template<typename Traits>
0062     struct inverter<detail::assert_word_matcher<detail::word_boundary<mpl::true_>, Traits> >
0063     {
0064         typedef detail::assert_word_matcher<detail::word_boundary<mpl::false_>, Traits> type;
0065         static type call(detail::assert_word_matcher<detail::word_boundary<mpl::true_>, Traits> t)
0066         {
0067             return type(t.word());
0068         }
0069     };
0070 
0071     struct as_inverse : proto::callable
0072     {
0073         template<typename Sig>
0074         struct result;
0075 
0076         template<typename This, typename Matcher>
0077         struct result<This(Matcher)>
0078           : inverter<UNCVREF(Matcher)>
0079         {};
0080 
0081         template<typename Matcher>
0082         typename inverter<Matcher>::type operator ()(Matcher const &matcher) const
0083         {
0084             return inverter<Matcher>::call(matcher);
0085         }
0086     };
0087 
0088 }}}
0089 
0090 #undef UNCV
0091 #undef UNREF
0092 #undef UNCVREF
0093 
0094 #endif