scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

XmlStreamReader Class Reference

XML stream parser that supports errors as well as warnings. More...

#include <XmlStreamReader.h>

Inheritance diagram for XmlStreamReader:
[legend]
Collaboration diagram for XmlStreamReader:
[legend]

Public Member Functions

 XmlStreamReader ()
 
 XmlStreamReader (QIODevice *device)
 
 XmlStreamReader (const QByteArray &data)
 
 XmlStreamReader (const QString &data)
 
 XmlStreamReader (const char *data)
 
QStringList warningStrings () const
 
bool hasWarnings () const
 
void raiseWarning (const QString &message=QString())
 
void raiseError (const QString &message=QString())
 
 CLASS_ACCESSOR (QString, d_error_prefix, errorPrefix, ErrorPrefix)
 
 CLASS_ACCESSOR (QString, d_error_postfix, errorPostfix, ErrorPostfix)
 
 CLASS_ACCESSOR (QString, d_warning_prefix, warningPrefix, WarningPrefix)
 
 CLASS_ACCESSOR (QString, d_warning_postfix, warningPostfix, WarningPostfix)
 
bool skipToNextTag ()
 Go to the next start or end element tag. More...
 
bool skipToEndElement ()
 Go to the end element tag of the current element. More...
 
int readAttributeInt (const QString &name, bool *ok)
 Read an XML attribute and convert it to int. More...
 

Private Member Functions

void init ()
 

Private Attributes

QStringList d_warnings
 
QString d_error_prefix
 
QString d_error_postfix
 
QString d_warning_prefix
 
QString d_warning_postfix
 

Detailed Description

XML stream parser that supports errors as well as warnings.

File : XmlStreamReader.h Project : SciDAVis

Description : XML stream parser that supports errors as well as warnings

Copyright : (C) 2008-2009 Tilman Benkert (thzs*gmx.net) (replace * with @ in the email addresses)

  • This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *
    • This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *
    • You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA *
    • This class also adds line and column numbers to the error message.

Definition at line 41 of file XmlStreamReader.h.

Constructor & Destructor Documentation

◆ XmlStreamReader() [1/5]

XmlStreamReader::XmlStreamReader ( )

File : XmlStreamReader.cpp Project : SciDAVis

Description : XML stream parser that supports errors as well as warnings

Copyright : (C) 2008-2009 Tilman Benkert (thzs*gmx.net) (replace * with @ in the email addresses)

  • This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *
    • This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *
    • You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA *

Definition at line 33 of file XmlStreamReader.cpp.

34 {
35  init();
36 }

References init().

Here is the call graph for this function:

◆ XmlStreamReader() [2/5]

XmlStreamReader::XmlStreamReader ( QIODevice *  device)

Definition at line 38 of file XmlStreamReader.cpp.

39 : QXmlStreamReader(device)
40 {
41  init();
42 }

References init().

Here is the call graph for this function:

◆ XmlStreamReader() [3/5]

XmlStreamReader::XmlStreamReader ( const QByteArray &  data)

Definition at line 44 of file XmlStreamReader.cpp.

45 : QXmlStreamReader(data)
46 {
47  init();
48 }

References init().

Here is the call graph for this function:

◆ XmlStreamReader() [4/5]

XmlStreamReader::XmlStreamReader ( const QString &  data)

Definition at line 50 of file XmlStreamReader.cpp.

51 : QXmlStreamReader(data)
52 {
53  init();
54 }

References init().

Here is the call graph for this function:

◆ XmlStreamReader() [5/5]

XmlStreamReader::XmlStreamReader ( const char *  data)

Definition at line 56 of file XmlStreamReader.cpp.

57 : QXmlStreamReader(data)
58 {
59  init();
60 }

References init().

Here is the call graph for this function:

Member Function Documentation

◆ CLASS_ACCESSOR() [1/4]

XmlStreamReader::CLASS_ACCESSOR ( QString  ,
d_error_postfix  ,
errorPostfix  ,
ErrorPostfix   
)

◆ CLASS_ACCESSOR() [2/4]

XmlStreamReader::CLASS_ACCESSOR ( QString  ,
d_error_prefix  ,
errorPrefix  ,
ErrorPrefix   
)

◆ CLASS_ACCESSOR() [3/4]

XmlStreamReader::CLASS_ACCESSOR ( QString  ,
d_warning_postfix  ,
warningPostfix  ,
WarningPostfix   
)

◆ CLASS_ACCESSOR() [4/4]

XmlStreamReader::CLASS_ACCESSOR ( QString  ,
d_warning_prefix  ,
warningPrefix  ,
WarningPrefix   
)

◆ hasWarnings()

bool XmlStreamReader::hasWarnings ( ) const

Definition at line 75 of file XmlStreamReader.cpp.

76 {
77  return !(d_warnings.isEmpty());
78 }

References d_warnings.

Referenced by ApplicationWindow::openMatrix(), and ApplicationWindow::openTable().

Here is the caller graph for this function:

◆ init()

void XmlStreamReader::init ( )
private

Definition at line 62 of file XmlStreamReader.cpp.

63 {
64  d_error_prefix = QObject::tr("XML reader error: ","prefix for XML error messages");
65  d_error_postfix = QObject::tr(" (loading failed)", "postfix for XML error messages");
66  d_warning_prefix = QObject::tr("XML reader warning: ","prefix for XML warning messages");
67  d_warning_postfix = QObject::tr("", "postfix for XML warning messages");
68 }

References d_error_postfix, d_error_prefix, d_warning_postfix, and d_warning_prefix.

Referenced by XmlStreamReader().

Here is the caller graph for this function:

◆ raiseError()

void XmlStreamReader::raiseError ( const QString &  message = QString())

Definition at line 80 of file XmlStreamReader.cpp.

81 {
82  QString prefix2 = QString(QObject::tr("line %1, column %2: ").arg(lineNumber()).arg(columnNumber()));
83  QXmlStreamReader::raiseError(d_error_prefix+prefix2+message+d_error_postfix);
84 }

References d_error_postfix, and d_error_prefix.

Referenced by future::Folder::load(), Project::load(), future::Matrix::load(), future::Table::load(), AbstractSimpleFilter::load(), Double2StringFilter::load(), Column::load(), future::Matrix::readCellElement(), future::Folder::readChildAspectElement(), future::Matrix::readColumnWidthElement(), future::Table::readColumnWidthElement(), future::Matrix::readCoordinatesElement(), future::Matrix::readDisplayElement(), future::Matrix::readRowHeightElement(), skipToEndElement(), skipToNextTag(), Column::XmlReadFormula(), Column::XmlReadMask(), and Column::XmlReadRow().

Here is the caller graph for this function:

◆ raiseWarning()

void XmlStreamReader::raiseWarning ( const QString &  message = QString())

Definition at line 86 of file XmlStreamReader.cpp.

87 {
88  QString prefix2 = QString(QObject::tr("line %1, column %2: ").arg(lineNumber()).arg(columnNumber()));
89  d_warnings.append(d_warning_prefix+prefix2+message+d_warning_postfix);
90 }

References d_warning_postfix, d_warning_prefix, and d_warnings.

Referenced by future::Folder::load(), Project::load(), future::Matrix::load(), future::Table::load(), AbstractSimpleFilter::load(), Column::load(), AbstractAspect::readBasicAttributes(), and future::Folder::readChildAspectElement().

Here is the caller graph for this function:

◆ readAttributeInt()

int XmlStreamReader::readAttributeInt ( const QString &  name,
bool *  ok 
)

Read an XML attribute and convert it to int.

Parameters
nameattribute name
okpointer to report back whether the attribute value could be determined (may be NULL)
Returns
the attriute value if found and converted, otherwise zero (in this case *ok is false)

Definition at line 110 of file XmlStreamReader.cpp.

111 {
112  QString str = attributes().value(namespaceUri().toString(), name).toString();
113  if (str.isEmpty())
114  {
115  if (ok) *ok = false;
116  return 0;
117  }
118  return str.toInt(ok);
119 }

References name(), str, and toString().

Referenced by Project::load(), future::Matrix::load(), future::Table::load(), future::Matrix::readCellElement(), future::Matrix::readColumnWidthElement(), future::Table::readColumnWidthElement(), future::Matrix::readCoordinatesElement(), future::Matrix::readDisplayElement(), future::Matrix::readRowHeightElement(), Column::XmlReadFormula(), Column::XmlReadMask(), and Column::XmlReadRow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skipToEndElement()

bool XmlStreamReader::skipToEndElement ( )

Go to the end element tag of the current element.

If the end of the document is reached, an error is raised.

Returns
false if end of document reached, otherwise true

Definition at line 121 of file XmlStreamReader.cpp.

122 {
123  int depth = 1;
124  if (atEnd())
125  {
126  raiseError(QObject::tr("unexpected end of document"));
127  return false;
128  }
129  do {
130  readNext();
131  if (isEndElement()) depth--;
132  if (isStartElement()) depth++;
133  } while (!((isEndElement() && depth == 0) || atEnd()));
134  if (atEnd())
135  {
136  raiseError(QObject::tr("unexpected end of document"));
137  return false;
138  }
139  return true;
140 }

References raiseError().

Referenced by future::Folder::load(), Project::load(), future::Matrix::load(), future::Table::load(), AbstractSimpleFilter::load(), Column::load(), future::Folder::readChildAspectElement(), future::Matrix::readCoordinatesElement(), future::Matrix::readDisplayElement(), and Column::XmlReadMask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skipToNextTag()

bool XmlStreamReader::skipToNextTag ( )

Go to the next start or end element tag.

If the end of the document is reached, an error is raised.

Returns
false if end of document reached, otherwise true

Definition at line 92 of file XmlStreamReader.cpp.

93 {
94  if (atEnd())
95  {
96  raiseError(QObject::tr("unexpected end of document"));
97  return false;
98  }
99  do {
100  readNext();
101  } while (!(isStartElement() || isEndElement() || atEnd()));
102  if (atEnd())
103  {
104  raiseError(QObject::tr("unexpected end of document"));
105  return false;
106  }
107  return true;
108 }

References raiseError().

Referenced by Project::load(), future::Folder::readChildAspectElement(), Column::XmlReadInputFilter(), and Column::XmlReadOutputFilter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ warningStrings()

QStringList XmlStreamReader::warningStrings ( ) const

Definition at line 70 of file XmlStreamReader.cpp.

71 {
72  return d_warnings;
73 }

References d_warnings.

Referenced by ApplicationWindow::openMatrix(), and ApplicationWindow::openTable().

Here is the caller graph for this function:

Member Data Documentation

◆ d_error_postfix

QString XmlStreamReader::d_error_postfix
private

Definition at line 85 of file XmlStreamReader.h.

Referenced by init(), and raiseError().

◆ d_error_prefix

QString XmlStreamReader::d_error_prefix
private

Definition at line 84 of file XmlStreamReader.h.

Referenced by init(), and raiseError().

◆ d_warning_postfix

QString XmlStreamReader::d_warning_postfix
private

Definition at line 87 of file XmlStreamReader.h.

Referenced by init(), and raiseWarning().

◆ d_warning_prefix

QString XmlStreamReader::d_warning_prefix
private

Definition at line 86 of file XmlStreamReader.h.

Referenced by init(), and raiseWarning().

◆ d_warnings

QStringList XmlStreamReader::d_warnings
private

Definition at line 83 of file XmlStreamReader.h.

Referenced by hasWarnings(), raiseWarning(), and warningStrings().


The documentation for this class was generated from the following files:
XmlStreamReader::d_warnings
QStringList d_warnings
Definition: XmlStreamReader.h:83
XmlStreamReader::raiseError
void raiseError(const QString &message=QString())
Definition: XmlStreamReader.cpp:80
data
Definition: exp_saturation.c:37
str
#define str(x)
Definition: PythonScripting.cpp:41
toString
S toString(const QString &x)
Deal with conversion between QString and std::string/std::wstring in a generic way.
XmlStreamReader::d_warning_postfix
QString d_warning_postfix
Definition: XmlStreamReader.h:87
XmlStreamReader::d_error_postfix
QString d_error_postfix
Definition: XmlStreamReader.h:85
XmlStreamReader::init
void init()
Definition: XmlStreamReader.cpp:62
name
char * name()
Definition: exp_saturation.c:45
XmlStreamReader::d_error_prefix
QString d_error_prefix
Definition: XmlStreamReader.h:84
XmlStreamReader::d_warning_prefix
QString d_warning_prefix
Definition: XmlStreamReader.h:86