File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6767where my_module is the module where the enum is declared. You can also
6868create a new scope around a class:</ p >
6969< code > < pre >
70- < span class =identifier > scope </ span > < span class =identifier > in_X</ span > < span class =special > ( </ span > < span class =identifier > class_</ span > < span class =special > <</ span > < span class =identifier > X</ span > < span class =special > >(</ span > < span class =string > "X"</ span > < span class =special > )
70+ < span class =identifier > scope </ span > < span class =identifier > in_X</ span > < span class =special > = </ span > < span class =identifier > class_</ span > < span class =special > <</ span > < span class =identifier > X</ span > < span class =special > >(</ span > < span class =string > "X"</ span > < span class =special > )
7171 </ span > < span class =special > .</ span > < span class =identifier > def</ span > < span class =special > ( </ span > < span class =special > ... </ span > < span class =special > )
7272 </ span > < span class =special > .</ span > < span class =identifier > def</ span > < span class =special > ( </ span > < span class =special > ... </ span > < span class =special > )
73- </ span > < span class =special > ) ;
73+ </ span > < span class =special > ;
7474
7575 </ span > < span class =comment > // Expose X::nested as X.nested
7676 </ span > < span class =identifier > enum_</ span > < span class =special > <</ span > < span class =identifier > X</ span > < span class =special > ::</ span > < span class =identifier > nested</ span > < span class =special > >(</ span > < span class =string > "nested"</ span > < span class =special > )
Original file line number Diff line number Diff line change @@ -1148,10 +1148,10 @@ You can access those values in Python as
11481148where my_module is the module where the enum is declared. You can also
11491149create a new scope around a class:
11501150
1151- scope in_X( class_<X>("X")
1151+ scope in_X = class_<X>("X")
11521152 .def( ... )
11531153 .def( ... )
1154- ) ;
1154+ ;
11551155
11561156 // Expose X::nested as X.nested
11571157 enum_<X::nested>("nested")
Original file line number Diff line number Diff line change @@ -81,20 +81,23 @@ <h4><a name="scope-spec-synopsis"></a>Class <code>scope</code>
8181namespace boost { namespace python
8282{
8383 class scope : public < a href =
84- "object.html#object-spec "> object</ a > , private < a href =
85- "../../../utility/utility.htm#Class noncopyable "> noncopyable</ a >
84+ "object.html#object-spec "> object</ a >
8685 {
8786 public:
88- explicit scope(object const&);
87+ scope(scope const&);
88+ scope(object const&);
8989 scope();
9090 ~scope()
91+ private:
92+ void operator=(scope const&);
9193 };
9294}}
9395</ pre >
9496
9597 < h4 > < a name ="scope-spec-ctors "> </ a > Class < code > scope</ code > constructors
9698 and destructor</ h4 >
9799< pre >
100+ explicit scope(scope const& x);
98101explicit scope(object const& x);
99102</ pre >
100103 Stores a reference to the current associated scope object, and sets the
Original file line number Diff line number Diff line change 1313namespace boost { namespace python {
1414
1515class BOOST_PYTHON_DECL scope
16- : public object, private noncopyable
16+ : public object
1717{
1818 public:
19- explicit inline scope (object const &);
19+ inline scope (scope const &);
20+ inline scope (object const &);
2021 inline scope ();
2122 inline ~scope ();
2223
2324 private: // data members
2425 PyObject* m_previous_scope;
2526
27+ private: // unimplemented functions
28+ void operator =(scope const &);
29+
2630 private: // static members
2731
2832 // Use a PyObject* to avoid problems with static destruction after Py_Finalize
@@ -59,6 +63,14 @@ namespace converter
5963 };
6064}
6165
66+ // Placing this after the specialization above suppresses a CWPro8.3 bug
67+ inline scope::scope (scope const & new_scope)
68+ : object(new_scope)
69+ , m_previous_scope(current_scope)
70+ {
71+ current_scope = python::incref (new_scope.ptr ());
72+ }
73+
6274}} // namespace boost::python
6375
6476#endif // SCOPE_DWA2002724_HPP
Original file line number Diff line number Diff line change @@ -33,10 +33,11 @@ BOOST_PYTHON_MODULE(nested_ext)
3333 using namespace boost ::python;
3434
3535 // Establish X as the current scope.
36- scope x_class (
37- class_<X>(" X" , init<int >())
38- .def (str (self))
39- );
36+ scope x_class
37+ = class_<X>(" X" , init<int >())
38+ .def (str (self))
39+ ;
40+
4041
4142 // Y will now be defined in the current scope
4243 class_<Y>(" Y" , init<int >())
You can’t perform that action at this time.
0 commit comments