ARTS 2.5.11 (git: 6827797f)
xml_io_base.h File Reference
#include <memory>
#include "arts.h"
#include "xml_io_general_types.h"

Go to the source code of this file.

Classes

class  XMLAttribute
 XML attribute class. More...
 
class  XMLTag
 The ARTS XML tag class. More...
 

Enumerations

enum  FileType : Index { FILE_TYPE_ASCII = 0 , FILE_TYPE_ZIPPED_ASCII = 1 , FILE_TYPE_BINARY = 2 }
 
enum  NumericType { NUMERIC_TYPE_FLOAT , NUMERIC_TYPE_DOUBLE }
 
enum  EndianType { ENDIAN_TYPE_LITTLE , ENDIAN_TYPE_BIG }
 

Functions

void xml_parse_error (const String &str_error)
 Throws XML parser runtime error.
 
void xml_data_parse_error (XMLTag &tag, const String &str_error)
 Throws XML parser runtime error.
 
void xml_set_stream_precision (ostream &os)
 
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_parse_from_stream (istream &, Vector &, bifstream *, XMLTag &, const Verbosity &verbosity)
 Parses Vector from XML input stream.
 
void xml_parse_from_stream (istream &, ArrayOfString &, bifstream *, XMLTag &, const Verbosity &)
 Parse ArrayOfString from XML input stream.
 
FileType string2filetype (const String &file_format)
 
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_read_footer_from_stream (istream &is, const Verbosity &verbosity)
 Reads closing root tag.
 
void xml_write_header_to_stream (ostream &os, FileType ftype, const Verbosity &verbosity)
 Writes XML header and root tag.
 
void xml_write_footer_to_stream (ostream &os, const Verbosity &verbosity)
 Write closing root tag.
 
void xml_open_input_file (ifstream &ifs, const String &name, const Verbosity &verbosity)
 Open file for XML input.
 
void xml_open_output_file (ofstream &file, const String &name)
 Open file for XML output.
 
template<typename T >
void xml_read_from_file_base (const String &filename, T &type, const Verbosity &verbosity)
 Reads data from XML file.
 
template<typename T >
void xml_write_to_file_base (const String &filename, const T &type, const FileType ftype, const Verbosity &verbosity)
 Write data to XML file.
 

Enumeration Type Documentation

◆ EndianType

enum EndianType
Enumerator
ENDIAN_TYPE_LITTLE 
ENDIAN_TYPE_BIG 

Definition at line 32 of file xml_io_base.h.

◆ FileType

enum FileType : Index
Enumerator
FILE_TYPE_ASCII 
FILE_TYPE_ZIPPED_ASCII 
FILE_TYPE_BINARY 

Definition at line 25 of file xml_io_base.h.

◆ NumericType

Enumerator
NUMERIC_TYPE_FLOAT 
NUMERIC_TYPE_DOUBLE 

Definition at line 31 of file xml_io_base.h.

Function Documentation

◆ parse_xml_tag_content_as_string()

void parse_xml_tag_content_as_string ( std::istream &  is_xml,
String content 
)

Get the content of an xml tag as a string.

Definition at line 706 of file xml_io_base.cc.

Referenced by xml_read_from_stream().

◆ string2filetype()

FileType string2filetype ( const String file_format)

◆ xml_data_parse_error()

void xml_data_parse_error ( XMLTag tag,
const String str_error 
)

Throws XML parser runtime error.

This is used quite often inside the data parsing routines so it's a function for itself.

Parameters
tagXMLTag
str_errorError description

Definition at line 537 of file xml_io_base.cc.

References XMLTag::write_to_stream().

◆ xml_open_input_file()

void xml_open_input_file ( ifstream &  ifs,
const String name,
const Verbosity verbosity 
)

Open file for XML input.

This function opens an XML file for reading.

Parameters
ifsInput filestream
nameFilename

Definition at line 432 of file xml_io_base.cc.

References CREATE_OUT3.

Referenced by xml_find_and_open_input_file(), and xml_read_from_file_base().

◆ xml_open_output_file()

void xml_open_output_file ( ofstream &  file,
const String name 
)

Open file for XML output.

This function opens an XML file for writing.

Parameters
fileOutput filestream
nameFilename

Definition at line 342 of file xml_io_base.cc.

Referenced by xml_write_to_file_base().

◆ xml_parse_error()

void xml_parse_error ( const String str_error)

Throws XML parser runtime error.

This is used quite often inside the parsing routines so it's a function for itself.

Parameters
str_errorError description

Definition at line 522 of file xml_io_base.cc.

Referenced by XMLTag::check_attribute(), XMLTag::check_name(), ArtsXMLTag::get_attribute_value(), XMLTag::get_attribute_value(), XMLTag::read_from_stream(), xml_read_from_stream(), and xml_read_header_from_stream().

◆ xml_parse_from_stream() [1/2]

void xml_parse_from_stream ( istream &  is_xml,
ArrayOfString astring,
bifstream pbifs,
XMLTag tag,
const Verbosity verbosity 
)

Parse ArrayOfString from XML input stream.

Parameters
is_xmlXML Input stream
astringArrayOfString return value
pbifsPointer to binary input stream. NULL in case of ASCII file.
tagXML tag object

Definition at line 2771 of file xml_io_array_types.cc.

References XMLTag::check_attribute(), XMLTag::get_attribute_value(), and xml_read_from_stream().

Referenced by xml_read_from_stream().

◆ xml_parse_from_stream() [2/2]

void xml_parse_from_stream ( istream &  is_xml,
Vector &  vector,
bifstream pbifs,
XMLTag tag,
const Verbosity verbosity 
)

Parses Vector from XML input stream.

Parameters
is_xmlXML Input stream
vectorVector return value
pbifsPointer to binary input stream. NULL in case of ASCII file.
tagXML tag object

Definition at line 1077 of file xml_io_general_types.cc.

References XMLTag::get_attribute_value(), binistream::readDoubleArray(), and xml_data_parse_error().

Referenced by xml_read_from_stream().

◆ xml_read_footer_from_stream()

void xml_read_footer_from_stream ( istream &  is,
const Verbosity verbosity 
)

Reads closing root tag.

Checks whether XML file ends correctly with </arts>.

Parameters
isInput stream

Definition at line 638 of file xml_io_base.cc.

References XMLTag::check_name(), and XMLTag::read_from_stream().

Referenced by xml_read_from_file_base().

◆ xml_read_from_file_base()

template<typename T >
void xml_read_from_file_base ( const String filename,
T &  type,
const Verbosity verbosity 
)

Reads data from XML file.

This is a generic functions that is used to read the XML header and footer info and calls the overloaded functions to read the data.

Parameters
filenameXML filename
typeGeneric return value

Definition at line 228 of file xml_io_base.h.

References CREATE_OUT2, FILE_TYPE_ASCII, my_basic_string< charT >::nelem(), xml_open_input_file(), xml_read_footer_from_stream(), xml_read_from_stream(), and xml_read_header_from_stream().

Referenced by xml_read_from_file().

◆ xml_read_header_from_stream()

void xml_read_header_from_stream ( istream &  is,
FileType ftype,
NumericType ntype,
EndianType etype,
const Verbosity verbosity 
)

Reads XML header and root tag.

Check whether XML file has correct version tag and reads arts root tag information.

Parameters
isInput stream
ftypeFile type
ntypeNumeric type
etypeEndian type

Definition at line 557 of file xml_io_base.cc.

References XMLTag::check_name(), ENDIAN_TYPE_BIG, ENDIAN_TYPE_LITTLE, FILE_TYPE_ASCII, FILE_TYPE_BINARY, XMLTag::get_attribute_value(), NUMERIC_TYPE_DOUBLE, NUMERIC_TYPE_FLOAT, XMLTag::read_from_stream(), and xml_parse_error().

Referenced by ReadArrayOfARTSCAT(), ReadARTSCAT(), and xml_read_from_file_base().

◆ xml_set_stream_precision()

void xml_set_stream_precision ( ostream &  os)

Definition at line 688 of file xml_io_base.cc.

Referenced by xml_write_to_stream().

◆ xml_write_footer_to_stream()

void xml_write_footer_to_stream ( ostream &  os,
const Verbosity verbosity 
)

Write closing root tag.

Parameters
osOutput stream

Definition at line 679 of file xml_io_base.cc.

References XMLTag::set_name(), and XMLTag::write_to_stream().

Referenced by xml_write_to_file_base().

◆ xml_write_header_to_stream()

void xml_write_header_to_stream ( ostream &  os,
FileType  ftype,
const Verbosity verbosity 
)

Writes XML header and root tag.

Parameters
osOutput stream
ftypeFile type

Definition at line 650 of file xml_io_base.cc.

References XMLTag::add_attribute(), FILE_TYPE_ASCII, FILE_TYPE_BINARY, FILE_TYPE_ZIPPED_ASCII, XMLTag::set_name(), and XMLTag::write_to_stream().

Referenced by xml_write_to_file_base().

◆ xml_write_to_file_base()

template<typename T >
void xml_write_to_file_base ( const String filename,
const T &  type,
const FileType  ftype,
const Verbosity verbosity 
)

Write data to XML file.

This is a generic functions that is used to write the XML header and footer info and calls the overloaded functions to write the data.

Parameters
filenameXML filename
typeGeneric input value
no_clobber0: Overwrite, 1: Use unique filename
ftypeFile type

Definition at line 296 of file xml_io_base.h.

References CREATE_OUT2, FILE_TYPE_ASCII, FILE_TYPE_ZIPPED_ASCII, xml_open_output_file(), xml_write_footer_to_stream(), xml_write_header_to_stream(), and xml_write_to_stream().

Referenced by xml_write_to_file().