Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/docstring.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: 2.8 KB
RevLine 
[29]1// Copyright David Abrahams 2002.
2// Distributed under the Boost Software License, Version 1.0. (See
3// accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5#include <boost/python/operators.hpp>
6#include <boost/python/class.hpp>
7#include <boost/python/module.hpp>
8#include <boost/python/def.hpp>
9#include <boost/python/docstring_options.hpp>
10#include <boost/python/scope.hpp>
11#include <boost/python/manage_new_object.hpp>
12#include "test_class.hpp"
13
14// Just use math.h here; trying to use std::pow() causes too much
15// trouble for non-conforming compilers and libraries.
16#include <math.h>
17
18using namespace boost::python;
19
20typedef test_class<> X;
21
22X* create(int x)
23{
24    return new X(x);
25}
26
27unsigned long fact(unsigned long n)
28{
29    return n <= 1 ? n : n * fact(n - 1);
30}
31
32BOOST_PYTHON_MODULE(docstring_ext)
33{
34    scope().attr("__doc__") =
35        "A simple test module for documentation strings\n"
36        "Exercised by docstring.py"
37        ;
38
39    class_<X>("X",
40              "A simple class wrapper around a C++ int\n"
41              "includes some error-checking"
42
43              , init<int>(
44                  "this is the __init__ function\n"
45                  "its documentation has two lines."
46                )
47
48        )
49        .def("value", &X::value,
50             "gets the value of the object")
51        .def( "value", &X::value,
52            "also gets the value of the object")
53        ;
54
55    def("create", create, return_value_policy<manage_new_object>(),
56        "creates a new X object");
57
58    def("fact", fact, "compute the factorial");
59
60    {
61      docstring_options doc_options;
62      doc_options.disable_user_defined();
63      def("fact_usr_off_1", fact, "usr off 1");
64      doc_options.enable_user_defined();
65      def("fact_usr_on_1", fact, "usr on 1");
66      doc_options.disable_user_defined();
67      def("fact_usr_off_2", fact, "usr off 2");
68    }
69    def("fact_usr_on_2", fact, "usr on 2");
70
71    {
72      docstring_options doc_options(true, false);
73      def("fact_sig_off_1", fact, "sig off 1");
74      doc_options.enable_signatures();
75      def("fact_sig_on_1", fact, "sig on 1");
76      doc_options.disable_signatures();
77      def("fact_sig_off_2", fact, "sig off 2");
78    }
79    def("fact_sig_on_2", fact, "sig on 2");
80
81    {
82      docstring_options doc_options(false);
83      def("fact_usr_off_sig_off_1", fact, "usr off sig off 1");
84      {
85        docstring_options nested_doc_options;
86        def("fact_usr_on_sig_on_1", fact, "usr on sig on 1");
87        nested_doc_options.disable_all();
88        nested_doc_options.enable_user_defined();
89        def("fact_usr_on_sig_off_1", fact, "usr on sig off 1");
90        nested_doc_options.enable_all();
91        def("fact_usr_on_sig_on_2", fact, "usr on sig on 2");
92      }
93      def("fact_usr_off_sig_off_2", fact, "usr off sig off 2");
94    }
95}
96
97#include "module_tail.cpp"
Note: See TracBrowser for help on using the repository browser.