hydrogen 1.2.3
Xml.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef H2C_XML_H
24#define H2C_XML_H
25
26#include <core/Object.h>
27#include <QtCore/QString>
28#include <QColor>
29#include <QtXml/QDomDocument>
30
31namespace H2Core
32{
33
38class XMLNode : public H2Core::Object<XMLNode>, public QDomNode
39{
41 public:
43 XMLNode( );
45 XMLNode( QDomNode node );
46
52 XMLNode createNode( const QString& name );
53
63 int read_int( const QString& node, int default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent = false );
73 bool read_bool( const QString& node, bool default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent = false );
84 bool read_bool( const QString& node, bool default_value, bool* pFound, bool inexistent_ok=true, bool empty_ok=true, bool bSilent = false );
94 float read_float( const QString& node, float default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent = false );
95 float read_float( const QString& node, float default_value, bool *pFound, bool inexistent_ok=true, bool empty_ok=true, bool bSilent = false );
105 QString read_string( const QString& node, const QString& default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent = false );
106 QColor read_color( const QString& node, const QColor& defaultValue = QColor( 97, 167, 251 ), bool inexistent_ok=true, bool empty_ok=true, bool bSilent = false );
107
117 QString read_attribute( const QString& attribute, const QString& default_value, bool inexistent_ok, bool empty_ok, bool bSilent = false );
118
125 QString read_text( bool empty_ok, bool bSilent = false );
126
132 void write_int( const QString& node, const int value );
138 void write_bool( const QString& node, const bool value );
144 void write_float( const QString& node, const float value );
150 void write_string( const QString& node, const QString& value );
151 void write_color( const QString& node, const QColor& color );
152
158 void write_attribute( const QString& attribute, const QString& value );
159 private:
168 QString read_child_node( const QString& node, bool inexistent_ok, bool empty_ok, bool bSilent = false );
174 void write_child_node( const QString& node, const QString& text );
175};
176
181class XMLDoc : public H2Core::Object<XMLDoc>, public QDomDocument
182{
184 public:
186 XMLDoc( );
194 bool read( const QString& filepath, const QString& schemapath=nullptr, bool bSilent = false );
199 bool write( const QString& filepath );
205 XMLNode set_root( const QString& node_name, const QString& xmlns = nullptr );
206};
207
208};
209
210#endif // H2C_XML_H
211
212/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:224
XMLDoc is a subclass of QDomDocument with read and write methods.
Definition Xml.h:182
XMLNode set_root(const QString &node_name, const QString &xmlns=nullptr)
create the xml header and root node
Definition Xml.cpp:391
bool read(const QString &filepath, const QString &schemapath=nullptr, bool bSilent=false)
read the content of an xml file
Definition Xml.cpp:296
bool write(const QString &filepath)
write itself into a file
Definition Xml.cpp:370
XMLDoc()
basic constructor
Definition Xml.cpp:294
XMLNode is a subclass of QDomNode with read and write values methods.
Definition Xml.h:39
int read_int(const QString &node, int default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
reads an integer stored into a child node
Definition Xml.cpp:170
void write_attribute(const QString &attribute, const QString &value)
write a string as an attribute of the node
Definition Xml.cpp:256
QString read_child_node(const QString &node, bool inexistent_ok, bool empty_ok, bool bSilent=false)
reads a string stored into a child node
Definition Xml.cpp:70
bool read_bool(const QString &node, bool default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
reads a boolean stored into a child node
Definition Xml.cpp:184
QString read_attribute(const QString &attribute, const QString &default_value, bool inexistent_ok, bool empty_ok, bool bSilent=false)
reads an attribute from the node
Definition Xml.cpp:230
QColor read_color(const QString &node, const QColor &defaultValue=QColor(97, 167, 251), bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
Definition Xml.cpp:107
void write_child_node(const QString &node, const QString &text)
write a string into a child node
Definition Xml.cpp:261
QString read_string(const QString &node, const QString &default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
reads a string stored into a child node
Definition Xml.cpp:95
float read_float(const QString &node, float default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
reads a float stored into a child node
Definition Xml.cpp:139
void write_color(const QString &node, const QColor &color)
Definition Xml.cpp:273
void write_float(const QString &node, const float value)
write a float into a child node
Definition Xml.cpp:280
XMLNode createNode(const QString &name)
create a new XMLNode that has to be appended into de XMLDoc
Definition Xml.cpp:63
XMLNode()
basic constructor
Definition Xml.cpp:60
void write_string(const QString &node, const QString &value)
write a string into a child node
Definition Xml.cpp:269
void write_bool(const QString &node, const bool value)
write a boolean into a child node
Definition Xml.cpp:288
QString read_text(bool empty_ok, bool bSilent=false)
reads the text (content) from the node
Definition Xml.cpp:221
void write_int(const QString &node, const int value)
write an integer into a child node
Definition Xml.cpp:284