70 if (name ==
"stdout") {
72 }
else if (name ==
"stderr") {
79 throw IOError(
"Given port number '" + name.substr(name.find(
":") + 1) +
"' is not numeric.");
81 throw IOError(
"No port number given.");
84 const int len = (int)name.length();
85 std::string name2 = name;
88 const std::string::size_type metaTimeIndex = prefix.find(
"TIME");
89 if (metaTimeIndex != std::string::npos) {
93 struct tm* timeinfo = localtime(&rawtime);
94 strftime(buffer, 80,
"%Y-%m-%d-%H-%M-%S", timeinfo);
95 prefix.replace(metaTimeIndex, 4, std::string(buffer));
102 dev->
getOStream() << std::setiosflags(std::ios::fixed);
110 const std::string& rootElement,
111 const std::string& schemaFile) {
116 if (rootElement !=
"") {
127 throw InvalidArgument(
"Device '" + devName +
"' has not been created.");
135 std::vector<OutputDevice*> errorDevices;
136 std::vector<OutputDevice*> nonErrorDevices;
139 errorDevices.push_back(i->second);
141 nonErrorDevices.push_back(i->second);
144 for (std::vector<OutputDevice*>::iterator i = nonErrorDevices.begin(); i != nonErrorDevices.end(); ++i) {
152 for (std::vector<OutputDevice*>::iterator i = errorDevices.begin(); i != errorDevices.end(); ++i) {
156 std::cerr <<
"Error on closing error output devices." << std::endl;
157 std::cerr << e.what() << std::endl;
165 std::ostringstream oss;
169 if (v < pow(10., -precision)) {
170 oss.setf(std::ios::scientific, std::ios::floatfield);
172 oss.setf(std::ios::fixed , std::ios::floatfield);
173 oss.setf(std::ios::showpoint);
174 oss << std::setprecision(precision);
209 if (i->second ==
this) {
226 const std::string& schemaFile,
227 std::map<SumoXMLAttr, std::string> attrs) {
228 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.
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.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
OutputDevice(const bool binary=false, const int defaultIndentation=0)
Constructor.
virtual bool ok()
returns the information whether one can write into the device
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
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.
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.
bool closeTag()
Closes the most recently opened tag.
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.