PageRenderTime 44ms CodeModel.GetById 13ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/qi/detail/parse_auto.hpp

http://pythonocc.googlecode.com/
C++ Header | 183 lines | 139 code | 20 blank | 24 comment | 0 complexity | d38bf7ffe6f9df7564b6bd19920a83dd MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2010 Hartmut Kaiser
  3
  4    Distributed under the Boost Software License, Version 1.0. (See accompanying
  5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6=============================================================================*/
  7#if !defined(BOOST_SPIRIT_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM)
  8#define BOOST_SPIRIT_DETAIL_PARSE_AUTO_DEC_02_2009_0426PM
  9
 10#if defined(_MSC_VER)
 11#pragma once
 12#endif
 13
 14#include <boost/spirit/home/qi/parse.hpp>
 15#include <boost/spirit/home/qi/auto/create_parser.hpp>
 16#include <boost/utility/enable_if.hpp>
 17#include <boost/mpl/not.hpp>
 18#include <boost/mpl/and.hpp>
 19
 20namespace boost { namespace spirit { namespace qi { namespace detail
 21{
 22    ///////////////////////////////////////////////////////////////////////////
 23    template <typename Expr>
 24    struct parse_impl<Expr
 25      , typename enable_if<traits::meta_create_exists<qi::domain, Expr> >::type>
 26    {
 27        template <typename Iterator>
 28        static bool call(Iterator& first, Iterator last, Expr& expr)
 29        {
 30            return qi::parse(first, last, create_parser<Expr>(), expr);
 31        }
 32
 33        template <typename Iterator>
 34        static bool call(Iterator& first, Iterator last, Expr const& expr)
 35        {
 36            return qi::parse(first, last, create_parser<Expr>()
 37              , const_cast<Expr&>(expr));
 38        }
 39    };
 40
 41    // the following specializations are needed to explicitly disambiguate 
 42    // the two possible specializations for parse_impl<char> and 
 43    // parse_impl<wchar_t>
 44    template <>
 45    struct parse_impl<char>
 46    {
 47        template <typename Iterator>
 48        static bool call(Iterator& first, Iterator last, char& expr)
 49        {
 50            return qi::parse(first, last, create_parser<char>(), expr);
 51        }
 52
 53        template <typename Iterator>
 54        static bool call(Iterator& first, Iterator last, char const&)
 55        {
 56            return qi::parse(first, last, create_parser<char>());
 57        }
 58    };
 59
 60    template <>
 61    struct parse_impl<wchar_t>
 62    {
 63        template <typename Iterator>
 64        static bool call(Iterator& first, Iterator last, wchar_t& expr)
 65        {
 66            return qi::parse(first, last, create_parser<wchar_t>(), expr);
 67        }
 68
 69        template <typename Iterator>
 70        static bool call(Iterator& first, Iterator last, wchar_t const&)
 71        {
 72            return qi::parse(first, last, create_parser<wchar_t>());
 73        }
 74    };
 75
 76    ///////////////////////////////////////////////////////////////////////////
 77    template <typename Expr>
 78    struct phrase_parse_impl<Expr
 79      , typename enable_if<traits::meta_create_exists<qi::domain, Expr> >::type>
 80    {
 81        template <typename Iterator, typename Skipper>
 82        static bool call(Iterator& first, Iterator last, Expr& expr
 83          , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
 84        {
 85            return qi::phrase_parse(first, last, create_parser<Expr>()
 86              , skipper, post_skip, expr);
 87        }
 88
 89        template <typename Iterator, typename Skipper>
 90        static bool call(Iterator& first, Iterator last, Expr const& expr
 91          , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
 92        {
 93            return qi::phrase_parse(first, last, create_parser<Expr>()
 94              , skipper, post_skip, const_cast<Expr&>(expr));
 95        }
 96    };
 97
 98    // the following specializations are needed to explicitly disambiguate 
 99    // the two possible specializations for phrase_parse_impl<char> and 
100    // phrase_parse_impl<wchar_t>
101    template <>
102    struct phrase_parse_impl<char>
103    {
104        template <typename Iterator, typename Skipper>
105        static bool call(Iterator& first, Iterator last, char& expr
106          , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
107        {
108            return qi::phrase_parse(first, last, create_parser<char>()
109              , skipper, post_skip, expr);
110        }
111
112        template <typename Iterator, typename Skipper>
113        static bool call(Iterator& first, Iterator last, char const&
114          , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
115        {
116            return qi::phrase_parse(first, last, create_parser<char>()
117              , skipper, post_skip);
118        }
119    };
120
121    template <>
122    struct phrase_parse_impl<wchar_t>
123    {
124        template <typename Iterator, typename Skipper>
125        static bool call(Iterator& first, Iterator last, wchar_t& expr
126          , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
127        {
128            return qi::phrase_parse(first, last, create_parser<wchar_t>()
129              , skipper, post_skip, expr);
130        }
131
132        template <typename Iterator, typename Skipper>
133        static bool call(Iterator& first, Iterator last, wchar_t const&
134          , Skipper const& skipper, BOOST_SCOPED_ENUM(skip_flag) post_skip)
135        {
136            return qi::phrase_parse(first, last, create_parser<wchar_t>()
137              , skipper, post_skip);
138        }
139    };
140}}}}
141
142namespace boost { namespace spirit { namespace qi
143{
144    ///////////////////////////////////////////////////////////////////////////
145    template <typename Iterator, typename Expr>
146    inline bool
147    parse(
148        Iterator& first
149      , Iterator last
150      , Expr& expr)
151    {
152        // Make sure the iterator is at least a forward_iterator. If you got a 
153        // compilation error here, then you are using an input_iterator while
154        // calling this function, you need to supply at least a 
155        // forward_iterator instead.
156        BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
157
158        return detail::parse_impl<Expr>::call(first, last, expr);
159    }
160
161    ///////////////////////////////////////////////////////////////////////////
162    template <typename Iterator, typename Expr, typename Skipper>
163    inline bool
164    phrase_parse(
165        Iterator& first
166      , Iterator last
167      , Expr& expr
168      , Skipper const& skipper
169      , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip)
170    {
171        // Make sure the iterator is at least a forward_iterator. If you got a 
172        // compilation error here, then you are using an input_iterator while
173        // calling this function, you need to supply at least a 
174        // forward_iterator instead.
175        BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>));
176
177        return detail::phrase_parse_impl<Expr>::call(
178            first, last, expr, skipper, post_skip);
179    }
180}}}
181
182#endif
183