Marble

GeoTagHandler.h
1/*
2 SPDX-FileCopyrightText: 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef MARBLE_GEOTAGHANDLER_H
8#define MARBLE_GEOTAGHANDLER_H
9
10#include <QHash>
11#include "marble_export.h"
12#include "GeoParser.h"
13
14namespace Marble
15{
16
17class GeoNode;
18
19/**
20 * @brief A base class for XML tag handlers
21 * This is a base class that is used in the GeoParser architecture. To implement
22 * a new GeoData format you will need to subclass GeoTagHandler and reimplement
23 * the @see parse(GeoParser&) method. You also need to register the newly
24 * implemented GeoTagHandler by declaring an instance of the helper structure
25 * @see GeoTagHandlerRegistrar with a corresponding @see QualifiedName.
26 */
27class MARBLE_EXPORT GeoTagHandler
28{
29public:
30 // API to be implemented by child handlers.
31 virtual GeoNode* parse(GeoParser&) const = 0;
32
33protected: // This base class is not directly constructable nor is it copyable.
35 virtual ~GeoTagHandler();
36
37private:
38 GeoTagHandler(const GeoTagHandler&) = delete;
39 GeoTagHandler& operator=(const GeoTagHandler&) = delete;
40
41private: // Only our registrar is allowed to register tag handlers.
42 friend struct GeoTagHandlerRegistrar;
43 static void registerHandler(const GeoParser::QualifiedName&, const GeoTagHandler*);
44 static void unregisterHandler(const GeoParser::QualifiedName&);
45
46private: // Only our parser is allowed to access tag handlers.
47 friend class GeoParser;
48 static const GeoTagHandler* recognizes(const GeoParser::QualifiedName&);
49
50private:
52
53 static TagHash* tagHandlerHash();
54 static TagHash* s_tagHandlerHash;
55};
56
57// Helper structure
58struct GeoTagHandlerRegistrar
59{
60public:
61 GeoTagHandlerRegistrar(const GeoParser::QualifiedName& name, const GeoTagHandler* handler)
62 :m_name( name )
63 {
64 GeoTagHandler::registerHandler(name, handler);
65 }
66
67 ~GeoTagHandlerRegistrar()
68 {
69 GeoTagHandler::unregisterHandler(m_name);
70 }
71
72private:
73 GeoParser::QualifiedName m_name;
74};
75
76// Macros to ease registering new handlers
77#define GEODATA_DEFINE_TAG_HANDLER(Module, UpperCaseModule, Name, NameSpace) \
78 static GeoTagHandlerRegistrar s_handler##Name##NameSpace(GeoParser::QualifiedName(QLatin1String(Module##Tag_##Name), QLatin1String(NameSpace)), \
79 new UpperCaseModule##Name##TagHandler());
80
81}
82
83#endif
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
A base class for XML tag handlers This is a base class that is used in the GeoParser architecture.
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.