• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////
2 // as_inverse.hpp
3 //
4 //  Copyright 2008 Eric Niebler. Distributed under the Boost
5 //  Software License, Version 1.0. (See accompanying file
6 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 
8 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007
9 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007
10 
11 // MS compatible compilers support #pragma once
12 #if defined(_MSC_VER)
13 # pragma once
14 #endif
15 
16 #include <boost/mpl/sizeof.hpp>
17 #include <boost/mpl/not.hpp>
18 #include <boost/xpressive/detail/detail_fwd.hpp>
19 #include <boost/xpressive/detail/static/static.hpp>
20 #include <boost/proto/core.hpp>
21 
22 #define UNCV(x) typename remove_const<x>::type
23 #define UNREF(x) typename remove_reference<x>::type
24 #define UNCVREF(x) UNCV(UNREF(x))
25 
26 namespace boost { namespace xpressive { namespace grammar_detail
27 {
28 
29     template<typename T>
30     struct inverter
31     {
32         typedef T type;
callboost::xpressive::grammar_detail::inverter33         static T call(T t)
34         {
35             t.inverse();
36             return t;
37         }
38     };
39 
40     template<typename Traits, typename ICase, typename Not>
41     struct inverter<detail::literal_matcher<Traits, ICase, Not> >
42     {
43         typedef detail::literal_matcher<Traits, ICase, typename mpl::not_<Not>::type> type;
callboost::xpressive::grammar_detail::inverter44         static type call(detail::literal_matcher<Traits, ICase, Not> t)
45         {
46             return type(t.ch_);
47         }
48     };
49 
50     template<typename Traits>
51     struct inverter<detail::logical_newline_matcher<Traits> >
52     {
53         // ~_ln matches any one character that is not in the "newline" character class
54         typedef detail::posix_charset_matcher<Traits> type;
callboost::xpressive::grammar_detail::inverter55         static type call(detail::logical_newline_matcher<Traits> t)
56         {
57             return type(t.newline(), true);
58         }
59     };
60 
61     template<typename Traits>
62     struct inverter<detail::assert_word_matcher<detail::word_boundary<mpl::true_>, Traits> >
63     {
64         typedef detail::assert_word_matcher<detail::word_boundary<mpl::false_>, Traits> type;
callboost::xpressive::grammar_detail::inverter65         static type call(detail::assert_word_matcher<detail::word_boundary<mpl::true_>, Traits> t)
66         {
67             return type(t.word());
68         }
69     };
70 
71     struct as_inverse : proto::callable
72     {
73         template<typename Sig>
74         struct result;
75 
76         template<typename This, typename Matcher>
77         struct result<This(Matcher)>
78           : inverter<UNCVREF(Matcher)>
79         {};
80 
81         template<typename Matcher>
operator ()boost::xpressive::grammar_detail::as_inverse82         typename inverter<Matcher>::type operator ()(Matcher const &matcher) const
83         {
84             return inverter<Matcher>::call(matcher);
85         }
86     };
87 
88 }}}
89 
90 #undef UNCV
91 #undef UNREF
92 #undef UNCVREF
93 
94 #endif
95