• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • parser
GeoParser.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 
4  This file is part of the KDE project
5 
6  This library is free software you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef MARBLE_GEOPARSER_H
23 #define MARBLE_GEOPARSER_H
24 
25 #include <QPair>
26 #include <QStack>
27 #include <QXmlStreamReader>
28 
29 #include "geodata_export.h"
30 
31 namespace Marble
32 {
33 
34 typedef int GeoDataGenericSourceType;
35 
36 class GeoDocument;
37 class GeoNode;
38 class GeoStackItem;
39 
40 class GEODATA_EXPORT GeoParser : public QXmlStreamReader
41 {
42  public:
43  typedef QPair<QString, QString> QualifiedName; // Tag Name & Namespace pair
44 
45  explicit GeoParser( GeoDataGenericSourceType sourceType );
46  virtual ~GeoParser();
47 
54  bool read( QIODevice* );
55 
61  GeoDocument* releaseDocument();
62  GeoDocument* activeDocument() { return m_document; }
63 
64  // Used by tag handlers, to be overridden by GeoDataParser/GeoSceneParser
65  virtual bool isValidElement( const QString& tagName ) const;
66 
67  // Used by tag handlers, to access a parent element's associated GeoStackItem
68  GeoStackItem parentElement( unsigned int depth = 0 ) const;
69 
70  // Used by tag handlers, to emit a warning while parsing
71  void raiseWarning( const QString& );
72 
73  // Used by tag handlers, to retrieve the value for an attribute of the currently parsed element
74  QString attribute( const char* attributeName ) const;
75 
76 protected:
84  virtual bool isValidRootElement() = 0;
85 
86  virtual GeoDocument* createDocument() const = 0;
87 
88 protected:
89  GeoDocument* m_document;
90  GeoDataGenericSourceType m_source;
91 
92 private:
93  void parseDocument();
94  QStack<GeoStackItem> m_nodeStack;
95 };
96 
97 class GeoStackItem
98 {
99  public:
100  GeoStackItem()
101  : m_qualifiedName(),
102  m_node( 0 )
103  {
104  }
105 
106  GeoStackItem( const GeoParser::QualifiedName& qualifiedName, GeoNode* node )
107  : m_qualifiedName( qualifiedName ),
108  m_node( node )
109  {
110  }
111 
112  // Fast path for tag handlers
113  bool represents( const char* tagName ) const
114  {
115  return m_node && tagName == m_qualifiedName.first;
116  }
117 
118  // Helper for tag handlers. Does NOT guard against miscasting. Use with care.
119  template<class T>
120  T* nodeAs()
121  {
122  Q_ASSERT( dynamic_cast<T*>( m_node ) != 0 );
123  return static_cast<T*>(m_node);
124  }
125 
126  template<class T>
127  bool is() const
128  {
129  return 0 != dynamic_cast<T*>(m_node);
130  }
131 
132  GeoParser::QualifiedName qualifiedName() const { return m_qualifiedName; }
133  GeoNode* associatedNode() const { return m_node; }
134 
135 private:
136  friend class GeoParser;
137  void assignNode( GeoNode* node ) { m_node = node; }
138  GeoParser::QualifiedName m_qualifiedName;
139  GeoNode* m_node;
140 };
141 
142 }
143 
144 #endif
Marble::GeoParser::activeDocument
GeoDocument * activeDocument()
Definition: GeoParser.h:62
Marble::GeoStackItem::nodeAs
T * nodeAs()
Definition: GeoParser.h:120
Marble::GeoParser::m_document
GeoDocument * m_document
Definition: GeoParser.h:89
Marble::GeoParser::m_source
GeoDataGenericSourceType m_source
Definition: GeoParser.h:90
Marble::GeoNode
A shared base class for all classes that are mapped to a specific tag (ie.
Definition: GeoDocument.h:60
Marble::GeoStackItem::GeoStackItem
GeoStackItem()
Definition: GeoParser.h:100
Marble::GeoParser
Definition: GeoParser.h:40
Marble::GeoStackItem::represents
bool represents(const char *tagName) const
Definition: GeoParser.h:113
Marble::GeoStackItem
Definition: GeoParser.h:97
Marble::GeoDocument
A shared base class between GeoDataDocument/GeoSourceDocument.
Definition: GeoDocument.h:42
Marble::GeoStackItem::GeoStackItem
GeoStackItem(const GeoParser::QualifiedName &qualifiedName, GeoNode *node)
Definition: GeoParser.h:106
Marble::GeoDataGenericSourceType
int GeoDataGenericSourceType
Definition: GeoParser.h:34
GEODATA_EXPORT
#define GEODATA_EXPORT
Definition: geodata_export.h:22
geodata_export.h
QXmlStreamReader
Marble::GeoStackItem::associatedNode
GeoNode * associatedNode() const
Definition: GeoParser.h:133
Marble::GeoParser::QualifiedName
QPair< QString, QString > QualifiedName
Definition: GeoParser.h:43
Marble::GeoStackItem::is
bool is() const
Definition: GeoParser.h:127
Marble::GeoStackItem::qualifiedName
GeoParser::QualifiedName qualifiedName() const
Definition: GeoParser.h:132
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal