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

rax_parser.h

00001 /***************************************************************************
00002                           rax_parser.h  -  description
00003                              -------------------
00004     begin                : Sat Feb 1 2003
00005     copyright            : (C) 2003 by Moritz Franosch
00006     email                : mail@Franosch.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef RAX_PARSER_H
00019 #define RAX_PARSER_H
00020 
00021 #include <stack>
00022 #include <map>
00023 
00024 #include "xercesc/sax/HandlerBase.hpp"
00025 
00026 #include "askosdata/pointer.h"
00027 
00028 #include "rax_handler.h"
00029 
00030 
00035 class RAX_Handler_Pointer : public Pointer<RAX_Handler> {
00036 
00037 private:
00038 
00039   static Pointer<RAX_Handler> default_handler;
00040   // default handler that just calls RAX_Parser::start_element(),
00041   // RAX_Parser::end_element(), RAX_Parser::text(), respectively.
00042 
00043 public:
00044 
00049   RAX_Handler_Pointer();
00050 
00053   RAX_Handler_Pointer(const Pointer<RAX_Handler> handler);
00054   
00057   //  RAX_Handler* operator->();
00058 
00059 };
00060 
00061 
00066 class RAX_Parser : private HandlerBase {
00067 
00068 private:
00069 
00070   // stack of maps between element names and their handlers
00071   std::stack< std::map<std::string,RAX_Handler_Pointer> > handlers;
00072 
00073   std::string collected_text; // text characters collected between element tags
00074 
00075   // stack of elements is pushed and poped according to the nested
00076   // structure of XML-elements
00077   std::stack<std::string> element_stack;
00078 
00081   virtual void startElement(const XMLCh* const name, AttributeList& attributes);
00082 
00085   virtual void endElement(const XMLCh* const name);
00086 
00089   virtual void characters(const XMLCh* const chars, const unsigned int length);
00090 
00095   virtual void warning(const SAXParseException& exception);
00096 
00101   virtual void error(const SAXParseException& exception);
00102 
00107   virtual void fatalError(const SAXParseException& exception);
00108 
00111   void text(const std::string& name);
00112 
00113 public: 
00114 
00117   static const std::string xmlch_to_string(const XMLCh* const name);
00118 
00121   RAX_Parser();
00122 
00134   virtual void start_element(const std::string& name, AttributeList& attributes);
00135 
00145   virtual void end_element(const std::string& name);
00146 
00158   virtual void text(const std::string& name, const std::string& t);
00159 
00164   bool parse(const std::string& filename);
00165 
00168   void push_handlers();
00169 
00172   void pop_handlers();
00173   
00176   void set_handler(const std::string& element_name, Pointer<RAX_Handler> handler);
00177 
00180   virtual ~RAX_Parser();
00181 
00182 };
00183 
00184 
00185 #endif // RAX_PARSER_H

Generated on Fri Apr 22 11:06:42 2005 for partsim.kdevelop by doxygen 1.3.6