Commit bd4a5293 by Wenzel Jakob

more flexible function creation syntax

parent 38bd7113
......@@ -18,3 +18,4 @@ Debug
.vs
CTestTestfile.cmake
Testing
autogen
......@@ -8,12 +8,11 @@
BSD-style license that can be found in the LICENSE file.
*/
#if !defined(__PYBIND_CAST)
#define __PYBIND_CAST
#pragma once
#include "pytypes.h"
#include "mpl.h"
#include "typeid.h"
#include <pybind/pytypes.h>
#include <pybind/mpl.h>
#include <pybind/typeid.h>
#include <map>
#include <array>
......@@ -474,10 +473,11 @@ TYPE_CASTER_PYTYPE(int_)
TYPE_CASTER_PYTYPE(list)
TYPE_CASTER_PYTYPE(slice)
TYPE_CASTER_PYTYPE(tuple)
TYPE_CASTER_PYTYPE(function)
#undef TYPE_CASTER
#undef TYPE_CASTER_NUMBER
#undef TYPE_CASTER_PYTYPE
#undef TYPE_CASTER_NUMBER
NAMESPACE_END(detail)
......@@ -522,5 +522,3 @@ template <typename ... Args> inline object handle::call(Args&&... args_) {
}
NAMESPACE_END(pybind)
#endif /* __PYBIND_CAST */
......@@ -7,8 +7,7 @@
BSD-style license that can be found in the LICENSE file.
*/
#if !defined(__PYBIND_COMMON_H)
#define __PYBIND_COMMON_H
#pragma once
#if !defined(NAMESPACE_BEGIN)
#define NAMESPACE_BEGIN(name) namespace name {
......@@ -145,5 +144,3 @@ inline internals &get_internals();
NAMESPACE_END(detail)
NAMESPACE_END(pybind)
#endif /* __PYBIND_COMMON_H */
......@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file.
*/
#if !defined(__PYBIND_MPL_H)
#define __PYBIND_MPL_H
#pragma once
#include "common.h"
#include <pybind/common.h>
#include <tuple>
NAMESPACE_BEGIN(pybind)
......@@ -80,7 +79,15 @@ template <> struct tuple_dispatch<void> {
NAMESPACE_END(detail)
/// 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
template <typename ReturnType, typename... Args>
......@@ -186,5 +193,3 @@ struct function_traits<std::function<ReturnType(Args...)>> {
NAMESPACE_END(mpl)
NAMESPACE_END(pybind)
#endif /* __PYBIND_MPL_H */
......@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file.
*/
#if !defined(__PYBIND_OPERATOR)
#define __PYBIND_OPERATOR
#pragma once
#include "pybind.h"
#include <pybind/pybind.h>
#include <type_traits>
NAMESPACE_BEGIN(pybind)
......@@ -147,5 +146,3 @@ NAMESPACE_END(detail)
using detail::self;
NAMESPACE_END(pybind)
#endif /* __PYBIND_OPERATOR */
......@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file.
*/
#if !defined(__PYBIND_PYTYPES_H)
#define __PYBIND_PYTYPES_H
#pragma once
#include "common.h"
#include <pybind/common.h>
#include <utility>
NAMESPACE_BEGIN(pybind)
......@@ -208,7 +207,7 @@ inline detail::accessor handle::attr(const char *key) { return detail::accessor(
#define PYTHON_OBJECT_DEFAULT(Name, Parent, CheckFun) \
PYTHON_OBJECT(Name, Parent, CheckFun) \
Name() : object() { }
Name() : Parent() { }
class str : public object {
public:
......@@ -295,6 +294,11 @@ public:
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 {
public:
PYTHON_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
......@@ -335,5 +339,3 @@ inline internals &get_internals() {
}
NAMESPACE_END(detail)
NAMESPACE_END(pybind)
#endif /* __PYBIND_PYTYPES_H */
......@@ -7,10 +7,9 @@
BSD-style license that can be found in the LICENSE file.
*/
#if !defined(__PYBIND_TYPEID_H)
#define __PYBIND_TYPEID_H
#pragma once
#include "common.h"
#include <pybind/typeid.h>
#include <cstdio>
#include <cstdlib>
#if defined(__GNUG__)
......@@ -48,6 +47,3 @@ template <typename T> static std::string type_id() {
}
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