digiKam
galleryxmlutils.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2006-04-04
7  * Description : a tool to generate HTML image galleries
8  *
9  * Copyright (C) 2006-2010 by Aurelien Gateau <aurelien dot gateau at free dot fr>
10  * Copyright (C) 2012-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_GALLERY_XML_UTILS_H
25 #define DIGIKAM_GALLERY_XML_UTILS_H
26 
27 // Qt includes
28 
29 #include <QString>
30 #include <QMap>
31 
32 // libxml includes
33 
34 #include <libxml/xmlwriter.h>
35 
37 {
38 
43 template <class Ptr, void(*freeFcn)(Ptr)>
44 
45 class CWrapper
46 {
47 public:
48 
50  : m_ptr(nullptr)
51  {
52  }
53 
54  // cppcheck-suppress noExplicitConstructor
55  CWrapper(Ptr ptr) // krazy:exclude=explicit
56  : m_ptr(ptr)
57  {
58  }
59 
61  {
62  freeFcn(m_ptr);
63  }
64 
65  operator Ptr() const
66  {
67  return m_ptr;
68  }
69 
70  bool operator!() const
71  {
72  return !m_ptr;
73  }
74 
75  void assign(Ptr ptr)
76  {
77  if (m_ptr)
78  {
79  freeFcn(m_ptr);
80  }
81 
82  m_ptr = ptr;
83  }
84 
85 private:
86 
87  Ptr m_ptr;
88 };
89 
90 // --------------------------------------------------------------------------
91 
95 class XMLWriter
96 {
97 public:
98 
99  bool open(const QString& name);
100  operator xmlTextWriterPtr() const;
101 
102  void writeElement(const char* element, const QString& value);
103  void writeElement(const char* element, int value);
104 
105 private:
106 
108 };
109 
110 
111 // --------------------------------------------------------------------------
116 {
117 public:
118 
119  void write(XMLWriter& writer) const;
120  void append(const QString& key, const QString& value);
121  void append(const QString& key, int value);
122 
123 private:
124 
125  typedef QMap<QString, QString> Map;
126 
127  Map m_map;
128 };
129 
130 // --------------------------------------------------------------------------
131 
136 {
137 public:
138 
139  explicit XMLElement(XMLWriter& writer,
140  const QString& element,
141  const XMLAttributeList* attributeList = nullptr);
142  ~XMLElement();
143 
144 private:
145 
146  XMLWriter& m_writer;
147 };
148 
149 } // namespace DigikamGenericHtmlGalleryPlugin
150 
151 #endif // DIGIKAM_GALLERY_XML_UTILS_H
Definition: galleryxmlutils.h:46
~CWrapper()
Definition: galleryxmlutils.h:60
CWrapper(Ptr ptr)
Definition: galleryxmlutils.h:55
bool operator!() const
Definition: galleryxmlutils.h:70
CWrapper()
Definition: galleryxmlutils.h:49
void assign(Ptr ptr)
Definition: galleryxmlutils.h:75
Definition: galleryxmlutils.h:116
void write(XMLWriter &writer) const
Definition: galleryxmlutils.cpp:80
void append(const QString &key, const QString &value)
Definition: galleryxmlutils.cpp:97
Definition: galleryxmlutils.h:136
~XMLElement()
Definition: galleryxmlutils.cpp:125
XMLElement(XMLWriter &writer, const QString &element, const XMLAttributeList *attributeList=nullptr)
Definition: galleryxmlutils.cpp:109
Definition: galleryxmlutils.h:96
bool open(const QString &name)
Definition: galleryxmlutils.cpp:33
void writeElement(const char *element, const QString &value)
Definition: galleryxmlutils.cpp:63
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: galleryconfig.cpp:30