// Copyright 2005 Alexander Nasonov. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef FILE_access_protected_functions_hpp_INCLUDED #define FILE_access_protected_functions_hpp_INCLUDED #include #include #include #include #include #include #include #ifndef ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY #define ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY 10 #endif namespace access_protected_functions { template struct wrapped_member_function; #define m(z,i,cv) template \ struct wrapped_member_function { \ typedef R(C::*function_type)(BOOST_PP_ENUM_PARAMS(i,T)) cv; \ C cv& ref; function_type fn; \ wrapped_member_function(C cv& ref, function_type fn) \ : ref(ref), fn(fn) {} \ R operator()(BOOST_PP_ENUM_BINARY_PARAMS(i,T,a)) const { \ return (ref.*fn)(BOOST_PP_ENUM_PARAMS(i,a)); } \ }; BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, m, BOOST_PP_EMPTY()) BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, m, const) BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, m, volatile) BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, m, const volatile) #undef m } #define AUX_ACCESS_PROTECTED_FUNCTIONS_USING(_,class_,fn) using class_::fn; #define AUX_ACCESS_PROTECTED_FUNCTIONS_ACCESS(z,i,cv) template \ static wrapped_member_function \ get(T cv& ref, R (C::*fn)(BOOST_PP_ENUM_PARAMS(i,T)) cv) \ { typedef R(C::*function_type)(BOOST_PP_ENUM_PARAMS(i,T)) cv; \ return wrapped_member_function(ref,fn); } #define DECLARE_ACCESS_PROTECTED_FUNCTIONS(functions) \ namespace access_protected_functions { namespace { \ template struct accessor : T { \ BOOST_PP_SEQ_FOR_EACH(AUX_ACCESS_PROTECTED_FUNCTIONS_USING, \ T, functions) \ BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, \ AUX_ACCESS_PROTECTED_FUNCTIONS_ACCESS, BOOST_PP_EMPTY()) \ BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, \ AUX_ACCESS_PROTECTED_FUNCTIONS_ACCESS, const) \ BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, \ AUX_ACCESS_PROTECTED_FUNCTIONS_ACCESS, volatile) \ BOOST_PP_REPEAT_1(ACCESS_PROTECTED_FUNCTIONS_MAX_ARITY, \ AUX_ACCESS_PROTECTED_FUNCTIONS_ACCESS, const volatile) \ }; \ } } #define ACCESS_PROTECTED_FUNCTION(class_,ref,fn,args) \ ::access_protected_functions::accessor::get(ref, \ & ::access_protected_functions::accessor::fn) args #endif // #ifndef FILE_access_protected_function_hpp_INCLUDED