Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/pickle4.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.1 KB
Line 
1// Copyright Ralf W. Grosse-Kunstleve 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)
4
5/*
6    This example shows how to enable pickling without using the
7    pickle_suite. The pickling interface (__getinitargs__) is
8    implemented in Python.
9
10    For more information refer to boost/libs/python/doc/pickle.html.
11 */
12
13#include <boost/python/module.hpp>
14#include <boost/python/class.hpp>
15
16#include <string>
17
18namespace {
19
20  // A friendly class.
21  class world
22  {
23    private:
24      std::string country;
25    public:
26      world(const std::string& country) {
27        this->country = country;
28      }
29      std::string greet() const { return "Hello from " + country + "!"; }
30      std::string get_country() const { return country; }
31  };
32
33}
34
35BOOST_PYTHON_MODULE(pickle4_ext)
36{
37  using namespace boost::python;
38  class_<world>("world", init<const std::string&>())
39      .enable_pickling()
40      .def("greet", &world::greet)
41      .def("get_country", &world::get_country)
42      ;
43}
Note: See TracBrowser for help on using the repository browser.