Skip to content

Commit

Permalink
add support for C++20 module (and C++23 std module)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthapz committed Oct 31, 2024
1 parent 2587d67 commit e354e1a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "pugixml.hpp"

#ifndef PUGIXML_EXPORT_MODULE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -44,6 +45,7 @@
#if defined(__linux__) || defined(__APPLE__)
#include <sys/stat.h>
#endif
#endif

#ifdef _MSC_VER
# pragma warning(push)
Expand Down Expand Up @@ -196,8 +198,10 @@ namespace pugi
typedef unsigned __int32 uint32_t;
}
#else
#ifndef PUGIXML_EXPORT_MODULE
# include <stdint.h>
#endif
#endif

// Memory allocation
PUGI_IMPL_NS_BEGIN
Expand Down
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 (arseny.kapoulkine@gmail.com)
* 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 (kristen@tima.net)
*/

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
24 changes: 16 additions & 8 deletions src/pugixml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#ifndef HEADER_PUGIXML_HPP
#define HEADER_PUGIXML_HPP

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

Expand All @@ -37,6 +38,7 @@
# include <iosfwd>
# include <string>
#endif
#endif

// Check if std::string_view is both requested and available
#if defined(PUGIXML_STRING_VIEW) && !defined(PUGIXML_NO_STL)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -183,7 +191,7 @@ namespace pugi
}

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

0 comments on commit e354e1a

Please sign in to comment.