Skip to content

Commit bcf8b86

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

File tree

3 files changed

+121
-38
lines changed

3 files changed

+121
-38
lines changed

src/pugixml.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,35 @@
1616

1717
#include "pugixml.hpp"
1818

19-
#include <stdlib.h>
20-
#include <stdio.h>
21-
#include <string.h>
22-
#include <assert.h>
23-
#include <limits.h>
24-
25-
#ifdef PUGIXML_WCHAR_MODE
26-
# include <wchar.h>
27-
#endif
19+
#ifndef PUGIXML_EXPORT_MODULE
20+
# include <stdlib.h>
21+
# include <stdio.h>
22+
# include <string.h>
23+
# include <assert.h>
24+
# include <limits.h>
25+
26+
# ifdef PUGIXML_WCHAR_MODE
27+
# include <wchar.h>
28+
# endif
2829

29-
#ifndef PUGIXML_NO_XPATH
30-
# include <math.h>
31-
# include <float.h>
32-
#endif
30+
# ifndef PUGIXML_NO_XPATH
31+
# include <math.h>
32+
# include <float.h>
33+
# endif
3334

34-
#ifndef PUGIXML_NO_STL
35-
# include <istream>
36-
# include <ostream>
37-
# include <string>
38-
#endif
35+
# ifndef PUGIXML_NO_STL
36+
# include <istream>
37+
# include <ostream>
38+
# include <string>
39+
# endif
3940

4041
// For placement new
41-
#include <new>
42+
# include <new>
4243

4344
// For load_file
44-
#if defined(__linux__) || defined(__APPLE__)
45-
#include <sys/stat.h>
45+
# if defined(__linux__) || defined(__APPLE__)
46+
# include <sys/stat.h>
47+
# endif
4648
#endif
4749

4850
#ifdef _MSC_VER
@@ -196,7 +198,9 @@ namespace pugi
196198
typedef unsigned __int32 uint32_t;
197199
}
198200
#else
199-
# include <stdint.h>
201+
# ifndef PUGIXML_EXPORT_MODULE
202+
# include <stdint.h>
203+
# endif
200204
#endif
201205

202206
// Memory allocation

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: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@
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
27-
#include <stddef.h>
28+
# include <stddef.h>
2829

2930
// Include exception header for XPath
30-
#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
31-
# include <exception>
32-
#endif
31+
# if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
32+
# include <exception>
33+
# endif
3334

3435
// Include STL headers
35-
#ifndef PUGIXML_NO_STL
36-
# include <iterator>
37-
# include <iosfwd>
38-
# include <string>
36+
# ifndef PUGIXML_NO_STL
37+
# include <iterator>
38+
# include <iosfwd>
39+
# include <string>
40+
# endif
3941
#endif
4042

4143
// Check if std::string_view is both requested and available
@@ -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)