PageRenderTime 97ms CodeModel.GetById 89ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/spirit/home/lex/lexer/lexertl/iterator.hpp

http://hadesmem.googlecode.com/
C++ Header | 121 lines | 77 code | 19 blank | 25 comment | 1 complexity | 9a314a1caf1cce96af8a17108f89678c MD5 | raw file
  1//  Copyright (c) 2001-2011 Hartmut Kaiser
  2// 
  3//  Distributed under the Boost Software License, Version 1.0. (See accompanying 
  4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5
  6#if !defined(BOOST_SPIRIT_LEX_LEXER_ITERATOR_MAR_16_2007_0353PM)
  7#define BOOST_SPIRIT_LEX_LEXER_ITERATOR_MAR_16_2007_0353PM
  8
  9#if defined(_MSC_VER)
 10#pragma once
 11#endif
 12
 13#if defined(BOOST_SPIRIT_DEBUG)
 14#include <boost/spirit/home/support/iterators/detail/buf_id_check_policy.hpp>
 15#else
 16#include <boost/spirit/home/support/iterators/detail/no_check_policy.hpp>
 17#endif
 18#include <boost/spirit/home/support/iterators/detail/split_functor_input_policy.hpp>
 19#include <boost/spirit/home/support/iterators/detail/ref_counted_policy.hpp>
 20#include <boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp>
 21#include <boost/spirit/home/support/iterators/multi_pass.hpp>
 22
 23namespace boost { namespace spirit { namespace lex { namespace lexertl
 24{ 
 25    ///////////////////////////////////////////////////////////////////////////
 26    template <typename FunctorData>
 27    struct make_multi_pass
 28    {
 29        // Divide the given functor type into its components (unique and 
 30        // shared) and build a std::pair from these parts
 31        typedef std::pair<typename FunctorData::unique
 32          , typename FunctorData::shared> functor_data_type;
 33
 34        // This is the result type returned from the iterator
 35        typedef typename FunctorData::result_type result_type;
 36
 37        // Compose the multi_pass iterator policy type from the appropriate 
 38        // policies
 39        typedef iterator_policies::split_functor_input input_policy;
 40        typedef iterator_policies::ref_counted ownership_policy;
 41#if defined(BOOST_SPIRIT_DEBUG)
 42        typedef iterator_policies::buf_id_check check_policy;
 43#else
 44        typedef iterator_policies::no_check check_policy;
 45#endif
 46        typedef iterator_policies::split_std_deque storage_policy;
 47
 48        typedef iterator_policies::default_policy<
 49                ownership_policy, check_policy, input_policy, storage_policy>
 50            policy_type;
 51
 52        // Compose the multi_pass iterator from the policy
 53        typedef spirit::multi_pass<functor_data_type, policy_type> type;
 54    };
 55
 56    ///////////////////////////////////////////////////////////////////////////
 57    //  lexer_iterator exposes an iterator for a lexertl based dfa (lexer) 
 58    //  The template parameters have the same semantics as described for the
 59    //  functor above.
 60    ///////////////////////////////////////////////////////////////////////////
 61    template <typename Functor>
 62    class iterator : public make_multi_pass<Functor>::type
 63    {
 64    public:
 65        typedef typename Functor::unique unique_functor_type;
 66        typedef typename Functor::shared shared_functor_type;
 67
 68        typedef typename Functor::iterator_type base_iterator_type;
 69        typedef typename Functor::result_type token_type;
 70
 71    private:
 72        typedef typename make_multi_pass<Functor>::functor_data_type 
 73            functor_type;
 74        typedef typename make_multi_pass<Functor>::type base_type;
 75        typedef typename Functor::char_type char_type;
 76
 77    public:
 78        // create a new iterator encapsulating the lexer object to be used
 79        // for tokenization
 80        template <typename IteratorData>
 81        iterator(IteratorData const& iterdata_, base_iterator_type& first
 82              , base_iterator_type const& last, char_type const* state = 0)
 83          : base_type(functor_type(unique_functor_type()
 84              , shared_functor_type(iterdata_, first, last))) 
 85        {
 86            set_state(map_state(state));
 87        }
 88
 89        // create an end iterator usable for end of range checking
 90        iterator() {}
 91
 92        // (wash): < mgaunard> T it; T it2 = ++it; doesn't ocmpile
 93        //         < mgaunard> this gets fixed by adding
 94        iterator(const base_type& base)
 95          : base_type(base) { }
 96
 97        // set the new required state for the underlying lexer object
 98        std::size_t set_state(std::size_t state)
 99        {
100            return unique_functor_type::set_state(*this, state);
101        }
102
103        // get the curent state for the underlying lexer object
104        std::size_t get_state()
105        {
106            return unique_functor_type::get_state(*this);
107        }
108
109        // map the given state name to a corresponding state id as understood
110        // by the underlying lexer object
111        std::size_t map_state(char_type const* statename)
112        {
113            return (0 != statename) 
114              ? unique_functor_type::map_state(*this, statename)
115              : 0;
116        }
117    };
118
119}}}}
120
121#endif