Marble

GeoTagHandler.h
1 /*
2  SPDX-FileCopyrightText: 2007, 2008 Nikolas Zimmermann <[email protected]>
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 
14 namespace Marble
15 {
16 
17 class 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  */
27 class MARBLE_EXPORT GeoTagHandler
28 {
29 public:
30  // API to be implemented by child handlers.
31  virtual GeoNode* parse(GeoParser&) const = 0;
32 
33 protected: // This base class is not directly constructable nor is it copyable.
34  GeoTagHandler();
35  virtual ~GeoTagHandler();
36 
37 private:
38  GeoTagHandler(const GeoTagHandler&) = delete;
39  GeoTagHandler& operator=(const GeoTagHandler&) = delete;
40 
41 private: // 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 
46 private: // Only our parser is allowed to access tag handlers.
47  friend class GeoParser;
48  static const GeoTagHandler* recognizes(const GeoParser::QualifiedName&);
49 
50 private:
52 
53  static TagHash* tagHandlerHash();
54  static TagHash* s_tagHandlerHash;
55 };
56 
57 // Helper structure
58 struct GeoTagHandlerRegistrar
59 {
60 public:
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 
72 private:
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:34
Binds a QML item to a specific geodetic location in screen coordinates.
A base class for XML tag handlers This is a base class that is used in the GeoParser architecture.
Definition: GeoTagHandler.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.