Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for C++20 module (and C++23 std module)
Browse files Browse the repository at this point in the history
Arthapz committed Oct 31, 2024

Verified

This commit was signed with the committer’s verified signature.
Arthapz Arthur Laurent
1 parent 2587d67 commit bcf8b86
Showing 3 changed files with 121 additions and 38 deletions.
48 changes: 26 additions & 22 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
@@ -16,33 +16,35 @@

#include "pugixml.hpp"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <limits.h>

#ifdef PUGIXML_WCHAR_MODE
# include <wchar.h>
#endif
#ifndef PUGIXML_EXPORT_MODULE
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <assert.h>
# include <limits.h>

# ifdef PUGIXML_WCHAR_MODE
# include <wchar.h>
# endif

#ifndef PUGIXML_NO_XPATH
# include <math.h>
# include <float.h>
#endif
# ifndef PUGIXML_NO_XPATH
# include <math.h>
# include <float.h>
# endif

#ifndef PUGIXML_NO_STL
# include <istream>
# include <ostream>
# include <string>
#endif
# ifndef PUGIXML_NO_STL
# include <istream>
# include <ostream>
# include <string>
# endif

// For placement new
#include <new>
# include <new>

// For load_file
#if defined(__linux__) || defined(__APPLE__)
#include <sys/stat.h>
# if defined(__linux__) || defined(__APPLE__)
# include <sys/stat.h>
# endif
#endif

#ifdef _MSC_VER
@@ -196,7 +198,9 @@ namespace pugi
typedef unsigned __int32 uint32_t;
}
#else
# include <stdint.h>
# ifndef PUGIXML_EXPORT_MODULE
# include <stdint.h>
# endif
#endif

// Memory allocation
71 changes: 71 additions & 0 deletions src/pugixml.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* pugixml parser - version 1.14
* --------------------------------------------------------
* Copyright (C) 2006-2024, by Arseny Kapoulkine ([email protected])
* Report bugs and download new versions at https://pugixml.org/
*
* This library is distributed under the MIT License. See notice at the end
* of this file.
*
* This work is based on the pugxml parser, which is:
* Copyright (C) 2003, by Kristen Wegner ([email protected])
*/

module;

#define PUGIXML_EXPORT_MODULE

#include <pugiconfig.hpp>

#ifndef PUGIXML_USE_STD_MODULE
# include <string_view>
# include <iterator>
# include <istream>
# include <ostream>
# include <string>
# include <new>
# include <exception>
#endif

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <stdint.h>

#ifdef PUGIXML_WCHAR_MODE
# include <wchar.h>
#endif

#ifndef PUGIXML_NO_XPATH
# include <math.h>
# include <float.h>
#endif

#if defined(__linux__) || defined(__APPLE__)
# include <sys/stat.h>
#endif

export module pugixml;

#ifdef PUGIXML_USE_STD_MODULE
import std.compat;
#endif

#define PUGIXML_MODULE_EXPORT export
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
#endif
#include <pugixml.hpp>
#if defined(__clang__)
# pragma clang diagnostic pop
#endif


module :private;

#define PUGIXML_SOURCE "pugixml.cpp"
#include PUGIXML_SOURCE
40 changes: 24 additions & 16 deletions src/pugixml.hpp
Original file line number Diff line number Diff line change
@@ -23,19 +23,21 @@
#ifndef HEADER_PUGIXML_HPP
#define HEADER_PUGIXML_HPP

#ifndef PUGIXML_EXPORT_MODULE
// Include stddef.h for size_t and ptrdiff_t
#include <stddef.h>
# include <stddef.h>

// Include exception header for XPath
#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
# include <exception>
#endif
# if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
# include <exception>
# endif

// Include STL headers
#ifndef PUGIXML_NO_STL
# include <iterator>
# include <iosfwd>
# include <string>
# ifndef PUGIXML_NO_STL
# include <iterator>
# include <iosfwd>
# include <string>
# endif
#endif

// Check if std::string_view is both requested and available
@@ -48,8 +50,10 @@
#endif

// Include string_view if appropriate
#ifdef PUGIXML_HAS_STRING_VIEW
# include <string_view>
#ifndef PUGIXML_MODULE_EXPORT
# ifdef PUGIXML_HAS_STRING_VIEW
# include <string_view>
# endif
#endif

// Macro for deprecated features
@@ -150,11 +154,11 @@
// If C++ is 2017 or higher, add 'inline' qualifiers for constants
// required for C++20 module
#ifndef PUGIXML_CONSTANT
# if __cplusplus >= 201703
# define PUGIXML_CONSTANT inline PUGIXML_CONSTEXPR
# else
# define PUGIXML_CONSTANT PUGIXML_CONSTEXPR
# endif
# if __cplusplus >= 201703
# define PUGIXML_CONSTANT inline PUGIXML_CONSTEXPR
# else
# define PUGIXML_CONSTANT PUGIXML_CONSTEXPR
# endif
#endif

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

#ifndef PUGIXML_MODULE_EXPORT
# define PUGIXML_MODULE_EXPORT
#endif

namespace pugi
{
// Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE
@@ -183,7 +191,7 @@ namespace pugi
}

// The PugiXML namespace
namespace pugi
PUGIXML_MODULE_EXPORT namespace pugi
{
// Tree node types
enum xml_node_type

0 comments on commit bcf8b86

Please sign in to comment.