Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-28 09:59:46

0001 /*=============================================================================
0002     Copyright (c) 2002 Juan Carlos Arevalo-Baeza
0003     Copyright (c) 2002-2006 Hartmut Kaiser
0004     Copyright (c) 2003 Giovanni Bajo
0005     http://spirit.sourceforge.net/
0006 
0007     Use, modification and distribution is subject to the Boost Software
0008     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0009     http://www.boost.org/LICENSE_1_0.txt)
0010 =============================================================================*/
0011 #ifndef BOOST_SPIRIT_CLASSIC_ITERATOR_IMPL_POSITION_ITERATOR_IPP
0012 #define BOOST_SPIRIT_CLASSIC_ITERATOR_IMPL_POSITION_ITERATOR_IPP
0013 
0014 #include <boost/config.hpp>
0015 #include <boost/iterator_adaptors.hpp>
0016 #include <boost/type_traits/add_const.hpp>
0017 #include <boost/mpl/if.hpp>
0018 #include <boost/type_traits/is_same.hpp>
0019 #include <boost/spirit/home/classic/core/nil.hpp>  // for nil_t
0020 #include <iterator> // for std::iterator_traits
0021 
0022 namespace boost { namespace spirit {
0023 
0024 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0025 
0026 ///////////////////////////////////////////////////////////////////////////////
0027 //
0028 //  position_policy<file_position_without_column>
0029 //
0030 //  Specialization to handle file_position_without_column. Only take care of
0031 //  newlines since no column tracking is needed.
0032 //
0033 ///////////////////////////////////////////////////////////////////////////////
0034 template <typename String>
0035 class position_policy<file_position_without_column_base<String> > {
0036 
0037 public:
0038     void next_line(file_position_without_column_base<String>& pos)
0039     {
0040         ++pos.line;
0041     }
0042 
0043     void set_tab_chars(unsigned int /*chars*/){}
0044     void next_char(file_position_without_column_base<String>& /*pos*/)    {}
0045     void tabulation(file_position_without_column_base<String>& /*pos*/)   {}
0046 };
0047 
0048 ///////////////////////////////////////////////////////////////////////////////
0049 //
0050 //  position_policy<file_position>
0051 //
0052 //  Specialization to handle file_position. Track characters and tabulation
0053 //  to compute the current column correctly.
0054 //
0055 //  Default tab size is 4. You can change this with the set_tabchars member
0056 //  of position_iterator.
0057 //
0058 ///////////////////////////////////////////////////////////////////////////////
0059 template <typename String>
0060 class position_policy<file_position_base<String> > {
0061 
0062 public:
0063     position_policy()
0064         : m_CharsPerTab(4)
0065     {}
0066 
0067     void next_line(file_position_base<String>& pos)
0068     {
0069         ++pos.line;
0070         pos.column = 1;
0071     }
0072 
0073     void set_tab_chars(unsigned int chars)
0074     {
0075         m_CharsPerTab = chars;
0076     }
0077 
0078     void next_char(file_position_base<String>& pos)
0079     {
0080         ++pos.column;
0081     }
0082 
0083     void tabulation(file_position_base<String>& pos)
0084     {
0085         pos.column += m_CharsPerTab - (pos.column - 1) % m_CharsPerTab;
0086     }
0087 
0088 private:
0089     unsigned int m_CharsPerTab;
0090 };
0091 
0092 /* namespace boost::spirit { */ namespace iterator_ { namespace impl {
0093 
0094 template <typename T>
0095 struct make_const : boost::add_const<T>
0096 {};
0097 
0098 template <typename T>
0099 struct make_const<T&>
0100 {
0101     typedef typename boost::add_const<T>::type& type;
0102 };
0103 
0104 ///////////////////////////////////////////////////////////////////////////////
0105 //
0106 //  position_iterator_base_generator
0107 //
0108 //  Metafunction to generate the iterator type using boost::iterator_adaptors,
0109 //  hiding all the metaprogramming thunking code in it. It is used
0110 //  mainly to keep the public interface (position_iterator) cleanear.
0111 //
0112 ///////////////////////////////////////////////////////////////////////////////
0113 template <typename MainIterT, typename ForwardIterT, typename PositionT>
0114 struct position_iterator_base_generator
0115 {
0116 private:
0117     typedef std::iterator_traits<ForwardIterT> traits;
0118     typedef typename traits::value_type value_type;
0119     typedef typename traits::iterator_category iter_category_t;
0120     typedef typename traits::reference reference;
0121 
0122     // Position iterator is always a non-mutable iterator
0123     typedef typename boost::add_const<value_type>::type const_value_type;
0124 
0125 public:
0126     // Check if the MainIterT is nil. If it's nil, it means that the actual
0127     //  self type is position_iterator. Otherwise, it's a real type we
0128     //  must use
0129     typedef typename boost::mpl::if_<
0130         typename boost::is_same<MainIterT, nil_t>::type,
0131         position_iterator<ForwardIterT, PositionT, nil_t>,
0132         MainIterT
0133     >::type main_iter_t;
0134 
0135     typedef boost::iterator_adaptor<
0136         main_iter_t,
0137         ForwardIterT,
0138         const_value_type,
0139         boost::forward_traversal_tag,
0140         typename make_const<reference>::type
0141     > type;
0142 };
0143 
0144 }}
0145 
0146 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0147 
0148 }} /* namespace boost::spirit::iterator_::impl */
0149 
0150 #endif