| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,10 +67,10 @@ | |||
| 67 | 67 | where my_module is the module where the enum is declared. You can also | |
| 68 | 68 | create a new scope around a class:</p> | |
| 69 | 69 | <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>) | ||
| 71 | 71 | </span><span class=special>.</span><span class=identifier>def</span><span class=special>( </span><span class=special>... </span><span class=special>) | |
| 72 | 72 | </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>; | ||
| 74 | 74 | ||
| 75 | 75 | </span><span class=comment>// Expose X::nested as X.nested | |
| 76 | 76 | </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 | |||
| 1148 | 1148 | where my_module is the module where the enum is declared. You can also | |
| 1149 | 1149 | create a new scope around a class: | |
| 1150 | 1150 | ||
| 1151 | - scope in_X(class_<X>("X") | ||
| 1151 | + scope in_X = class_<X>("X") | ||
| 1152 | 1152 | .def( ... ) | |
| 1153 | 1153 | .def( ... ) | |
| 1154 | - ); | ||
| 1154 | + ; | ||
| 1155 | 1155 | ||
| 1156 | 1156 | // Expose X::nested as X.nested | |
| 1157 | 1157 | 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> | |||
| 81 | 81 | namespace boost { namespace python | |
| 82 | 82 | { | |
| 83 | 83 | 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> | ||
| 86 | 85 | { | |
| 87 | 86 | public: | |
| 88 | - explicit scope(object const&); | ||
| 87 | + scope(scope const&); | ||
| 88 | + scope(object const&); | ||
| 89 | 89 | scope(); | |
| 90 | 90 | ~scope() | |
| 91 | + private: | ||
| 92 | + void operator=(scope const&); | ||
| 91 | 93 | }; | |
| 92 | 94 | }} | |
| 93 | 95 | </pre> | |
| 94 | 96 | ||
| 95 | 97 | <h4><a name="scope-spec-ctors"></a>Class <code>scope</code> constructors | |
| 96 | 98 | and destructor</h4> | |
| 97 | 99 | <pre> | |
| 100 | + explicit scope(scope const& x); | ||
| 98 | 101 | explicit scope(object const& x); | |
| 99 | 102 | </pre> | |
| 100 | 103 | Stores a reference to the current associated scope object, and sets the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,16 +13,20 @@ | |||
| 13 | 13 | namespace boost { namespace python { | |
| 14 | 14 | ||
| 15 | 15 | class BOOST_PYTHON_DECL scope | |
| 16 | - : public object, private noncopyable | ||
| 16 | + : public object | ||
| 17 | 17 | { | |
| 18 | 18 | public: | |
| 19 | - explicit inline scope(object const&); | ||
| 19 | + inline scope(scope const&); | ||
| 20 | + inline scope(object const&); | ||
| 20 | 21 | inline scope(); | |
| 21 | 22 | inline ~scope(); | |
| 22 | 23 | ||
| 23 | 24 | private: // data members | |
| 24 | 25 | PyObject* m_previous_scope; | |
| 25 | 26 | ||
| 27 | + private: // unimplemented functions | ||
| 28 | + void operator=(scope const&); | ||
| 29 | + | ||
| 26 | 30 | private: // static members | |
| 27 | 31 | ||
| 28 | 32 | // Use a PyObject* to avoid problems with static destruction after Py_Finalize | |
@@ -59,6 +63,14 @@ namespace converter | |||
| 59 | 63 | }; | |
| 60 | 64 | } | |
| 61 | 65 | ||
| 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 | + | ||
| 62 | 74 | }} // namespace boost::python | |
| 63 | 75 | ||
| 64 | 76 | #endif // SCOPE_DWA2002724_HPP | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,10 +33,11 @@ BOOST_PYTHON_MODULE(nested_ext) | |||
| 33 | 33 | using namespace boost::python; | |
| 34 | 34 | ||
| 35 | 35 | // 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 | + | ||
| 40 | 41 | ||
| 41 | 42 | // Y will now be defined in the current scope | |
| 42 | 43 | class_<Y>("Y", init<int>()) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments