SUMO - Simulation of Urban MObility

MSTriggeredXMLReader.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The basic class for classes that read XML-triggers
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 // ===========================================================================
00021 // included modules
00022 // ===========================================================================
00023 #ifdef _MSC_VER
00024 #include <windows_config.h>
00025 #else
00026 #include <config.h>
00027 #endif
00028 
00029 #include <string>
00030 #include <xercesc/sax2/SAX2XMLReader.hpp>
00031 #include <xercesc/sax/SAXException.hpp>
00032 #include <xercesc/sax/SAXParseException.hpp>
00033 #include <utils/common/TplConvert.h>
00034 #include <utils/common/MsgHandler.h>
00035 #include <utils/common/UtilExceptions.h>
00036 #include <utils/xml/SUMOSAXHandler.h>
00037 #include <utils/xml/XMLSubSys.h>
00038 #include <microsim/MSEventControl.h>
00039 #include "MSTriggeredReader.h"
00040 #include "MSTriggeredXMLReader.h"
00041 #include <utils/common/WrappingCommand.h>
00042 
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046 
00047 
00048 // ===========================================================================
00049 // method definitions
00050 // ===========================================================================
00051 MSTriggeredXMLReader::MSTriggeredXMLReader(MSNet& net,
00052         const std::string& filename)
00053     : MSTriggeredReader(net),
00054       SUMOSAXHandler(filename),
00055       myParser(0), myHaveMore(true) {
00056     Command* c = new WrappingCommand< MSTriggeredReader >(this, &MSTriggeredReader::wrappedExecute);
00057     MSNet::getInstance()->getInsertionEvents().addEvent(c, net.getCurrentTimeStep(), MSEventControl::NO_CHANGE);
00058 }
00059 
00060 
00061 MSTriggeredXMLReader::~MSTriggeredXMLReader() {}
00062 
00063 
00064 bool
00065 MSTriggeredXMLReader::readNextTriggered() {
00066     while (myHaveMore&&myParser->parseNext(myToken)) {
00067         if (nextRead()) {
00068             return true;
00069         }
00070     }
00071     myHaveMore = false;
00072     return false;
00073 }
00074 
00075 
00076 void
00077 MSTriggeredXMLReader::myInit() {
00078     try {
00079         myParser = XMLSubSys::getSAXReader(*this);
00080         if (!myParser->parseFirst(getFileName().c_str(), myToken)) {
00081             throw ProcessError("Can not read XML-file '" + getFileName() + "'.");
00082 
00083         }
00084     } catch (SAXException& e) {
00085         throw ProcessError(TplConvert<XMLCh>::_2str(e.getMessage()));
00086 
00087     } catch (XMLException& e) {
00088         throw ProcessError(TplConvert<XMLCh>::_2str(e.getMessage()));
00089 
00090     }
00091 
00092     if (readNextTriggered()) {
00093         if (myOffset<MSNet::getInstance()->getCurrentTimeStep()) {
00094             myOffset = MSNet::getInstance()->getCurrentTimeStep() + 1;
00095             // !!! Warning?
00096         }
00097     } else {
00098         myHaveMore = false;
00099     }
00100 }
00101 
00102 
00103 
00104 /****************************************************************************/
00105 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines