63 if (name ==
"stdout") {
65 }
else if (name ==
"stderr") {
72 throw IOError(
"Given port number '" + name.substr(name.find(
":") + 1) +
"' is not numeric.");
74 throw IOError(
"No port number given.");
77 const int len = (int)name.length();
78 std::string name2 = name;
81 const std::string::size_type metaTimeIndex = prefix.find(
"TIME");
82 if (metaTimeIndex != std::string::npos) {
86 struct tm* timeinfo = localtime(&rawtime);
87 strftime(buffer, 80,
"%Y-%m-%d-%H-%M-%S", timeinfo);
88 prefix.replace(metaTimeIndex, 4, std::string(buffer));
95 dev->
getOStream() << std::setiosflags(std::ios::fixed);
103 const std::string& rootElement,
104 const std::string& schemaFile) {
109 if (rootElement !=
"") {
120 throw InvalidArgument(
"Device '" + devName +
"' has not been created.");
128 std::vector<OutputDevice*> errorDevices;
129 std::vector<OutputDevice*> nonErrorDevices;
132 errorDevices.push_back(i->second);
134 nonErrorDevices.push_back(i->second);
137 for (std::vector<OutputDevice*>::iterator i = nonErrorDevices.begin(); i != nonErrorDevices.end(); ++i) {
146 if (!keepErrorRetrievers) {
147 for (std::vector<OutputDevice*>::iterator i = errorDevices.begin(); i != errorDevices.end(); ++i) {
151 std::cerr <<
"Error on closing error output devices." << std::endl;
152 std::cerr << e.what() << std::endl;
161 std::ostringstream oss;
165 if (v < pow(10., -precision)) {
166 oss.setf(std::ios::scientific, std::ios::floatfield);
168 oss.setf(std::ios::fixed , std::ios::floatfield);
169 oss.setf(std::ios::showpoint);
170 oss << std::setprecision(precision);
211 if (i->second ==
this) {
229 const std::string& schemaFile,
230 std::map<SumoXMLAttr, std::string> attrs) {
231 if (schemaFile !=
"") {
void close()
Closes the device and removes it from the dictionary.
SumoXMLTag
Numbers representing SUMO-XML - element names.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
bool isRetriever(OutputDevice *retriever) const
Returns whether the given output device retrieves messages from the handler.
static std::map< std::string, OutputDevice * > myOutputDevices
map from names to output devices
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 bool isSocket(const std::string &name)
Returns the information whether the given name represents a socket.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
static std::string realString(const double v, const int precision=gPrecision)
Helper method for string formatting.
static void removeRetrieverFromAllInstances(OutputDevice *out)
ensure that that given output device is no longer used as retriever by any instance ...
An output device for TCP/IP network connections.
static OptionsCont & getOptions()
Retrieves the options.
void inform(const std::string &msg, const char progress=0)
Retrieves a message to this 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 OutputDevice * getDevice()
Returns the single cout instance.
An output device that encapsulates an ofstream.
const std::string & getFilename()
get filename or suitable description of this device
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
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...
virtual ~OutputDevice()
Destructor.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
OutputFormatter * myFormatter
The formatter for XML.
OutputDevice(const bool binary=false, const int defaultIndentation=0, const std::string &filename="")
Constructor.
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 storage of an output device and its base (abstract) implementation.
static void closeAll(bool keepErrorRetrievers=false)
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static OutputDevice * getDevice()
Returns the single cerr instance.
virtual std::ostream & getOStream()=0
Returns the associated ostream.
virtual void postWriteHook()
Called after every write access.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.