2019-11-30 02:08:41 +08:00
|
|
|
// sol3
|
2017-12-20 17:58:32 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
// The MIT License (MIT)
|
2017-08-22 03:25:43 +08:00
|
|
|
|
2020-08-13 22:42:37 +08:00
|
|
|
// Copyright (c) 2013-2020 Rapptz, ThePhD and contributors
|
2017-08-22 03:25:43 +08:00
|
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
// this software and associated documentation files (the "Software"), to deal in
|
|
|
|
// the Software without restriction, including without limitation the rights to
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
// subject to the following conditions:
|
|
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#ifndef SOL_FILTERS_HPP
|
|
|
|
#define SOL_FILTERS_HPP
|
|
|
|
|
2020-08-10 05:17:06 +08:00
|
|
|
#include <sol/traits.hpp>
|
2019-04-29 04:45:40 +08:00
|
|
|
|
2017-08-22 03:25:43 +08:00
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace sol {
|
|
|
|
namespace detail {
|
2020-12-17 04:25:35 +08:00
|
|
|
struct policy_base_tag { };
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace detail
|
2017-08-22 03:25:43 +08:00
|
|
|
|
|
|
|
template <int Target, int... In>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct static_stack_dependencies : detail::policy_base_tag { };
|
2017-08-22 03:25:43 +08:00
|
|
|
typedef static_stack_dependencies<-1, 1> self_dependency;
|
|
|
|
template <int... In>
|
2020-12-17 04:25:35 +08:00
|
|
|
struct returns_self_with : detail::policy_base_tag { };
|
2017-08-22 03:25:43 +08:00
|
|
|
typedef returns_self_with<> returns_self;
|
|
|
|
|
2019-05-21 15:57:10 +08:00
|
|
|
struct stack_dependencies : detail::policy_base_tag {
|
2017-08-22 03:25:43 +08:00
|
|
|
int target;
|
|
|
|
std::array<int, 64> stack_indices;
|
|
|
|
std::size_t len;
|
|
|
|
|
|
|
|
template <typename... Args>
|
2019-11-30 02:08:41 +08:00
|
|
|
stack_dependencies(int stack_target, Args&&... args) : target(stack_target), stack_indices(), len(sizeof...(Args)) {
|
2017-08-22 03:25:43 +08:00
|
|
|
std::size_t i = 0;
|
2020-12-17 04:25:35 +08:00
|
|
|
(void)detail::swallow { int(), (stack_indices[i++] = static_cast<int>(std::forward<Args>(args)), int())... };
|
2017-08-22 03:25:43 +08:00
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
int& operator[](std::size_t i) {
|
2017-08-22 03:25:43 +08:00
|
|
|
return stack_indices[i];
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
const int& operator[](std::size_t i) const {
|
2017-08-22 03:25:43 +08:00
|
|
|
return stack_indices[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t size() const {
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
};
|
2017-09-13 14:46:56 +08:00
|
|
|
|
2019-05-21 15:57:10 +08:00
|
|
|
template <typename F, typename... Policies>
|
|
|
|
struct policy_wrapper {
|
|
|
|
typedef std::index_sequence_for<Policies...> indices;
|
2017-08-22 03:25:43 +08:00
|
|
|
|
|
|
|
F value;
|
2019-05-21 15:57:10 +08:00
|
|
|
std::tuple<Policies...> policies;
|
2017-08-22 03:25:43 +08:00
|
|
|
|
2019-05-21 15:57:10 +08:00
|
|
|
template <typename Fx, typename... Args, meta::enable<meta::neg<std::is_same<meta::unqualified_t<Fx>, policy_wrapper>>> = meta::enabler>
|
2019-11-30 02:08:41 +08:00
|
|
|
policy_wrapper(Fx&& fx, Args&&... args) : value(std::forward<Fx>(fx)), policies(std::forward<Args>(args)...) {
|
2017-09-13 14:46:56 +08:00
|
|
|
}
|
2017-08-22 03:25:43 +08:00
|
|
|
|
2019-05-21 15:57:10 +08:00
|
|
|
policy_wrapper(const policy_wrapper&) = default;
|
|
|
|
policy_wrapper& operator=(const policy_wrapper&) = default;
|
|
|
|
policy_wrapper(policy_wrapper&&) = default;
|
|
|
|
policy_wrapper& operator=(policy_wrapper&&) = default;
|
2017-08-22 03:25:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename F, typename... Args>
|
2019-05-21 15:57:10 +08:00
|
|
|
auto policies(F&& f, Args&&... args) {
|
|
|
|
return policy_wrapper<std::decay_t<F>, std::decay_t<Args>...>(std::forward<F>(f), std::forward<Args>(args)...);
|
2017-08-22 03:25:43 +08:00
|
|
|
}
|
2019-04-29 04:45:40 +08:00
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template <typename T>
|
2019-05-21 15:57:10 +08:00
|
|
|
using is_policy = meta::is_specialization_of<T, policy_wrapper>;
|
2019-11-30 02:08:41 +08:00
|
|
|
|
2019-04-29 04:45:40 +08:00
|
|
|
template <typename T>
|
2019-05-21 15:57:10 +08:00
|
|
|
inline constexpr bool is_policy_v = is_policy<T>::value;
|
2019-11-30 02:08:41 +08:00
|
|
|
} // namespace detail
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace sol
|
2017-08-22 03:25:43 +08:00
|
|
|
|
|
|
|
#endif // SOL_FILTERS_HPP
|