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 "GeoParser.h"
11#include "marble_export.h"
12#include <QHash>
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 {
59public:
60 GeoTagHandlerRegistrar(const GeoParser::QualifiedName &name, const GeoTagHandler *handler)
61 : m_name(name)
62 {
63 GeoTagHandler::registerHandler(name, handler);
64 }
65
66 ~GeoTagHandlerRegistrar()
67 {
68 GeoTagHandler::unregisterHandler(m_name);
69 }
70
71private:
72 GeoParser::QualifiedName m_name;
73};
74
75// Macros to ease registering new handlers
76#define GEODATA_DEFINE_TAG_HANDLER(Module, UpperCaseModule, Name, NameSpace) \
77 static GeoTagHandlerRegistrar s_handler##Name##NameSpace(GeoParser::QualifiedName(QLatin1String(Module##Tag_##Name), QLatin1String(NameSpace)), \
78 new UpperCaseModule##Name##TagHandler());
79
80}
81
82#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 Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.