All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pySignatureExt.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_PY_SIGNATURE_EXT_H
8#define PXR_BASE_TF_PY_SIGNATURE_EXT_H
9
10#include "pxr/external/boost/python/common.hpp"
11#include "pxr/external/boost/python/type_list.hpp"
12
13// This file extends pxr_boost::python::detail::get_signature to support member
14// function pointers that have lvalue ref-qualifiers. For example:
15//
16// class Foo {
17// void f() &;
18// };
19//
20// Without this extension, pxr_boost::python cannot wrap ref-qualified member
21// functions like this.
22//
23// This utility does not support rvalue ref-qualifiers. There isn't really such
24// a thing as an rvalue in Python, so it doesn't make sense to wrap rvalue
25// ref-qualified member functions. And boost.python's infrastructure always
26// requires an lvalue for 'this' accordingly.
27//
28// To use this utility, #include this file before any other file in your
29// wrapXXX.cpp file; the order matters.
30
31namespace PXR_BOOST_NAMESPACE { namespace python { namespace detail {
32
33template <class Ret, class TheCls, class ... Args>
34auto get_signature(Ret (TheCls::*)(Args...) &, void* =nullptr) {
35 return python::type_list<Ret, TheCls &, Args...>();
36}
37template <class Ret, class TheCls, class ... Args>
38auto get_signature(Ret (TheCls::*)(Args...) const &, void* =nullptr) {
39 return python::type_list<Ret, TheCls &, Args...>();
40}
41
42}}}
43
44#include "pxr/external/boost/python/signature.hpp"
45
46#endif // PXR_BASE_TF_PY_SIGNATURE_EXT_H