#include <OutputDevice_String.h>

Please note that the device gots responsible for the stream and deletes it (it should not be deleted elsewhere).
Definition at line 46 of file OutputDevice_String.h.
OutputDevice member methods | ||||
| void | close () throw () | |||
| Closes the device and removes it from the dictionary. | ||||
| bool | closeTag (bool abbreviated=false) throw () | |||
| Closes the most recently opened tag. | ||||
| OutputDevice & | indent () throw () | |||
| Adds indentation. | ||||
| void | inform (const std::string &msg) | |||
| Retrieves a message to this device. | ||||
| virtual bool | ok () throw () | |||
| returns the information whether one can write into the device | ||||
| OutputDevice & | openTag (const std::string &xmlElement) throw () | |||
| Opens an XML tag. | ||||
| template<class T> | ||||
| OutputDevice & | operator<< (const T &t) | |||
| Abstract output operator. | ||||
| void | setPrecision (unsigned int precision=OUTPUT_ACCURACY) throw () | |||
| Sets the precison or resets it to default. | ||||
| bool | writeXMLHeader (const std::string &rootElement, const bool writeConfig=true, const std::string &attrs="", const std::string &comment="") throw () | |||
| Writes an XML header with optional configuration. | ||||
| virtual void | postWriteHook () throw () | |||
| Called after every write access. | ||||
Public Member Functions | ||||
| std::string | getString () throw () | |||
| Returns the current content as a string. | ||||
| OutputDevice_String () throw (IOError) | ||||
Constructor
| ||||
| ~OutputDevice_String () throw () | ||||
| Destructor. | ||||
Static Public Member Functions | ||||
static access methods to OutputDevices | ||||
| static void | closeAll () throw () | |||
| static bool | createDeviceByOption (const std::string &optionName, const std::string &rootElement="") throw (IOError) | |||
| Creates the device using the output definition stored in the named option. | ||||
| static OutputDevice & | getDevice (const std::string &name, const std::string &base="") throw (IOError) | |||
| Returns the described OutputDevice. | ||||
| static OutputDevice & | getDeviceByOption (const std::string &name) throw (IOError, InvalidArgument) | |||
| Returns the device described by the option. | ||||
Protected Member Functions | ||||
Methods that override/implement OutputDevice-methods | ||||
| std::ostream & | getOStream () throw () | |||
| Returns the associated ostream. | ||||
Private Attributes | ||||
| std::ostringstream | myStream | |||
| The wrapped ofstream. | ||||
| OutputDevice_String::OutputDevice_String | ( | ) | throw (IOError) |
Constructor
| IOError | Should not be thrown by this implementation. |
Definition at line 42 of file OutputDevice_String.cpp.
| OutputDevice_String::~OutputDevice_String | ( | ) | throw () |
| void OutputDevice::close | ( | ) | throw () [inherited] |
Closes the device and removes it from the dictionary.
Definition at line 133 of file OutputDevice.cpp.
References OutputDevice::closeTag(), and OutputDevice::myOutputDevices.
Referenced by RONet::closeOutput(), GUIDialog_ViewSettings::onCmdExportSetting(), GUIParameterTracker::onCmdSave(), GUIDialog_Breakpoints::onCmdSave(), RODFDetectorCon::save(), PCPolyContainer::save(), GUISelectedStorage::save(), GUISelectedStorage::SingleTypeSelections::save(), RODFDetectorCon::saveAsPOIs(), GUIDialog_ViewSettings::saveDecals(), NBNodeCont::savePlain(), NBEdgeCont::savePlain(), RODFDetectorCon::saveRoutes(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), and RODFDetectorCon::writeValidationDetectors().
00133 { 00134 while (closeTag()); 00135 for (DeviceMap::iterator i=myOutputDevices.begin(); i!=myOutputDevices.end(); ++i) { 00136 if (i->second == this) { 00137 myOutputDevices.erase(i); 00138 break; 00139 } 00140 } 00141 delete this; 00142 }
| void OutputDevice::closeAll | ( | ) | throw () [static, inherited] |
Closes all registered devices
Definition at line 115 of file OutputDevice.cpp.
References OutputDevice::myOutputDevices.
Referenced by GUIRunThread::deleteSim(), and main().
00115 { 00116 while (myOutputDevices.size()!=0) { 00117 myOutputDevices.begin()->second->close(); 00118 } 00119 myOutputDevices.clear(); 00120 }
Closes the most recently opened tag.
The topmost xml-element from the stack is written into the stream as a closing element ("</" + element + ">") and is then removed from the stack. If abbreviated closing is requested, only "/>" is the output.
| [in] | name | whether abbreviated closing is performed |
Definition at line 188 of file OutputDevice.cpp.
References OutputDevice::getOStream(), OutputDevice::indent(), OutputDevice::myXMLStack, and OutputDevice::postWriteHook().
Referenced by OutputDevice::close(), MSPersonControl::erase(), ROVehicle::saveAllAsXML(), MSVehicleControl::scheduleVehicleRemoval(), RORouteDef_Complete::writeXMLDefinition(), RORouteDef_Alternatives::writeXMLDefinition(), and RORoute::writeXMLDefinition().
00188 { 00189 if (!myXMLStack.empty()) { 00190 if (abbreviated) { 00191 getOStream() << "/>" << std::endl; 00192 } else { 00193 std::string indent(4*(myXMLStack.size()-1), ' '); 00194 getOStream() << indent << "</" << myXMLStack.back() << ">" << std::endl; 00195 } 00196 myXMLStack.pop_back(); 00197 postWriteHook(); 00198 return true; 00199 } 00200 return false; 00201 }
| bool OutputDevice::createDeviceByOption | ( | const std::string & | optionName, | |
| const std::string & | rootElement = "" | |||
| ) | throw (IOError) [static, inherited] |
Creates the device using the output definition stored in the named option.
Creates and returns the device named by the option. Asks whether the option and retrieves the name from the option if so. Optionally the XML header gets written as well. Returns whether a device was created (option was set).
Please note, that we do not have to consider the "application base" herein, because this call is only used to get file names of files referenced within XML-declarations of structures which paths already is aware of the cwd.
| [in] | optionName | The name of the option to use for retrieving the output definition |
| [in] | rootElement | The root element to use (XML-output) |
| IOError | If the output could not be built for any reason (error message is supplied) |
Definition at line 91 of file OutputDevice.cpp.
References OutputDevice::getDevice(), OptionsCont::getOptions(), and OutputDevice::writeXMLHeader().
Referenced by MSFrame::buildStreams(), NBNetBuilder::compute(), NBNodeCont::computeNodeShapes(), and main().
00092 { 00093 if (!OptionsCont::getOptions().isSet(optionName)) { 00094 return false; 00095 } 00096 OutputDevice& dev = OutputDevice::getDevice(OptionsCont::getOptions().getString(optionName)); 00097 if (rootElement != "") { 00098 dev.writeXMLHeader(rootElement); 00099 } 00100 return true; 00101 }
| OutputDevice & OutputDevice::getDevice | ( | const std::string & | name, | |
| const std::string & | base = "" | |||
| ) | throw (IOError) [static, inherited] |
Returns the described OutputDevice.
Creates and returns the named device. "stdout" and "-" refer to standard out, "hostname:port" initiates socket connection. Otherwise a filename is assumed and the second parameter may be used to give a base directory. If there already is a device with the same name this one is returned.
| [in] | name | The description of the output name/port/whatever |
| [in] | base | The base path the application is run within |
| IOError | If the output could not be built for any reason (error message is supplied) |
Definition at line 60 of file OutputDevice.cpp.
References TplConvert< E >::_2int(), FileHelpers::checkForRelativity(), OutputDevice::getOStream(), FileHelpers::isSocket(), and OutputDevice::setPrecision().
Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addRouteProbeDetector(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), NBNetBuilder::buildLoaded(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), OutputDevice::createDeviceByOption(), OutputDevice::getDeviceByOption(), MsgHandler::initOutputOptions(), GUIDialog_ViewSettings::onCmdExportSetting(), GUIParameterTracker::onCmdSave(), GUIDialog_EditViewport::onCmdSave(), GUIDialog_Breakpoints::onCmdSave(), RONet::openOutput(), RODFDetectorCon::save(), PCPolyContainer::save(), GUISelectedStorage::save(), GUISelectedStorage::SingleTypeSelections::save(), RODFDetectorCon::saveAsPOIs(), GUIDialog_ViewSettings::saveDecals(), NBNodeCont::savePlain(), NBEdgeCont::savePlain(), RODFDetectorCon::saveRoutes(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), and RODFDetectorCon::writeValidationDetectors().
00061 { 00062 // check whether the device has already been aqcuired 00063 if (myOutputDevices.find(name)!=myOutputDevices.end()) { 00064 return *myOutputDevices[name]; 00065 } 00066 // build the device 00067 OutputDevice *dev = 0; 00068 // check whether the device shall print to stdout 00069 if (name=="stdout" || name=="-") { 00070 dev = new OutputDevice_COUT(); 00071 } else if (FileHelpers::isSocket(name)) { 00072 try { 00073 int port = TplConvert<char>::_2int(name.substr(name.find(":")+1).c_str()); 00074 dev = new OutputDevice_Network(name.substr(0, name.find(":")), port); 00075 } catch (NumberFormatException &) { 00076 throw IOError("Given port number '" + name.substr(name.find(":")+1) + "' is not numeric."); 00077 } catch (EmptyData &) { 00078 throw IOError("No port number given."); 00079 } 00080 } else { 00081 dev = new OutputDevice_File(FileHelpers::checkForRelativity(name, base)); 00082 } 00083 dev->setPrecision(); 00084 dev->getOStream() << std::setiosflags(std::ios::fixed); 00085 myOutputDevices[name] = dev; 00086 return *dev; 00087 }
| OutputDevice & OutputDevice::getDeviceByOption | ( | const std::string & | name | ) | throw (IOError, InvalidArgument) [static, inherited] |
Returns the device described by the option.
Returns the device named by the option. If the option is unknown, unset or the device was not created before, InvalidArgument is thrown.
Please note, that we do not have to consider the "application base" herein.
| [in] | name | The name of the option to use for retrieving the output definition |
| IOError | If the output could not be built for any reason (error message is supplied) | |
| InvalidArgument | If the option with the given name does not exist |
Definition at line 105 of file OutputDevice.cpp.
References OutputDevice::getDevice(), OptionsCont::getOptions(), and OptionsCont::getString().
Referenced by NBNodeShapeComputer::compute(), NBNodeShapeComputer::computeNodeShapeByCrosses(), MSPersonControl::erase(), main(), MSVehicleControl::scheduleVehicleRemoval(), NBNode::sortNodesEdges(), and MSNet::writeOutput().
00105 { 00106 std::string devName = OptionsCont::getOptions().getString(optionName); 00107 if (myOutputDevices.find(devName)==myOutputDevices.end()) { 00108 throw InvalidArgument("Device '" + devName + "' has not been created."); 00109 } 00110 return OutputDevice::getDevice(devName); 00111 }
| std::ostream & OutputDevice_String::getOStream | ( | ) | throw () [protected, virtual] |
Returns the associated ostream.
Implements OutputDevice.
Definition at line 57 of file OutputDevice_String.cpp.
References myStream.
00057 { 00058 return myStream; 00059 }
| std::string OutputDevice_String::getString | ( | ) | throw () |
Returns the current content as a string.
Definition at line 51 of file OutputDevice_String.cpp.
References myStream.
Referenced by GUICompleteSchemeStorage::writeSettings().
00051 { 00052 return myStream.str(); 00053 }
| OutputDevice & OutputDevice::indent | ( | ) | throw () [inherited] |
Adds indentation.
An intendation, depending on the current xml-element-stack size, is written.
Definition at line 171 of file OutputDevice.cpp.
References OutputDevice::getOStream(), OutputDevice::myXMLStack, and OutputDevice::postWriteHook().
Referenced by OutputDevice::closeTag().
00171 { 00172 getOStream() << std::string(4*myXMLStack.size(), ' '); 00173 postWriteHook(); 00174 return *this; 00175 }
| void OutputDevice::inform | ( | const std::string & | msg | ) | [inherited] |
Retrieves a message to this device.
Implementation of the MessageRetriever interface. Writes the given message to the output device.
| [in] | msg | The msg to write to the device |
Definition at line 209 of file OutputDevice.cpp.
References OutputDevice::getOStream(), and OutputDevice::postWriteHook().
00209 { 00210 getOStream() << msg << '\n'; 00211 postWriteHook(); 00212 }
| bool OutputDevice::ok | ( | ) | throw () [virtual, inherited] |
returns the information whether one can write into the device
Definition at line 128 of file OutputDevice.cpp.
References OutputDevice::getOStream().
00128 { 00129 return getOStream().good(); 00130 }
| OutputDevice & OutputDevice::openTag | ( | const std::string & | xmlElement | ) | throw () [inherited] |
Opens an XML tag.
An intendation, depending on the current xml-element-stack size, is written followed by the given xmlelement ("<" + xmlElement) The xmlelement is added to the stack, then.
| [in] | xmlElement | Name of element to open |
Definition at line 179 of file OutputDevice.cpp.
References OutputDevice::getOStream(), OutputDevice::myXMLStack, and OutputDevice::postWriteHook().
Referenced by MSPersonControl::erase(), MSVehicleControl::scheduleVehicleRemoval(), RORouteDef_Complete::writeXMLDefinition(), RORouteDef_Alternatives::writeXMLDefinition(), RORoute::writeXMLDefinition(), OutputDevice::writeXMLHeader(), and MSVehicle::writeXMLRoute().
00179 { 00180 getOStream() << std::string(4*myXMLStack.size(), ' ') << "<" << xmlElement; 00181 postWriteHook(); 00182 myXMLStack.push_back(xmlElement); 00183 return *this; 00184 }
| OutputDevice& OutputDevice::operator<< | ( | const T & | t | ) | [inline, inherited] |
Abstract output operator.
Definition at line 222 of file OutputDevice.h.
References OutputDevice::getOStream(), and OutputDevice::postWriteHook().
00222 { 00223 getOStream() << t; 00224 postWriteHook(); 00225 return *this; 00226 }
| void OutputDevice::postWriteHook | ( | ) | throw () [protected, virtual, inherited] |
Called after every write access.
Default implementation does nothing.
Reimplemented in MsgRetrievingFunction< T >, and OutputDevice_Network.
Definition at line 205 of file OutputDevice.cpp.
Referenced by OutputDevice::closeTag(), OutputDevice::indent(), OutputDevice::inform(), OutputDevice::openTag(), and OutputDevice::operator<<().
| void OutputDevice::setPrecision | ( | unsigned int | precision = OUTPUT_ACCURACY |
) | throw () [inherited] |
Sets the precison or resets it to default.
| [in] | precision | The accuracy (number of digits behind '.') to set |
Definition at line 146 of file OutputDevice.cpp.
References OutputDevice::getOStream().
Referenced by MSVTypeProbe::execute(), OutputDevice::getDevice(), NBNodeCont::savePlain(), RORouteDef_Alternatives::writeXMLDefinition(), and RORoute::writeXMLDefinition().
00146 { 00147 getOStream() << std::setprecision(precision); 00148 }
| bool OutputDevice::writeXMLHeader | ( | const std::string & | rootElement, | |
| const bool | writeConfig = true, |
|||
| const std::string & | attrs = "", |
|||
| const std::string & | comment = "" | |||
| ) | throw () [inherited] |
Writes an XML header with optional configuration.
If something has been written (myXMLStack is not empty), nothing is written and false returned.
| [in] | rootElement | The root element to use |
| [in] | writeConfig | Whether the configuration used while this file was generated shall be saved |
| [in] | attrs | Additional attributes to save within the rootElement |
| [in] | comment | Additional comment (saved in front the rootElement) |
Definition at line 152 of file OutputDevice.cpp.
References OptionsCont::getOptions(), OutputDevice::getOStream(), OutputDevice::myXMLStack, OutputDevice::openTag(), and OptionsCont::writeXMLHeader().
Referenced by OutputDevice::createDeviceByOption(), RONet::openOutput(), RODFDetectorCon::save(), PCPolyContainer::save(), RODFDetectorCon::saveAsPOIs(), NBNodeCont::savePlain(), NBEdgeCont::savePlain(), RODFDetectorCon::saveRoutes(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), and RODFDetectorCon::writeValidationDetectors().
00153 { 00154 if (myXMLStack.empty()) { 00155 OptionsCont::getOptions().writeXMLHeader(getOStream(), writeConfig); 00156 if (comment != "") { 00157 getOStream() << comment << "\n"; 00158 } 00159 openTag(rootElement); 00160 if (attrs != "") { 00161 getOStream() << " " << attrs; 00162 } 00163 getOStream() << ">\n"; 00164 return true; 00165 } 00166 return false; 00167 }
std::ostringstream OutputDevice_String::myStream [private] |
The wrapped ofstream.
Definition at line 76 of file OutputDevice_String.h.
Referenced by getOStream(), and getString().
1.5.6