ARTS 2.5.0 (git: 9ee3ac6c)
xml_io.h
Go to the documentation of this file.
1/* Copyright (C) 2002-2012 Oliver Lemke <olemke@core-dump.info>
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 USA. */
17
19// File description
21
30#ifndef xml_io_h
31#define xml_io_h
32
33#include "arts.h"
34#include "xml_io_base.h"
35#include "xml_io_arts_types.h"
36
38// XML parser classes
40
42
45class ArtsXMLTag : public XMLTag {
46 public:
47 ArtsXMLTag(const Verbosity& rverbosity) : XMLTag(rverbosity){};
48
50
56 void add_attribute(const String& aname, const std::vector<QuantumNumberType>& value);
57
65 void add_attribute(const String& aname, const ArrayOfSpecies& value, const bool self, const bool bath);
66
68
77 void get_attribute_value(const String& aname, SpeciesTag& value);
78
89 void get_attribute_value(const String& aname, ArrayOfSpecies& value, bool& self, bool& bath);
90
98 void get_attribute_value(const String& aname, std::vector<QuantumNumberType>& value);
99
107 void get_attribute_value(const String& aname, QuantumNumbers& value);
108};
109
111// General XML handling routines
113
115 istream &, Vector &, bifstream *, ArtsXMLTag &, const Verbosity &verbosity);
116
118 istream &, ArrayOfString &, bifstream *, ArtsXMLTag &, const Verbosity &);
119
121// Generic IO routines for XML files
123
132void xml_find_and_open_input_file(std::shared_ptr<istream>& ifs,
133 const String& filename,
134 const Verbosity& verbosity);
135
137// Default file names
139
140void filename_xml(String& filename, const String& varname);
141
142void filename_xml_with_index(String& filename,
143 const Index& file_index,
144 const String& varname,
145 const Index& digits = 0);
146
148// Generic IO routines for XML files
150
152
159template <typename T>
160void xml_read_from_file(const String& filename,
161 T& type,
162 const Verbosity& verbosity) {
164
165 String xml_file = filename;
166 find_xml_file(xml_file, verbosity);
167 xml_read_from_file_base(xml_file, type, verbosity);
168}
169
171
180template <typename T>
181void xml_write_to_file(const String& filename,
182 const T& type,
183 const FileType ftype,
184 const Index no_clobber,
185 const Verbosity& verbosity) {
187
188 String efilename = add_basedir(filename);
189
190 std::unique_ptr<ostream> ofs;
191
192 if (no_clobber) make_filename_unique(efilename, ".xml");
193
194 xml_write_to_file_base(efilename, type, ftype, verbosity);
195}
196
197#endif
The global header file for ARTS.
The ARTS XML tag class.
Definition: xml_io.h:45
void add_attribute(const String &aname, const std::vector< QuantumNumberType > &value)
Adds value of attribute as type std::vector<QuantumNumberType> to tag.
Definition: xml_io.cc:42
void get_attribute_value(const String &aname, SpeciesTag &value)
Returns value of attribute as type SpeciesTag.
Definition: xml_io.cc:70
ArtsXMLTag(const Verbosity &rverbosity)
Definition: xml_io.h:47
Container class for Quantum Numbers.
Definition: quantum.h:112
The Vector class.
Definition: matpackI.h:876
The ARTS XML tag class.
Definition: xml_io_base.h:68
void add_attribute(const String &aname, const String &value)
Adds a String attribute to tag.
Definition: xml_io_base.cc:60
void get_attribute_value(const String &aname, String &value)
Returns value of attribute as String.
Definition: xml_io_base.cc:124
Binary output file stream class.
Definition: bifstream.h:42
void make_filename_unique(String &filename, const String &extension)
Make filename unique.
Definition: file.cc:571
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
Definition: file.cc:414
String add_basedir(const String &path)
Definition: file.cc:499
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
#define CREATE_OUT2
Definition: messages.h:206
char Type type
Species::Tag SpeciesTag
Definition: species_tags.h:99
void xml_write_to_file(const String &filename, const T &type, const FileType ftype, const Index no_clobber, const Verbosity &verbosity)
Write data to XML file.
Definition: xml_io.h:181
void xml_find_and_open_input_file(std::shared_ptr< istream > &ifs, const String &filename, const Verbosity &verbosity)
Open plain or zipped xml file.
Definition: xml_io.cc:154
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Definition: xml_io.h:160
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Definition: xml_io.cc:218
void filename_xml_with_index(String &filename, const Index &file_index, const String &varname, const Index &digits=0)
Gives the default filename, with file index, for the XML formats.
Definition: xml_io.cc:234
void xml_parse_from_stream(istream &, Vector &, bifstream *, ArtsXMLTag &, const Verbosity &verbosity)
This file contains private function declarations and template instantiation to handle XML data files.
FileType
Definition: xml_io_base.h:40
void xml_write_to_file_base(const String &filename, const T &type, const FileType ftype, const Verbosity &verbosity)
Write data to XML file.
Definition: xml_io_base.h:311
void xml_read_from_file_base(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Definition: xml_io_base.h:243