1 /*=============================================================================
2 Copyright (c) 2002 Juan Carlos Arevalo-Baeza
3 Copyright (c) 2002-2006 Hartmut Kaiser
4 Copyright (c) 2003 Giovanni Bajo
5 http://spirit.sourceforge.net/
7 Use, modification and distribution is subject to the Boost Software
8 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 http://www.boost.org/LICENSE_1_0.txt)
10 =============================================================================*/
11 #ifndef POSITION_ITERATOR_IPP
12 #define POSITION_ITERATOR_IPP
14 #include <boost/config.hpp>
15 #include <boost/iterator_adaptors.hpp>
16 #include <boost/type_traits/add_const.hpp>
17 #include <boost/mpl/if.hpp>
18 #include <boost/type_traits/is_same.hpp>
19 #include <boost/spirit/home/classic/core/nil.hpp> // for nil_t
20 #include <boost/detail/iterator.hpp> // for boost::detail::iterator_traits
22 namespace boost { namespace spirit {
24 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
26 ///////////////////////////////////////////////////////////////////////////////
28 // position_policy<file_position_without_column>
30 // Specialization to handle file_position_without_column. Only take care of
31 // newlines since no column tracking is needed.
33 ///////////////////////////////////////////////////////////////////////////////
34 template <typename String>
35 class position_policy<file_position_without_column_base<String> > {
38 void next_line(file_position_without_column_base<String>& pos)
43 void set_tab_chars(unsigned int /*chars*/){}
44 void next_char(file_position_without_column_base<String>& /*pos*/) {}
45 void tabulation(file_position_without_column_base<String>& /*pos*/) {}
48 ///////////////////////////////////////////////////////////////////////////////
50 // position_policy<file_position>
52 // Specialization to handle file_position. Track characters and tabulation
53 // to compute the current column correctly.
55 // Default tab size is 4. You can change this with the set_tabchars member
56 // of position_iterator.
58 ///////////////////////////////////////////////////////////////////////////////
59 template <typename String>
60 class position_policy<file_position_base<String> > {
67 void next_line(file_position_base<String>& pos)
73 void set_tab_chars(unsigned int chars)
75 m_CharsPerTab = chars;
78 void next_char(file_position_base<String>& pos)
83 void tabulation(file_position_base<String>& pos)
85 pos.column += m_CharsPerTab - (pos.column - 1) % m_CharsPerTab;
89 unsigned int m_CharsPerTab;
92 /* namespace boost::spirit { */ namespace iterator_ { namespace impl {
94 ///////////////////////////////////////////////////////////////////////////////
96 // position_iterator_base_generator
98 // Metafunction to generate the iterator type using boost::iterator_adaptors,
99 // hiding all the metaprogramming thunking code in it. It is used
100 // mainly to keep the public interface (position_iterator) cleanear.
102 ///////////////////////////////////////////////////////////////////////////////
103 template <typename MainIterT, typename ForwardIterT, typename PositionT>
104 struct position_iterator_base_generator
107 typedef boost::detail::iterator_traits<ForwardIterT> traits;
108 typedef typename traits::value_type value_type;
109 typedef typename traits::iterator_category iter_category_t;
111 // Position iterator is always a non-mutable iterator
112 typedef typename boost::add_const<value_type>::type const_value_type;
115 // Check if the MainIterT is nil. If it's nil, it means that the actual
116 // self type is position_iterator. Otherwise, it's a real type we
118 typedef typename boost::mpl::if_<
119 typename boost::is_same<MainIterT, nil_t>::type,
120 position_iterator<ForwardIterT, PositionT, nil_t>,
124 typedef boost::iterator_adaptor<
128 boost::forward_traversal_tag
134 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
136 }} /* namespace boost::spirit::iterator_::impl */