22static inline std::string quotation_mark_replacement{
"”"};
23static inline std::string quotation_mark_original{
"\""};
38 if (
name != expected_name)
55 auto pos = value.find(quotation_mark_original);
56 while (pos not_eq std::string::npos) {
57 value.replace(pos, quotation_mark_original.length(), quotation_mark_replacement);
58 pos = value.find(quotation_mark_original);
99 if (actual_value ==
"*not found*") {
101 }
else if (actual_value != value) {
102 xml_parse_error(
"Attribute " + aname +
" has value \"" + actual_value +
103 "\" but \"" + value +
"\" was expected.");
109 return std::any_of(
attribs.cbegin(),
attribs.cend(), [&](
auto& attr){return attr.name == aname;});
128 if (it->name == aname) {
136 auto pos = value.find(quotation_mark_replacement);
137 while (pos not_eq std::string::npos) {
138 value.replace(pos, quotation_mark_replacement.length(), quotation_mark_original);
139 pos = value.find(quotation_mark_replacement);
154 istringstream strstr(
"");
157 strstr.str(attribute_value);
167 istringstream strstr(
"");
170 strstr.str(attribute_value);
189 istringstream sstr(
"");
195 while (is.good() && isspace(is.peek())) {
211 if (is.bad() || is.eof()) {
215 if (is.get() !=
'>') {
219 sstr.str(tag.str() +
'>');
220 out3 <<
"Read: " << sstr.str() <<
'\n';
224 if (
name[
name.length() - 1] ==
'>') {
233 out3 <<
"Name: " <<
name <<
'\n';
236 while (token !=
">") {
239 pos = token.find(
"=", 0);
244 attr.
name = token.substr(0, pos);
245 token.erase(0, pos + 1);
247 if (token[0] !=
'\"') {
255 if (!ntoken.length())
break;
256 token +=
" " + ntoken;
266 attr.
value = token.substr(1, pos - 1);
270 out3 <<
"Attr: " << attr.
name <<
'\n';
271 out3 <<
"Value: " << attr.
value <<
'\n';
273 if (token[token.length() - 1] ==
'>') {
283 if (
name ==
"comment") {
287 if (is.bad() || is.eof()) {
289 "Unexpected end of file while looking for "
311 os <<
' ' << it->name <<
"=\"" << it->value <<
'\"';
323 throw std::runtime_error(
324 "file_format contains illegal string. "
325 "Valid values are:\n"
326 " ascii: XML output\n"
327 " zascii: Zipped XML output\n"
328 " binary: XML + binary output");
348 file.exceptions(ios::badbit | ios::failbit);
352 file.open(name.c_str());
353 }
catch (
const std::exception&) {
355 os <<
"Cannot open output file: " << name <<
'\n'
356 <<
"Maybe you don't have write access "
357 <<
"to the directory or the file?";
358 throw runtime_error(os.str());
368 os <<
"Cannot open output file: " << name <<
'\n'
369 <<
"Maybe you don't have write access "
370 <<
"to the directory or the file?";
371 throw runtime_error(os.str());
390 file.exceptions(ios::badbit | ios::failbit);
395 if (nname.
nelem() < 3 || nname.substr(nname.length() - 3, 3) !=
".gz") {
400 file.
open(nname.c_str());
401 }
catch (
const ios::failure&) {
403 os <<
"Cannot open output file: " << nname <<
'\n'
404 <<
"Maybe you don't have write access "
405 <<
"to the directory or the file?";
406 throw runtime_error(os.str());
416 os <<
"Cannot open output file: " << nname <<
'\n'
417 <<
"Maybe you don't have write access "
418 <<
"to the directory or the file?";
419 throw runtime_error(os.str());
441 ifs.exceptions(ios::badbit);
445 ifs.open(name.c_str());
446 }
catch (
const ios::failure&) {
448 os <<
"Cannot open input file: " << name <<
'\n'
449 <<
"Maybe the file does not exist?";
450 throw runtime_error(os.str());
458 os <<
"Cannot open input file: " << name <<
'\n'
459 <<
"Maybe the file does not exist?";
460 throw runtime_error(os.str());
463 out3 <<
"- Reading input file " << name <<
"\n";
484 ifs.exceptions(ios::badbit);
488 ifs.
open(name.c_str());
489 }
catch (
const ios::failure&) {
491 os <<
"Cannot open input file: " << name <<
'\n'
492 <<
"Maybe the file does not exist?";
493 throw runtime_error(os.str());
501 os <<
"Cannot open input file: " << name <<
'\n'
502 <<
"Maybe the file does not exist?";
503 throw runtime_error(os.str());
506 out3 <<
"- Reading input file " << name <<
"\n";
524 os <<
"XML parse error: " << str_error <<
'\n'
525 <<
"Check syntax of XML file\n";
526 throw runtime_error(os.str());
539 os <<
"XML data parse error: Error reading ";
541 os << str_error <<
"\n"
542 <<
"Check syntax of XML file. A possible cause is that the file "
543 <<
"contains NaN or Inf values.\n";
544 throw runtime_error(os.str());
567 while (!is.fail() && isspace(is.peek())) is.get();
571 if (
string(str) !=
"<?xml") {
573 "Input file is not a valid xml file "
574 "(<?xml not found)");
589 if (strtype ==
"binary") {
597 if (strtype ==
"little") {
600 if (strtype ==
"big") {
609 os <<
" Error: Unknown endian type \"" << strtype
610 <<
"\" specified in XML file.\n";
611 throw runtime_error(os.str());
616 if (strtype ==
"float") {
618 }
else if (strtype ==
"double") {
620 }
else if (strtype ==
"") {
626 os <<
" Error: Unknown numeric type \"" << strtype
627 <<
"\" specified in XML file.\n";
628 throw runtime_error(os.str());
655 os <<
"<?xml version=\"1.0\"?>" <<
'\n';
698#error Numeric must be double or float
702 os << setprecision(precision);
710 dummy = (char)is_xml.peek();
711 while (is_xml && dummy !=
'<') {
714 dummy = (char)is_xml.peek();
717 if (!is_xml)
throw std::runtime_error(
"Unexpected end of file.");
The global header file for ARTS.
This file contains the class declaration of bifstream.
This file contains the class declaration of bofstream.
bool has_attribute(const String &aname) const
Returns if the attribute exists or not.
void add_attribute(const String &aname, String value)
void write_to_stream(ostream &os)
Write XML tag.
void check_name(const String &expected_name)
Check tag name.
void read_from_stream(istream &is)
Reads next XML tag.
Array< XMLAttribute > attribs
void get_attribute_value(const String &aname, String &value)
void set_name(const String &new_name)
void check_attribute(const String &aname, const String &value)
Checks whether attribute has the expected value.
Input manipulator class for doubles to enable nan and inf parsing.
void open(const char *name, int gz_open_mode=std::ios::in)
static const Index npos
Define npos:
void open(const char *name, int gz_open_mode=std::ios::out)
This file contains basic functions to handle ASCII files.
void xml_write_footer_to_stream(ostream &os, const Verbosity &verbosity)
Write closing root tag.
void xml_data_parse_error(XMLTag &tag, const String &str_error)
Throws XML parser runtime error.
void xml_open_input_file(ifstream &ifs, const String &name, const Verbosity &verbosity)
Open file for XML input.
void xml_read_footer_from_stream(istream &is, const Verbosity &verbosity)
Reads closing root tag.
void parse_xml_tag_content_as_string(std::istream &is_xml, String &content)
Get the content of an xml tag as a string.
void xml_read_header_from_stream(istream &is, FileType &ftype, NumericType &ntype, EndianType &etype, const Verbosity &verbosity)
Reads XML header and root tag.
void xml_write_header_to_stream(ostream &os, FileType ftype, const Verbosity &verbosity)
Writes XML header and root tag.
void xml_set_stream_precision(ostream &os)
FileType string2filetype(const String &file_format)
void xml_open_output_file(ofstream &file, const String &name)
Open file for XML output.
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.