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

xml_element_parser.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 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 XML_PARSERBASIC_XML_ELEMENT_PARSER_H
00021 #define XML_PARSERBASIC_XML_ELEMENT_PARSER_H
00022 
00023 
00024 namespace xml_parser {
00025 
00035 template< typename E, typename A >
00036 class basic_xml_element_parser : public grammar_to_parser::basic_non_terminal<E,A>
00037 {
00038 public:
00039 typedef typename grammar_to_parser::basic_parser<E>::parser_list 
00040                                                                                                                 parser_list;
00041 typedef typename grammar_to_parser::basic_parser<E>::parser_list_iterator 
00042                                                                                                                 parser_list_iterator;
00043 typedef typename basic_xml_attribute_list_parser<E>::attributes_parsers_list 
00044                                                                                                                 attributes_parsers_list;
00045 typedef typename std::basic_string<E> std_string;
00046 
00047         enum xml_special_chars {
00048                 left_bracket = '<',
00049                 right_bracket = '>',
00050                 end_tag_char = '/'
00051         };
00052         
00053         basic_xml_element_parser(std::basic_string<E> tag_name) :
00054                 m_begin_left_bracket(std_string(1,left_bracket)),
00055                 m_begin_tag_name(tag_name),
00056                 m_begin_right_bracket(std_string(1,right_bracket)),
00057                 m_end_left_bracket(std_string(1,left_bracket)),
00058                 m_end_char(std_string(1,end_tag_char)),
00059                 m_end_tag_name(tag_name),
00060                 m_end_right_bracket(std_string(1,right_bracket)),
00061                 grammar_to_parser::basic_non_terminal<E,A>() {};
00062                         
00063 protected:
00064         grammar_to_parser::basic_pattern_parser<E>      m_begin_left_bracket; // '<'
00065         grammar_to_parser::basic_pattern_parser<E>      m_begin_tag_name;
00066         // here will come attributes list parser from compound class 
00067         // implementing push_attributes_parser() method 
00068         basic_xml_attribute_list_parser<E>                      m_attribute_list_parser;
00069         grammar_to_parser::basic_pattern_parser<E>      m_begin_right_bracket;
00070         // here will come value parsers from compound class 
00071         // implementing push_value_parsers() method
00072         grammar_to_parser::basic_pattern_parser<E>      m_end_left_bracket;
00073         grammar_to_parser::basic_pattern_parser<E>      m_end_char;
00074         grammar_to_parser::basic_pattern_parser<E>      m_end_tag_name;
00075         grammar_to_parser::basic_pattern_parser<E>      m_end_right_bracket;
00076         
00077         virtual void prepare_symbols()
00078         {
00079                 if( !m_symbols_valid ) 
00080                 {
00081                         m_symbols.push_back(&m_begin_left_bracket);
00082                         m_symbols.push_back(&m_begin_tag_name);
00083                         
00084                         // assign attribute parsers into attribute list parser
00085                         attributes_parsers_list attributes_parsers;
00086                         get_valid().push_attributes_parsers(attributes_parsers);
00087                         m_attribute_list_parser.assign_attributes_parsers(attributes_parsers);
00088                         m_symbols.push_back(&m_attribute_list_parser);
00089                         
00090                         m_symbols.push_back(&m_begin_right_bracket);
00091                         get_valid().push_parsers(m_symbols);
00092                         m_symbols.push_back(&m_end_left_bracket);
00093                         m_symbols.push_back(&m_end_char);
00094                         m_symbols.push_back(&m_end_tag_name);
00095                         m_symbols.push_back(&m_end_right_bracket);
00096                         m_symbols_valid = true;
00097                 }
00098                 
00099         }
00100 };
00101 
00102 
00103 
00108 template<typename A>
00109 class xml_element_parser : public basic_xml_element_parser<char,A>
00110 {
00111 public:
00112         
00113         xml_element_parser<A>(std::string tag_name) : 
00114                 basic_xml_element_parser<char,A>(tag_name) {};
00115 };
00116 
00121 template<typename A>
00122 class wxml_element_parser : public basic_xml_element_parser<wchar_t,A>
00123 {
00124 public:
00125         wxml_element_parser<A>(std::wstring tag_name) : 
00126                 basic_xml_element_parser<wchar_t,A>(tag_name) {};
00127 };
00128 
00129 
00130 };
00131 
00132 #endif

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