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

xml_parser.h

Go to the documentation of this file.
00001 
00002 // Common Text Transformation Library
00003 // Copyright (C) 1997-2006 by Igor Kholodov. 
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library 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 GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the
00017 // Free Software Foundation, Inc.,
00018 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 // mailto:cttl@users.sourceforge.net
00021 // http://sourceforge.net/projects/cttl/
00023 
00029 // xml_parser.h
00030 
00031 #ifndef _XML_PARSER_H_INCLUDED_
00032 #define _XML_PARSER_H_INCLUDED_
00033 
00045 template< typename UniverseT >
00046 struct parser {
00047 
00049     typedef UniverseT universe_T;
00050 
00052     typedef typename UniverseT::strict_edge_T strict_universe_T;
00053 
00055     typedef typename UniverseT::node_T node_T;
00056 
00058     typedef typename UniverseT::char_T char_T;
00059 
00061     std::vector< std::string > vect_xml_names;
00062 
00064     std::map< std::string, size_t > map_xml_names;
00065 
00066     // A pair has to be be assembled to represent a dictionary:
00067     std::pair< std::vector< std::string >*, std::map< std::string, size_t >* > xml_name_dictionary;
00068 
00070     std::vector< std::string > vect_xml_text;
00071 
00073     std::stack< size_t > xml_offset_stack;
00074 
00076     std::vector< int > vect_xml_tree;
00077 
00079     parser()
00080         :
00081         xml_name_dictionary( &vect_xml_names, &map_xml_names ),
00082         vect_xml_tree( 1 )
00083     {
00084     }
00085 
00086 public:
00088     void error_show( universe_T& universe_, char_T const* message_ )
00089     {
00090 #ifndef SUPPRESS_VERBOSE_ERRORS
00091         size_t offset_from_ = offset_stack_guard< universe_T >::offset( universe_, xml_offset_stack.top() );
00092         size_t offset_to_ = universe_.first.offset();
00093 
00094         if ( offset_from_ < offset_to_ )
00095             std::cout
00096                 << "..."
00097                 << universe_.parent().container().text_absolute_substring( offset_from_, std::min( offset_to_, offset_from_ + 50 ) )
00098                 << "..."
00099                 ;
00100 
00101         std::cout
00102             << std::endl
00103             << "*** Error: "
00104 #ifdef DISPOSE_CONSUMED_DATA
00105             << '@'
00106             << offset_from_
00107             << '-'
00108             << offset_to_
00109 #else
00110             << "line "
00111             << universe_.first.line()
00112 #endif // DISPOSE_CONSUMED_DATA
00113            << '\t'
00114             << message_
00115             << std::endl
00116             ;
00117 #endif // SUPPRESS_VERBOSE_ERRORS
00118     }
00119 
00121     size_t error_parser_failed( universe_T& universe_ )
00122     {
00123         error_show(
00124             universe_,
00125             "error_parser_failed"
00126             );
00127         return universe_T::string_T::npos;
00128     }
00129 
00131     size_t error_bad_pi( universe_T& universe_ )
00132     {
00133         error_show(
00134             universe_,
00135             "missing PI name"
00136             );
00137         return universe_T::string_T::npos;
00138     }
00139 
00141     size_t error_missing_close_element( universe_T& universe_ )
00142     {
00143         error_show(
00144             universe_,
00145             "error_missing_close_element"
00146             );
00147         return universe_T::string_T::npos;
00148     }
00149 
00151     size_t error_missing_pi_close( universe_T& universe_ )
00152     {
00153         error_show(
00154             universe_,
00155             "error_missing_pi_close"
00156             );
00157         return universe_T::string_T::npos;
00158     }
00159 
00161     size_t error_missing_comment_close( universe_T& universe_ )
00162     {
00163         error_show(
00164             universe_,
00165             "error_missing_comment_close"
00166             );
00167         return universe_T::string_T::npos;
00168     }
00169 
00171     size_t error_bad_attr_format( universe_T& universe_ )
00172     {
00173         error_show(
00174             universe_,
00175             "error_bad_attr_format"
00176             );
00177         return universe_T::string_T::npos;
00178     }
00179     
00180 };  // struct parser
00181 
00182 
00183 #endif //_XML_PARSER_H_INCLUDED_

Generated on Thu Nov 2 17:43:27 2006 for CTTL XML stream parser sample by  doxygen 1.3.9.1