Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

matches.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Radko Mihal                                     *
00003  *   rmihal@pobox.sk                                                       *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
00019  ***************************************************************************/
00020 #ifndef EXTENDED_REGULAR_EXPRESSIONMATCHES_H
00021 #define EXTENDED_REGULAR_EXPRESSIONMATCHES_H
00022 
00023 namespace extended_regular_expression {
00024 
00025 
00026 class matches
00027 {
00028 public:
00029         
00030 typedef std::map<std::string, match>                    matches_coll;
00031 typedef matches_coll::key_type                                  match_key;
00032 typedef matches_coll::value_type                                match_value;
00033 typedef std::list<match>                                                matches_ret_coll;
00034 
00035 protected:
00036         matches_coll                                                            m_matches;
00037 
00038 public: 
00039         void insert( match_key key, match value )
00040         {
00041                 m_matches.insert( match_value( key, value ) );
00042                 
00043         }
00044         
00045         match get( match_key key )
00046         {
00047                 matches_coll::iterator it = m_matches.find( key );
00048                 if( it != m_matches.end() )
00049                 {
00050                         return (*it).second;
00051                 }
00052                 else
00053                 {
00054                         return match(); // with return match, which is not valid (its 
00055                                                         // is_valid() returns false)
00056                 }
00057         }
00058         
00059         void get_all(matches_ret_coll& l)
00060         {
00061                 matches_coll::iterator it = m_matches.begin();
00062                 while( it != m_matches.end() )
00063                 {
00064                         l.push_back( (*it).second );
00065                         it++;
00066                 }
00067         }
00068         
00069         void get_all(matches_coll& m)
00070         {
00071                 m = m_matches;
00072         }
00073         
00074         void clear()
00075         {
00076                 m_matches.clear();
00077         }
00078         
00079         void extend( matches::match_key parent_key, 
00080                                 matches& sub_matches )
00081         {
00082                 matches_coll ret_coll;
00083                 sub_matches.get_all( ret_coll );
00084                 
00085                 matches_coll::iterator it = ret_coll.begin();
00086                 while( it != ret_coll.end() )
00087                 {
00088                         matches::match_key new_key = parent_key;
00089                         new_key += (*it).first; // the key if (*it).first must begin with dot
00090                         insert( new_key, (*it).second );
00091                         it++;
00092                 }
00093         }
00094         
00095     matches() {};
00096     ~matches() {};
00097 
00098 };
00099 
00100 };
00101 
00102 #endif

Generated on Sun Jul 2 18:39:43 2006 for grammar2parser.kdevelop by  doxygen 1.4.1