libstdc++
regex_cursor.h
Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010, 2011 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /**
00026  *  @file bits/regex_cursor.h
00027  *  This is an internal header file, included by other library headers.
00028  *  Do not attempt to use it directly. @headername{regex}
00029  */
00030 
00031 namespace std _GLIBCXX_VISIBILITY(default)
00032 {
00033 namespace __regex
00034 {
00035 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00036 
00037   // ABC for pattern matching
00038   struct _PatternCursor
00039   {
00040     virtual ~_PatternCursor() { };
00041     virtual void _M_next() = 0;
00042     virtual bool _M_at_end() const = 0;
00043   };
00044 
00045   // Provides a cursor into the specific target string.
00046   template<typename _FwdIterT>
00047     class _SpecializedCursor
00048     : public _PatternCursor
00049     {
00050     public:
00051       _SpecializedCursor(const _FwdIterT& __b, const _FwdIterT __e)
00052       : _M_b(__b), _M_c(__b), _M_e(__e)
00053       { }
00054 
00055       typename std::iterator_traits<_FwdIterT>::value_type
00056       _M_current() const
00057       { return *_M_c; }
00058 
00059       void
00060       _M_next()
00061       { ++_M_c; }
00062 
00063       _FwdIterT
00064       _M_pos() const
00065       { return _M_c; }
00066 
00067       const _FwdIterT&
00068       _M_begin() const
00069       { return _M_b; }
00070 
00071       const _FwdIterT&
00072       _M_end() const
00073       { return _M_e; }
00074 
00075       bool
00076       _M_at_end() const
00077       { return _M_c == _M_e; }
00078 
00079     private:
00080       _FwdIterT _M_b;
00081       _FwdIterT _M_c;
00082       _FwdIterT _M_e;
00083     };
00084 
00085   // Helper function to create a cursor specialized for an iterator class.
00086   template<typename _FwdIterT>
00087     inline _SpecializedCursor<_FwdIterT>
00088     __cursor(const _FwdIterT& __b, const _FwdIterT __e)
00089     { return _SpecializedCursor<_FwdIterT>(__b, __e); }
00090 
00091 _GLIBCXX_END_NAMESPACE_VERSION
00092 } // namespace __regex
00093 } // namespace