ARTS 2.5.9 (git: 825fa5f2)
XMLTag Class Reference

The ARTS XML tag class. More...

#include <xml_io_base.h>

Inheritance diagram for XMLTag:
ArtsXMLTag

Public Member Functions

 XMLTag (const Verbosity &rverbosity)
 
Stringget_name ()
 
void check_name (const String &expected_name)
 Check tag name. More...
 
void set_name (const String &new_name)
 
void add_attribute (const String &aname, String value)
 
void add_attribute (const String &aname, const Index &value)
 Adds an Index attribute to tag. More...
 
void add_attribute (const String &aname, const Numeric &value)
 Adds value of attribute as type Numeric to tag. More...
 
void check_attribute (const String &aname, const String &value)
 Checks whether attribute has the expected value. More...
 
void get_attribute_value (const String &aname, String &value)
 
void get_attribute_value (const String &aname, Index &value)
 Returns value of attribute as type Index. More...
 
void get_attribute_value (const String &aname, Numeric &value)
 Returns value of attribute as type Numeric. More...
 
void read_from_stream (istream &is)
 Reads next XML tag. More...
 
void write_to_stream (ostream &os)
 Write XML tag. More...
 
bool has_attribute (const String &aname) const
 Returns if the attribute exists or not. More...
 

Protected Attributes

String name
 
Array< XMLAttributeattribs
 
const Verbosityverbosity
 

Detailed Description

The ARTS XML tag class.

Handles reading, writing and constructing of XML tags.

Definition at line 70 of file xml_io_base.h.

Constructor & Destructor Documentation

◆ XMLTag()

XMLTag::XMLTag ( const Verbosity rverbosity)
inline

Definition at line 72 of file xml_io_base.h.

Member Function Documentation

◆ add_attribute() [1/3]

void XMLTag::add_attribute ( const String aname,
const Index value 
)

Adds an Index attribute to tag.

Parameters
anameAttribute name
valueAttribute value

Definition at line 88 of file xml_io_base.cc.

◆ add_attribute() [2/3]

void XMLTag::add_attribute ( const String aname,
const Numeric value 
)

Adds value of attribute as type Numeric to tag.

Parameters
[in]anameAttribute name
[in]valueSet value

Definition at line 95 of file xml_io_base.cc.

References add_attribute(), and v.

◆ add_attribute() [3/3]

void XMLTag::add_attribute ( const String aname,
String  value 
)

Adds a String attribute to tag

All " are replaced by ” to work in the XML tag

Parameters
anameAttribute name
valueAttribute value

Definition at line 67 of file xml_io_base.cc.

References attribs, XMLAttribute::name, and XMLAttribute::value.

Referenced by add_attribute(), xml_write_header_to_stream(), and xml_write_to_stream().

◆ check_attribute()

void XMLTag::check_attribute ( const String aname,
const String value 
)

Checks whether attribute has the expected value.

If the attribute has another value or is unknown an exception is thrown.

Parameters
anameAttribute name
valueExpected value

Definition at line 111 of file xml_io_base.cc.

References get_attribute_value(), and xml_parse_error().

Referenced by xml_parse_from_stream(), and xml_read_from_stream().

◆ check_name()

void XMLTag::check_name ( const String expected_name)

Check tag name.

Checks whether the name of the tag is correct. Throws runtime error otherwise.

Parameters
expected_nameExpected tag name

Definition at line 54 of file xml_io_base.cc.

References name, and xml_parse_error().

Referenced by read_from_stream(), ReadArrayOfARTSCAT(), ReadARTSCAT(), xml_read_footer_from_stream(), xml_read_from_stream(), and xml_read_header_from_stream().

◆ get_attribute_value() [1/3]

void XMLTag::get_attribute_value ( const String aname,
Index value 
)

Returns value of attribute as type Index.

Searches for the matching attribute and returns it value. If no attribute with the given name exists, return value is set to not found*.

Parameters
anameAttribute name
valueReturn value

Definition at line 169 of file xml_io_base.cc.

References get_attribute_value(), name, and xml_parse_error().

◆ get_attribute_value() [2/3]

void XMLTag::get_attribute_value ( const String aname,
Numeric value 
)

Returns value of attribute as type Numeric.

Searches for the matching attribute and returns it value. If no attribute with the given name exists, return value is set to -1e99.

Parameters
[in]anameAttribute name
[out]valueReturn value

Definition at line 182 of file xml_io_base.cc.

References get_attribute_value(), name, and xml_parse_error().

◆ get_attribute_value() [3/3]

void XMLTag::get_attribute_value ( const String aname,
String value 
)

Returns value of attribute as String

Searches for the matching attribute and returns it value. If no attribute with the given name exists, return value is set to not found*.

Replaces all ” with " to counter XML-tag problems

Parameters
anameAttribute name
valueReturn value

Definition at line 140 of file xml_io_base.cc.

References attribs.

Referenced by check_attribute(), get_attribute_value(), xml_parse_from_stream(), xml_read_from_stream(), and xml_read_header_from_stream().

◆ get_name()

String & XMLTag::get_name ( )
inline

Definition at line 74 of file xml_io_base.h.

References name.

Referenced by xml_read_from_stream().

◆ has_attribute()

bool XMLTag::has_attribute ( const String aname) const

Returns if the attribute exists or not.

Parameters
[in]anameAttribute name
Returns
bool Does this attribute exist?

Definition at line 125 of file xml_io_base.cc.

References attribs.

Referenced by xml_read_from_stream().

◆ read_from_stream()

void XMLTag::read_from_stream ( istream &  is)

Reads next XML tag.

Reads the name and attributes of the next XML tag from stream.

Parameters
isInput stream

Definition at line 201 of file xml_io_base.cc.

References attribs, check_name(), CREATE_OUT3, XMLAttribute::name, name, my_basic_string< char >::npos, read_from_stream(), XMLAttribute::value, and xml_parse_error().

Referenced by read_from_stream(), ReadArrayOfARTSCAT(), ReadARTSCAT(), xml_read_footer_from_stream(), xml_read_from_stream(), and xml_read_header_from_stream().

◆ set_name()

void XMLTag::set_name ( const String new_name)
inline

Definition at line 78 of file xml_io_base.h.

References name.

Referenced by xml_write_footer_to_stream(), xml_write_header_to_stream(), and xml_write_to_stream().

◆ write_to_stream()

void XMLTag::write_to_stream ( ostream &  os)

Write XML tag.

Puts the tag together and writes it to stream.

Parameters
osOutput stream

Definition at line 322 of file xml_io_base.cc.

References attribs, and name.

Referenced by xml_data_parse_error(), xml_write_footer_to_stream(), xml_write_header_to_stream(), and xml_write_to_stream().

Member Data Documentation

◆ attribs

Array<XMLAttribute> XMLTag::attribs
protected

List of attributes

Definition at line 121 of file xml_io_base.h.

Referenced by add_attribute(), get_attribute_value(), has_attribute(), read_from_stream(), and write_to_stream().

◆ name

String XMLTag::name
protected

◆ verbosity

const Verbosity& XMLTag::verbosity
protected

Definition at line 122 of file xml_io_base.h.


The documentation for this class was generated from the following files: