/usr/include/boost/python/detail/defaults_gen.hpp is in libboost1.55-dev 1.55.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | ///////////////////////////////////////////////////////////////////////////////
//
// Copyright David Abrahams 2002, Joel de Guzman, 2002.
// 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 DEFAULTS_GEN_JDG20020807_HPP
#define DEFAULTS_GEN_JDG20020807_HPP
#include <boost/python/detail/preprocessor.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/repeat_from_to.hpp>
#include <boost/preprocessor/enum.hpp>
#include <boost/preprocessor/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/tuple.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/empty.hpp>
#include <boost/preprocessor/comma_if.hpp>
#include <boost/config.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/deref.hpp>
#include <cstddef>
namespace boost { namespace python {
namespace detail
{
// overloads_base is used as a base class for all function
// stubs. This class holds the doc_string of the stubs.
struct overloads_base
{
overloads_base(char const* doc_)
: m_doc(doc_) {}
overloads_base(char const* doc_, detail::keyword_range const& kw)
: m_doc(doc_), m_keywords(kw) {}
char const* doc_string() const
{
return m_doc;
}
detail::keyword_range const& keywords() const
{
return m_keywords;
}
private:
char const* m_doc;
detail::keyword_range m_keywords;
};
// overloads_proxy is generated by the overloads_common operator[] (see
// below). This class holds a user defined call policies of the stubs.
template <class CallPoliciesT, class OverloadsT>
struct overloads_proxy
: public overloads_base
{
typedef typename OverloadsT::non_void_return_type non_void_return_type;
typedef typename OverloadsT::void_return_type void_return_type;
overloads_proxy(
CallPoliciesT const& policies_
, char const* doc
, keyword_range const& kw
)
: overloads_base(doc, kw)
, policies(policies_)
{}
CallPoliciesT
call_policies() const
{
return policies;
}
CallPoliciesT policies;
};
// overloads_common is our default function stubs base class. This
// class returns the default_call_policies in its call_policies()
// member function. It can generate a overloads_proxy however through
// its operator[]
template <class DerivedT>
struct overloads_common
: public overloads_base
{
overloads_common(char const* doc)
: overloads_base(doc) {}
overloads_common(char const* doc, keyword_range const& kw)
: overloads_base(doc, kw) {}
default_call_policies
call_policies() const
{
return default_call_policies();
}
template <class CallPoliciesT>
overloads_proxy<CallPoliciesT, DerivedT>
operator[](CallPoliciesT const& policies) const
{
return overloads_proxy<CallPoliciesT, DerivedT>(
policies, this->doc_string(), this->keywords());
}
};
}}} // namespace boost::python::detail
#define BOOST_PYTHON_TYPEDEF_GEN(z, index, data) \
typedef typename ::boost::mpl::next<BOOST_PP_CAT(iter, index)>::type \
BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \
typedef typename ::boost::mpl::deref<BOOST_PP_CAT(iter, index)>::type \
BOOST_PP_CAT(T, index);
#define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \
static RT BOOST_PP_CAT(func_, \
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
BOOST_PP_ENUM_BINARY_PARAMS_Z( \
1, index, T, arg)) \
{ \
BOOST_PP_TUPLE_ELEM(3, 2, data) \
BOOST_PP_TUPLE_ELEM(3, 0, data)( \
BOOST_PP_ENUM_PARAMS( \
index, \
arg)); \
}
#define BOOST_PYTHON_GEN_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
struct fstubs_name \
{ \
BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
BOOST_STATIC_CONSTANT(int, max_args = n_funcs); \
\
template <typename SigT> \
struct gen \
{ \
typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
typedef typename ::boost::mpl::deref<rt_iter>::type RT; \
typedef typename ::boost::mpl::next<rt_iter>::type iter0; \
\
BOOST_PP_REPEAT_2ND( \
n_args, \
BOOST_PYTHON_TYPEDEF_GEN, \
0) \
\
BOOST_PP_REPEAT_FROM_TO_2( \
BOOST_PP_SUB_D(1, n_args, n_dflts), \
BOOST_PP_INC(n_args), \
BOOST_PYTHON_FUNC_WRAPPER_GEN, \
(fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
}; \
}; \
///////////////////////////////////////////////////////////////////////////////
#define BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN(z, index, data) \
static RT BOOST_PP_CAT(func_, \
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
ClassT obj BOOST_PP_COMMA_IF(index) \
BOOST_PP_ENUM_BINARY_PARAMS_Z(1, index, T, arg) \
) \
{ \
BOOST_PP_TUPLE_ELEM(3, 2, data) obj.BOOST_PP_TUPLE_ELEM(3, 0, data)( \
BOOST_PP_ENUM_PARAMS(index, arg) \
); \
}
#define BOOST_PYTHON_GEN_MEM_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
struct fstubs_name \
{ \
BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \
BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \
\
template <typename SigT> \
struct gen \
{ \
typedef typename ::boost::mpl::begin<SigT>::type rt_iter; \
typedef typename ::boost::mpl::deref<rt_iter>::type RT; \
\
typedef typename ::boost::mpl::next<rt_iter>::type class_iter; \
typedef typename ::boost::mpl::deref<class_iter>::type ClassT; \
typedef typename ::boost::mpl::next<class_iter>::type iter0; \
\
BOOST_PP_REPEAT_2ND( \
n_args, \
BOOST_PYTHON_TYPEDEF_GEN, \
0) \
\
BOOST_PP_REPEAT_FROM_TO_2( \
BOOST_PP_SUB_D(1, n_args, n_dflts), \
BOOST_PP_INC(n_args), \
BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN, \
(fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \
}; \
};
#define BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
fstubs_name(char const* doc = 0) \
: ::boost::python::detail::overloads_common<fstubs_name>(doc) {} \
template <std::size_t N> \
fstubs_name(char const* doc, ::boost::python::detail::keywords<N> const& keywords) \
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
N,n_args>::too_many_keywords assertion; \
} \
template <std::size_t N> \
fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0) \
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
N,n_args>::too_many_keywords assertion; \
}
# if defined(BOOST_NO_VOID_RETURNS)
# define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
struct fstubs_name \
: public ::boost::python::detail::overloads_common<fstubs_name> \
{ \
BOOST_PYTHON_GEN_FUNCTION( \
fname, non_void_return_type, n_args, n_dflts, return) \
BOOST_PYTHON_GEN_FUNCTION( \
fname, void_return_type, n_args, n_dflts, ;) \
\
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
};
# define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
struct fstubs_name \
: public ::boost::python::detail::overloads_common<fstubs_name> \
{ \
BOOST_PYTHON_GEN_MEM_FUNCTION( \
fname, non_void_return_type, n_args, n_dflts, return) \
BOOST_PYTHON_GEN_MEM_FUNCTION( \
fname, void_return_type, n_args, n_dflts, ;) \
\
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts) \
};
# else // !defined(BOOST_NO_VOID_RETURNS)
# define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
struct fstubs_name \
: public ::boost::python::detail::overloads_common<fstubs_name> \
{ \
BOOST_PYTHON_GEN_FUNCTION( \
fname, non_void_return_type, n_args, n_dflts, return) \
\
typedef non_void_return_type void_return_type; \
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \
};
# define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \
struct fstubs_name \
: public ::boost::python::detail::overloads_common<fstubs_name> \
{ \
BOOST_PYTHON_GEN_MEM_FUNCTION( \
fname, non_void_return_type, n_args, n_dflts, return) \
\
typedef non_void_return_type void_return_type; \
BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args + 1, n_dflts) \
};
# endif // !defined(BOOST_NO_VOID_RETURNS)
///////////////////////////////////////////////////////////////////////////////
//
// MAIN MACROS
//
// Given generator_name, fname, min_args and max_args, These macros
// generate function stubs that forward to a function or member function
// named fname. max_args is the arity of the function or member function
// fname. fname can have default arguments. min_args is the minimum
// arity that fname can accept.
//
// There are two versions:
//
// 1. BOOST_PYTHON_FUNCTION_OVERLOADS for free functions
// 2. BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS for member functions.
//
// For instance, given a function:
//
// int
// foo(int a, char b = 1, unsigned c = 2, double d = 3)
// {
// return a + b + c + int(d);
// }
//
// The macro invocation:
//
// BOOST_PYTHON_FUNCTION_OVERLOADS(foo_stubs, foo, 1, 4)
//
// Generates this code:
//
// struct foo_stubsNonVoid
// {
// static const int n_funcs = 4;
// static const int max_args = n_funcs;
//
// template <typename SigT>
// struct gen
// {
// typedef typename ::boost::mpl::begin<SigT>::type rt_iter;
// typedef typename rt_iter::type RT;
// typedef typename rt_iter::next iter0;
// typedef typename iter0::type T0;
// typedef typename iter0::next iter1;
// typedef typename iter1::type T1;
// typedef typename iter1::next iter2;
// typedef typename iter2::type T2;
// typedef typename iter2::next iter3;
// typedef typename iter3::type T3;
// typedef typename iter3::next iter4;
//
// static RT func_0(T0 arg0)
// { return foo(arg0); }
//
// static RT func_1(T0 arg0, T1 arg1)
// { return foo(arg0, arg1); }
//
// static RT func_2(T0 arg0, T1 arg1, T2 arg2)
// { return foo(arg0, arg1, arg2); }
//
// static RT func_3(T0 arg0, T1 arg1, T2 arg2, T3 arg3)
// { return foo(arg0, arg1, arg2, arg3); }
// };
// };
//
// struct foo_overloads
// : public boost::python::detail::overloads_common<foo_overloads>
// {
// typedef foo_overloadsNonVoid non_void_return_type;
// typedef foo_overloadsNonVoid void_return_type;
//
// foo_overloads(char const* doc = 0)
// : boost::python::detail::overloads_common<foo_overloads>(doc) {}
// };
//
// The typedefs non_void_return_type and void_return_type are
// used to handle compilers that do not support void returns. The
// example above typedefs non_void_return_type and
// void_return_type to foo_overloadsNonVoid. On compilers that do
// not support void returns, there are two versions:
// foo_overloadsNonVoid and foo_overloadsVoid. The "Void"
// version is almost identical to the "NonVoid" version except
// for the return type (void) and the lack of the return keyword.
//
// See the overloads_common above for a description of the
// foo_overloads' base class.
//
///////////////////////////////////////////////////////////////////////////////
#define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
BOOST_PYTHON_GEN_FUNCTION_STUB( \
fname, \
generator_name, \
max_args, \
BOOST_PP_SUB_D(1, max_args, min_args))
#define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \
BOOST_PYTHON_GEN_MEM_FUNCTION_STUB( \
fname, \
generator_name, \
max_args, \
BOOST_PP_SUB_D(1, max_args, min_args))
// deprecated macro names (to be removed)
#define BOOST_PYTHON_FUNCTION_GENERATOR BOOST_PYTHON_FUNCTION_OVERLOADS
#define BOOST_PYTHON_MEM_FUN_GENERATOR BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
///////////////////////////////////////////////////////////////////////////////
#endif // DEFAULTS_GEN_JDG20020807_HPP
|