PageRenderTime 29ms CodeModel.GetById 17ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/spirit/repository/home/qi/operator/detail/keywords.hpp

http://hadesmem.googlecode.com/
C++ Header | 115 lines | 88 code | 14 blank | 13 comment | 2 complexity | 0e89cc4b3b53c29cfdd8808543732707 MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2011 Joel de Guzman
  3    Copyright (c) 2011 Thomas Bernard
  4
  5    Distributed under the Boost Software License, Version 1.0. (See accompanying
  6    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7=============================================================================*/
  8#if !defined(SPIRIT_KEYWORDS_DETAIL_MARCH_13_2007_1145PM)
  9#define SPIRIT_KEYWORDS_DETAIL_MARCH_13_2007_1145PM
 10
 11#if defined(_MSC_VER)
 12#pragma once
 13#endif
 14
 15namespace boost { namespace spirit { namespace repository { namespace qi { namespace detail {
 16        
 17        // This helper class enables jumping over intermediate directives 
 18        // down the kwd parser iteration count checking policy
 19        struct register_successful_parse
 20        {
 21            template <typename Subject>
 22            static bool call(Subject const &subject,bool &flag, int &counter)
 23            {
 24                return subject.iter.register_successful_parse(flag,counter);
 25            }
 26            template <typename Subject, typename Action>
 27            static bool call(spirit::qi::action<Subject, Action> const &subject,bool &flag, int &counter)
 28            {
 29                return subject.subject.iter.register_successful_parse(flag,counter);
 30            }
 31            template <typename Subject>
 32            static bool call(spirit::qi::hold_directive<Subject> const &subject,bool &flag, int &counter)
 33            {
 34                return subject.subject.iter.register_successful_parse(flag,counter);
 35            }
 36        };
 37        // Variant visitor class which handles dispatching the parsing to the selected parser
 38        // This also handles passing the correct attributes and flags/counters to the subject parsers       
 39 
 40        template < typename Elements, typename Iterator ,typename Context ,typename Skipper
 41                  ,typename Flags ,typename Counters ,typename Attribute, typename NoCasePass>
 42        class parse_dispatcher
 43            : public boost::static_visitor<bool>
 44        {
 45            public:
 46            parse_dispatcher(const Elements &elements,Iterator& first, Iterator const& last
 47          , Context& context, Skipper const& skipper
 48          , Flags &flags, Counters &counters, Attribute& attr) : 
 49                 elements(elements), first(first), last(last)
 50               , context(context), skipper(skipper)
 51               , flags(flags),counters(counters), attr(attr)
 52            {}
 53            
 54            template<typename T> bool operator()(T& idx) const
 55            {    
 56                return call(idx,typename traits::not_is_unused<Attribute>::type());
 57            }
 58            
 59            template <typename Subject,typename Index> 
 60            bool call_subject_unused(
 61                  Subject const &subject, Iterator &first, Iterator const &last
 62                , Context& context, Skipper const& skipper
 63                , Index& idx ) const
 64            {
 65                Iterator save = first;
 66                skipper_keyword_marker<Skipper,NoCasePass> marked_skipper(skipper,flags[Index::value],counters[Index::value]);
 67                
 68                if(subject.parse(first,last,context,marked_skipper,unused))
 69                {
 70                        return true;
 71                }
 72                save = save;
 73                return false;
 74            }            
 75 
 76            
 77            template <typename Subject,typename Index> 
 78            bool call_subject(
 79                  Subject const &subject, Iterator &first, Iterator const &last
 80                , Context& context, Skipper const& skipper
 81                , Index& idx ) const
 82            {
 83               
 84                Iterator save = first;
 85                skipper_keyword_marker<Skipper,NoCasePass> marked_skipper(skipper,flags[Index::value],counters[Index::value]);
 86                if(subject.parse(first,last,context,marked_skipper,fusion::at_c<Index::value>(attr)))
 87                {
 88                        return true;
 89                }
 90                save = save;
 91                return false;
 92            }
 93
 94            // Handle unused attributes
 95            template <typename T> bool call(T &idx, mpl::false_) const{                            
 96                return call_subject_unused(fusion::at_c<T::value>(elements), first, last, context, skipper, idx );
 97            }
 98            // Handle normal attributes
 99            template <typename T> bool call(T &idx, mpl::true_) const{
100                return call_subject(fusion::at_c<T::value>(elements), first, last, context, skipper, idx);
101            }
102            
103            const Elements &elements;
104            Iterator &first;
105            const Iterator &last;
106            Context & context;
107            const Skipper &skipper;
108            Flags &flags;
109            Counters &counters;
110            Attribute &attr;
111        };
112      
113}}}}}
114
115#endif