// The MIT License (MIT) // Copyright (c) 2013-2017 Rapptz, ThePhD and contributors // 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_PROPERTY_HPP #define SOL_PROPERTY_HPP #include "types.hpp" #include #include namespace sol { struct no_prop { }; template struct property_wrapper { typedef std::integral_constant::value> can_read; typedef std::integral_constant::value> can_write; typedef std::conditional_t Read; typedef std::conditional_t Write; Read read; Write write; template property_wrapper(Rx&& r, Wx&& w) : read(std::forward(r)), write(std::forward(w)) {} }; namespace property_detail { template inline decltype(auto) property(std::true_type, R&& read, W&& write) { return property_wrapper, std::decay_t>(std::forward(read), std::forward(write)); } template inline decltype(auto) property(std::false_type, W&& write, R&& read) { return property_wrapper, std::decay_t>(std::forward(read), std::forward(write)); } template inline decltype(auto) property(std::true_type, R&& read) { return property_wrapper, void>(std::forward(read), no_prop()); } template inline decltype(auto) property(std::false_type, W&& write) { return property_wrapper>(no_prop(), std::forward(write)); } } // property_detail template inline decltype(auto) property(F&& f, G&& g) { typedef lua_bind_traits> left_traits; typedef lua_bind_traits> right_traits; return property_detail::property(meta::boolean<(left_traits::free_arity < right_traits::free_arity)>(), std::forward(f), std::forward(g)); } template inline decltype(auto) property(F&& f) { typedef lua_bind_traits> left_traits; return property_detail::property(meta::boolean<(left_traits::free_arity < 2)>(), std::forward(f)); } template inline decltype(auto) readonly_property(F&& f) { return property_detail::property(std::true_type(), std::forward(f)); } template inline decltype(auto) writeonly_property(F&& f) { return property_detail::property(std::false_type(), std::forward(f)); } template struct readonly_wrapper { T v; readonly_wrapper(T v) : v(std::move(v)) {} operator T& () { return v; } operator const T& () const { return v; } }; // Allow someone to make a member variable readonly (const) template inline auto readonly(R T::* v) { return readonly_wrapper>(v); } template struct var_wrapper { T value; template var_wrapper(Args&&... args) : value(std::forward(args)...) {} var_wrapper(const var_wrapper&) = default; var_wrapper(var_wrapper&&) = default; var_wrapper& operator=(const var_wrapper&) = default; var_wrapper& operator=(var_wrapper&&) = default; }; template inline auto var(V&& v) { typedef meta::unqualified_t T; return var_wrapper(std::forward(v)); } namespace meta { template struct is_member_object : std::is_member_object_pointer {}; template struct is_member_object> : std::true_type {}; } } // sol #endif // SOL_PROPERTY_HPP