~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/future/lib/XmlStreamReader.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : XmlStreamReader.h
 
3
    Project              : SciDAVis
 
4
    Description          : XML stream parser that supports errors as well as warnings
 
5
    --------------------------------------------------------------------
 
6
    Copyright            : (C) 2008-2009 Tilman Benkert (thzs*gmx.net)
 
7
                           (replace * with @ in the email addresses) 
 
8
                           
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#ifndef XML_STREAM_READER_H
 
30
#define XML_STREAM_READER_H
 
31
 
 
32
#include <QXmlStreamReader>
 
33
#include <QString>
 
34
#include <QStringList>
 
35
#include "lib/macros.h"
 
36
 
 
37
//! XML stream parser that supports errors as well as warnings
 
38
/**
 
39
 * This class also adds line and column numbers to the error message.
 
40
 */
 
41
class XmlStreamReader : public QXmlStreamReader
 
42
{
 
43
        public:
 
44
                XmlStreamReader();
 
45
                XmlStreamReader(QIODevice * device);
 
46
                XmlStreamReader(const QByteArray & data);
 
47
                XmlStreamReader(const QString & data);
 
48
                XmlStreamReader(const char * data);
 
49
 
 
50
                QStringList warningStrings() const;
 
51
                bool hasWarnings() const;
 
52
                void raiseWarning(const QString & message = QString());
 
53
                void raiseError(const QString & message = QString());
 
54
                CLASS_ACCESSOR(QString, d_error_prefix, errorPrefix, ErrorPrefix);
 
55
                CLASS_ACCESSOR(QString, d_error_postfix, errorPostfix, ErrorPostfix);
 
56
                CLASS_ACCESSOR(QString, d_warning_prefix, warningPrefix, WarningPrefix);
 
57
                CLASS_ACCESSOR(QString, d_warning_postfix, warningPostfix, WarningPostfix);
 
58
 
 
59
                //! Go to the next start or end element tag
 
60
                /**
 
61
                 *      If the end of the document is reached, an error is raised.
 
62
                 *
 
63
                 * \return false if end of document reached, otherwise true
 
64
                 */
 
65
                bool skipToNextTag();
 
66
                //! Go to the end element tag of the current element
 
67
                /**
 
68
                 *      If the end of the document is reached, an error is raised.
 
69
                 *
 
70
                 * \return false if end of document reached, otherwise true
 
71
                 */
 
72
                bool skipToEndElement();
 
73
                
 
74
                //! Read an XML attribute and convert it to int
 
75
                /**
 
76
                 * \param name attribute name
 
77
                 * \param ok pointer to report back whether the attribute value could be determined (may be NULL)
 
78
                 * \return the attriute value if found and converted, otherwise zero (in this case *ok is false)
 
79
                 */
 
80
                int readAttributeInt(const QString & name, bool * ok);
 
81
 
 
82
        private:
 
83
                QStringList d_warnings;
 
84
                QString d_error_prefix;
 
85
                QString d_error_postfix;
 
86
                QString d_warning_prefix;
 
87
                QString d_warning_postfix;
 
88
 
 
89
                void init();
 
90
};
 
91
 
 
92
#endif // XML_STREAM_READER_H