]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/example/quickstart/extending.cpp
1 // Copyright Ralf W. Grosse-Kunstleve 2002-2004. Distributed under the Boost
2 // Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #include <boost/python/class.hpp>
6 #include <boost/python/module.hpp>
7 #include <boost/python/def.hpp>
11 namespace { // Avoid cluttering the global namespace.
17 hello(const std::string
& country
) { this->country
= country
; }
18 std::string
greet() const { return "Hello from " + country
; }
23 // A function taking a hello object as an argument.
24 std::string
invite(const hello
& w
) {
25 return w
.greet() + "! Please come soon!";
29 BOOST_PYTHON_MODULE(extending
)
31 using namespace boost::python
;
32 class_
<hello
>("hello", init
<std::string
>())
33 // Add a regular member function.
34 .def("greet", &hello::greet
)
35 // Add invite() as a member of hello!
36 .def("invite", invite
)
39 // Also add invite() as a regular function to the module.
40 def("invite", invite
);