diff --git a/test/bienstman1.cpp b/test/bienstman1.cpp index e6d5e42f..5e035d68 100644 --- a/test/bienstman1.cpp +++ b/test/bienstman1.cpp @@ -24,18 +24,13 @@ BOOST_PYTHON_MODULE_INIT(bienstman1_ext) using boost::python::return_value_policy; using boost::python::reference_existing_object; - module m("bienstman1_ext"); - - m - .add(class_ >("A")) + class_ >("A"); - .add( - class_("V", no_init) + class_("V", no_init) .def("inside", &V::inside, return_value_policy()) .def("outside", outside, return_value_policy()) - ) - ; + ; } diff --git a/test/bienstman2.cpp b/test/bienstman2.cpp index b2ef1957..79c4dfb0 100644 --- a/test/bienstman2.cpp +++ b/test/bienstman2.cpp @@ -15,15 +15,10 @@ BOOST_PYTHON_MODULE_INIT(bienstman2_ext) { using namespace boost::python; - module m("bienstman2_ext"); - - m - .add(class_("C")) - .add(class_("D")) - .add( - class_("E") + class_("C"); + class_("D"); + class_("E") .def("fe", &E::fe) // this compiles. - .def("fe2", &E::fe2) // this doesn't. - ) - ; + .def("fe2", &E::fe2) // this doesn't... well, now it does ;-) + ; } diff --git a/test/bienstman3.cpp b/test/bienstman3.cpp index 494965a2..9b2985e1 100644 --- a/test/bienstman3.cpp +++ b/test/bienstman3.cpp @@ -15,15 +15,7 @@ BOOST_PYTHON_MODULE_INIT(bienstman3_ext) { using namespace boost::python; - module m("bienstman3_ext"); - - m - .add( - class_("V", no_init) - ) + class_("V", no_init); + class_("B", args()); - .add( - class_("B", args()) - ) - ; } diff --git a/test/bienstman4.cpp b/test/bienstman4.cpp index b44b4bf8..22ed6b6f 100644 --- a/test/bienstman4.cpp +++ b/test/bienstman4.cpp @@ -21,15 +21,16 @@ BOOST_PYTHON_MODULE_INIT(bienstman4_ext) implicitly_convertible(); - module("bienstman4_ext") - .add(class_("Expression") - .def("add", &Expression::add)) - .add(class_("T1") - .add(class_("Term" - , args())) - ; + class_("Expression") + .def("add", &Expression::add) + ; + + class_("T1") + ; + + class_("Term", args()) + ; - Type1 t1; Expression e; e.add(t1); diff --git a/test/bienstman5.cpp b/test/bienstman5.cpp index 96eb7023..57b36f21 100644 --- a/test/bienstman5.cpp +++ b/test/bienstman5.cpp @@ -15,15 +15,9 @@ struct M {M(const std::complex&) {} }; BOOST_PYTHON_MODULE_INIT(bienstman5_ext) { using namespace boost::python; - using boost::mpl::type_list; - module m("bienstman5_ext"); - - m - .add(class_("M") - .def_init(args const&>())) - ; - + class_("M", args const&>()) + ; } diff --git a/test/cltree.cpp b/test/cltree.cpp index d99a4862..8b96aad3 100755 --- a/test/cltree.cpp +++ b/test/cltree.cpp @@ -48,40 +48,21 @@ public: }; -BOOST_PYTHON_MODULE_INIT(cltree) { - - boost::python::module m("cltree"); - m - .add( - boost::python::class_("basic") - .def_init(boost::python::args<>()) +BOOST_PYTHON_MODULE_INIT(cltree) +{ + boost::python::class_("basic") .def("__repr__",&basic::repr) - ) - ; + ; - m - .add(boost::python::class_ - ,boost::noncopyable - >("constant") - .def_init(boost::python::args<>()) - ) + boost::python::class_, boost::noncopyable>("constant") + ; - .add(boost::python::class_("symbol") - .def_init(boost::python::args<>()) - ) - .add(boost::python::class_ - ,variable_wrapper - //,boost::noncopyable // leads to compiler failure?! - >("variable") - .def_init(boost::python::args<>()) - ) - ; + boost::python::class_("symbol") + ; + + boost::python::class_, variable_wrapper>("variable") + ; } #include "module_tail.cpp" diff --git a/test/data_members.cpp b/test/data_members.cpp index 30c8d22f..5092bba9 100644 --- a/test/data_members.cpp +++ b/test/data_members.cpp @@ -22,20 +22,17 @@ double get_fair_value(X const& x) { return x.value(); } BOOST_PYTHON_MODULE_INIT(data_members_ext) { - module("data_members_ext") - .add( - class_("X", args()) - .def("value", &X::value) - .def("set", &X::set) - .def_readonly("x", &X::x) - .add_property("get_fair_value", object(&get_fair_value)) - ) - .add( - class_("Y", args()) - .def("value", &Y::value) - .def("set", &Y::set) - .def_readwrite("x", &Y::x) - ) + class_("X", args()) + .def("value", &X::value) + .def("set", &X::set) + .def_readonly("x", &X::x) + .add_property("get_fair_value", object(&get_fair_value)) + ; + + class_("Y", args()) + .def("value", &Y::value) + .def("set", &Y::set) + .def_readwrite("x", &Y::x) ; } diff --git a/test/extract.cpp b/test/extract.cpp index aec75308..946f5ba1 100644 --- a/test/extract.cpp +++ b/test/extract.cpp @@ -99,12 +99,6 @@ BOOST_PYTHON_MODULE_INIT(extract_ext) { implicitly_convertible(); - class_ x_class("X", args()); - - x_class - .def( "__repr__", x_rep) - ; - module("extract_ext") .def("extract_bool", extract_bool) .def("extract_list", extract_list) @@ -124,12 +118,15 @@ BOOST_PYTHON_MODULE_INIT(extract_ext) .def("check_X_ptr", check_X_ptr) .def("check_X_ref", check_X_ref) - .add(x_class) .def("double_X", double_X) .def("count_Xs", &X::count) ; + object x_class( + class_("X", args()) + .def( "__repr__", x_rep)); + // Instantiate an X object through the Python interface object x_obj = x_class(3); diff --git a/test/iterator.cpp b/test/iterator.cpp index c5ce6f32..8f59d4b7 100644 --- a/test/iterator.cpp +++ b/test/iterator.cpp @@ -74,51 +74,51 @@ BOOST_PYTHON_MODULE_INIT(iterator_ext) { module("iterator_ext") .def("range", &::range) - .add( - class_("list_int") - .def("push_back", push_back) - .def("back", back) - .def("__iter__", iterator()) - ) - .add( - class_("list_range") + ; - // We can specify data members - .def("__iter__" - , range(&list_range::first, &list_range::second)) - ) - .add( - class_("two_lists") + class_("list_int") + .def("push_back", push_back) + .def("back", back) + .def("__iter__", iterator()) + ; - // We can spcify member functions - .add_property( - "primes" - , range(&two_lists::one_begin, &two_lists::one_end)) + class_("list_range") - // Prove that we can explicitly specify call policies - .add_property( - "evens" - , range >( - &two_lists::two_begin, &two_lists::two_end)) + // We can specify data members + .def("__iter__" + , range(&list_range::first, &list_range::second)) + ; - // Prove that we can specify call policies and target - .add_property( - "twosies" - , range, two_lists>( - // And we can use adaptable function objects when - // partial specialization is available. + class_("two_lists") + + // We can spcify member functions + .add_property( + "primes" + , range(&two_lists::one_begin, &two_lists::one_end)) + + // Prove that we can explicitly specify call policies + .add_property( + "evens" + , range >( + &two_lists::two_begin, &two_lists::two_end)) + + // Prove that we can specify call policies and target + .add_property( + "twosies" + , range, two_lists>( + // And we can use adaptable function objects when + // partial specialization is available. # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - two_lists::two_start() + two_lists::two_start() # else - &two_lists::two_begin + &two_lists::two_begin # endif - , &two_lists::two_end)) - ) - .add( - class_("list_list") - .def("push_back", push_list_back) - .def("__iter__", iterator >()) - ) + , &two_lists::two_end)) + ; + + class_("list_list") + .def("push_back", push_list_back) + .def("__iter__", iterator >()) ; } diff --git a/test/multi_arg_constructor.cpp b/test/multi_arg_constructor.cpp index 0114e151..562842a0 100644 --- a/test/multi_arg_constructor.cpp +++ b/test/multi_arg_constructor.cpp @@ -14,13 +14,10 @@ BOOST_PYTHON_MODULE_INIT(multi_arg_constructor_ext) using namespace boost::python; using boost::shared_ptr; - module("multi_arg_constructor_ext") - - .add(class_ >( - "A" - , args() - ) - ) + class_ >( + "A" + , args() + ) ; } diff --git a/test/operators.cpp b/test/operators.cpp index 9b2afc3e..ae90f996 100755 --- a/test/operators.cpp +++ b/test/operators.cpp @@ -58,31 +58,28 @@ std::ostream& operator<<(std::ostream& s, X const& x) BOOST_PYTHON_MODULE_INIT(operators_ext) { - module("operators_ext") - .add( - class_("X", args()) - .def("value", &X::value) - .def(self - self) - .def(self - int()) - .def(other() - self) - .def(-self) - .def(self < other()) - .def(self < self) - .def(1 < self) - .def(self -= self) - .def(abs(self)) - .def(str(self)) + class_("X", args()) + .def("value", &X::value) + .def(self - self) + .def(self - int()) + .def(other() - self) + .def(-self) + .def(self < other()) + .def(self < self) + .def(1 < self) + .def(self -= self) + .def(abs(self)) + .def(str(self)) - .def(pow(self,self)) - .def(pow(self,int())) - .def(pow(int(),self)) - ) - .add( - class_ >("Z", args()) - .def(int_(self)) - .def(float_(self)) - .def(complex_(self)) - ) + .def(pow(self,self)) + .def(pow(self,int())) + .def(pow(int(),self)) + ; + + class_ >("Z", args()) + .def(int_(self)) + .def(float_(self)) + .def(complex_(self)) ; } diff --git a/test/pickle1.cpp b/test/pickle1.cpp index 6edec23a..eab90299 100644 --- a/test/pickle1.cpp +++ b/test/pickle1.cpp @@ -50,11 +50,8 @@ namespace { BOOST_PYTHON_MODULE_INIT(pickle1_ext) { using namespace boost::python; - module("pickle1_ext") - .add(class_("world" - , args()) + class_("world", args()) .def("greet", &world::greet) .def_pickle(world_pickle_suite()) - ) - ; + ; } diff --git a/test/pickle2.cpp b/test/pickle2.cpp index 62c7c4b5..6fe2962d 100644 --- a/test/pickle2.cpp +++ b/test/pickle2.cpp @@ -89,13 +89,11 @@ namespace { // Avoid cluttering the global namespace. BOOST_PYTHON_MODULE_INIT(pickle2_ext) { - boost::python::module("pickle2_ext") - .add(boost::python::class_("world" - , boost::python::args()) - .def("greet", &world::greet) - .def("get_secret_number", &world::get_secret_number) - .def("set_secret_number", &world::set_secret_number) - .def_pickle(world_pickle_suite()) - ) - ; + boost::python::class_( + "world", boost::python::args()) + .def("greet", &world::greet) + .def("get_secret_number", &world::get_secret_number) + .def("set_secret_number", &world::set_secret_number) + .def_pickle(world_pickle_suite()) + ; } diff --git a/test/pickle3.cpp b/test/pickle3.cpp index 4aaaecb5..f4f8c20e 100644 --- a/test/pickle3.cpp +++ b/test/pickle3.cpp @@ -95,13 +95,11 @@ namespace { // Avoid cluttering the global namespace. BOOST_PYTHON_MODULE_INIT(pickle3_ext) { - boost::python::module("pickle3_ext") - .add(boost::python::class_("world" - , boost::python::args()) - .def("greet", &world::greet) - .def("get_secret_number", &world::get_secret_number) - .def("set_secret_number", &world::set_secret_number) - .def_pickle(world_pickle_suite()) - ) - ; + boost::python::class_( + "world", boost::python::args()) + .def("greet", &world::greet) + .def("get_secret_number", &world::get_secret_number) + .def("set_secret_number", &world::set_secret_number) + .def_pickle(world_pickle_suite()) + ; } diff --git a/test/virtual_functions.cpp b/test/virtual_functions.cpp index 45fe3636..3864498a 100644 --- a/test/virtual_functions.cpp +++ b/test/virtual_functions.cpp @@ -88,27 +88,24 @@ int X::counter; BOOST_PYTHON_MODULE_INIT(virtual_functions_ext) { - module("virtual_functions_ext") - .add( - class_("concrete", args()) - .def("value", &concrete::value) - .def("set", &concrete::set) - .def("call_f", &concrete::call_f) - .def("f", &concrete_callback::f_impl)) + class_("concrete", args()) + .def("value", &concrete::value) + .def("set", &concrete::set) + .def("call_f", &concrete::call_f) + .def("f", &concrete_callback::f_impl) + ; - .add( - class_ - >("abstract", args()) + class_ + >("abstract", args()) - .def("value", &abstract::value) - .def("call_f", &abstract::call_f) - .def("set", &abstract::set)) + .def("value", &abstract::value) + .def("call_f", &abstract::call_f) + .def("set", &abstract::set) + ; - .add( - class_("Y", args()) - .def("value", &Y::value) - .def("set", &Y::set) - ) + class_("Y", args()) + .def("value", &Y::value) + .def("set", &Y::set) ; }