61 if (name ==
"stdout") {
63 }
else if (name ==
"stderr") {
70 throw IOError(
"Given port number '" + name.substr(name.find(
":") + 1) +
"' is not numeric.");
72 throw IOError(
"No port number given.");
75 const int len = (int)name.length();
76 std::string name2 = name;
79 const std::string::size_type metaTimeIndex = prefix.find(
"TIME");
80 if (metaTimeIndex != std::string::npos) {
84 struct tm* timeinfo = localtime(&rawtime);
85 strftime(buffer, 80,
"%Y-%m-%d-%H-%M-%S", timeinfo);
86 prefix.replace(metaTimeIndex, 4, std::string(buffer));
93 dev->
getOStream() << std::setiosflags(std::ios::fixed);
101 const std::string& rootElement,
102 const std::string& schemaFile) {
107 if (rootElement !=
"") {
118 throw InvalidArgument(
"Device '" + devName +
"' has not been created.");
126 std::vector<OutputDevice*> errorDevices;
127 std::vector<OutputDevice*> nonErrorDevices;
130 errorDevices.push_back(i->second);
132 nonErrorDevices.push_back(i->second);
135 for (std::vector<OutputDevice*>::iterator i = nonErrorDevices.begin(); i != nonErrorDevices.end(); ++i) {
144 if (!keepErrorRetrievers) {
145 for (std::vector<OutputDevice*>::iterator i = errorDevices.begin(); i != errorDevices.end(); ++i) {
149 std::cerr <<
"Error on closing error output devices." << std::endl;
150 std::cerr << e.what() << std::endl;
159 std::ostringstream oss;
163 if (v < pow(10., -precision)) {
164 oss.setf(std::ios::scientific, std::ios::floatfield);
166 oss.setf(std::ios::fixed, std::ios::floatfield);
167 oss.setf(std::ios::showpoint);
168 oss << std::setprecision(precision);
179 myFilename(filename) {
204 if (i->second ==
this) {
222 const std::string& schemaFile,
223 std::map<SumoXMLAttr, std::string> attrs) {
224 if (schemaFile !=
"") {
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_ATTR_SCHEMA_LOCATION
static bool isSocket(const std::string &name)
Returns the information whether the given name represents a socket.
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
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
static void removeRetrieverFromAllInstances(OutputDevice *out)
ensure that that given output device is no longer used as retriever by any instance
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static OptionsCont & getOptions()
Retrieves the options.
static OutputDevice * getDevice()
Returns the single cerr instance.
static OutputDevice * getDevice()
Returns the single cout instance.
An output device that encapsulates an ofstream.
An output device for TCP/IP network connections.
Static storage of an output device and its base (abstract) implementation.
virtual ~OutputDevice()
Destructor.
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.
OutputDevice(const int defaultIndentation=0, const std::string &filename="")
Constructor.
static std::string realString(const double v, const int precision=gPrecision)
Helper method for string formatting.
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual void postWriteHook()
Called after every write access.
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.
const std::string & getFilename()
get filename or suitable description of this device
OutputFormatter * myFormatter
The formatter for XML.
virtual std::ostream & getOStream()=0
Returns the associated ostream.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
static void closeAll(bool keepErrorRetrievers=false)
void inform(const std::string &msg, const char progress=0)
Retrieves a message to this device.
static std::map< std::string, OutputDevice * > myOutputDevices
map from names to output devices
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
virtual bool ok()
returns the information whether one can write into the device
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...