File: copy_non_const_reference.html

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (146 lines) | stat: -rw-r--r-- 4,202 bytes parent folder | download | duplicates (2)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 1st August 2002), see www.w3.org">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" type="text/css" href="../boost.css">

    <title>Boost.Python -
    &lt;boost/python/copy_non_const_reference.hpp&gt;</title>
  </head>

  <body>
    <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
    "header">
      <tr>
        <td valign="top" width="300">
          <h3><a href="../../../../index.htm"><img height="86" width="277"
          alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
        </td>

        <td valign="top">
          <h1 align="center"><a href="../index.html">Boost.Python</a></h1>

          <h2 align="center">Header
          &lt;boost/python/copy_non_const_reference.hpp&gt;</h2>
        </td>
      </tr>
    </table>
    <hr>

    <h2>Contents</h2>

    <dl class="page-index">
      <dt><a href="#classes">Classes</a></dt>

      <dd>
        <dl class="page-index">
          <dt><a href="#copy_non_const_reference-spec">Class
          <code>copy_non_const_reference</code></a></dt>

          <dd>
            <dl class="page-index">
              <dt><a href="#copy_non_const_reference-spec-synopsis">Class
              <code>copy_non_const_reference</code> synopsis</a></dt>

              <dt><a href=
              "#copy_non_const_reference-spec-metafunctions">Class
              <code>copy_non_const_reference</code> metafunctions</a></dt>
            </dl>
          </dd>
        </dl>
      </dd>

      <dt><a href="#examples">Example</a></dt>
    </dl>
    <hr>

    <h2><a name="classes"></a>Classes</h2>

    <h3><a name="copy_non_const_reference-spec"></a>Class
    <code>copy_non_const_reference</code></h3>

    <p><code>copy_non_const_reference</code> is a model of <a href=
    "ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>
    which can be used to wrap C++ functions returning a
    reference-to-non-const type such that the referenced value is copied into
    a new Python object.</p>

    <h4><a name="copy_non_const_reference-spec-synopsis"></a>Class
    <code>copy_non_const_reference</code> synopsis</h4>
<pre>
namespace boost { namespace python
{
    struct copy_non_const_reference
    {
        template &lt;class T&gt; struct apply;
    };
}}
</pre>

    <h4><a name="copy_non_const_reference-spec-metafunctions"></a>Class
    <code>copy_non_const_reference</code> metafunctions</h4>
<pre>
template &lt;class T&gt; struct apply
</pre>

    <dl class="metafunction-semantics">
      <dt><b>Requires:</b> <code>T</code> is <code>U&amp;</code> for some
      non-const <code>U</code>.</dt>

      <dt><b>Returns:</b> <code>typedef <a href=
      "to_python_value.html#to_python_value-spec">to_python_value</a>&lt;T&gt;
      type;</code></dt>
    </dl>

    <h2><a name="examples"></a>Example</h2>

    <p>C++ code:</p>
<pre>
#include &lt;boost/python/module.hpp&gt;
#include &lt;boost/python/class.hpp&gt;
#include &lt;boost/python/copy_non_const_reference.hpp&gt;
#include &lt;boost/python/return_value_policy.hpp&gt;

// classes to wrap
struct Bar { int x; }

struct Foo {
   Foo(int x) : { b.x = x; }
   Bar&amp; get_bar() { return b; }
 private:
   Bar b;
};

// Wrapper code
using namespace boost::python;
BOOST_PYTHON_MODULE(my_module)
{
    class_&lt;Bar&gt;("Bar");

     class_&lt;Foo&gt;("Foo", init&lt;int&gt;())
        .def("get_bar", &amp;Foo::get_bar
            , return_value_policy&lt;copy_non_const_reference&gt;())
       ;
}
</pre>
    Python Code: 
<pre>
&gt;&gt;&gt; from my_module import *
&gt;&gt;&gt; f = Foo(3)         # create a Foo object
&gt;&gt;&gt; b = f.get_bar()    # make a copy of the internal Bar object
</pre>

    <p>Revised 
    <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
  13 November, 2002
  <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
    </p>

    <p><i>&copy; Copyright <a href=
    "../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
  </body>
</html>