regex_cursor.h

Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010 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  * You should not attempt to use it directly.
00029  */
00030 
00031 namespace std
00032 {
00033 namespace __regex
00034 {
00035   // ABC for pattern matching
00036   struct _PatternCursor
00037   {
00038     virtual ~_PatternCursor() { };
00039     virtual void _M_next() = 0;
00040     virtual bool _M_at_end() const = 0;
00041   };
00042 
00043   // Provides a cursor into the specific target string.
00044   template<typename _FwdIterT>
00045     class _SpecializedCursor
00046     : public _PatternCursor
00047     {
00048     public:
00049       _SpecializedCursor(const _FwdIterT& __b, const _FwdIterT __e)
00050       : _M_b(__b), _M_c(__b), _M_e(__e)
00051       { }
00052 
00053       typename std::iterator_traits<_FwdIterT>::value_type
00054       _M_current() const
00055       { return *_M_c; }
00056 
00057       void
00058       _M_next()
00059       { ++_M_c; }
00060 
00061       _FwdIterT
00062       _M_pos() const
00063       { return _M_c; }
00064 
00065       const _FwdIterT&
00066       _M_begin() const
00067       { return _M_b; }
00068 
00069       const _FwdIterT&
00070       _M_end() const
00071       { return _M_e; }
00072 
00073       bool
00074       _M_at_end() const
00075       { return _M_c == _M_e; }
00076 
00077     private:
00078       _FwdIterT _M_b;
00079       _FwdIterT _M_c;
00080       _FwdIterT _M_e;
00081     };
00082 
00083   // Helper funxtion to create a cursor specialized for an iterator class.
00084   template<typename _FwdIterT>
00085     inline _SpecializedCursor<_FwdIterT>
00086     __cursor(const _FwdIterT& __b, const _FwdIterT __e)
00087     { return _SpecializedCursor<_FwdIterT>(__b, __e); }
00088 
00089 } // namespace __regex
00090 } // namespace std
00091 
00092 /* vim: set ts=8 sw=2 sts=2: */