39constexpr std::string_view quotation_mark_replacement{
"”"};
40constexpr std::string_view quotation_mark_original{
"\""};
55 if (
name != expected_name)
72 auto pos = value.find(quotation_mark_original);
73 while (pos not_eq std::string::npos) {
74 value.replace(pos, quotation_mark_original.length(), quotation_mark_replacement);
75 pos = value.find(quotation_mark_original);
116 if (actual_value ==
"*not found*") {
118 }
else if (actual_value != value) {
119 xml_parse_error(
"Attribute " + aname +
" has value \"" + actual_value +
120 "\" but \"" + value +
"\" was expected.");
126 return std::any_of(
attribs.cbegin(),
attribs.cend(), [&](
auto& attr){return attr.name == aname;});
145 if (it->name == aname) {
153 auto pos = value.find(quotation_mark_replacement);
154 while (pos not_eq std::string::npos) {
155 value.replace(pos, quotation_mark_replacement.length(), quotation_mark_original);
156 pos = value.find(quotation_mark_replacement);
171 istringstream strstr(
"");
174 strstr.str(attribute_value);
184 istringstream strstr(
"");
187 strstr.str(attribute_value);
206 istringstream sstr(
"");
212 while (is.good() &&
isspace(is.peek())) {
228 if (is.bad() || is.eof()) {
232 if (is.get() !=
'>') {
236 sstr.str(tag.str() +
'>');
237 out3 <<
"Read: " << sstr.str() <<
'\n';
241 if (
name[
name.length() - 1] ==
'>') {
250 out3 <<
"Name: " <<
name <<
'\n';
253 while (token !=
">") {
256 pos = token.find(
"=", 0);
261 attr.
name = token.substr(0, pos);
262 token.erase(0, pos + 1);
264 if (token[0] !=
'\"') {
272 if (!ntoken.length())
break;
273 token +=
" " + ntoken;
283 attr.
value = token.substr(1, pos - 1);
287 out3 <<
"Attr: " << attr.
name <<
'\n';
288 out3 <<
"Value: " << attr.
value <<
'\n';
290 if (token[token.length() - 1] ==
'>') {
300 if (
name ==
"comment") {
304 if (is.bad() || is.eof()) {
306 "Unexpected end of file while looking for "
328 os <<
' ' << it->name <<
"=\"" << it->value <<
'\"';
340 throw std::runtime_error(
341 "file_format contains illegal string. "
342 "Valid values are:\n"
343 " ascii: XML output\n"
344 " zascii: Zipped XML output\n"
345 " binary: XML + binary output");
365 file.exceptions(ios::badbit | ios::failbit);
369 file.open(name.c_str());
370 }
catch (
const std::exception&) {
372 os <<
"Cannot open output file: " << name <<
'\n'
373 <<
"Maybe you don't have write access "
374 <<
"to the directory or the file?";
375 throw runtime_error(os.str());
385 os <<
"Cannot open output file: " << name <<
'\n'
386 <<
"Maybe you don't have write access "
387 <<
"to the directory or the file?";
388 throw runtime_error(os.str());
407 file.exceptions(ios::badbit | ios::failbit);
412 if (nname.
nelem() < 3 || nname.substr(nname.length() - 3, 3) !=
".gz") {
417 file.
open(nname.c_str());
418 }
catch (
const ios::failure&) {
420 os <<
"Cannot open output file: " << nname <<
'\n'
421 <<
"Maybe you don't have write access "
422 <<
"to the directory or the file?";
423 throw runtime_error(os.str());
433 os <<
"Cannot open output file: " << nname <<
'\n'
434 <<
"Maybe you don't have write access "
435 <<
"to the directory or the file?";
436 throw runtime_error(os.str());
458 ifs.exceptions(ios::badbit);
462 ifs.open(name.c_str());
463 }
catch (
const ios::failure&) {
465 os <<
"Cannot open input file: " << name <<
'\n'
466 <<
"Maybe the file does not exist?";
467 throw runtime_error(os.str());
475 os <<
"Cannot open input file: " << name <<
'\n'
476 <<
"Maybe the file does not exist?";
477 throw runtime_error(os.str());
480 out3 <<
"- Reading input file " << name <<
"\n";
501 ifs.exceptions(ios::badbit);
505 ifs.
open(name.c_str());
506 }
catch (
const ios::failure&) {
508 os <<
"Cannot open input file: " << name <<
'\n'
509 <<
"Maybe the file does not exist?";
510 throw runtime_error(os.str());
518 os <<
"Cannot open input file: " << name <<
'\n'
519 <<
"Maybe the file does not exist?";
520 throw runtime_error(os.str());
523 out3 <<
"- Reading input file " << name <<
"\n";
541 os <<
"XML parse error: " << str_error <<
'\n'
542 <<
"Check syntax of XML file\n";
543 throw runtime_error(os.str());
556 os <<
"XML data parse error: Error reading ";
558 os << str_error <<
"\n"
559 <<
"Check syntax of XML file. A possible cause is that the file "
560 <<
"contains NaN or Inf values.\n";
561 throw runtime_error(os.str());
584 while (!is.fail() &&
isspace(is.peek())) is.get();
588 if (
string(str) !=
"<?xml") {
590 "Input file is not a valid xml file "
591 "(<?xml not found)");
606 if (strtype ==
"binary") {
614 if (strtype ==
"little") {
617 if (strtype ==
"big") {
626 os <<
" Error: Unknown endian type \"" << strtype
627 <<
"\" specified in XML file.\n";
628 throw runtime_error(os.str());
633 if (strtype ==
"float") {
635 }
else if (strtype ==
"double") {
637 }
else if (strtype ==
"") {
643 os <<
" Error: Unknown numeric type \"" << strtype
644 <<
"\" specified in XML file.\n";
645 throw runtime_error(os.str());
672 os <<
"<?xml version=\"1.0\"?>" <<
'\n';
715#error Numeric must be double or float
727 dummy = (
char)is_xml.peek();
728 while (is_xml && dummy !=
'<') {
731 dummy = (
char)is_xml.peek();
734 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.
NUMERIC Numeric
The type to use for all floating point numbers.
INDEX Index
The type to use for all integer numbers and indices.
constexpr int isspace(int ch) noexcept
Returns 1 if x is a standard space-character.
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.