diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2018-07-03 11:43:55 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2018-07-03 11:43:55 +0300 |
commit | 53d415a3b69d2680c15ae2c56a9baf9b149ad71d (patch) | |
tree | b55e046b3b7a2e504c9abebf4a15a3dddff67eba /include/llfio/v2.0/config.hpp | |
parent | 69e9c42365a92bc1af57a843f48513e19aaf0cdf (diff) |
Rename afio to llfio part 1 of many
Diffstat (limited to 'include/llfio/v2.0/config.hpp')
-rw-r--r-- | include/llfio/v2.0/config.hpp | 494 |
1 files changed, 494 insertions, 0 deletions
diff --git a/include/llfio/v2.0/config.hpp b/include/llfio/v2.0/config.hpp new file mode 100644 index 00000000..c6f08c9d --- /dev/null +++ b/include/llfio/v2.0/config.hpp @@ -0,0 +1,494 @@ +/* Configures AFIO +(C) 2015-2018 Niall Douglas <http://www.nedproductions.biz/> (24 commits) +File Created: Dec 2015 + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License in the accompanying file +Licence.txt or at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Distributed under the Boost Software License, Version 1.0. + (See accompanying file Licence.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +#ifndef AFIO_CONFIG_HPP +#define AFIO_CONFIG_HPP + +//#include <iostream> +//#define AFIO_LOG_TO_OSTREAM std::cerr +//#define AFIO_LOGGING_LEVEL 6 +//#define AFIO_DISABLE_PATHS_IN_FAILURE_INFO + +//! \file config.hpp Configures a compiler environment for AFIO header and source code + +//! \defgroup config Configuration macros + +#if !defined(AFIO_HEADERS_ONLY) && !defined(BOOST_ALL_DYN_LINK) +//! \brief Whether AFIO is a headers only library. Defaults to 1 unless BOOST_ALL_DYN_LINK is defined. \ingroup config +#define AFIO_HEADERS_ONLY 1 +#endif + +//! \def AFIO_DISABLE_PATHS_IN_FAILURE_INFO +//! \brief Define to not record the current handle's path in any failure info. +#if DOXYGEN_IS_IN_THE_HOUSE +#define AFIO_DISABLE_PATHS_IN_FAILURE_INFO not defined +#endif + +#if !defined(AFIO_LOGGING_LEVEL) +//! \brief How much detail to log. 0=disabled, 1=fatal, 2=error, 3=warn, 4=info, 5=debug, 6=all. +//! Defaults to error level. \ingroup config +#ifdef NDEBUG +#define AFIO_LOGGING_LEVEL 1 // fatal +#else +#define AFIO_LOGGING_LEVEL 3 // warn +#endif +#endif + +#ifndef AFIO_LOG_TO_OSTREAM +#if !defined(NDEBUG) && !defined(AFIO_DISABLE_LOG_TO_OSTREAM) +#include <iostream> // for std::cerr +//! \brief Any `ostream` to also log to. If `NDEBUG` is not defined, `std::cerr` is the default. +#define AFIO_LOG_TO_OSTREAM std::cerr +#endif +#endif + +#if !defined(AFIO_LOG_BACKTRACE_LEVELS) +//! \brief Bit mask of which log levels should be stack backtraced +//! which will slow those logs thirty fold or so. Defaults to (1U<<1U)|(1U<<2U)|(1U<<3U) i.e. stack backtrace +//! on fatal, error and warn logs. \ingroup config +#define AFIO_LOG_BACKTRACE_LEVELS ((1U << 1U) | (1U << 2U) | (1U << 3U)) +#endif + +#if !defined(AFIO_LOGGING_MEMORY) +#ifdef NDEBUG +#define AFIO_LOGGING_MEMORY 4096 +#else +//! \brief How much memory to use for the log. +//! Defaults to 4Kb if NDEBUG defined, else 1Mb. \ingroup config +#define AFIO_LOGGING_MEMORY (1024 * 1024) +#endif +#endif + +#if !defined(AFIO_EXPERIMENTAL_STATUS_CODE) +//! \brief Whether to use SG14 experimental `status_code` instead of `std::error_code` +#define AFIO_EXPERIMENTAL_STATUS_CODE 0 +#endif + + +#if defined(_WIN32) +#if !defined(_UNICODE) +#error AFIO cannot target the ANSI Windows API. Please define _UNICODE to target the Unicode Windows API. +#endif +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x0600 +#elif _WIN32_WINNT < 0x0600 +#error _WIN32_WINNT must at least be set to Windows Vista for AFIO to work +#endif +#if defined(NTDDI_VERSION) && NTDDI_VERSION < 0x06000000 +#error NTDDI_VERSION must at least be set to Windows Vista for AFIO to work +#endif +#endif + +#ifdef __APPLE__ +#define AFIO_MISSING_PIOV 1 +#endif + +// Pull in detection of __MINGW64_VERSION_MAJOR +#ifdef __MINGW32__ +#include <_mingw.h> +#endif + +#include "quickcpplib/include/cpp_feature.h" + +#ifndef __cpp_exceptions +#error AFIO needs C++ exceptions to be turned on +#endif +#ifndef __cpp_alias_templates +#error AFIO needs template alias support in the compiler +#endif +#ifndef __cpp_variadic_templates +#error AFIO needs variadic template support in the compiler +#endif +#if __cpp_constexpr < 201304L && !defined(_MSC_VER) +#error AFIO needs relaxed constexpr (C++ 14) support in the compiler +#endif +#ifndef __cpp_init_captures +#error AFIO needs lambda init captures support in the compiler (C++ 14) +#endif +#ifndef __cpp_attributes +#error AFIO needs attributes support in the compiler +#endif +#ifndef __cpp_variable_templates +#error AFIO needs variable template support in the compiler +#endif +#ifndef __cpp_generic_lambdas +#error AFIO needs generic lambda support in the compiler +#endif +#ifdef __has_include +// clang-format off +#if !__has_include(<filesystem>) && !__has_include(<experimental/filesystem>) +// clang-format on +#error AFIO needs an implementation of the Filesystem TS in the standard library +#endif +#endif + + +#include "quickcpplib/include/import.h" + +#if defined(AFIO_UNSTABLE_VERSION) && !defined(AFIO_DISABLE_ABI_PERMUTATION) +#include "../revision.hpp" +#define AFIO_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(afio_v2, AFIO_PREVIOUS_COMMIT_UNIQUE)) +#else +#define AFIO_V2 (QUICKCPPLIB_BIND_NAMESPACE_VERSION(afio_v2)) +#endif +/*! \def AFIO_V2 +\ingroup config +\brief The namespace configuration of this AFIO v2. Consists of a sequence +of bracketed tokens later fused by the preprocessor into namespace and C++ module names. +*/ +#if DOXYGEN_IS_IN_THE_HOUSE +//! The AFIO namespace +namespace afio_v2_xxx +{ + //! Collection of file system based algorithms + namespace algorithm + { + } + //! YAML databaseable empirical testing of a storage's behaviour + namespace storage_profile + { + } + //! Utility routines often useful when using AFIO + namespace utils + { + } +} +/*! \brief The namespace of this AFIO v2 which will be some unknown inline +namespace starting with `v2_` inside the `boost::afio` namespace. +\ingroup config +*/ +#define AFIO_V2_NAMESPACE afio_v2_xxx +/*! \brief Expands into the appropriate namespace markup to enter the AFIO v2 namespace. +\ingroup config +*/ +#define AFIO_V2_NAMESPACE_BEGIN \ + namespace afio_v2_xxx \ + { +/*! \brief Expands into the appropriate namespace markup to enter the C++ module +exported AFIO v2 namespace. +\ingroup config +*/ +#define AFIO_V2_NAMESPACE_EXPORT_BEGIN \ + export namespace afio_v2_xxx \ + { +/*! \brief Expands into the appropriate namespace markup to exit the AFIO v2 namespace. +\ingroup config +*/ +#define AFIO_V2_NAMESPACE_END } +#elif defined(GENERATING_AFIO_MODULE_INTERFACE) +#define AFIO_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(AFIO_V2) +#define AFIO_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(AFIO_V2) +#define AFIO_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_EXPORT_BEGIN(AFIO_V2) +#define AFIO_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(AFIO_V2) +#else +#define AFIO_V2_NAMESPACE QUICKCPPLIB_BIND_NAMESPACE(AFIO_V2) +#define AFIO_V2_NAMESPACE_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(AFIO_V2) +#define AFIO_V2_NAMESPACE_EXPORT_BEGIN QUICKCPPLIB_BIND_NAMESPACE_BEGIN(AFIO_V2) +#define AFIO_V2_NAMESPACE_END QUICKCPPLIB_BIND_NAMESPACE_END(AFIO_V2) +#endif + +AFIO_V2_NAMESPACE_BEGIN +class handle; +class file_handle; +AFIO_V2_NAMESPACE_END + +// Bring in the Boost-lite macros +#include "quickcpplib/include/config.hpp" +#if AFIO_LOGGING_LEVEL +#include "quickcpplib/include/ringbuffer_log.hpp" +#include "quickcpplib/include/utils/thread.hpp" +#endif +// Bring in filesystem +#if defined(__has_include) +// clang-format off +#if __has_include(<filesystem>) && __cplusplus >= 202000 +#include <filesystem> +AFIO_V2_NAMESPACE_BEGIN +namespace filesystem = std::filesystem; +AFIO_V2_NAMESPACE_END +#elif __has_include(<experimental/filesystem>) +#include <experimental/filesystem> +AFIO_V2_NAMESPACE_BEGIN +namespace filesystem = std::experimental::filesystem; +AFIO_V2_NAMESPACE_END +#endif +#elif __PCPP_ALWAYS_TRUE__ +#include <experimental/filesystem> +AFIO_V2_NAMESPACE_BEGIN +namespace filesystem = std::experimental::filesystem; +AFIO_V2_NAMESPACE_END +// clang-format on +#elif defined(_MSC_VER) +#include <filesystem> +AFIO_V2_NAMESPACE_BEGIN +namespace filesystem = std::experimental::filesystem; +AFIO_V2_NAMESPACE_END +#else +#error No <filesystem> implementation found +#endif +AFIO_V2_NAMESPACE_BEGIN +struct path_hasher +{ + size_t operator()(const filesystem::path &p) const { return std::hash<filesystem::path::string_type>()(p.native()); } +}; +AFIO_V2_NAMESPACE_END +#include <ctime> // for struct timespec + + +// Configure AFIO_DECL +#if(defined(AFIO_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(AFIO_STATIC_LINK) + +#if defined(AFIO_SOURCE) +#define AFIO_DECL QUICKCPPLIB_SYMBOL_EXPORT +#define AFIO_BUILD_DLL +#else +#define AFIO_DECL QUICKCPPLIB_SYMBOL_IMPORT +#endif +#else +#define AFIO_DECL +#endif // building a shared library + +// Configure AFIO_THREAD_LOCAL +#ifndef AFIO_THREAD_LOCAL_IS_CXX11 +#define AFIO_THREAD_LOCAL_IS_CXX11 QUICKCPPLIB_THREAD_LOCAL_IS_CXX11 +#endif +#ifndef AFIO_THREAD_LOCAL +#define AFIO_THREAD_LOCAL QUICKCPPLIB_THREAD_LOCAL +#endif +#ifndef AFIO_TEMPLATE +#define AFIO_TEMPLATE(...) QUICKCPPLIB_TEMPLATE(__VA_ARGS__) +#endif +#ifndef AFIO_TREQUIRES +#define AFIO_TREQUIRES(...) QUICKCPPLIB_TREQUIRES(__VA_ARGS__) +#endif +#ifndef AFIO_TEXPR +#define AFIO_TEXPR(...) QUICKCPPLIB_TEXPR(__VA_ARGS__) +#endif +#ifndef AFIO_TPRED +#define AFIO_TPRED(...) QUICKCPPLIB_TPRED(__VA_ARGS__) +#endif +#ifndef AFIO_REQUIRES +#define AFIO_REQUIRES(...) QUICKCPPLIB_REQUIRES(__VA_ARGS__) +#endif + +// A unique identifier generating macro +#define AFIO_GLUE2(x, y) x##y +#define AFIO_GLUE(x, y) AFIO_GLUE2(x, y) +#define AFIO_UNIQUE_NAME AFIO_GLUE(__t, __COUNTER__) + +// Used to tag functions which need to be made free by the AST tool +#ifndef AFIO_MAKE_FREE_FUNCTION +#if 0 //__cplusplus >= 201700 // makes annoying warnings +#define AFIO_MAKE_FREE_FUNCTION [[afio::make_free_function]] +#else +#define AFIO_MAKE_FREE_FUNCTION +#endif +#endif + +// Bring in bitfields +#include "quickcpplib/include/bitfield.hpp" +// Bring in scoped undo +#include "quickcpplib/include/scoped_undo.hpp" +AFIO_V2_NAMESPACE_BEGIN +using QUICKCPPLIB_NAMESPACE::scoped_undo::undoer; +AFIO_V2_NAMESPACE_END +// Bring in a span implementation +#include "quickcpplib/include/span.hpp" +AFIO_V2_NAMESPACE_BEGIN +using namespace QUICKCPPLIB_NAMESPACE::span; +AFIO_V2_NAMESPACE_END +// Bring in an optional implementation +#include "quickcpplib/include/optional.hpp" +AFIO_V2_NAMESPACE_BEGIN +using namespace QUICKCPPLIB_NAMESPACE::optional; +AFIO_V2_NAMESPACE_END +// Bring in a byte implementation +#include "quickcpplib/include/byte.hpp" +AFIO_V2_NAMESPACE_BEGIN +using QUICKCPPLIB_NAMESPACE::byte::byte; +using QUICKCPPLIB_NAMESPACE::byte::to_byte; +AFIO_V2_NAMESPACE_END +// Bring in a string_view implementation +#include "quickcpplib/include/string_view.hpp" +AFIO_V2_NAMESPACE_BEGIN +using namespace QUICKCPPLIB_NAMESPACE::string_view; +AFIO_V2_NAMESPACE_END +// Bring in a persistent implementation +#include "quickcpplib/include/persistent.hpp" +AFIO_V2_NAMESPACE_BEGIN +using namespace QUICKCPPLIB_NAMESPACE::persistence; +AFIO_V2_NAMESPACE_END + + +AFIO_V2_NAMESPACE_BEGIN + +namespace detail +{ + // Used to cast an unknown input to some unsigned integer + AFIO_TEMPLATE(class T, class U) + AFIO_TREQUIRES(AFIO_TPRED(std::is_unsigned<T>::value && !std::is_same<std::decay_t<U>, std::nullptr_t>::value)) + inline T unsigned_integer_cast(U &&v) { return static_cast<T>(v); } + AFIO_TEMPLATE(class T) + AFIO_TREQUIRES(AFIO_TPRED(std::is_unsigned<T>::value)) + inline T unsigned_integer_cast(std::nullptr_t /* unused */) { return static_cast<T>(0); } + AFIO_TEMPLATE(class T, class U) + AFIO_TREQUIRES(AFIO_TPRED(std::is_unsigned<T>::value)) + inline T unsigned_integer_cast(U *v) { return static_cast<T>(reinterpret_cast<uintptr_t>(v)); } +} // namespace detail + +AFIO_V2_NAMESPACE_END + + +AFIO_V2_NAMESPACE_BEGIN + +namespace detail +{ + // A move only capable lightweight std::function, as std::function can't handle move only callables + template <class F> class function_ptr; + template <class R, class... Args> class function_ptr<R(Args...)> + { + struct function_ptr_storage + { + function_ptr_storage() = default; + function_ptr_storage(const function_ptr_storage &) = delete; + function_ptr_storage(function_ptr_storage &&) = delete; + function_ptr_storage &operator=(const function_ptr_storage &) = delete; + function_ptr_storage &operator=(function_ptr_storage &&) = delete; + virtual ~function_ptr_storage() = default; + virtual R operator()(Args &&... args) = 0; + }; + template <class U> struct function_ptr_storage_impl : public function_ptr_storage + { + U c; + template <class... Args2> + constexpr explicit function_ptr_storage_impl(Args2 &&... args) + : c(std::forward<Args2>(args)...) + { + } + R operator()(Args &&... args) final { return c(std::move(args)...); } + }; + function_ptr_storage *ptr; + template <class U> struct emplace_t + { + }; + template <class U, class V> friend inline function_ptr<U> make_function_ptr(V &&f); // NOLINT + template <class U> + explicit function_ptr(std::nullptr_t, U &&f) + : ptr(new function_ptr_storage_impl<typename std::decay<U>::type>(std::forward<U>(f))) + { + } + template <class R_, class U, class... Args2> friend inline function_ptr<R_> emplace_function_ptr(Args2 &&... args); // NOLINT + template <class U, class... Args2> + explicit function_ptr(emplace_t<U> /*unused*/, Args2 &&... args) + : ptr(new function_ptr_storage_impl<U>(std::forward<Args2>(args)...)) + { + } + + public: + constexpr function_ptr() noexcept : ptr(nullptr) {} + constexpr explicit function_ptr(function_ptr_storage *p) noexcept : ptr(p) {} + constexpr function_ptr(function_ptr &&o) noexcept : ptr(o.ptr) { o.ptr = nullptr; } + function_ptr &operator=(function_ptr &&o) noexcept + { + delete ptr; + ptr = o.ptr; + o.ptr = nullptr; + return *this; + } + function_ptr(const function_ptr &) = delete; + function_ptr &operator=(const function_ptr &) = delete; + ~function_ptr() { delete ptr; } + explicit constexpr operator bool() const noexcept { return !!ptr; } + constexpr R operator()(Args... args) const { return (*ptr)(std::move(args)...); } + constexpr function_ptr_storage *get() noexcept { return ptr; } + constexpr void reset(function_ptr_storage *p = nullptr) noexcept + { + delete ptr; + ptr = p; + } + constexpr function_ptr_storage *release() noexcept + { + auto p = ptr; + ptr = nullptr; + return p; + } + }; + template <class R, class U> inline function_ptr<R> make_function_ptr(U &&f) { return function_ptr<R>(nullptr, std::forward<U>(f)); } + template <class R, class U, class... Args> inline function_ptr<R> emplace_function_ptr(Args &&... args) { return function_ptr<R>(typename function_ptr<R>::template emplace_t<U>(), std::forward<Args>(args)...); } +} // namespace detail + +// Native handle support +namespace win +{ + using handle = void *; + using dword = unsigned long; +} + +AFIO_V2_NAMESPACE_END + + +#if 0 +/////////////////////////////////////////////////////////////////////////////// +// Auto library naming +#if !defined(AFIO_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(AFIO_NO_LIB) && !AFIO_STANDALONE && !AFIO_HEADERS_ONLY + +#define BOOST_LIB_NAME boost_afio + +// tell the auto-link code to select a dll when required: +#if defined(BOOST_ALL_DYN_LINK) || defined(AFIO_DYN_LINK) +#define BOOST_DYN_LINK +#endif + +#include <boost/config/auto_link.hpp> + +#endif // auto-linking disabled +#endif + +//#define BOOST_THREAD_VERSION 4 +//#define BOOST_THREAD_PROVIDES_VARIADIC_THREAD +//#define BOOST_THREAD_DONT_PROVIDE_FUTURE +//#define BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK +#if AFIO_HEADERS_ONLY == 1 && !defined(AFIO_SOURCE) +/*! \brief Expands into the appropriate markup to declare an `extern` +function exported from the AFIO DLL if not building headers only. +\ingroup config +*/ +#define AFIO_HEADERS_ONLY_FUNC_SPEC inline +/*! \brief Expands into the appropriate markup to declare a class member +function exported from the AFIO DLL if not building headers only. +\ingroup config +*/ +#define AFIO_HEADERS_ONLY_MEMFUNC_SPEC inline +/*! \brief Expands into the appropriate markup to declare a virtual class member +function exported from the AFIO DLL if not building headers only. +\ingroup config +*/ +#define AFIO_HEADERS_ONLY_VIRTUAL_SPEC inline virtual +#else +#define AFIO_HEADERS_ONLY_FUNC_SPEC extern AFIO_DECL +#define AFIO_HEADERS_ONLY_MEMFUNC_SPEC +#define AFIO_HEADERS_ONLY_VIRTUAL_SPEC virtual +#endif + +#endif |