From 8f989f318bf63cd67081d5c33153f82906625a36 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 3 Oct 2002 20:59:43 +0000 Subject: [PATCH] doc update [SVN r15684] --- doc/v2/enum.html | 203 +++++++++++++++++++++++++++++++++++++++++++++ doc/v2/init.html | 3 +- doc/v2/module.html | 8 +- 3 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 doc/v2/enum.html diff --git a/doc/v2/enum.html b/doc/v2/enum.html new file mode 100644 index 00000000..38d878b1 --- /dev/null +++ b/doc/v2/enum.html @@ -0,0 +1,203 @@ + + + + + + + + + Boost.Python - <boost/python/enum.hpp> + + + + + + + + + +
+

C++ Boost

+
+

Boost.Python

+ +

Header <boost/python/enum.hpp>

+
+
+ +

Contents

+ +
+
Introduction
+ +
Classes
+ +
+
+
Class template + enum_
+ +
+
+
Class template enum_ + synopsis
+ +
Class template enum_ + constructors
+ +
Class template enum_ + modifier functions
+
+
+ +
+
+ +
Example(s)
+
+
+ +

Introduction

+ +

<boost/python/enum.hpp> defines the + interface through which users expose their C++ enumeration types + to Python. It declares the + enum_ class template, which is parameterized on the + enumeration type being exposed.

+ + +

Classes

+ +

Class template + enum_<T>

+ +

Creates a Python class derived from Python's int + type which is associated with the C++ type passed as its first + parameter. + +

Class template enum_ + synopsis

+
+namespace boost { namespace python
+{
+  template <class T>
+  class enum_ : public object
+  {
+    enum_(char const* name);
+    inline enum_<T>& value(char const* name, T);
+  };
+}}
+
+ +

Class template enum_ + constructors

+
+enum_(char const* name);
+
+ +
+
Requires: name is an ntbs which conforms to Python's identifier + naming rules. + +
Effects: Constructs an enum_ object + holding a Python extension type derived from int + which is named name. The + named attribute of the current scope is bound to the new + extension type.
+
+ +

Class template + enum_ modifier functions

+
+inline enum_<T>& value(char const* name, T x);
+
+ +
+
Requires: name is an ntbs which conforms to Python's identifier + naming rules. + +
Effects: adds an instance of the wrapped enumeration + type with value x to the type's dictionary as the + named attribute
. + +
Returns: *this
+ +
+ +

Example(s)

+ +

C++ module definition +

+#include <boost/python/enum.hpp>
+#include <boost/python/def.hpp>
+#include <boost/python/module.hpp>
+
+using namespace boost::python;
+
+enum color { red = 1, green = 2, blue = 4 };
+
+color identity_(color x) { return x; }
+
+BOOST_PYTHON_MODULE(enums)
+{
+    enum_<color>("color")
+        .value("red", red)
+        .value("green", green)
+        .value("blue", blue)
+        ;
+    
+    def("identity", identity_);
+}
+
+

Interactive Python: +

+>>> from enums import *
+
+>>> identity(color.red)
+enums.color.red
+
+>>> identity(color.green)
+enums.color.green
+
+>>> identity(color.blue)
+enums.color.blue
+
+>>> identity(color(1))
+enums.color.red
+
+>>> identity(color(2))
+enums.color.green
+
+>>> identity(color(3))
+enums.color(3)
+
+>>> identity(color(4))
+enums.color.blue
+
+>>> identity(1)
+Traceback (most recent call last):
+  File "<stdin>", line 1, in ?
+TypeError: bad argument type for built-in operation
+
+
+ + Revised + + 03 October, 2002 + + +

© Copyright Dave Abrahams 2002. All Rights + Reserved.

+ + + diff --git a/doc/v2/init.html b/doc/v2/init.html index 710287ef..2f6b938e 100644 --- a/doc/v2/init.html +++ b/doc/v2/init.html @@ -22,8 +22,7 @@

Boost.Python

-

Headers <boost/python/init.hpp>, - <boost/python/class_fwd.hpp>

+

Headers <boost/python/init.hpp>

diff --git a/doc/v2/module.html b/doc/v2/module.html index 42658832..e6b170b3 100644 --- a/doc/v2/module.html +++ b/doc/v2/module.html @@ -71,9 +71,11 @@ This macro generates two functions in the scope where it is used: and void init_module_name(), whose body must follow the macro invocation. init_name passes init_module_name to () so that any C++ -exceptions generated are safely processeed. - +href="errors.html#handle_exception">handle_exception() so +that any C++ exceptions generated are safely processeed. During the +body of init_name, the current scope refers to the module +being initialized.

Example(s)