Skip to content

Commit e354e1a

Browse files
committed
add support for C++20 module (and C++23 std module)
1 parent 2587d67 commit e354e1a

File tree

3 files changed

+91
-8
lines changed

3 files changed

+91
-8
lines changed

src/pugixml.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "pugixml.hpp"
1818

19+
#ifndef PUGIXML_EXPORT_MODULE
1920
#include <stdlib.h>
2021
#include <stdio.h>
2122
#include <string.h>
@@ -44,6 +45,7 @@
4445
#if defined(__linux__) || defined(__APPLE__)
4546
#include <sys/stat.h>
4647
#endif
48+
#endif
4749

4850
#ifdef _MSC_VER
4951
# pragma warning(push)
@@ -196,8 +198,10 @@ namespace pugi
196198
typedef unsigned __int32 uint32_t;
197199
}
198200
#else
201+
#ifndef PUGIXML_EXPORT_MODULE
199202
# include <stdint.h>
200203
#endif
204+
#endif
201205

202206
// Memory allocation
203207
PUGI_IMPL_NS_BEGIN

src/pugixml.cppm

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* pugixml parser - version 1.14
3+
* --------------------------------------------------------
4+
* Copyright (C) 2006-2024, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
5+
* Report bugs and download new versions at https://pugixml.org/
6+
*
7+
* This library is distributed under the MIT License. See notice at the end
8+
* of this file.
9+
*
10+
* This work is based on the pugxml parser, which is:
11+
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
12+
*/
13+
14+
module;
15+
16+
#define PUGIXML_EXPORT_MODULE
17+
18+
#include <pugiconfig.hpp>
19+
20+
#ifndef PUGIXML_USE_STD_MODULE
21+
# include <string_view>
22+
# include <iterator>
23+
# include <istream>
24+
# include <ostream>
25+
# include <string>
26+
# include <new>
27+
# include <exception>
28+
#endif
29+
30+
#include <stddef.h>
31+
#include <stdlib.h>
32+
#include <stdio.h>
33+
#include <string.h>
34+
#include <assert.h>
35+
#include <limits.h>
36+
#include <stdint.h>
37+
38+
#ifdef PUGIXML_WCHAR_MODE
39+
# include <wchar.h>
40+
#endif
41+
42+
#ifndef PUGIXML_NO_XPATH
43+
# include <math.h>
44+
# include <float.h>
45+
#endif
46+
47+
#if defined(__linux__) || defined(__APPLE__)
48+
# include <sys/stat.h>
49+
#endif
50+
51+
export module pugixml;
52+
53+
#ifdef PUGIXML_USE_STD_MODULE
54+
import std.compat;
55+
#endif
56+
57+
#define PUGIXML_MODULE_EXPORT export
58+
#if defined(__clang__)
59+
# pragma clang diagnostic push
60+
# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
61+
#endif
62+
#include <pugixml.hpp>
63+
#if defined(__clang__)
64+
# pragma clang diagnostic pop
65+
#endif
66+
67+
68+
module :private;
69+
70+
#define PUGIXML_SOURCE "pugixml.cpp"
71+
#include PUGIXML_SOURCE

src/pugixml.hpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#ifndef HEADER_PUGIXML_HPP
2424
#define HEADER_PUGIXML_HPP
2525

26+
#ifndef PUGIXML_EXPORT_MODULE
2627
// Include stddef.h for size_t and ptrdiff_t
2728
#include <stddef.h>
2829

@@ -37,6 +38,7 @@
3738
# include <iosfwd>
3839
# include <string>
3940
#endif
41+
#endif
4042

4143
// Check if std::string_view is both requested and available
4244
#if defined(PUGIXML_STRING_VIEW) && !defined(PUGIXML_NO_STL)
@@ -48,8 +50,10 @@
4850
#endif
4951

5052
// Include string_view if appropriate
51-
#ifdef PUGIXML_HAS_STRING_VIEW
52-
# include <string_view>
53+
#ifndef PUGIXML_MODULE_EXPORT
54+
# ifdef PUGIXML_HAS_STRING_VIEW
55+
# include <string_view>
56+
# endif
5357
#endif
5458

5559
// Macro for deprecated features
@@ -150,11 +154,11 @@
150154
// If C++ is 2017 or higher, add 'inline' qualifiers for constants
151155
// required for C++20 module
152156
#ifndef PUGIXML_CONSTANT
153-
# if __cplusplus >= 201703
154-
# define PUGIXML_CONSTANT inline PUGIXML_CONSTEXPR
155-
# else
156-
# define PUGIXML_CONSTANT PUGIXML_CONSTEXPR
157-
# endif
157+
# if __cplusplus >= 201703
158+
# define PUGIXML_CONSTANT inline PUGIXML_CONSTEXPR
159+
# else
160+
# define PUGIXML_CONSTANT PUGIXML_CONSTEXPR
161+
# endif
158162
#endif
159163

160164
// Character interface macros
@@ -166,6 +170,10 @@
166170
# define PUGIXML_CHAR char
167171
#endif
168172

173+
#ifndef PUGIXML_MODULE_EXPORT
174+
# define PUGIXML_MODULE_EXPORT
175+
#endif
176+
169177
namespace pugi
170178
{
171179
// Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE
@@ -183,7 +191,7 @@ namespace pugi
183191
}
184192

185193
// The PugiXML namespace
186-
namespace pugi
194+
PUGIXML_MODULE_EXPORT namespace pugi
187195
{
188196
// Tree node types
189197
enum xml_node_type

0 commit comments

Comments
 (0)