diff --git a/doc/v2/instance_holder.html b/doc/v2/instance_holder.html index 5f5a751a..db524825 100755 --- a/doc/v2/instance_holder.html +++ b/doc/v2/instance_holder.html @@ -45,13 +45,13 @@
Class instance_holder synopsis -
Class +
Class instance_holder destructor -
Class +
Class instance_holder modifier functions -
Class +
Class instance_holder observer functions @@ -112,7 +112,7 @@ namespace boost { namespace python }} -

Class instance_holder +

Class instance_holder destructor

 virtual ~instance_holder();
@@ -122,7 +122,7 @@ virtual ~instance_holder();
       
Effects: destroys the object -

Class +

Class instance_holder modifiers

 void install(PyObject* inst) throw();
@@ -137,7 +137,7 @@ void install(PyObject* inst) throw();
       
Throws: nothing -

Class instance_holder +

Class instance_holder observers

 virtual void* holds(type_info x) = 0;
@@ -199,7 +199,7 @@ struct pointer_holder : instance_holder
 
     

Revised - 19 November, 2002 + 29 May, 2002 diff --git a/doc/v2/lvalue_from_python.html b/doc/v2/lvalue_from_python.html deleted file mode 100644 index a0591128..00000000 --- a/doc/v2/lvalue_from_python.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - Boost.Python - <boost/python/lvalue_from_python.hpp> - - - -
-

-

- -
-

Boost.Python

- -

Header <boost/python/lvalue_from_python.hpp>

-
-


- -

Contents

- -
-
Introduction - - -
Classes - -
-
-
Class Template lvalue_from_python - -
-
- -
Class Template - lvalue_from_python synopsis - -
Class Template - lvalue_from_python constructor -
-
- -
-
Class Template get_member - -
-
- -
Class Template - get_member synopsis - -
Class Template - get_member static functions -
-
- -
Example -
-
- -

Introduction

- - <boost/python/lvalue_from_python.hpp> supplies - a facility for extracting C++ objects from within instances of a - given Python type. This is typically useful for dealing with - "traditional" Python extension types. - -

Classes

- -

Class template lvalue_from_python

- -

Class template lvalue_from_python will register - from_python converters which extract a references and pointers to - a C++ type which is held within an object of a given Python - type. Its template arguments are: - -

- - - - - - - - - -
- lvalue_from_python Requirements
- - In the table below, x denotes an object of type PythonObject& - -
Parameter - - Requirements - - Description - - Default - -
python_type - - A compile-time constant PyTypeObject* - - The Python type of instances convertible by this - converter. Python subtypes are also convertible. - -
Value - - A non-reference type. - - The C++ type to be extracted - -
PythonObject - - initial sizeof(PyObject) bytes are - layout-compatible with PyObject. - - The C++ type used to hold Python instances of - python_type. - - Value - -
Extract - - Value& v = Extract::execute(x); - - A type whose static execute function extracts a Value reference from within an object of type PythonObject. - - An unspecified type whose execute function consists of return x; -
- - If only the first two template arguments are supplied, these - converters extract the entire PythonObject as a - whole. - -

- - If the lifetime of the lvalue_from_python object ends - before the last attempt to convert to one its target types, the - behavior is undefined. The easiest way to ensure correct behavior - is to declare an lvalue_from_python instance as a - static local in a module init - function, as shown in the example - below. - -

Class template lvalue_from_python synopsis

-
-namespace boost { namespace python
-{
-   template <
-      PyTypeObject const* python_type
-      , class Value
-      , class PythonObject = Value
-      , class Extract = unspecified
-      >
-   class lvalue_from_python
-   {
-      lvalue_from_python();
-   };
-}}
-
- -

Class template lvalue_from_python constructor

-
-lvalue_from_python();
-
- -
- -
Effects: Registers from_python converters which - extract - Value&, Value const&, - Value*, or Value const* from Python - objects of type python_type using - Extract::execute(). - -
- -

Class template get_member

- -

get_member can be used with - lvalue_from_python in the common case where the C++ - type to be extracted is a member of the Python object. - -

Class template get_member synopsis

-
-namespace boost { namespace python
-{
-  template <class Class, class Member, Member (Class::*mp)>
-  struct get_member
-  {
-     static Member& execute(Class& c);
-  };
-}}
-
- -

Class template get_member static functions

-
-Member& execute(Class& c);
-
- -
- -
Returns: c.*mp - -
- - -

Example

- -This example presumes that someone has implemented the standard noddy -example module from the Python documentation, and we want to build -a module which manipulates Noddys. Since -noddy_NoddyObject is so simple that it carries no -interesting information, the example is a bit contrived: it assumes -you want to keep track of one particular object for some reason. - -

C++ module definition

- -
-#include <boost/python/reference.hpp>
-#include <boost/python/module.hpp>
-
-// definition lifted from the Python docs
-typedef struct {
-   PyObject_HEAD
-} noddy_NoddyObject;
-
-using namespace boost::python;
-static ref cache;
-
-bool is_cached(noddy_NoddyObject* x)
-{
-   return x == cache.get();
-}
-
-void set_cache(noddy_NoddyObject* x)
-{
-   cache.reset((PyObject*)x, ref::increment_count);
-}
-
-BOOST_PYTHON_MODULE_INIT(noddy_cache)
-{
-   module noddy_cache("noddy_cache")
-      .def("is_cached", is_cached)
-      .def("set_cache", set_cache)
-      ;
-}
-
- -

Python code

- -
->>> import noddy
->>> n = noddy.new_noddy()
->>> import noddy_cache
->>> noddy_cache.is_cached(n)
-0
->>> noddy_cache.set_cache(n)
->>> noddy_cache.is_cached(n)
-1
->>> noddy_cache.is_cached(noddy.new_noddy())
-0
-
- -

Revised - - 05 November, 2001 - - - -

© Copyright Dave - Abrahams 2002. All Rights Reserved. - diff --git a/doc/v2/ptr.html b/doc/v2/ptr.html index 3b68451b..71cc6975 100644 --- a/doc/v2/ptr.html +++ b/doc/v2/ptr.html @@ -93,11 +93,11 @@ which can be similarly used to prevent copying of referents.

ptr(p) returns an instance of pointer_wrapper<>, which + href="#pointer_wrapper-spec">pointer_wrapper<>, which can be detected using the is_pointer_wrapper<> + href="#is_pointer_wrapper-spec">is_pointer_wrapper<> metafunction; unwrap_pointer<> is a + href="#unwrap_pointer-spec">unwrap_pointer<> is a metafunction which extracts the original pointer type from a pointer_wrapper<>. These classes can be thought of as implementation details. @@ -252,7 +252,7 @@ void pass_as_arg(expensive_to_copy* x, PyObject* f)

Revised - 07 May, 2002 + 29 May, 2002 diff --git a/doc/v2/reference.html b/doc/v2/reference.html index c36afe20..8bd19545 100644 --- a/doc/v2/reference.html +++ b/doc/v2/reference.html @@ -497,37 +497,6 @@ -

type_from_python.hpp - -
-
-
Classes - -
-
-
type_from_python - -
identity_extractor - -
member_extractor -
-
- -
value_from_python.hpp - -
-
-
Classes - -
-
-
value_from_python -
-

Utility and Infrastructure

@@ -615,7 +584,7 @@

Revised - 05 November, 2002 + 29 May, 2002 diff --git a/doc/v2/with_custodian_and_ward.html b/doc/v2/with_custodian_and_ward.html index ebcbcaa0..ae816063 100644 --- a/doc/v2/with_custodian_and_ward.html +++ b/doc/v2/with_custodian_and_ward.html @@ -26,11 +26,11 @@

Classes -
-
-
Class Template with_custodian_and_ward +
+ +
Class Template with_custodian_and_ward
@@ -40,6 +40,17 @@
Class with_custodian_and_ward static functions
+ +
Class Template with_custodian_and_ward_postcall +
+
+ +
Class Template + with_custodian_and_ward_postcall synopsis + +
Class + with_custodian_and_ward_postcall static functions +
@@ -141,8 +152,8 @@ namespace boost { namespace python }}
-

Class - default_call_policies static functions

+

Class + with_custodian_and_ward static functions

 bool precall(PyObject* args);
@@ -229,8 +240,8 @@ namespace boost { namespace python
 }}
 
-

Class - default_call_policies static functions

+

Class + with_custodian_and_ward_postcall static functions

 PyObject* postcall(PyObject* args, PyObject* result);
@@ -260,9 +271,9 @@ to implement return_internal_reference
 
 
-template 
+template <std::size_t owner_arg = 1, class Base = default_call_policies>
 struct return_internal_reference
-    : with_custodian_and_ward_postcall<0, owner_arg, Base>
+    : with_custodian_and_ward_postcall<0, owner_arg, Base>
 {
    typedef reference_existing_object result_converter;
 };
@@ -270,7 +281,7 @@ struct return_internal_reference
 
     

Revised - 19 February, 2002 + 29 May, 2002

© Copyright Dave diff --git a/include/boost/python/type_from_python.hpp b/include/boost/python/type_from_python.hpp deleted file mode 100644 index 9fcd1f8f..00000000 --- a/include/boost/python/type_from_python.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TYPE_FROM_PYTHON_DWA2002130_HPP -# define TYPE_FROM_PYTHON_DWA2002130_HPP - -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - // Given a pointer-to-function of 1 parameter returning a reference - // type, return the type_id of the function's return type. - template - inline type_info extractor_type_id(T&(*)(U)) - { - return type_id(); - } - - // A function generator whose static execute() function is an lvalue - // from_python converter using the given Extractor. U is expected to - // be the actual type of the PyObject instance from which the result - // is being extracted. - template - struct normalized_extractor - { - static inline void* execute(PyObject* op) - { - typedef typename boost::add_reference::type param; - return &Extractor::execute( - boost::python::detail::void_ptr_to_reference( - op, (param(*)())0 ) - ); - } - }; - - // Given an Extractor type and a pointer to its execute function, - // return a new object whose static execute function does the same - // job but is a conforming lvalue from_python conversion function. - // - // usage: normalize(&Extractor::execute) - template - inline normalized_extractor - normalize(T(*)(U), Extractor* = 0) - { - return normalized_extractor(); - } -} - -// An Extractor which extracts the given member from a Python object -// whose instances are stored as InstanceType. -template -struct member_extractor -{ - static MemberType& execute(InstanceType& c) - { - (void)c.ob_type; // static assertion - return c.*member; - } -}; - -// An Extractor which simply extracts the entire python object -// instance of InstanceType. -template -struct identity_extractor -{ - static InstanceType& execute(InstanceType& c) - { - (void)c.ob_type; // static assertion - return c; - } -}; - -// Registers a from_python conversion which extracts lvalues using -// Extractor's static execute function from Python objects whose type -// object is python_type. -template -struct type_from_python -{ - type_from_python() - { - converter::registry::insert( - &extract, detail::extractor_type_id(&Extractor::execute)); - } - - static void* extract(PyObject* op) - { - return PyObject_TypeCheck(op, const_cast(python_type)) - ? const_cast( - static_cast( - detail::normalize(&Extractor::execute).execute(op))) - : 0 - ; - } -}; - -}} // namespace boost::python - -#endif // TYPE_FROM_PYTHON_DWA2002130_HPP