From 66ff762fbb22fd3830f8731365c454ca156f6774 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 3 Oct 2002 18:40:58 +0000 Subject: [PATCH] doc update [SVN r15681] --- doc/v2/def.html | 195 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 doc/v2/def.html diff --git a/doc/v2/def.html b/doc/v2/def.html new file mode 100644 index 00000000..25a78bf8 --- /dev/null +++ b/doc/v2/def.html @@ -0,0 +1,195 @@ + + + + + + + + + Boost.Python - <boost/python/def.hpp> + + + + + + + + + +
+

C++ Boost

+
+

Boost.Python

+ +

Header <boost/python/def.hpp>

+
+
+ +

Contents

+ +
+
Introduction
+ +
Functions
+ +
+
+
def
+
+
+ +
Example
+
+
+ +

Introduction

+ +

def() is the function which can + be used to expose C++ functions and callable objects as Python functions + in the current scope.

+ +

Functions

+
+template <class F>
+void def(char const* name, F f);
+
+template <class Fn, class A1>
+void def(char const* name, Fn fn, A1 const&);
+
+template <class Fn, class A1, class A2>
+void def(char const* name, Fn fn, A1 const&, A2 const&);
+
+template <class Fn, class A1, class A2, class A3>
+void def(char const* name, Fn fn, A1 const&, A2 const&, A3 const&);
+
+ +
+
Requires: name is an ntbs which conforms to Python's identifier + naming rules.
+ +
+
    +
  • + If a1 is the result of an overload-dispatch-expression, + only the second form is allowed and fn must be a pointer to + function or pointer to member function whose arity is the same as A1's maximum + arity. + +
    +
    Effects: For each prefix P of + Fn's sequence of argument types, beginning with + the one whose length is A1's minimum + arity, adds a + name(...) function overload + to the current scope. Each overload + generated invokes a1's call-expression with + P, using a copy of a1's call policies. If the longest valid + prefix of A1 contains N types and + a1 holds M keywords, an initial sequence + of the keywords are used for all but the first + N - M arguments of each + overload.
    +
    +
    +
  • + +
  • + Otherwise, a single function overload built around fn (which must + not be null) is added to the current + scope: + +
      +
    • If fn is a function or member function pointer, + a1-a3 (if supplied) may be selected + in any order from the table below.
    • + +
    • Otherwise, Fn must be [derived from] object, and + a1-a2 (if supplied) may be selcted in any order + from the first two rows of the table below. To be useful, + fn should be + callable.
    • +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Memnonic NameRequirements/Type propertiesEffects
    docstringAny ntbs.Value will be bound to the __doc__ attribute + of the resulting method overload.
    policiesA model of CallPoliciesA copy will be used as the call policies of the resulting + method overload.
    keywordsThe result of a keyword-expression + specifying no more arguments than the arity of fn.A copy will be used as the call policies of the resulting + method overload.
    +
  • +
+
+
+ +

Example

+
+#include <boost/python/def.hpp>
+#include <boost/python/module.hpp>
+#include <boost/python/args.hpp>
+
+char const* foo(int x, int y) { return "foo"; }
+
+BOOST_PYTHON_MODULE(def_test)
+{
+    def("foo", foo, args("x", "y"), "foo's docstring");
+}
+
+ +

+ + 03 October, 2002 + +

+ +

© Copyright Dave Abrahams 2002. All Rights + Reserved.

+ + +