Commit bd4a5293 by Wenzel Jakob

more flexible function creation syntax

parent 38bd7113
...@@ -18,3 +18,4 @@ Debug ...@@ -18,3 +18,4 @@ Debug
.vs .vs
CTestTestfile.cmake CTestTestfile.cmake
Testing Testing
autogen
...@@ -8,12 +8,11 @@ ...@@ -8,12 +8,11 @@
BSD-style license that can be found in the LICENSE file. BSD-style license that can be found in the LICENSE file.
*/ */
#if !defined(__PYBIND_CAST) #pragma once
#define __PYBIND_CAST
#include "pytypes.h" #include <pybind/pytypes.h>
#include "mpl.h" #include <pybind/mpl.h>
#include "typeid.h" #include <pybind/typeid.h>
#include <map> #include <map>
#include <array> #include <array>
...@@ -474,10 +473,11 @@ TYPE_CASTER_PYTYPE(int_) ...@@ -474,10 +473,11 @@ TYPE_CASTER_PYTYPE(int_)
TYPE_CASTER_PYTYPE(list) TYPE_CASTER_PYTYPE(list)
TYPE_CASTER_PYTYPE(slice) TYPE_CASTER_PYTYPE(slice)
TYPE_CASTER_PYTYPE(tuple) TYPE_CASTER_PYTYPE(tuple)
TYPE_CASTER_PYTYPE(function)
#undef TYPE_CASTER #undef TYPE_CASTER
#undef TYPE_CASTER_NUMBER
#undef TYPE_CASTER_PYTYPE #undef TYPE_CASTER_PYTYPE
#undef TYPE_CASTER_NUMBER
NAMESPACE_END(detail) NAMESPACE_END(detail)
...@@ -522,5 +522,3 @@ template <typename ... Args> inline object handle::call(Args&&... args_) { ...@@ -522,5 +522,3 @@ template <typename ... Args> inline object handle::call(Args&&... args_) {
} }
NAMESPACE_END(pybind) NAMESPACE_END(pybind)
#endif /* __PYBIND_CAST */
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
BSD-style license that can be found in the LICENSE file. BSD-style license that can be found in the LICENSE file.
*/ */
#if !defined(__PYBIND_COMMON_H) #pragma once
#define __PYBIND_COMMON_H
#if !defined(NAMESPACE_BEGIN) #if !defined(NAMESPACE_BEGIN)
#define NAMESPACE_BEGIN(name) namespace name { #define NAMESPACE_BEGIN(name) namespace name {
...@@ -145,5 +144,3 @@ inline internals &get_internals(); ...@@ -145,5 +144,3 @@ inline internals &get_internals();
NAMESPACE_END(detail) NAMESPACE_END(detail)
NAMESPACE_END(pybind) NAMESPACE_END(pybind)
#endif /* __PYBIND_COMMON_H */
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file. BSD-style license that can be found in the LICENSE file.
*/ */
#if !defined(__PYBIND_MPL_H) #pragma once
#define __PYBIND_MPL_H
#include "common.h" #include <pybind/common.h>
#include <tuple> #include <tuple>
NAMESPACE_BEGIN(pybind) NAMESPACE_BEGIN(pybind)
...@@ -80,7 +79,15 @@ template <> struct tuple_dispatch<void> { ...@@ -80,7 +79,15 @@ template <> struct tuple_dispatch<void> {
NAMESPACE_END(detail) NAMESPACE_END(detail)
/// For lambda functions delegate to their 'operator()' /// For lambda functions delegate to their 'operator()'
template <typename T> struct function_traits : public function_traits<typename detail::make_function_type<T>> { }; template <typename T> struct function_traits : function_traits<typename detail::make_function_type<T>> { };
/* Deal with reference arguments */
template <typename ReturnType, typename... Args>
struct function_traits<ReturnType(*&)(Args...)> : function_traits<ReturnType(*)(Args...)> {};
template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType(ClassType::*&)(Args...)> : function_traits<ReturnType(ClassType::*)(Args...)> {};
template <typename ClassType, typename ReturnType, typename... Args>
struct function_traits<ReturnType(ClassType::*&)(Args...) const> : function_traits<ReturnType(ClassType::*)(Args...) const> {};
/// Type traits for function pointers /// Type traits for function pointers
template <typename ReturnType, typename... Args> template <typename ReturnType, typename... Args>
...@@ -186,5 +193,3 @@ struct function_traits<std::function<ReturnType(Args...)>> { ...@@ -186,5 +193,3 @@ struct function_traits<std::function<ReturnType(Args...)>> {
NAMESPACE_END(mpl) NAMESPACE_END(mpl)
NAMESPACE_END(pybind) NAMESPACE_END(pybind)
#endif /* __PYBIND_MPL_H */
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file. BSD-style license that can be found in the LICENSE file.
*/ */
#if !defined(__PYBIND_OPERATOR) #pragma once
#define __PYBIND_OPERATOR
#include "pybind.h" #include <pybind/pybind.h>
#include <type_traits> #include <type_traits>
NAMESPACE_BEGIN(pybind) NAMESPACE_BEGIN(pybind)
...@@ -147,5 +146,3 @@ NAMESPACE_END(detail) ...@@ -147,5 +146,3 @@ NAMESPACE_END(detail)
using detail::self; using detail::self;
NAMESPACE_END(pybind) NAMESPACE_END(pybind)
#endif /* __PYBIND_OPERATOR */
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file. BSD-style license that can be found in the LICENSE file.
*/ */
#if !defined(__PYBIND_PYTYPES_H) #pragma once
#define __PYBIND_PYTYPES_H
#include "common.h" #include <pybind/common.h>
#include <utility> #include <utility>
NAMESPACE_BEGIN(pybind) NAMESPACE_BEGIN(pybind)
...@@ -208,7 +207,7 @@ inline detail::accessor handle::attr(const char *key) { return detail::accessor( ...@@ -208,7 +207,7 @@ inline detail::accessor handle::attr(const char *key) { return detail::accessor(
#define PYTHON_OBJECT_DEFAULT(Name, Parent, CheckFun) \ #define PYTHON_OBJECT_DEFAULT(Name, Parent, CheckFun) \
PYTHON_OBJECT(Name, Parent, CheckFun) \ PYTHON_OBJECT(Name, Parent, CheckFun) \
Name() : object() { } Name() : Parent() { }
class str : public object { class str : public object {
public: public:
...@@ -295,6 +294,11 @@ public: ...@@ -295,6 +294,11 @@ public:
void append(const object &object) { PyList_Append(m_ptr, (PyObject *) object.ptr()); } void append(const object &object) { PyList_Append(m_ptr, (PyObject *) object.ptr()); }
}; };
class function : public object {
public:
PYTHON_OBJECT_DEFAULT(function, object, PyFunction_Check)
};
class buffer : public object { class buffer : public object {
public: public:
PYTHON_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer) PYTHON_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
...@@ -335,5 +339,3 @@ inline internals &get_internals() { ...@@ -335,5 +339,3 @@ inline internals &get_internals() {
} }
NAMESPACE_END(detail) NAMESPACE_END(detail)
NAMESPACE_END(pybind) NAMESPACE_END(pybind)
#endif /* __PYBIND_PYTYPES_H */
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file. BSD-style license that can be found in the LICENSE file.
*/ */
#if !defined(__PYBIND_TYPEID_H) #pragma once
#define __PYBIND_TYPEID_H
#include "common.h" #include <pybind/typeid.h>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#if defined(__GNUG__) #if defined(__GNUG__)
...@@ -48,6 +47,3 @@ template <typename T> static std::string type_id() { ...@@ -48,6 +47,3 @@ template <typename T> static std::string type_id() {
} }
NAMESPACE_END(pybind) NAMESPACE_END(pybind)
#endif /* __PYBIND_TYPEID_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment