 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
62 if (name ==
"stdout") {
64 }
else if (name ==
"stderr") {
71 throw IOError(
"Given port number '" + name.substr(name.find(
":") + 1) +
"' is not numeric.");
73 throw IOError(
"No port number given.");
76 const int len = (int)name.length();
77 std::string name2 = name;
80 const std::string::size_type metaTimeIndex = prefix.find(
"TIME");
81 if (metaTimeIndex != std::string::npos) {
85 struct tm* timeinfo = localtime(&rawtime);
86 strftime(buffer, 80,
"%Y-%m-%d-%H-%M-%S", timeinfo);
87 prefix.replace(metaTimeIndex, 4, std::string(buffer));
91 dev =
new OutputDevice_File(name2, len > 4 && name.substr(len - 4) ==
".sbx", len > 3 && name.substr(len - 3) ==
".gz");
94 dev->
getOStream() << std::setiosflags(std::ios::fixed);
102 const std::string& rootElement,
103 const std::string& schemaFile) {
108 if (rootElement !=
"") {
119 throw InvalidArgument(
"Device '" + devName +
"' has not been created.");
127 std::vector<OutputDevice*> errorDevices;
128 std::vector<OutputDevice*> nonErrorDevices;
131 errorDevices.push_back(i->second);
133 nonErrorDevices.push_back(i->second);
136 for (std::vector<OutputDevice*>::iterator i = nonErrorDevices.begin(); i != nonErrorDevices.end(); ++i) {
145 if (!keepErrorRetrievers) {
146 for (std::vector<OutputDevice*>::iterator i = errorDevices.begin(); i != errorDevices.end(); ++i) {
150 std::cerr <<
"Error on closing error output devices." << std::endl;
151 std::cerr << e.what() << std::endl;
160 std::ostringstream oss;
164 if (v < pow(10., -precision)) {
165 oss.setf(std::ios::scientific, std::ios::floatfield);
167 oss.setf(std::ios::fixed, std::ios::floatfield);
168 oss.setf(std::ios::showpoint);
169 oss << std::setprecision(precision);
181 myFilename(filename) {
210 if (i->second ==
this) {
228 const std::string& schemaFile,
229 std::map<SumoXMLAttr, std::string> attrs) {
230 if (schemaFile !=
"") {
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
static void closeAll(bool keepErrorRetrievers=false)
Static storage of an output device and its base (abstract) implementation.
OutputFormatter * myFormatter
The formatter for XML.
static void removeRetrieverFromAllInstances(OutputDevice *out)
ensure that that given output device is no longer used as retriever by any instance
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
virtual std::ostream & getOStream()=0
Returns the associated ostream.
bool isRetriever(OutputDevice *retriever) const
Returns whether the given output device retrieves messages from the handler.
OutputDevice(const bool binary=false, const int defaultIndentation=0, const std::string &filename="")
Constructor.
static OptionsCont & getOptions()
Retrieves the options.
void close()
Closes the device and removes it from the dictionary.
SumoXMLTag
Numbers representing SUMO-XML - element names.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual void postWriteHook()
Called after every write access.
static std::string prependToLastPathComponent(const std::string &prefix, const std::string &path)
prepend the given prefix to the last path component of the given file path
An output device that encapsulates an ofstream.
void inform(const std::string &msg, const char progress=0)
Retrieves a message to this device.
static bool isSocket(const std::string &name)
Returns the information whether the given name represents a socket.
static OutputDevice * getDevice()
Returns the single cout instance.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
static std::map< std::string, OutputDevice * > myOutputDevices
map from names to output devices
static OutputDevice * getDevice()
Returns the single cerr instance.
static std::string realString(const double v, const int precision=gPrecision)
Helper method for string formatting.
virtual bool ok()
returns the information whether one can write into the device
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
const std::string & getFilename()
get filename or suitable description of this device
virtual ~OutputDevice()
Destructor.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
An output device for TCP/IP network connections.