65 SetConsoleOutputCP(CP_UTF8);
74 const int len = (int)name.length();
75 bool isParquet = (oc.
exists(
"output.format") && oc.
getString(
"output.format") ==
"parquet") || (len > 8 && name.substr(len - 8) ==
".parquet");
78 WRITE_WARNING(
"Compiled without Parquet support, falling back to XML.")
84 if (name ==
"stdout") {
86 }
else if (name ==
"stderr") {
90 const bool ipv6 = name[0] ==
'[';
91 const size_t sepIndex = name.find(
":", ipv6 ? name.find(
"]") : 0);
93 dev =
new OutputDevice_Network(ipv6 ? name.substr(1, sepIndex - 2) : name.substr(0, sepIndex), port);
95 throw IOError(
"Given port number '" + name.substr(name.find(
":") + 1) +
"' is not numeric.");
97 throw IOError(
TL(
"No port number given."));
100 std::string name2 = (name ==
"nul" || name ==
"NUL") ?
"/dev/null" : name;
101 if (usePrefix && oc.
isSet(
"output-prefix") && name2 !=
"/dev/null") {
102 std::string prefix = oc.
getString(
"output-prefix");
103 const std::string::size_type metaTimeIndex = prefix.find(
"TIME");
104 if (metaTimeIndex != std::string::npos) {
107 struct tm* timeinfo = localtime(&rawtime);
108 strftime(buffer, 80,
"%Y-%m-%d-%H-%M-%S", timeinfo);
109 prefix.replace(metaTimeIndex, 4, buffer);
116 if ((oc.
exists(
"output.format") && oc.
getString(
"output.format") ==
"csv") || (len > 4 && name.substr(len - 4) ==
".csv") || (len > 7 && name.substr(len - 7) ==
".csv.gz")) {
125 dev->
getOStream() << std::setiosflags(std::ios::fixed);
133 const std::string& rootElement,
134 const std::string& schemaFile) {
139 if (rootElement !=
"") {
150 throw InvalidArgument(
"Output device '" + devName +
"' for option '" + optionName +
"' has not been created.");
159 item.second->flush();
166 std::vector<OutputDevice*> errorDevices;
167 std::vector<OutputDevice*> nonErrorDevices;
170 errorDevices.push_back(i->second);
172 nonErrorDevices.push_back(i->second);
183 if (!keepErrorRetrievers) {
188 std::cerr <<
"Error on closing error output devices." << std::endl;
189 std::cerr << e.what() << std::endl;
229 if (i->second ==
this) {
247 const std::string& schemaFile,
248 std::map<SumoXMLAttr, std::string> attrs,
249 bool includeConfig) {
250 if (schemaFile !=
"") {
300 for (std::string attrName : attrList) {
301 if (attrName ==
"all") {
303 }
else if (special.count(attrName) > 0) {
304 result |= special.find(attrName)->second;
309 WRITE_ERRORF(
TL(
"Unknown attribute '%' to write in %."), attrName, desc);
#define WRITE_ERRORF(...)
#define WRITE_WARNING(msg)
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::bitset< 96 > SumoXMLAttrMask
@ 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.
bool isRetriever(OutputDevice *retriever) const
Returns whether the given output device retrieves messages from the handler.
static void removeRetrieverFromAllInstances(OutputDevice *out)
ensure that that given output device is no longer used as retriever by any instance
A storage for options typed value containers)
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)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
static OptionsCont & getOptions()
Retrieves the options.
static const std::chrono::time_point< std::chrono::system_clock > & getLoadTime()
Return the time stamp of the last init.
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 std::ostream & getOStream()=0
Returns the associated ostream.
virtual ~OutputDevice()
Destructor.
OutputDevice(const int defaultIndentation=0, const std::string &filename="")
Constructor.
void inform(const std::string &msg, const bool progress=false)
Retrieves a message to this device.
void close()
Closes the device and removes it from the dictionary.
static const SumoXMLAttrMask parseWrittenAttributes(const std::vector< std::string > &attrList, const std::string &desc, const std::map< std::string, SumoXMLAttrMask > &special=std::map< std::string, SumoXMLAttrMask >())
Parses a list of strings for attribute names and sets the relevant bits in the returned mask.
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, CSV or Parquet.
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 precision or resets it to default.
const std::string myFilename
static void closeAll(bool keepErrorRetrievers=false)
void setFormatter(OutputFormatter *formatter)
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
static int myPrevConsoleCP
old console code page to restore after ending
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
static std::map< std::string, OutputDevice * > myOutputDevices
map from names to output devices
virtual bool ok()
returns the information whether one can write into the device
static SequentialStringBijection Attrs
The names of SUMO-XML attributes for use in netbuild.
static std::string substituteEnvironment(const std::string &str, const std::chrono::time_point< std::chrono::system_clock > *const timeRef=nullptr)
Replaces an environment variable with its value (similar to bash); syntax for a variable is ${NAME}.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...