File: to_python_indirect.qbk

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (65 lines) | stat: -rw-r--r-- 2,748 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[section boost/python/to_python_indirect.hpp]
[section Introduction]
 <boost/python/to_python_indirect.hpp> supplies a way to construct new Python objects that hold wrapped C++ class instances via a pointer or smart pointer.
 [endsect]
[section Class `to_python_indirect`]
Class template `to_python_indirect` converts objects of its first argument type to python as extension class instances, using the ownership policy provided by its 2nd argument.
[table
[[Parameter][Requirements][Description]]
 [[T][Either `U cv&` (where cv is any optional cv-qualification) or a [link concepts.dereferenceable Dereferenceable] type such that `*x` is convertible to `U const&`, where `U` is a class type. ][`A` type deferencing a C++ class exposed to Python using class template [link high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel `class_`]. ]]
[[MakeHolder][`h = MakeHolder::execute(p);` ][A class whose static `execute()` creates an `instance_holder`. ]]
 ]
Instantiations of to_python_indirect are models of [link concepts.resultconverter `ResultConverter`]. 
``
namespace boost { namespace python
{
  template <class T, class MakeHolder>
  struct to_python_indirect
  {
     static bool convertible();
     PyObject* operator()(T ptr_or_reference) const;
   private:
     static PyTypeObject* type();
  };
}}
``
[endsect]
[section Class `to_python_indirect` observers]
``PyObject* operator()(T x) const;``
[variablelist
[[Requires][`x` refers to an object (if it is a pointer type, it is non-null). `convertible() == true`.]]
[[Effects][Creates an appropriately-typed Boost.Python extension class instance, uses MakeHolder to create an instance_holder from x, installs the instance_holder in the new extension class instance, and returns a pointer to it.]]
]
[endsect]
[section Class `to_python_indirect` statics]
``bool convertible()``
[variablelist
[[Effects][Returns true iff any module has registered a Python type corresponding to U. ]]
]
[endsect]
[endsect]
[section Example]
This example replicates the functionality of [link function_invocation_and_creation.models_of_resultconvertergenerat.boost_python_reference_existing_.class_reference_existing_object `reference_existing_object`], but without some of the compile-time error checking. 
``
struct make_reference_holder
{
   typedef boost::python::objects::instance_holder* result_type;
   template <class T>
   static result_type execute(T* p)
   {
      return new boost::python::objects::pointer_holder<T*, T>(p);
   }
};

struct reference_existing_object
{
   // metafunction returning the ResultConverter
   template <class T>
   struct apply
   {
      typedef boost::python::to_python_indirect<T,make_reference_holder> type;
   };
};
``
[endsect]
[endsect]