dxx-rebirth/common/include/physfs_list.h
Kp 3d5de92058 Fix OS X clang build
OS X still uses clang-14, which lacks sufficient std::ranges support for
recent Rebirth changes.

- Rewrite uses of std::ranges::SYMBOL to ranges::SYMBOL
- Add a stub header that, on gcc, provides for each SYMBOL a statement
  `using std::ranges::SYMBOL;`, to delegate back to the standard library
  implementation.
- On clang, define a minimal implementation of the required symbols,
  without constraint enforcement.  Compile-testing with gcc will catch
  constraint violations.

Once OS X clang ships a standard library with the required features,
this stub header will be removed and the uses changed back to their full
names.
2022-10-31 00:51:32 +00:00

91 lines
1.9 KiB
C++

/*
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
* It is copyright by its individual contributors, as recorded in the
* project's Git history. See COPYING.txt at the top level for license
* terms and a link to the Git history.
*/
#pragma once
#include <physfs.h>
typedef char file_extension_t[5];
#ifdef __cplusplus
#include <cstdint>
#include <memory>
#include "null_sentinel_iterator.h"
#include "dxxsconf.h"
#include "dsx-ns.h"
#include "fwd-partial_range.h"
#include <array>
#include "backports-ranges.h"
namespace dcx {
class PHYSFS_list_deleter
{
public:
void operator()(char **list) const
{
PHYSFS_freeList(list);
}
};
template <typename D>
class PHYSFSX_uncounted_list_template : public std::unique_ptr<char *[], D>
{
public:
typedef null_sentinel_iterator<char *> const_iterator;
using std::unique_ptr<char *[], D>::unique_ptr;
const_iterator begin() const
{
return this->get();
}
const_iterator end() const
{
return {};
}
};
template <typename D>
class PHYSFSX_counted_list_template : public PHYSFSX_uncounted_list_template<D>
{
typedef PHYSFSX_uncounted_list_template<D> base_ptr;
using typename base_ptr::pointer;
uint_fast32_t count = 0;
public:
using base_ptr::base_ptr;
uint_fast32_t get_count() const
{
return count;
}
void set_count(uint_fast32_t c)
{
count = c;
}
void reset()
{
base_ptr::reset();
}
void reset(pointer p)
{
count = 0;
base_ptr::reset(p);
}
};
typedef PHYSFSX_uncounted_list_template<PHYSFS_list_deleter> PHYSFSX_uncounted_list;
typedef PHYSFSX_counted_list_template<PHYSFS_list_deleter> PHYSFSX_counted_list;
[[nodiscard]]
__attribute_nonnull()
PHYSFSX_uncounted_list PHYSFSX_findFiles(const char *path, ranges::subrange<const file_extension_t *> exts);
[[nodiscard]]
__attribute_nonnull()
PHYSFSX_uncounted_list PHYSFSX_findabsoluteFiles(const char *path, const char *realpath, ranges::subrange<const file_extension_t *> exts);
}
#endif