00001 /*************************************************************************** 00002 * SpikeStream Application * 00003 * Copyright (C) 2007 by David Gamez * 00004 * david@davidgamez.eu * 00005 * Version 0.1 * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 ***************************************************************************/ 00022 00023 //SpikeStream includes 00024 #include "MonitorXmlHandler.h" 00025 #include "Utilities.h" 00026 #include "Debug.h" 00027 00028 //Other includes 00029 #include <iostream> 00030 using namespace std; 00031 00032 /*! Constructor. */ 00033 MonitorXmlHandler::MonitorXmlHandler(MonitorDataPlotter* monDatPlot) : QXmlDefaultHandler() { 00034 //Store reference to the NeuronMonitor 00035 monitorDataPlotter = monDatPlot; 00036 } 00037 00038 00039 /*! Destructor. */ 00040 MonitorXmlHandler::~MonitorXmlHandler(){ 00041 #ifdef MEMORY_DEBUG 00042 cout<<"DELETING MONITOR XML HANDLER"<<endl; 00043 #endif//MEMORY_DEBUG 00044 } 00045 00046 00047 //------------------------------------------------------------------------- 00048 //-------------------------- PUBLIC METHODS ----------------------------- 00049 //------------------------------------------------------------------------- 00050 00051 /*! Returns true if an error has been encountered during parsing. */ 00052 bool MonitorXmlHandler::getParseError(){ 00053 return parseError; 00054 } 00055 00056 00057 /*! Returns a string describing the parsing error. */ 00058 QString MonitorXmlHandler::getParseErrorString(){ 00059 return parseErrorString; 00060 } 00061 00062 00063 //------------------------------------------------------------------------- 00064 //------------------------- PROTECTED METHODS ----------------------------- 00065 //------------------------------------------------------------------------- 00066 00067 /*! Called when parser encounters characters. */ 00068 bool MonitorXmlHandler::characters(const QString& chars){ 00069 try{ 00070 if(currentElement == "description") 00071 newGraph.description = chars; 00072 else if(currentElement == "range_high") 00073 newGraph.rangeHigh = Utilities::getDouble(chars.ascii()); 00074 else if(currentElement == "range_low") 00075 newGraph.rangeLow = Utilities::getDouble(chars.ascii()); 00076 else{ 00077 parseError = true; 00078 parseErrorString += "Unrecognized element."; 00079 cerr<<"MonitorXmlHandler: UNRECOGNIZED ELEMENT"<<endl; 00080 } 00081 } 00082 catch (std::exception& er) {// Catch-all for std exceptions 00083 parseError = true; 00084 parseErrorString += er.what(); 00085 } 00086 return true; 00087 } 00088 00089 00090 /*! Called when the parser encounters the end of an element. */ 00091 bool MonitorXmlHandler::endElement( const QString&, const QString&, const QString& qName){ 00092 if(qName == "data"){ 00093 monitorDataPlotter->addGraph(newGraph);//Struct passed by value, so should get copy 00094 } 00095 else if(qName == "monitor_info") 00096 monitorDataPlotter->loadingComplete(); 00097 return true; 00098 } 00099 00100 00101 /*! Called when the parser generates an error. */ 00102 bool MonitorXmlHandler::error ( const QXmlParseException& parseEx){ 00103 cerr<<"MonitorXmlHandler: PARSING ERROR"<<endl; 00104 parseError = true; 00105 parseErrorString += parseEx.message(); 00106 return true; 00107 } 00108 00109 00110 /*! Returns a default error string. */ 00111 QString MonitorXmlHandler::errorString (){ 00112 return QString("MonitorXmlHandler: Default error string"); 00113 00114 } 00115 00116 00117 /*! Called when the parser generates a fatal error. */ 00118 bool MonitorXmlHandler::fatalError ( const QXmlParseException& parseEx){ 00119 cerr<<"MonitorXmlHandler: PARSING FATAL ERROR"<<endl; 00120 parseError = true; 00121 parseErrorString += parseEx.message(); 00122 return true; 00123 } 00124 00125 00126 /*! Called when parser reaches the start of the document. */ 00127 bool MonitorXmlHandler::startDocument(){ 00128 parseError = false; 00129 parseErrorString = ""; 00130 return true; 00131 } 00132 00133 00134 /*! Called when parser reaches the start of an element. */ 00135 bool MonitorXmlHandler::startElement(const QString&, const QString&, const QString& qName, const QXmlAttributes& xmlAttributes){ 00136 currentElement = qName; 00137 return true; 00138 } 00139 00140 00141 /*! Called when the parser generates a warning. */ 00142 bool MonitorXmlHandler::warning ( const QXmlParseException& ){ 00143 cerr<<"MonitorXmlHandler: PARSING WARNING"<<endl; 00144 return true; 00145 } 00146 00147
1.4.4