From c18afd78f56bdd3b0e7cc1d819491f4673b85bb0 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 17 Sep 2002 06:09:24 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'factor_out_redundant_macro_code_into_base_class'. [SVN r15400] --- include/boost/python/arg_from_python.hpp | 52 - include/boost/python/args.hpp | 34 - include/boost/python/back_reference.hpp | 101 -- include/boost/python/base_type_traits.hpp | 36 - include/boost/python/bases.hpp | 60 - include/boost/python/borrowed.hpp | 20 - include/boost/python/call.hpp | 64 - include/boost/python/call_method.hpp | 64 - include/boost/python/callback.hpp | 829 ----------- include/boost/python/caller.hpp | 1279 ---------------- include/boost/python/cast.hpp | 106 -- include/boost/python/class.hpp | 436 ------ include/boost/python/class_builder.hpp | 182 --- include/boost/python/class_fwd.hpp | 30 - include/boost/python/classes.hpp | 677 --------- include/boost/python/conversions.hpp | 415 ------ .../python/converter/arg_from_python.hpp | 336 ----- .../boost/python/converter/arg_to_python.hpp | 247 ---- .../python/converter/arg_to_python_base.hpp | 35 - .../python/converter/builtin_converters.hpp | 123 -- include/boost/python/converter/callback.hpp | 278 ---- .../converter/callback_from_python_base.hpp | 25 - .../converter/callback_to_python_base.hpp | 45 - .../python/converter/constructor_function.hpp | 18 - .../python/converter/convertible_function.hpp | 15 - .../python/converter/find_from_python.hpp | 29 - .../boost/python/converter/from_python.hpp | 43 - .../python/converter/from_python_data.hpp | 129 -- .../python/converter/from_python_function.hpp | 18 - .../converter/from_python_stage1_data.hpp | 21 - include/boost/python/converter/implicit.hpp | 57 - .../converter/lvalue_from_python_chain.hpp | 70 - .../converter/obj_mgr_arg_from_python.hpp | 116 -- .../boost/python/converter/object_manager.hpp | 232 --- .../converter/pointee_to_python_function.hpp | 51 - .../python/converter/pointer_type_id.hpp | 69 - .../python/converter/pyobject_traits.hpp | 42 - .../boost/python/converter/pyobject_type.hpp | 36 - .../converter/pytype_arg_from_python.hpp | 99 -- .../converter/pytype_object_mgr_traits.hpp | 43 - include/boost/python/converter/registered.hpp | 54 - .../python/converter/registered_pointee.hpp | 63 - .../boost/python/converter/registrations.hpp | 67 - include/boost/python/converter/registry.hpp | 52 - .../python/converter/return_from_python.hpp | 151 -- .../converter/rvalue_from_python_chain.hpp | 39 - .../converter/rvalue_from_python_data.hpp | 140 -- include/boost/python/converter/smart_ptr.hpp | 70 - .../python/converter/to_python_function.hpp | 50 - .../converter/to_python_function_type.hpp | 30 - include/boost/python/converter/type_id.hpp | 176 --- include/boost/python/copy_const_reference.hpp | 42 - .../boost/python/copy_mutable_reference.hpp | 41 - .../boost/python/copy_non_const_reference.hpp | 42 - include/boost/python/cross_module.hpp | 329 ----- include/boost/python/data_members.hpp | 111 -- include/boost/python/def.hpp | 94 -- .../boost/python/default_call_policies.hpp | 78 - .../boost/python/detail/aix_init_module.hpp | 24 - .../boost/python/detail/api_placeholder.hpp | 14 - .../boost/python/detail/arg_tuple_size.hpp | 127 -- include/boost/python/detail/base_object.hpp | 60 - include/boost/python/detail/borrowed_ptr.hpp | 112 -- include/boost/python/detail/call_object.hpp | 66 - include/boost/python/detail/caller.hpp | 105 -- include/boost/python/detail/cast.hpp | 81 -- include/boost/python/detail/char_array.hpp | 23 - include/boost/python/detail/config.hpp | 117 -- include/boost/python/detail/construct.hpp | 43 - include/boost/python/detail/convertible.hpp | 39 - include/boost/python/detail/cv_category.hpp | 34 - .../boost/python/detail/decorated_type_id.hpp | 77 - include/boost/python/detail/def_helper.hpp | 61 - include/boost/python/detail/defaults_def.hpp | 249 ---- include/boost/python/detail/dependent.hpp | 28 - include/boost/python/detail/destroy.hpp | 83 -- .../boost/python/detail/exception_handler.hpp | 48 - .../boost/python/detail/extension_class.hpp | 1002 ------------- .../boost/python/detail/force_instantiate.hpp | 33 - include/boost/python/detail/functions.hpp | 311 ---- include/boost/python/detail/if_else.hpp | 117 -- .../boost/python/detail/indirect_traits.hpp | 395 ----- include/boost/python/detail/init_function.hpp | 562 -------- include/boost/python/detail/make_tuple.hpp | 31 - include/boost/python/detail/map_entry.hpp | 44 - .../python/detail/member_function_cast.hpp | 113 -- include/boost/python/detail/module_base.hpp | 45 - include/boost/python/detail/module_info.hpp | 51 - include/boost/python/detail/module_init.hpp | 53 - include/boost/python/detail/msvc_typeinfo.hpp | 102 -- include/boost/python/detail/none.hpp | 21 - include/boost/python/detail/not_specified.hpp | 15 - include/boost/python/detail/operator_id.hpp | 55 - include/boost/python/detail/pointee.hpp | 36 - include/boost/python/detail/preprocessor.hpp | 67 - include/boost/python/detail/python22_fixed.h | 140 -- .../python/detail/python_library_include.hpp | 183 --- include/boost/python/detail/raw_pyobject.hpp | 33 - .../boost/python/detail/referent_storage.hpp | 75 - include/boost/python/detail/result.hpp | 124 -- include/boost/python/detail/returning.hpp | 215 --- include/boost/python/detail/signatures.hpp | 251 ---- include/boost/python/detail/singleton.hpp | 68 - .../boost/python/detail/string_literal.hpp | 90 -- include/boost/python/detail/target.hpp | 75 - .../python/detail/translate_exception.hpp | 45 - include/boost/python/detail/type_list.hpp | 40 - .../boost/python/detail/type_list_impl.hpp | 55 - .../python/detail/type_list_impl_no_pts.hpp | 101 -- .../boost/python/detail/type_list_utils.hpp | 28 - include/boost/python/detail/types.hpp | 413 ------ include/boost/python/detail/unwind_type.hpp | 151 -- include/boost/python/detail/void_adaptor.hpp | 39 - include/boost/python/detail/void_ptr.hpp | 34 - include/boost/python/detail/void_return.hpp | 43 - include/boost/python/detail/wrap_function.hpp | 40 - include/boost/python/detail/wrap_python.hpp | 157 -- include/boost/python/dict.hpp | 130 -- include/boost/python/enum.hpp | 78 - include/boost/python/errors.hpp | 57 - include/boost/python/exception_translator.hpp | 25 - include/boost/python/extract.hpp | 240 --- include/boost/python/from_python.hpp | 49 - include/boost/python/handle.hpp | 241 ---- include/boost/python/handle_fwd.hpp | 17 - include/boost/python/has_back_reference.hpp | 22 - include/boost/python/implicit.hpp | 28 - include/boost/python/init.hpp | 368 ----- include/boost/python/instance_holder.hpp | 57 - include/boost/python/iterator.hpp | 115 -- include/boost/python/list.hpp | 117 -- include/boost/python/long.hpp | 55 - include/boost/python/lvalue_from_pytype.hpp | 104 -- include/boost/python/make_function.hpp | 64 - include/boost/python/manage_new_object.hpp | 40 - include/boost/python/module.hpp | 108 -- include/boost/python/module_builder.hpp | 76 - include/boost/python/module_init.hpp | 61 - include/boost/python/object.hpp | 23 - .../boost/python/object/add_to_namespace.hpp | 24 - .../python/object/auto_ptr_generator.hpp | 23 - include/boost/python/object/class.hpp | 52 - .../boost/python/object/class_converters.hpp | 84 -- include/boost/python/object/class_detail.hpp | 20 - include/boost/python/object/class_object.hpp | 26 - include/boost/python/object/class_wrapper.hpp | 29 - include/boost/python/object/construct.hpp | 24 - include/boost/python/object/enum_base.hpp | 34 - include/boost/python/object/find_instance.hpp | 40 - include/boost/python/object/forward.hpp | 109 -- include/boost/python/object/function.hpp | 72 - .../boost/python/object/function_handle.hpp | 40 - .../boost/python/object/function_object.hpp | 24 - include/boost/python/object/inheritance.hpp | 167 --- include/boost/python/object/instance.hpp | 51 - include/boost/python/object/iterator.hpp | 217 --- include/boost/python/object/iterator_core.hpp | 19 - include/boost/python/object/life_support.hpp | 17 - include/boost/python/object/make_holder.hpp | 86 -- include/boost/python/object/make_instance.hpp | 72 - .../boost/python/object/pickle_support.hpp | 123 -- .../boost/python/object/pointer_holder.hpp | 158 -- include/boost/python/object/py_function.hpp | 22 - include/boost/python/object/select_holder.hpp | 148 -- include/boost/python/object/value_holder.hpp | 131 -- .../boost/python/object/value_holder_fwd.hpp | 17 - include/boost/python/object_attributes.hpp | 67 - include/boost/python/object_call.hpp | 22 - include/boost/python/object_core.hpp | 386 ----- include/boost/python/object_fwd.hpp | 17 - include/boost/python/object_items.hpp | 88 -- include/boost/python/object_operators.hpp | 94 -- include/boost/python/object_protocol.hpp | 80 - include/boost/python/object_protocol_core.hpp | 52 - include/boost/python/object_slices.hpp | 125 -- include/boost/python/objects.hpp | 396 ----- include/boost/python/operators.hpp | 555 ------- include/boost/python/operators2.hpp | 340 ----- include/boost/python/other.hpp | 113 -- include/boost/python/pointee.hpp | 40 - include/boost/python/proxy.hpp | 101 -- include/boost/python/ptr.hpp | 127 -- include/boost/python/py_interface.hpp | 700 --------- include/boost/python/refcount.hpp | 42 - include/boost/python/reference.hpp | 236 --- .../python/reference_existing_object.hpp | 45 - .../python/return_internal_reference.hpp | 42 - include/boost/python/return_value_policy.hpp | 20 - include/boost/python/scope.hpp | 64 - include/boost/python/self.hpp | 36 - include/boost/python/signature.hpp | 127 -- include/boost/python/slice_nil.hpp | 41 - include/boost/python/str.hpp | 375 ----- include/boost/python/tag.hpp | 17 - include/boost/python/to_python_converter.hpp | 39 - include/boost/python/to_python_indirect.hpp | 118 -- include/boost/python/to_python_value.hpp | 96 -- include/boost/python/tuple.hpp | 53 - include/boost/python/type_from_python.hpp | 103 -- include/boost/python/type_id.hpp | 134 -- .../boost/python/with_custodian_and_ward.hpp | 78 - test/Jamfile | 151 -- test/back_reference.cpp | 111 -- test/back_reference.py | 30 - test/bases.cpp | 63 - test/bienstman1.cpp | 37 - test/bienstman1.py | 18 - test/bienstman2.cpp | 25 - test/bienstman2.py | 15 - test/bienstman3.cpp | 22 - test/bienstman3.py | 25 - test/bienstman4.cpp | 40 - test/bienstman4.py | 18 - test/bienstman5.cpp | 24 - test/bienstman5.py | 16 - test/borrowed.cpp | 34 - test/callbacks.cpp | 149 -- test/callbacks.py | 133 -- test/cltree.cpp | 70 - test/complicated.hpp | 39 - test/comprehensive.cpp | 1265 ---------------- test/comprehensive.hpp | 235 --- test/comprehensive.py | 1281 ----------------- test/data_members.cpp | 39 - test/data_members.py | 32 - test/defaults.cpp | 179 --- test/defaults.py | 172 --- test/destroy_test.cpp | 81 -- test/dict.cpp | 81 -- test/dict.py | 40 - test/docstring.cpp | 60 - test/docstring.py | 54 - test/doctest.py | 1173 --------------- test/enum.cpp | 27 - test/enum.py | 42 - test/exception_translator.cpp | 25 - test/exception_translator.py | 22 - test/extract.cpp | 140 -- test/extract.py | 102 -- test/if_else.cpp | 45 - test/implicit.cpp | 38 - test/implicit.py | 26 - test/indirect_traits_test.cpp | 80 - test/input_iterator.cpp | 49 - test/iterator.cpp | 124 -- test/iterator.py | 72 - test/list.cpp | 145 -- test/list.py | 113 -- test/long.cpp | 51 - test/long.py | 26 - test/m1.cpp | 268 ---- test/m2.cpp | 99 -- test/member_function_cast.cpp | 55 - test/minimal.cpp | 17 - test/minimal.py | 2 - test/module_tail.cpp | 42 - test/multi_arg_constructor.cpp | 25 - test/multi_arg_constructor.py | 16 - test/nested.cpp | 51 - test/nested.py | 35 - test/newtest.py | 184 --- test/object.cpp | 318 ---- test/object.py | 126 -- test/object_fail1.cpp | 12 - test/object_manager.cpp | 34 - test/operators.cpp | 87 -- test/operators.py | 86 -- test/pickle1.cpp | 55 - test/pickle1.py | 31 - test/pickle2.cpp | 99 -- test/pickle2.py | 45 - test/pickle3.cpp | 107 -- test/pickle3.py | 40 - test/pointee.cpp | 35 - test/pointer_type_id_test.cpp | 39 - test/raw_pyobject_fail1.cpp | 12 - test/raw_pyobject_fail2.cpp | 14 - test/result.cpp | 112 -- test/select_arg_to_python_test.cpp | 65 - test/select_from_python_test.cpp | 157 -- test/select_holder.cpp | 79 - test/simple_type.hpp | 14 - test/str.cpp | 67 - test/str.py | 52 - test/string_literal.cpp | 38 - test/submod_subclass_api.cpp | 231 --- test/test_builtin_converters.cpp | 126 -- test/test_builtin_converters.py | 236 --- test/test_class.hpp | 33 - test/test_cltree.py | 40 - test/test_pointer_adoption.cpp | 126 -- test/test_pointer_adoption.py | 90 -- test/tuple.cpp | 29 - test/tuple.py | 32 - test/upcast.cpp | 19 - test/virtual_functions.cpp | 113 -- test/virtual_functions.py | 102 -- 297 files changed, 34442 deletions(-) delete mode 100755 include/boost/python/arg_from_python.hpp delete mode 100644 include/boost/python/args.hpp delete mode 100644 include/boost/python/back_reference.hpp delete mode 100755 include/boost/python/base_type_traits.hpp delete mode 100644 include/boost/python/bases.hpp delete mode 100755 include/boost/python/borrowed.hpp delete mode 100644 include/boost/python/call.hpp delete mode 100644 include/boost/python/call_method.hpp delete mode 100644 include/boost/python/callback.hpp delete mode 100644 include/boost/python/caller.hpp delete mode 100755 include/boost/python/cast.hpp delete mode 100644 include/boost/python/class.hpp delete mode 100644 include/boost/python/class_builder.hpp delete mode 100644 include/boost/python/class_fwd.hpp delete mode 100644 include/boost/python/classes.hpp delete mode 100644 include/boost/python/conversions.hpp delete mode 100755 include/boost/python/converter/arg_from_python.hpp delete mode 100755 include/boost/python/converter/arg_to_python.hpp delete mode 100755 include/boost/python/converter/arg_to_python_base.hpp delete mode 100644 include/boost/python/converter/builtin_converters.hpp delete mode 100644 include/boost/python/converter/callback.hpp delete mode 100644 include/boost/python/converter/callback_from_python_base.hpp delete mode 100644 include/boost/python/converter/callback_to_python_base.hpp delete mode 100644 include/boost/python/converter/constructor_function.hpp delete mode 100644 include/boost/python/converter/convertible_function.hpp delete mode 100644 include/boost/python/converter/find_from_python.hpp delete mode 100644 include/boost/python/converter/from_python.hpp delete mode 100644 include/boost/python/converter/from_python_data.hpp delete mode 100644 include/boost/python/converter/from_python_function.hpp delete mode 100644 include/boost/python/converter/from_python_stage1_data.hpp delete mode 100644 include/boost/python/converter/implicit.hpp delete mode 100644 include/boost/python/converter/lvalue_from_python_chain.hpp delete mode 100644 include/boost/python/converter/obj_mgr_arg_from_python.hpp delete mode 100755 include/boost/python/converter/object_manager.hpp delete mode 100644 include/boost/python/converter/pointee_to_python_function.hpp delete mode 100644 include/boost/python/converter/pointer_type_id.hpp delete mode 100644 include/boost/python/converter/pyobject_traits.hpp delete mode 100644 include/boost/python/converter/pyobject_type.hpp delete mode 100644 include/boost/python/converter/pytype_arg_from_python.hpp delete mode 100644 include/boost/python/converter/pytype_object_mgr_traits.hpp delete mode 100644 include/boost/python/converter/registered.hpp delete mode 100644 include/boost/python/converter/registered_pointee.hpp delete mode 100644 include/boost/python/converter/registrations.hpp delete mode 100644 include/boost/python/converter/registry.hpp delete mode 100755 include/boost/python/converter/return_from_python.hpp delete mode 100644 include/boost/python/converter/rvalue_from_python_chain.hpp delete mode 100644 include/boost/python/converter/rvalue_from_python_data.hpp delete mode 100644 include/boost/python/converter/smart_ptr.hpp delete mode 100644 include/boost/python/converter/to_python_function.hpp delete mode 100644 include/boost/python/converter/to_python_function_type.hpp delete mode 100644 include/boost/python/converter/type_id.hpp delete mode 100644 include/boost/python/copy_const_reference.hpp delete mode 100644 include/boost/python/copy_mutable_reference.hpp delete mode 100644 include/boost/python/copy_non_const_reference.hpp delete mode 100644 include/boost/python/cross_module.hpp delete mode 100644 include/boost/python/data_members.hpp delete mode 100644 include/boost/python/def.hpp delete mode 100644 include/boost/python/default_call_policies.hpp delete mode 100644 include/boost/python/detail/aix_init_module.hpp delete mode 100644 include/boost/python/detail/api_placeholder.hpp delete mode 100644 include/boost/python/detail/arg_tuple_size.hpp delete mode 100644 include/boost/python/detail/base_object.hpp delete mode 100755 include/boost/python/detail/borrowed_ptr.hpp delete mode 100644 include/boost/python/detail/call_object.hpp delete mode 100644 include/boost/python/detail/caller.hpp delete mode 100644 include/boost/python/detail/cast.hpp delete mode 100644 include/boost/python/detail/char_array.hpp delete mode 100644 include/boost/python/detail/config.hpp delete mode 100644 include/boost/python/detail/construct.hpp delete mode 100755 include/boost/python/detail/convertible.hpp delete mode 100644 include/boost/python/detail/cv_category.hpp delete mode 100755 include/boost/python/detail/decorated_type_id.hpp delete mode 100644 include/boost/python/detail/def_helper.hpp delete mode 100644 include/boost/python/detail/defaults_def.hpp delete mode 100644 include/boost/python/detail/dependent.hpp delete mode 100644 include/boost/python/detail/destroy.hpp delete mode 100644 include/boost/python/detail/exception_handler.hpp delete mode 100644 include/boost/python/detail/extension_class.hpp delete mode 100755 include/boost/python/detail/force_instantiate.hpp delete mode 100644 include/boost/python/detail/functions.hpp delete mode 100644 include/boost/python/detail/if_else.hpp delete mode 100644 include/boost/python/detail/indirect_traits.hpp delete mode 100644 include/boost/python/detail/init_function.hpp delete mode 100644 include/boost/python/detail/make_tuple.hpp delete mode 100644 include/boost/python/detail/map_entry.hpp delete mode 100644 include/boost/python/detail/member_function_cast.hpp delete mode 100644 include/boost/python/detail/module_base.hpp delete mode 100644 include/boost/python/detail/module_info.hpp delete mode 100644 include/boost/python/detail/module_init.hpp delete mode 100644 include/boost/python/detail/msvc_typeinfo.hpp delete mode 100644 include/boost/python/detail/none.hpp delete mode 100644 include/boost/python/detail/not_specified.hpp delete mode 100755 include/boost/python/detail/operator_id.hpp delete mode 100644 include/boost/python/detail/pointee.hpp delete mode 100644 include/boost/python/detail/preprocessor.hpp delete mode 100644 include/boost/python/detail/python22_fixed.h delete mode 100644 include/boost/python/detail/python_library_include.hpp delete mode 100644 include/boost/python/detail/raw_pyobject.hpp delete mode 100644 include/boost/python/detail/referent_storage.hpp delete mode 100755 include/boost/python/detail/result.hpp delete mode 100644 include/boost/python/detail/returning.hpp delete mode 100644 include/boost/python/detail/signatures.hpp delete mode 100644 include/boost/python/detail/singleton.hpp delete mode 100644 include/boost/python/detail/string_literal.hpp delete mode 100644 include/boost/python/detail/target.hpp delete mode 100644 include/boost/python/detail/translate_exception.hpp delete mode 100644 include/boost/python/detail/type_list.hpp delete mode 100644 include/boost/python/detail/type_list_impl.hpp delete mode 100644 include/boost/python/detail/type_list_impl_no_pts.hpp delete mode 100644 include/boost/python/detail/type_list_utils.hpp delete mode 100644 include/boost/python/detail/types.hpp delete mode 100644 include/boost/python/detail/unwind_type.hpp delete mode 100644 include/boost/python/detail/void_adaptor.hpp delete mode 100644 include/boost/python/detail/void_ptr.hpp delete mode 100644 include/boost/python/detail/void_return.hpp delete mode 100644 include/boost/python/detail/wrap_function.hpp delete mode 100644 include/boost/python/detail/wrap_python.hpp delete mode 100644 include/boost/python/dict.hpp delete mode 100644 include/boost/python/enum.hpp delete mode 100644 include/boost/python/errors.hpp delete mode 100644 include/boost/python/exception_translator.hpp delete mode 100644 include/boost/python/extract.hpp delete mode 100644 include/boost/python/from_python.hpp delete mode 100755 include/boost/python/handle.hpp delete mode 100755 include/boost/python/handle_fwd.hpp delete mode 100644 include/boost/python/has_back_reference.hpp delete mode 100644 include/boost/python/implicit.hpp delete mode 100644 include/boost/python/init.hpp delete mode 100755 include/boost/python/instance_holder.hpp delete mode 100644 include/boost/python/iterator.hpp delete mode 100644 include/boost/python/list.hpp delete mode 100644 include/boost/python/long.hpp delete mode 100755 include/boost/python/lvalue_from_pytype.hpp delete mode 100644 include/boost/python/make_function.hpp delete mode 100644 include/boost/python/manage_new_object.hpp delete mode 100644 include/boost/python/module.hpp delete mode 100644 include/boost/python/module_builder.hpp delete mode 100644 include/boost/python/module_init.hpp delete mode 100755 include/boost/python/object.hpp delete mode 100644 include/boost/python/object/add_to_namespace.hpp delete mode 100644 include/boost/python/object/auto_ptr_generator.hpp delete mode 100644 include/boost/python/object/class.hpp delete mode 100644 include/boost/python/object/class_converters.hpp delete mode 100644 include/boost/python/object/class_detail.hpp delete mode 100644 include/boost/python/object/class_object.hpp delete mode 100644 include/boost/python/object/class_wrapper.hpp delete mode 100644 include/boost/python/object/construct.hpp delete mode 100644 include/boost/python/object/enum_base.hpp delete mode 100644 include/boost/python/object/find_instance.hpp delete mode 100644 include/boost/python/object/forward.hpp delete mode 100644 include/boost/python/object/function.hpp delete mode 100644 include/boost/python/object/function_handle.hpp delete mode 100644 include/boost/python/object/function_object.hpp delete mode 100644 include/boost/python/object/inheritance.hpp delete mode 100644 include/boost/python/object/instance.hpp delete mode 100644 include/boost/python/object/iterator.hpp delete mode 100644 include/boost/python/object/iterator_core.hpp delete mode 100644 include/boost/python/object/life_support.hpp delete mode 100644 include/boost/python/object/make_holder.hpp delete mode 100644 include/boost/python/object/make_instance.hpp delete mode 100644 include/boost/python/object/pickle_support.hpp delete mode 100644 include/boost/python/object/pointer_holder.hpp delete mode 100644 include/boost/python/object/py_function.hpp delete mode 100644 include/boost/python/object/select_holder.hpp delete mode 100644 include/boost/python/object/value_holder.hpp delete mode 100644 include/boost/python/object/value_holder_fwd.hpp delete mode 100755 include/boost/python/object_attributes.hpp delete mode 100644 include/boost/python/object_call.hpp delete mode 100755 include/boost/python/object_core.hpp delete mode 100644 include/boost/python/object_fwd.hpp delete mode 100755 include/boost/python/object_items.hpp delete mode 100644 include/boost/python/object_operators.hpp delete mode 100755 include/boost/python/object_protocol.hpp delete mode 100755 include/boost/python/object_protocol_core.hpp delete mode 100644 include/boost/python/object_slices.hpp delete mode 100644 include/boost/python/objects.hpp delete mode 100644 include/boost/python/operators.hpp delete mode 100755 include/boost/python/operators2.hpp delete mode 100755 include/boost/python/other.hpp delete mode 100644 include/boost/python/pointee.hpp delete mode 100755 include/boost/python/proxy.hpp delete mode 100644 include/boost/python/ptr.hpp delete mode 100644 include/boost/python/py_interface.hpp delete mode 100755 include/boost/python/refcount.hpp delete mode 100644 include/boost/python/reference.hpp delete mode 100644 include/boost/python/reference_existing_object.hpp delete mode 100644 include/boost/python/return_internal_reference.hpp delete mode 100644 include/boost/python/return_value_policy.hpp delete mode 100644 include/boost/python/scope.hpp delete mode 100755 include/boost/python/self.hpp delete mode 100644 include/boost/python/signature.hpp delete mode 100644 include/boost/python/slice_nil.hpp delete mode 100644 include/boost/python/str.hpp delete mode 100644 include/boost/python/tag.hpp delete mode 100644 include/boost/python/to_python_converter.hpp delete mode 100644 include/boost/python/to_python_indirect.hpp delete mode 100644 include/boost/python/to_python_value.hpp delete mode 100644 include/boost/python/tuple.hpp delete mode 100644 include/boost/python/type_from_python.hpp delete mode 100755 include/boost/python/type_id.hpp delete mode 100644 include/boost/python/with_custodian_and_ward.hpp delete mode 100644 test/Jamfile delete mode 100644 test/back_reference.cpp delete mode 100644 test/back_reference.py delete mode 100644 test/bases.cpp delete mode 100644 test/bienstman1.cpp delete mode 100644 test/bienstman1.py delete mode 100644 test/bienstman2.cpp delete mode 100644 test/bienstman2.py delete mode 100644 test/bienstman3.cpp delete mode 100644 test/bienstman3.py delete mode 100644 test/bienstman4.cpp delete mode 100644 test/bienstman4.py delete mode 100644 test/bienstman5.cpp delete mode 100644 test/bienstman5.py delete mode 100755 test/borrowed.cpp delete mode 100644 test/callbacks.cpp delete mode 100644 test/callbacks.py delete mode 100755 test/cltree.cpp delete mode 100644 test/complicated.hpp delete mode 100644 test/comprehensive.cpp delete mode 100644 test/comprehensive.hpp delete mode 100644 test/comprehensive.py delete mode 100644 test/data_members.cpp delete mode 100644 test/data_members.py delete mode 100644 test/defaults.cpp delete mode 100644 test/defaults.py delete mode 100644 test/destroy_test.cpp delete mode 100644 test/dict.cpp delete mode 100644 test/dict.py delete mode 100644 test/docstring.cpp delete mode 100644 test/docstring.py delete mode 100644 test/doctest.py delete mode 100644 test/enum.cpp delete mode 100644 test/enum.py delete mode 100644 test/exception_translator.cpp delete mode 100644 test/exception_translator.py delete mode 100644 test/extract.cpp delete mode 100644 test/extract.py delete mode 100644 test/if_else.cpp delete mode 100644 test/implicit.cpp delete mode 100644 test/implicit.py delete mode 100644 test/indirect_traits_test.cpp delete mode 100644 test/input_iterator.cpp delete mode 100644 test/iterator.cpp delete mode 100644 test/iterator.py delete mode 100644 test/list.cpp delete mode 100644 test/list.py delete mode 100644 test/long.cpp delete mode 100644 test/long.py delete mode 100644 test/m1.cpp delete mode 100644 test/m2.cpp delete mode 100644 test/member_function_cast.cpp delete mode 100644 test/minimal.cpp delete mode 100644 test/minimal.py delete mode 100644 test/module_tail.cpp delete mode 100644 test/multi_arg_constructor.cpp delete mode 100644 test/multi_arg_constructor.py delete mode 100644 test/nested.cpp delete mode 100644 test/nested.py delete mode 100644 test/newtest.py delete mode 100755 test/object.cpp delete mode 100644 test/object.py delete mode 100755 test/object_fail1.cpp delete mode 100755 test/object_manager.cpp delete mode 100755 test/operators.cpp delete mode 100644 test/operators.py delete mode 100644 test/pickle1.cpp delete mode 100644 test/pickle1.py delete mode 100644 test/pickle2.cpp delete mode 100644 test/pickle2.py delete mode 100644 test/pickle3.cpp delete mode 100644 test/pickle3.py delete mode 100644 test/pointee.cpp delete mode 100644 test/pointer_type_id_test.cpp delete mode 100755 test/raw_pyobject_fail1.cpp delete mode 100755 test/raw_pyobject_fail2.cpp delete mode 100755 test/result.cpp delete mode 100644 test/select_arg_to_python_test.cpp delete mode 100644 test/select_from_python_test.cpp delete mode 100644 test/select_holder.cpp delete mode 100644 test/simple_type.hpp delete mode 100644 test/str.cpp delete mode 100644 test/str.py delete mode 100644 test/string_literal.cpp delete mode 100644 test/submod_subclass_api.cpp delete mode 100644 test/test_builtin_converters.cpp delete mode 100644 test/test_builtin_converters.py delete mode 100644 test/test_class.hpp delete mode 100644 test/test_cltree.py delete mode 100644 test/test_pointer_adoption.cpp delete mode 100644 test/test_pointer_adoption.py delete mode 100644 test/tuple.cpp delete mode 100644 test/tuple.py delete mode 100755 test/upcast.cpp delete mode 100644 test/virtual_functions.cpp delete mode 100644 test/virtual_functions.py diff --git a/include/boost/python/arg_from_python.hpp b/include/boost/python/arg_from_python.hpp deleted file mode 100755 index 1d033acd..00000000 --- a/include/boost/python/arg_from_python.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ARG_FROM_PYTHON_DWA2002128_HPP -# define ARG_FROM_PYTHON_DWA2002128_HPP - -# include - -namespace boost { namespace python { - -template -struct arg_from_python - : converter::select_arg_from_python::type -{ - typedef typename converter::select_arg_from_python::type base; - arg_from_python(PyObject*); -}; - -// specialization for PyObject* -template <> -struct arg_from_python -{ - typedef PyObject* result_type; - - arg_from_python(PyObject*) {} - bool convertible() const { return true; } - PyObject* operator()(PyObject* source) const { return source; } -}; - -template <> -struct arg_from_python -{ - typedef PyObject* const& result_type; - arg_from_python(PyObject*) {} - bool convertible() const { return true; } - PyObject*const& operator()(PyObject*const& source) const { return source; } -}; - -// -// implementations -// -template -inline arg_from_python::arg_from_python(PyObject* source) - : base(source) -{ -} - -}} // namespace boost::python - -#endif // ARG_FROM_PYTHON_DWA2002128_HPP diff --git a/include/boost/python/args.hpp b/include/boost/python/args.hpp deleted file mode 100644 index 941529f0..00000000 --- a/include/boost/python/args.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ARGS_DWA2002323_HPP -# define ARGS_DWA2002323_HPP -# include -# include -# include - -namespace boost { namespace python { - -enum no_init_t { no_init }; - -namespace detail -{ - template - struct args_base {}; -} -}} - -namespace boost { namespace python { - -// A type list for specifying arguments -template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, mpl::void_) > -struct args : detail::args_base > - , detail::type_list< BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A) >::type -{}; - -}} // namespace boost::python - - -# endif // ARGS_DWA2002323_HPP diff --git a/include/boost/python/back_reference.hpp b/include/boost/python/back_reference.hpp deleted file mode 100644 index 75a14525..00000000 --- a/include/boost/python/back_reference.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef BACK_REFERENCE_DWA2002510_HPP -# define BACK_REFERENCE_DWA2002510_HPP - -# include -# include -# include - -namespace boost { namespace python { - -template -struct back_reference -{ - private: // types - typedef typename detail::dependent::type source_t; - public: - typedef T type; - - back_reference(PyObject*, T); - source_t const& source() const; - T get() const; - private: - source_t m_source; - T m_value; -}; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -class is_back_reference -{ - public: - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -class is_back_reference > -{ - public: - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -# else // no partial specialization - -}} // namespace boost::python - -#include - -namespace boost { namespace python { - -namespace detail -{ - typedef char (&yes_back_reference_t)[1]; - typedef char (&no_back_reference_t)[2]; - - no_back_reference_t is_back_reference_test(...); - - template - yes_back_reference_t is_back_reference_test(boost::type< back_reference >); -} - -template -class is_back_reference -{ - public: - BOOST_STATIC_CONSTANT( - bool, value = ( - sizeof(detail::is_back_reference_test(boost::type())) - == sizeof(detail::yes_back_reference_t))); -}; - -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -// -// implementations -// -template -back_reference::back_reference(PyObject* p, T x) - : m_source(detail::borrowed_reference(p)) - , m_value(x) -{ -} - -template -typename back_reference::source_t const& back_reference::source() const -{ - return m_source; -} - -template -T back_reference::get() const -{ - return m_value; -} - -}} // namespace boost::python - -#endif // BACK_REFERENCE_DWA2002510_HPP diff --git a/include/boost/python/base_type_traits.hpp b/include/boost/python/base_type_traits.hpp deleted file mode 100755 index cae9ebc2..00000000 --- a/include/boost/python/base_type_traits.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef BASE_TYPE_TRAITS_DWA2002614_HPP -# define BASE_TYPE_TRAITS_DWA2002614_HPP - -namespace boost { namespace python { - -namespace detail -{ - struct unspecialized {}; -} - -// Derive from unspecialized so we can detect whether traits are -// specialized -template struct base_type_traits - : detail::unspecialized -{}; - -template <> -struct base_type_traits -{ - typedef PyObject type; -}; - -template <> -struct base_type_traits -{ - typedef PyObject type; -}; - -}} // namespace boost::python - -#endif // BASE_TYPE_TRAITS_DWA2002614_HPP diff --git a/include/boost/python/bases.hpp b/include/boost/python/bases.hpp deleted file mode 100644 index ec03dfba..00000000 --- a/include/boost/python/bases.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef BASES_DWA2002321_HPP -# define BASES_DWA2002321_HPP -# include -# include -# include -# include -# include - -namespace boost { namespace python { - - // A type list for specifying bases - template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PYTHON_MAX_BASES, typename B, mpl::void_) > - struct bases : detail::type_list< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, B) >::type - {}; - - namespace detail - { -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template struct specifies_bases - { - BOOST_STATIC_CONSTANT(bool, value = false); - }; - template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class B) > - struct specifies_bases< bases< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, B) > > - { - BOOST_STATIC_CONSTANT(bool, value = true); - }; -# else - template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class B) > - static char is_bases_helper(bases< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, B) > const&); - - static char (& is_bases_helper(...) )[256]; - - template struct specifies_bases - { - private: - static typename add_reference::type make(); - BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference::value); - public: - BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1)); - }; -# endif - template > - struct select_bases - : mpl::if_c< - specifies_bases::value - , T - , Prev - > - { - }; - } -}} // namespace boost::python - -#endif // BASES_DWA2002321_HPP diff --git a/include/boost/python/borrowed.hpp b/include/boost/python/borrowed.hpp deleted file mode 100755 index 10b1b5d1..00000000 --- a/include/boost/python/borrowed.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef BORROWED_DWA2002614_HPP -# define BORROWED_DWA2002614_HPP -# include - -namespace boost { namespace python { - -template -inline python::detail::borrowed* borrowed(T* p) -{ - return (detail::borrowed*)p; -} - -}} // namespace boost::python - -#endif // BORROWED_DWA2002614_HPP diff --git a/include/boost/python/call.hpp b/include/boost/python/call.hpp deleted file mode 100644 index 4edceee3..00000000 --- a/include/boost/python/call.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# ifndef CALL_DWA2002411_HPP -# define CALL_DWA2002411_HPP - -# include - -# include -# include -# include -# include - -# include -# include -# include -# include - -namespace boost { namespace python { - -# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \ - , converter::arg_to_python(a##n).get() - -# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET - -}} // namespace boost::python - -# endif // CALL_DWA2002411_HPP - -#elif BOOST_PP_ITERATION_DEPTH() == 1 -# line BOOST_PP_LINE(__LINE__, call.hpp) - -# define N BOOST_PP_ITERATION() - -template < - class R - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A) - > -typename detail::returnable::type -call(PyObject* callable - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, const& a) - , boost::type* = 0 - ) -{ - converter::return_from_python converter; - return converter( - PyEval_CallFunction( - callable - , const_cast("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")") - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil) - )); -} - -# undef N - -#endif diff --git a/include/boost/python/call_method.hpp b/include/boost/python/call_method.hpp deleted file mode 100644 index e8917c22..00000000 --- a/include/boost/python/call_method.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -# ifndef CALL_METHOD_DWA2002411_HPP -# define CALL_METHOD_DWA2002411_HPP - -# include - -# include -# include -# include -# include - -# include -# include -# include -# include - -namespace boost { namespace python { - -# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \ - , converter::arg_to_python(a##n).get() - -# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET - -}} // namespace boost::python - -# endif // CALL_METHOD_DWA2002411_HPP - -#elif BOOST_PP_ITERATION_DEPTH() == 1 -# line BOOST_PP_LINE(__LINE__, call_method.hpp) - -# define N BOOST_PP_ITERATION() - -template < - class R - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A) - > -typename detail::returnable::type -call_method(PyObject* self, char const* name - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, const& a) - , boost::type* = 0 - ) -{ - converter::return_from_python converter; - return converter( - PyEval_CallMethod( - self - , const_cast(name) - , const_cast("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")") - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil) - )); -} - -# undef N - -#endif // BOOST_PP_IS_ITERATING diff --git a/include/boost/python/callback.hpp b/include/boost/python/callback.hpp deleted file mode 100644 index 7240b5b7..00000000 --- a/include/boost/python/callback.hpp +++ /dev/null @@ -1,829 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file was generated for 10-argument python callbacks by gen_callback.python - -#ifndef CALLBACK_DWA_052100_H_ -# define CALLBACK_DWA_052100_H_ - -# include -# include - -namespace boost { namespace python { - -namespace detail { - template - inline void callback_adjust_refcount(PyObject*, type) {} - - inline void callback_adjust_refcount(PyObject* p, type) - { Py_INCREF(p); } -} - -// Calling Python from C++ -template -struct callback -{ - static R call_method(PyObject* self, const char* name) - { - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("()"))); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - static R call(PyObject* self) - { - ref result(PyEval_CallFunction(self, const_cast("()"))); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(O)"), - p1.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallFunction(self, const_cast("(O)"), - p1.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OO)"), - p1.get(), - p2.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallFunction(self, const_cast("(OO)"), - p1.get(), - p2.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallFunction(self, const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallFunction(self, const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } - - template - static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - detail::callback_adjust_refcount(result.get(), type()); - return from_python(result.get(), type()); - } -}; - -// This specialization wouldn't be needed, but MSVC6 doesn't correctly allow the following: -// void g(); -// void f() { return g(); } -template <> -struct callback -{ - - static void call_method(PyObject* self, const char* name) - { - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("()"))); - } - - static void call(PyObject* self) - { - ref result(PyEval_CallFunction(self, const_cast("()"))); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(O)"), - p1.get())); - } - - template - static void call(PyObject* self, const A1& a1) - { - ref p1(to_python(a1)); - ref result(PyEval_CallFunction(self, const_cast("(O)"), - p1.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OO)"), - p1.get(), - p2.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref result(PyEval_CallFunction(self, const_cast("(OO)"), - p1.get(), - p2.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref result(PyEval_CallFunction(self, const_cast("(OOO)"), - p1.get(), - p2.get(), - p3.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref result(PyEval_CallFunction(self, const_cast("(OOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get())); - } - - template - static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallMethod(self, const_cast(name), - const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - } - - template - static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) - { - ref p1(to_python(a1)); - ref p2(to_python(a2)); - ref p3(to_python(a3)); - ref p4(to_python(a4)); - ref p5(to_python(a5)); - ref p6(to_python(a6)); - ref p7(to_python(a7)); - ref p8(to_python(a8)); - ref p9(to_python(a9)); - ref p10(to_python(a10)); - ref result(PyEval_CallFunction(self, const_cast("(OOOOOOOOOO)"), - p1.get(), - p2.get(), - p3.get(), - p4.get(), - p5.get(), - p6.get(), - p7.get(), - p8.get(), - p9.get(), - p10.get())); - } -}; - -// Make it a compile-time error to try to return a const char* from a virtual -// function. The standard conversion -// -// from_python(PyObject* string, boost::python::type) -// -// returns a pointer to the character array which is internal to string. The -// problem with trying to do this in a standard callback function is that the -// Python string would likely be destroyed upon return from the calling function -// (boost::python::callback::call[_method]) when its reference count is -// decremented. If you absolutely need to do this and you're sure it's safe (it -// usually isn't), you can use -// -// boost::python::string result(boost::python::callback::call[_method](...args...)); -// ...result.c_str()... // access the char* array -template <> -struct callback -{ - // Try hard to generate a readable error message - typedef struct unsafe_since_python_string_may_be_destroyed {} call, call_method; -}; - -}} // namespace boost::python - -#endif // CALLBACK_DWA_052100_H_ diff --git a/include/boost/python/caller.hpp b/include/boost/python/caller.hpp deleted file mode 100644 index 35b2d618..00000000 --- a/include/boost/python/caller.hpp +++ /dev/null @@ -1,1279 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file generated for 10-argument member functions and 11-argument free -// functions by gen_caller.python - -#ifndef CALLER_DWA05090_H_ -# define CALLER_DWA05090_H_ - -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -// Calling C++ from Python -template -struct caller -{ - template - static PyObject* call(R (T::*pmf)(), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)()); - } - - template - static PyObject* call(R (T::*pmf)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()))); - } - - - template - static PyObject* call(R (T::*pmf)() const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)()); - } - - template - static PyObject* call(R (T::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()))); - } - - template - static PyObject* call(R (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - return to_python((target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()))); - } - - // Free functions - static PyObject* call(R (*f)(), PyObject* args, PyObject* /* keywords */ ) { - if (!PyArg_ParseTuple(args, const_cast(""))) - return 0; - return to_python(f()); - } - - template - static PyObject* call(R (*f)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) - return 0; - return to_python(f(from_python(a1, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()))); - } - - template - static PyObject* call(R (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - PyObject* a11; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11)) - return 0; - return to_python(f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()), - from_python(a11, type()))); - } - -}; - -template <> -struct caller -{ - template - static PyObject* call(void (T::*pmf)(), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type())); - return detail::none(); - } - - - template - static PyObject* call(void (T::*pmf)() const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &a1)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &self, &a1, &a2)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &self, &a1, &a2, &a3)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &self, &a1, &a2, &a3, &a4)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &self, &a1, &a2, &a3, &a4, &a5)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type())); - return detail::none(); - } - - template - static PyObject* call(void (T::*pmf)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const, PyObject* args, PyObject* /* keywords */ ) { - PyObject* self; - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &self, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - T& target = from_python(self, type()); - (target.*pmf)(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type())); - return detail::none(); - } - - - // Free functions - static PyObject* call(void (*f)(), PyObject* args, PyObject* /* keywords */ ) { - if (!PyArg_ParseTuple(args, const_cast(""))) - return 0; - f(); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) - return 0; - f(from_python(a1, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) - return 0; - f(from_python(a1, type()), - from_python(a2, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type())); - return detail::none(); - } - - template - static PyObject* call(void (*f)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11), PyObject* args, PyObject* /* keywords */ ) { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - PyObject* a11; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11)) - return 0; - f(from_python(a1, type()), - from_python(a2, type()), - from_python(a3, type()), - from_python(a4, type()), - from_python(a5, type()), - from_python(a6, type()), - from_python(a7, type()), - from_python(a8, type()), - from_python(a9, type()), - from_python(a10, type()), - from_python(a11, type())); - return detail::none(); - } - -}; - -}} // namespace boost::python - -#endif diff --git a/include/boost/python/cast.hpp b/include/boost/python/cast.hpp deleted file mode 100755 index d20cbd3a..00000000 --- a/include/boost/python/cast.hpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CAST_DWA200269_HPP -# define CAST_DWA200269_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template inline Target* upcast_impl(Source*, Target*); - - template - inline Target* upcast(Source* p, yes_convertible, no_convertible, Target*) - { - return p; - } - - template - inline Target* upcast(Source* p, no_convertible, no_convertible, Target*) - { - typedef typename base_type_traits::type base; - - return detail::upcast_impl((base*)p, (Target*)0); - } - - template - struct upcaster - { - template - static inline T* execute(T* x, T*) { return x; } - }; - - template <> - struct upcaster - { - template - static inline Target* execute(Source* x, Target*) - { - return detail::upcast( - x, detail::convertible::check(x) - , detail::convertible::check((Target*)0) - , (Target*)0); - } - }; - - - template - inline Target* downcast(Source* p, yes_convertible) - { - return static_cast(p); - } - - template - inline Target* downcast(Source* p, no_convertible, boost::type* = 0) - { - typedef typename base_type_traits::type base; - return (Target*)detail::downcast(p, convertible::check((base*)0)); - } - - template - inline void assert_castable(boost::type* = 0) - { - typedef char must_be_a_complete_type[sizeof(T)]; - } - - template - inline Target* upcast_impl(Source* x, Target*) - { - typedef typename add_cv::type src_t; - typedef typename add_cv::type target_t; - static bool const same = is_same::value; - - return detail::upcaster::execute(x, (Target*)0); - } -} - -template -inline Target* upcast(Source* x, Target* = 0) -{ - detail::assert_castable(); - detail::assert_castable(); - return detail::upcast_impl(x, (Target*)0); - -} - -template -inline Target* downcast(Source* x, Target* = 0) -{ - detail::assert_castable(); - detail::assert_castable(); - return detail::downcast(x, detail::convertible::check((Target*)0)); -} - -}} // namespace boost::python - -#endif // CAST_DWA200269_HPP diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp deleted file mode 100644 index de66ddcf..00000000 --- a/include/boost/python/class.hpp +++ /dev/null @@ -1,436 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CLASS_DWA200216_HPP -# define CLASS_DWA200216_HPP - -# include -# include -# include -# include - -# include - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - // This function object is used with mpl::for_each to write the id - // of the type a pointer to which is passed as its 2nd compile-time - // argument. into the iterator pointed to by its runtime argument - struct write_type_id - { - write_type_id(type_info**p) : p(p) {} - - // Here's the runtime behavior - template - void operator()(T*) const - { - *(*p)++ = type_id(); - } - - type_info** p; - }; - - template - struct select_held_type; - - template - struct has_noncopyable; - - template - struct operator_; - - // Register a to_python converter for a class T, depending on the - // type of the first (tag) argument. The 2nd argument is a pointer - // to the type of holder that must be created. The 3rd argument is a - // reference to the Python type object to be created. - template - static inline void register_copy_constructor(mpl::bool_c const&, SelectHolder const& , T* = 0) - { - typedef typename SelectHolder::type holder; - force_instantiate(objects::class_wrapper >()); - SelectHolder::register_(); - } - - // Tag dispatched to have no effect. - template - static inline void register_copy_constructor(mpl::bool_c const&, SelectHolder const&, T* = 0) - { - SelectHolder::register_(); - } - - template int assert_default_constructible(T const&); -} - -// -// class_ -// -// This is the primary mechanism through which users will expose -// C++ classes to Python. The three template arguments are: -// -template < - class T // class being wrapped - , class X1 // = detail::not_specified - , class X2 // = detail::not_specified - , class X3 // = detail::not_specified - > -class class_ : public objects::class_base -{ - private: // types - typedef objects::class_base base; - - typedef class_ self; - BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable::value)); - - typedef typename detail::select_held_type< - X1, typename detail::select_held_type< - X2, typename detail::select_held_type< - X3 - >::type>::type>::type held_type; - - typedef objects::select_holder holder_selector; - - typedef typename detail::select_bases::type - >::type - >::type bases; - - // A helper class which will contain an array of id objects to be - // passed to the base class constructor - struct id_vector - { - id_vector() - { - // Stick the derived class id into the first element of the array - ids[0] = type_id(); - - // Write the rest of the elements into succeeding positions. - type_info* p = ids + 1; - mpl::for_each(detail::write_type_id(&p), (bases*)0, (add_pointer*)0); - } - - BOOST_STATIC_CONSTANT( - std::size_t, size = mpl::size::value + 1); - type_info ids[size]; - }; - friend struct id_vector; - - public: - // Automatically derive the class name - only works on some - // compilers because type_info::name is sometimes mangled (gcc) -// class_(); // With default-constructor init function -// class_(no_init_t); // With no init function - - // Construct with the class name, with or without docstring, and default init() function - class_(char const* name, char const* doc = 0); - - // Construct with class name, no docstring, and no init() function - class_(char const* name, no_init_t); - - // Construct with class name, docstring, and no init() function - class_(char const* name, char const* doc, no_init_t); - - template - inline class_(char const* name, init_base const& i) - : base(name, id_vector::size, id_vector().ids) - { - this->register_(); - define_init(*this, i.derived()); - this->set_instance_size(holder_selector::additional_size()); - } - - template - inline class_(char const* name, char const* doc, init_base const& i) - : base(name, id_vector::size, id_vector().ids, doc) - { - this->register_(); - define_init(*this, i.derived()); - this->set_instance_size(holder_selector::additional_size()); - } - - // Wrap a member function or a non-member function which can take - // a T, T cv&, or T cv* as its first parameter, or a callable - // python object. - template - self& def(char const* name, F f) - { - this->def_impl(name, f, default_call_policies(), 0, &f); - return *this; - } - - template - self& def(init_base const& i) - { - define_init(*this, i.derived()); - return *this; - } - - template - self& def(char const* name, Arg1T arg1, Arg2T const& arg2) - { - // The arguments may be: - // def(name, function) - // def(name, function, policy) - // def(name, function, doc_string) - // def(name, signature, stubs) - - dispatch_def(&arg2, name, arg1, arg2); - return *this; - } - - template - self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3) - { - // The arguments are definitely: - // def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position - - dispatch_def(&arg2, name, arg1, arg2, arg3); - return *this; - } - - template - self& def(detail::operator_ const& op) - { - typedef detail::operator_ op_t; - return this->def(op.name(), &op_t::template apply::execute); - } - - // Define the constructor with the given Args, which should be an - // MPL sequence of types. - template - self& def_init(Args const&) - { - return this->def("__init__", - python::make_constructor( - // Using runtime type selection works around a CWPro7 bug. - holder_selector::execute((held_type*)0).get() - ) - ); - } - - template - self& def_init(Args const&, CallPolicyOrDoc const& policy_or_doc, char const* doc = 0) - { - typedef detail::def_helper helper; - - return this->def( - "__init__", - python::make_constructor( - helper::get_policy(policy_or_doc) - // Using runtime type selection works around a CWPro7 bug. - , holder_selector::execute((held_type*)0).get() - ) - , helper::get_doc(policy_or_doc, doc) - ); - } - - // Define the default constructor. - self& def_init() - { - this->def_init(mpl::list0<>::type()); - return *this; - } - - // - // Data member access - // - template - self& def_readonly(char const* name, D T::*pm) - { - this->add_property(name, make_getter(pm)); - return *this; - } - - template - self& def_readwrite(char const* name, D T::*pm) - { - return this->add_property(name, make_getter(pm), make_setter(pm)); - } - - // Property creation - template - self& add_property(char const* name, Get const& fget) - { - base::add_property(name, object(fget)); - return *this; - } - - template - self& add_property(char const* name, Get const& fget, Set const& fset) - { - base::add_property(name, object(fget), object(fset)); - return *this; - } - - template - self& setattr(char const* name, U const& x) - { - this->base::setattr(name, object(x)); - return *this; - } - - // Pickle support - template - self& def_pickle(PickleSuiteType const& x) - { - error_messages::must_be_derived_from_pickle_suite(x); - detail::pickle_suite_finalize::register_( - *this, - &PickleSuiteType::getinitargs, - &PickleSuiteType::getstate, - &PickleSuiteType::setstate, - PickleSuiteType::getstate_manages_dict()); - return *this; - } - - private: // helper functions - - template - inline void def_impl(char const* name, Fn fn, Policies const& policies - , char const* doc, ...) - { - objects::add_to_namespace( - *this, name, - make_function( - // This bit of nastiness casts F to a member function of T if possible. - detail::member_function_cast::stage1(fn).stage2((T*)0).stage3(fn) - , policies) - , doc); - } - - template - inline void def_impl(char const* name, F f, default_call_policies const& - , char const* doc, object const*) - { - objects::add_to_namespace(*this, name, f, doc); - } - - inline void register_() const; - - template - void dispatch_def( - void const*, - char const* name, - Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc = 0) - { - typedef detail::def_helper helper; - - this->def_impl( - name, fn, helper::get_policy(policy_or_doc), - helper::get_doc(policy_or_doc, doc), &fn); - - } - - template - void dispatch_def( - detail::func_stubs_base const*, - char const* name, - SigT sig, - StubsT const& stubs) - { - // convert sig to a type_list (see detail::get_signature in signature.hpp) - // before calling detail::define_with_defaults. - detail::define_with_defaults( - name, stubs, *this, detail::get_signature(sig)); - } -}; - - -// -// implementations -// - // register converters -template -inline void class_::register_() const -{ - objects::register_class_from_python(); - - detail::register_copy_constructor( - mpl::bool_c() - , holder_selector::execute((held_type*)0) - ); -} - -template -inline class_::class_(char const* name, char const* doc) - : base(name, id_vector::size, id_vector().ids, doc) -{ - this->register_(); - detail::force_instantiate(sizeof(detail::assert_default_constructible(T()))); - this->def_init(); - this->set_instance_size(holder_selector::additional_size()); -} - -template -inline class_::class_(char const* name, no_init_t) - : base(name, id_vector::size, id_vector().ids) -{ - this->register_(); - this->def_no_init(); -} - -template -inline class_::class_(char const* name, char const* doc, no_init_t) - : base(name, id_vector::size, id_vector().ids, doc) -{ - this->register_(); - this->def_no_init(); -} - -namespace detail -{ - template - struct has_noncopyable - : type_traits::ice_or< - is_same::value - , is_same::value - , is_same::value> - {}; - - - template - struct select_held_type - : mpl::if_c< - type_traits::ice_or< - specifies_bases::value - , is_same::value - >::value - , Prev - , T - > - { - }; -} - -}} // namespace boost::python - -#endif // CLASS_DWA200216_HPP diff --git a/include/boost/python/class_builder.hpp b/include/boost/python/class_builder.hpp deleted file mode 100644 index fe2a7b74..00000000 --- a/include/boost/python/class_builder.hpp +++ /dev/null @@ -1,182 +0,0 @@ -// Revision History: -// Mar 03 01 added: pickle safety measures (Ralf W. Grosse-Kunstleve) - -#ifndef CLASS_WRAPPER_DWA101000_H_ -# define CLASS_WRAPPER_DWA101000_H_ - -#include -#include -#include -#include -#include -#include - -namespace boost { namespace python { - -// Syntactic sugar to make wrapping classes more convenient -template > -class class_builder - : python_extension_class_converters // Works around MSVC6.x/GCC2.95.2 bug described below -{ - public: - class_builder(module_builder& module, const char* name) - : m_class(new detail::extension_class(name)) - { - module.add(ref(as_object(m_class.get()), ref::increment_count), name); - } - - template - class_builder(class_builder& cls, const char* name) - : m_class(new detail::extension_class(name)) - { - cls.add(ref(as_object(m_class.get()), ref::increment_count), name); - } - - template - class_builder(detail::extension_class* cls, - const char* name) - : m_class(new detail::extension_class(name)) - { - cls->set_attribute(name, - ref(as_object(m_class.get()), ref::increment_count)); - } - - ~class_builder() - {} - - inline void dict_defines_state() { - add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__dict_defines_state__"); - } - inline void getstate_manages_dict() { - add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__getstate_manages_dict__"); - } - - // define constructors - template - void def(const signature& s) - { m_class->def(s); } - - // export heterogeneous reverse-argument operators - // (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::left_operand()); - template - void def(operators o1, left_operand o2) - { m_class->def(o1, o2); } - - // export heterogeneous operators (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::right_operand()); - template - void def(operators o1, right_operand o2) - { m_class->def(o1, o2); } - - // define a function that passes Python arguments and keywords - // to C++ verbatim (as a 'tuple const &' and 'dictionary const &' - // respectively). This is useful for manual argument passing. - // It's also the only possibility to pass keyword arguments to C++. - // Fn must have a signatur that is compatible to - // PyObject * (*)(PyObject * aTuple, PyObject * aDictionary) - template - void def_raw(Fn fn, const char* name) - { m_class->def_raw(fn, name); } - - // define member functions. In fact this works for free functions, too - - // they act like static member functions, or if they start with the - // appropriate self argument (as a pointer or reference), they can be used - // just like ordinary member functions -- just like Python! - template - void def(Fn fn, const char* name) - { m_class->def(fn, name); } - - // Define a virtual member function with a default implementation. - // default_fn should be a function which provides the default implementation. - // Be careful that default_fn does not in fact call fn virtually! - template - void def(Fn fn, const char* name, DefaultFn default_fn) - { m_class->def(fn, name, default_fn); } - - // Provide a function which implements x., reading from the given - // member (pm) of the T obj - template - void def_getter(MemberType T::*pm, const char* name) - { m_class->def_getter(pm, name); } - - // Provide a function which implements assignment to x., writing to - // the given member (pm) of the T obj - template - void def_setter(MemberType T::*pm, const char* name) - { m_class->def_getter(pm, name); } - - // Expose the given member (pm) of the T obj as a read-only attribute - template - void def_readonly(MemberType T::*pm, const char* name) - { m_class->def_readonly(pm, name); } - - // Expose the given member (pm) of the T obj as a read/write attribute - template - void def_read_write(MemberType T::*pm, const char* name) - { m_class->def_read_write(pm, name); } - - // define the standard coercion needed for operator overloading - void def_standard_coerce() - { m_class->def_standard_coerce(); } - - // declare the given class a base class of this one and register - // conversion functions - template - void declare_base(class_builder const & base) - { - m_class->declare_base(base.get_extension_class()); - } - - // declare the given class a base class of this one and register - // upcast conversion function - template - void declare_base(class_builder const & base, without_downcast_t) - { - m_class->declare_base(base.get_extension_class(), without_downcast); - } - - // get the embedded ExtensioClass object - detail::extension_class * get_extension_class() const - { - return m_class.get(); - } - - // set an arbitrary attribute. Useful for non-function class data members, - // e.g. enums - void add(PyObject* x, const char* name) - { m_class->set_attribute(name, x); } - void add(ref x, const char* name) - { m_class->set_attribute(name, x); } - private: - // declare the given class a base class of this one and register - // conversion functions - template - void declare_base(detail::extension_class * base) - { - m_class->declare_base(base); - } - - // declare the given class a base class of this one and register - // upcast conversion function - template - void declare_base(detail::extension_class * base, without_downcast_t) - { - m_class->declare_base(base, without_downcast); - } - - reference > m_class; -}; - -// The bug mentioned at the top of this file is that on certain compilers static -// global functions declared within the body of a class template will only be -// generated when the class template is constructed, and when (for some reason) -// the construction does not occur via a new-expression. Otherwise, we could -// rely on the initialization of the m_class data member to cause all of the -// to_/from_python functions to come into being. - -}} // namespace boost::python - -#endif // CLASS_WRAPPER_DWA101000_H_ diff --git a/include/boost/python/class_fwd.hpp b/include/boost/python/class_fwd.hpp deleted file mode 100644 index 87f3ba32..00000000 --- a/include/boost/python/class_fwd.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CLASS_FWD_DWA200222_HPP -# define CLASS_FWD_DWA200222_HPP -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - struct empty_list; -} - -template < - class T // class being wrapped - // arbitrarily-ordered optional arguments. Full qualification needed for MSVC6 - , class X1 = ::boost::python::detail::not_specified - , class X2 = ::boost::python::detail::not_specified - , class X3 = ::boost::python::detail::not_specified - > -class class_; - -}} // namespace boost::python - -#endif // CLASS_FWD_DWA200222_HPP diff --git a/include/boost/python/classes.hpp b/include/boost/python/classes.hpp deleted file mode 100644 index 22fcb3d2..00000000 --- a/include/boost/python/classes.hpp +++ /dev/null @@ -1,677 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef SUBCLASS_DWA051500_H_ -# define SUBCLASS_DWA051500_H_ - -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -// A simple type which acts something like a built-in Python class obj. -class BOOST_PYTHON_DECL instance - : public boost::python::detail::python_object -{ - public: - instance(PyTypeObject* class_); - ~instance(); - - // Standard Python functions. - PyObject* repr(); - int compare(PyObject*); - PyObject* str(); - long hash(); - PyObject* call(PyObject* args, PyObject* keywords); - PyObject* getattr(const char* name, bool use_special_function = true); - int setattr(const char* name, PyObject* value); - - // Mapping methods - int length(); - PyObject* get_subscript(PyObject* key); - void set_subscript(PyObject* key, PyObject* value); - - // Sequence methods - PyObject* get_slice(int start, int finish); - void set_slice(int start, int finish, PyObject* value); - - // Number methods - PyObject* add(PyObject* other); - PyObject* subtract(PyObject* other); - PyObject* multiply(PyObject* other); - PyObject* divide(PyObject* other); - PyObject* remainder(PyObject* other); - PyObject* divmod(PyObject* other); - PyObject* power(PyObject*, PyObject*); - PyObject* negative(); - PyObject* positive(); - PyObject* absolute(); - int nonzero(); - PyObject* invert(); - PyObject* lshift(PyObject* other); - PyObject* rshift(PyObject* other); - PyObject* do_and(PyObject* other); - PyObject* do_xor(PyObject* other); - PyObject* do_or(PyObject* other); - int coerce(PyObject**, PyObject**); - PyObject* as_int(); - PyObject* as_long(); - PyObject* as_float(); - PyObject* oct(); - PyObject* hex(); - - // Rich comparisons - PyObject* lt(PyObject* other); - PyObject* le(PyObject* other); - PyObject* eq(PyObject* other); - PyObject* ne(PyObject* other); - PyObject* gt(PyObject* other); - PyObject* ge(PyObject* other); - - // Inplace operations. - PyObject* inplace_add(PyObject* other); - PyObject* inplace_subtract(PyObject* other); - PyObject* inplace_multiply(PyObject* other); - PyObject* inplace_divide(PyObject* other); - PyObject* inplace_remainder(PyObject* other); - PyObject* inplace_power(PyObject* exponent, PyObject* modulus); - PyObject* inplace_lshift(PyObject* other); - PyObject* inplace_rshift(PyObject* other); - PyObject* inplace_and(PyObject* other); - PyObject* inplace_or(PyObject* other); - PyObject* inplace_xor(PyObject* other); - - private: // noncopyable, without the size bloat - instance(const instance&); - void operator=(const instance&); - - private: // helper functions - int setattr_dict(PyObject* value); - - private: - dictionary m_name_space; -}; - -template class meta_class; - -namespace detail { - class BOOST_PYTHON_DECL class_base : public type_object_base - { - public: - class_base(PyTypeObject* meta_class_obj, string name, tuple bases, const dictionary& name_space); - tuple bases() const; - string name() const; - dictionary& dict(); - - // Standard Python functions. - PyObject* getattr(const char* name); - int setattr(const char* name, PyObject* value); - PyObject* repr() const; - void add_base(ref base); - - protected: - bool initialize_instance(instance* obj, PyObject* args, PyObject* keywords); - - private: // virtual functions - // Subclasses should override this to delete the particular obj type - virtual void delete_instance(PyObject*) const = 0; - - private: // boost::python::type_object_base required interface implementation - void instance_dealloc(PyObject*) const; // subclasses should not override this - - private: // noncopyable, without the size bloat - class_base(const class_base&); - void operator=(const class_base&); - - private: - string m_name; - tuple m_bases; - dictionary m_name_space; - }; - - void enable_named_method(class_base* type_obj, const char* name); -} - -// A type which acts a lot like a built-in Python class. T is the obj type, -// so class_t is a very simple "class-alike". -template -class class_t : public boost::python::detail::class_base -{ - public: - class_t(meta_class* meta_class_obj, string name, tuple bases, const dictionary& name_space); - ~class_t(); - - // Standard Python functions. - PyObject* call(PyObject* args, PyObject* keywords); - - private: // Implement mapping methods on instances - PyObject* instance_repr(PyObject*) const; - int instance_compare(PyObject*, PyObject* other) const; - PyObject* instance_str(PyObject*) const; - long instance_hash(PyObject*) const; - int instance_mapping_length(PyObject*) const; - PyObject* instance_mapping_subscript(PyObject*, PyObject*) const; - int instance_mapping_ass_subscript(PyObject*, PyObject*, PyObject*) const; - - private: // Implement sequence methods on instances - int instance_sequence_length(PyObject*) const; - PyObject* instance_sequence_item(PyObject* obj, int n) const; - int instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const; - PyObject* instance_sequence_slice(PyObject*, int start, int finish) const; - int instance_sequence_ass_slice(PyObject*, int start, int finish, PyObject* value) const; - - private: // Implement number methods on instances - PyObject* instance_number_add(PyObject*, PyObject*) const; - PyObject* instance_number_subtract(PyObject*, PyObject*) const; - PyObject* instance_number_multiply(PyObject*, PyObject*) const; - PyObject* instance_number_divide(PyObject*, PyObject*) const; - PyObject* instance_number_remainder(PyObject*, PyObject*) const; - PyObject* instance_number_divmod(PyObject*, PyObject*) const; - PyObject* instance_number_power(PyObject*, PyObject*, PyObject*) const; - PyObject* instance_number_negative(PyObject*) const; - PyObject* instance_number_positive(PyObject*) const; - PyObject* instance_number_absolute(PyObject*) const; - int instance_number_nonzero(PyObject*) const; - PyObject* instance_number_invert(PyObject*) const; - PyObject* instance_number_lshift(PyObject*, PyObject*) const; - PyObject* instance_number_rshift(PyObject*, PyObject*) const; - PyObject* instance_number_and(PyObject*, PyObject*) const; - PyObject* instance_number_xor(PyObject*, PyObject*) const; - PyObject* instance_number_or(PyObject*, PyObject*) const; - int instance_number_coerce(PyObject*, PyObject**, PyObject**) const; - PyObject* instance_number_int(PyObject*) const; - PyObject* instance_number_long(PyObject*) const; - PyObject* instance_number_float(PyObject*) const; - PyObject* instance_number_oct(PyObject*) const; - PyObject* instance_number_hex(PyObject*) const; - - PyObject* instance_number_inplace_add(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_subtract(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_multiply(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_divide(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_remainder(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_power(PyObject*, PyObject*, PyObject*) const; - PyObject* instance_number_inplace_lshift(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_rshift(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_and(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_or(PyObject*, PyObject*) const; - PyObject* instance_number_inplace_xor(PyObject*, PyObject*) const; - - private: // Implement rich comparisons - PyObject* instance_lt(PyObject*, PyObject*) const; - PyObject* instance_le(PyObject*, PyObject*) const; - PyObject* instance_eq(PyObject*, PyObject*) const; - PyObject* instance_ne(PyObject*, PyObject*) const; - PyObject* instance_gt(PyObject*, PyObject*) const; - PyObject* instance_ge(PyObject*, PyObject*) const; - - private: // Miscellaneous "special" methods - PyObject* instance_call(PyObject* obj, PyObject* args, PyObject* keywords) const; - PyObject* instance_getattr(PyObject* obj, const char* name) const; - int instance_setattr(PyObject* obj, const char* name, PyObject* value) const; - - private: // Implementation of boost::python::detail::class_base required interface - void delete_instance(PyObject*) const; -}; - -// The type of a class_t object. -template -class meta_class - : public boost::python::detail::reprable< - boost::python::detail::callable< - boost::python::detail::getattrable< - boost::python::detail::setattrable< - boost::python::detail::type_object > > > > >, - private boost::noncopyable -{ - public: - meta_class(); - - // Standard Python functions. - PyObject* call(PyObject* args, PyObject* keywords); - - struct type_object - : boost::python::detail::singleton > > - { - type_object() : singleton_base(&PyType_Type) {} - }; -}; - -// -// Member function implementations. -// -template -meta_class::meta_class() - : properties(type_object::instance()) -{ -} - -template -class_t::class_t(meta_class* meta_class_obj, string name, tuple bases, const dictionary& name_space) - : boost::python::detail::class_base(meta_class_obj, name, bases, name_space) -{ -} - -template -class_t::~class_t() -{ -} - -template -void class_t::delete_instance(PyObject* obj) const -{ - delete downcast(obj); -} - -template -PyObject* class_t::call(PyObject* args, PyObject* keywords) -{ - reference result(new T(this)); - if (!this->initialize_instance(result.get(), args, keywords)) - return 0; - else - return result.release(); -} - -template -PyObject* class_t::instance_repr(PyObject* obj) const -{ - return downcast(obj)->repr(); -} - -template -int class_t::instance_compare(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->compare(other); -} - -template -PyObject* class_t::instance_str(PyObject* obj) const -{ - return downcast(obj)->str(); -} - -template -long class_t::instance_hash(PyObject* obj) const -{ - return downcast(obj)->hash(); -} - -template -int class_t::instance_mapping_length(PyObject* obj) const -{ - return downcast(obj)->length(); -} - -template -int class_t::instance_sequence_length(PyObject* obj) const -{ - return downcast(obj)->length(); -} - -template -PyObject* class_t::instance_mapping_subscript(PyObject* obj, PyObject* key) const -{ - return downcast(obj)->get_subscript(key); -} - -template -PyObject* class_t::instance_sequence_item(PyObject* obj, int n) const -{ - ref key(to_python(n)); - return downcast(obj)->get_subscript(key.get()); -} - -template -int class_t::instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const -{ - ref key(to_python(n)); - downcast(obj)->set_subscript(key.get(), value); - return 0; -} - -template -int class_t::instance_mapping_ass_subscript(PyObject* obj, PyObject* key, PyObject* value) const -{ - downcast(obj)->set_subscript(key, value); - return 0; -} - -bool BOOST_PYTHON_DECL adjust_slice_indices(PyObject* obj, int& start, int& finish); - -template -PyObject* class_t::instance_sequence_slice(PyObject* obj, int start, int finish) const -{ - if (!adjust_slice_indices(obj, start, finish)) - return 0; - return downcast(obj)->get_slice(start, finish); -} - -template -int class_t::instance_sequence_ass_slice(PyObject* obj, int start, int finish, PyObject* value) const -{ - if (!adjust_slice_indices(obj, start, finish)) - return -1; - downcast(obj)->set_slice(start, finish, value); - return 0; -} - -template -PyObject* class_t::instance_call(PyObject* obj, PyObject* args, PyObject* keywords) const -{ - return downcast(obj)->call(args, keywords); -} - -template -PyObject* class_t::instance_getattr(PyObject* obj, const char* name) const -{ - return downcast(obj)->getattr(name); -} - - -template -int class_t::instance_setattr(PyObject* obj, const char* name, PyObject* value) const -{ - return downcast(obj)->setattr(name, value); -} - -template -PyObject* class_t::instance_number_add(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->add(other); -} - -template -PyObject* class_t::instance_number_subtract(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->subtract(other); -} - -template -PyObject* class_t::instance_number_multiply(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->multiply(other); -} - -template -PyObject* class_t::instance_number_divide(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->divide(other); -} - -template -PyObject* class_t::instance_number_remainder(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->remainder(other); -} - -template -PyObject* class_t::instance_number_divmod(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->divmod(other); -} - -template -PyObject* class_t::instance_number_power(PyObject* obj, PyObject* exponent, PyObject* modulus) const -{ - return downcast(obj)->power(exponent, modulus); -} - -template -PyObject* class_t::instance_number_negative(PyObject* obj) const -{ - return downcast(obj)->negative(); -} - -template -PyObject* class_t::instance_number_positive(PyObject* obj) const -{ - return downcast(obj)->positive(); -} - -template -PyObject* class_t::instance_number_absolute(PyObject* obj) const -{ - return downcast(obj)->absolute(); -} - -template -int class_t::instance_number_nonzero(PyObject* obj) const -{ - return downcast(obj)->nonzero(); -} - -template -PyObject* class_t::instance_number_invert(PyObject* obj) const -{ - return downcast(obj)->invert(); -} - -template -PyObject* class_t::instance_number_lshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->lshift(other); -} - -template -PyObject* class_t::instance_number_rshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->rshift(other); -} - -template -PyObject* class_t::instance_number_and(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->do_and(other); -} - -template -PyObject* class_t::instance_number_xor(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->do_xor(other); -} - -template -PyObject* class_t::instance_number_or(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->do_or(other); -} - -template -int class_t::instance_number_coerce(PyObject* obj, PyObject** x, PyObject** y) const -{ - return downcast(obj)->coerce(x, y); -} - -template -PyObject* class_t::instance_number_int(PyObject* obj) const -{ - return downcast(obj)->as_int(); -} - -template -PyObject* class_t::instance_number_long(PyObject* obj) const -{ - return downcast(obj)->as_long(); -} - -template -PyObject* class_t::instance_number_float(PyObject* obj) const -{ - return downcast(obj)->as_float(); -} - -template -PyObject* class_t::instance_number_oct(PyObject* obj) const -{ - return downcast(obj)->oct(); -} - -template -PyObject* class_t::instance_number_hex(PyObject* obj) const -{ - return downcast(obj)->hex(); -} - -template -PyObject* class_t::instance_number_inplace_add(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_add(other); -} - -template -PyObject* class_t::instance_number_inplace_subtract(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_subtract(other); -} - -template -PyObject* class_t::instance_number_inplace_multiply(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_multiply(other); -} - -template -PyObject* class_t::instance_number_inplace_divide(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_divide(other); -} - -template -PyObject* class_t::instance_number_inplace_remainder(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_remainder(other); -} - -template -PyObject* class_t::instance_number_inplace_power(PyObject* obj, PyObject* exponent, PyObject* modulus) const -{ - return downcast(obj)->inplace_power(exponent, modulus); -} - -template -PyObject* class_t::instance_number_inplace_lshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_lshift(other); -} - -template -PyObject* class_t::instance_number_inplace_rshift(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_rshift(other); -} - -template -PyObject* class_t::instance_number_inplace_and(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_and(other); -} - -template -PyObject* class_t::instance_number_inplace_or(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_or(other); -} - -template -PyObject* class_t::instance_number_inplace_xor(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->inplace_xor(other); -} - -template -PyObject* class_t::instance_lt(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->lt(other); -} - -template -PyObject* class_t::instance_le(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->le(other); -} - -template -PyObject* class_t::instance_eq(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->eq(other); -} - -template -PyObject* class_t::instance_ne(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->ne(other); -} - -template -PyObject* class_t::instance_gt(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->gt(other); -} - -template -PyObject* class_t::instance_ge(PyObject* obj, PyObject* other) const -{ - return downcast(obj)->ge(other); -} - -namespace detail { - inline dictionary& class_base::dict() - { - return m_name_space; - } - - inline tuple class_base::bases() const - { - return m_bases; - } -} - -template -PyObject* meta_class::call(PyObject* args, PyObject* /*keywords*/) -{ - PyObject* name; - PyObject* bases; - PyObject* name_space; - - if (!PyArg_ParseTuple(args, const_cast("O!O!O!"), - &PyString_Type, &name, - &PyTuple_Type, &bases, - &PyDict_Type, &name_space)) - { - return 0; - } - - return as_object( - new class_t(this, string(ref(name, ref::increment_count)), - tuple(ref(bases, ref::increment_count)), - dictionary(ref(name_space, ref::increment_count))) - ); -} - -namespace detail { - const string& setattr_string(); - const string& getattr_string(); - const string& delattr_string(); - - inline string class_base::name() const - { - return m_name; - } -} - - -}} // namespace boost::python -#endif diff --git a/include/boost/python/conversions.hpp b/include/boost/python/conversions.hpp deleted file mode 100644 index 83823494..00000000 --- a/include/boost/python/conversions.hpp +++ /dev/null @@ -1,415 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// Revision History: -// 31 Jul 01 convert int/double to complex (Peter Bienstman) -// 04 Mar 01 Fixed std::complex<> stuff to work with MSVC (David Abrahams) -// 03 Mar 01 added: converters for [plain] char and std::complex -// (Ralf W. Grosse-Kunstleve) - -#ifndef METHOD_DWA122899_H_ -# define METHOD_DWA122899_H_ - -# include -# include -# include -# include -# include -# include -# include - -# ifdef BOOST_MSVC6_OR_EARLIER -# pragma warning(push) -# pragma warning(disable:4275) // disable a bogus warning caused by -# endif - -# include - -# ifdef BOOST_MSVC6_OR_EARLIER -# pragma warning(pop) -# endif - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround - -// This can be instantiated on an enum to provide the to_python/from_python -// conversions, provided the values can fit in a long. -template -class py_enum_as_int_converters -{ - friend EnumType from_python(PyObject* x, boost::python::type) - { - return static_cast( - from_python(x, boost::python::type())); - } - - friend EnumType from_python(PyObject* x, boost::python::type) - { - return static_cast( - from_python(x, boost::python::type())); - } - - friend PyObject* to_python(EnumType x) - { - return to_python(static_cast(x)); - } -}; -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -namespace boost { namespace python { -template class enum_as_int_converters - : public BOOST_PYTHON_CONVERSION::py_enum_as_int_converters {}; - -template class wrapped_pointer; - -//#pragma warn_possunwant off -inline void decref_impl(PyObject* p) { Py_DECREF(p); } -inline void xdecref_impl(PyObject* p) { Py_XDECREF(p); } -//#pragma warn_possunwant reset - -template -inline void decref(T* p) -{ - char* const raw_p = reinterpret_cast(p); - char* const p_base = raw_p - offsetof(PyObject, ob_refcnt); - decref_impl(reinterpret_cast(p_base)); -} - -template -inline void xdecref(T* p) -{ - char* const raw_p = reinterpret_cast(p); - char* const p_base = raw_p - offsetof(PyObject, ob_refcnt); - xdecref_impl(reinterpret_cast(p_base)); -} - -namespace detail { - - void expect_complex(PyObject*); - - template - std::complex complex_from_python(PyObject* p, boost::python::type) - { - if (PyInt_Check(p)) return std::complex(PyInt_AS_LONG(p)); - if (PyLong_Check(p)) return std::complex(PyLong_AsDouble(p)); - if (PyFloat_Check(p)) return std::complex(PyFloat_AS_DOUBLE(p)); - - expect_complex(p); - - return std::complex( - static_cast(PyComplex_RealAsDouble(p)), - static_cast(PyComplex_ImagAsDouble(p))); - } - - template - PyObject* complex_to_python(const std::complex& sc) { - Py_complex pcc; - pcc.real = sc.real(); - pcc.imag = sc.imag(); - return PyComplex_FromCComplex(pcc); - } - -} - -}} // namespace boost::python - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE -// -// Converters -// -PyObject* to_python(long); -BOOST_PYTHON_DECL long from_python(PyObject* p, boost::python::type); -long from_python(PyObject* p, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned long); -BOOST_PYTHON_DECL unsigned long from_python(PyObject* p, boost::python::type); -unsigned long from_python(PyObject* p, boost::python::type); - -PyObject* to_python(int); -BOOST_PYTHON_DECL int from_python(PyObject*, boost::python::type); -int from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned int); -BOOST_PYTHON_DECL unsigned int from_python(PyObject*, boost::python::type); -unsigned int from_python(PyObject*, boost::python::type); - -PyObject* to_python(short); -BOOST_PYTHON_DECL short from_python(PyObject*, boost::python::type); -short from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned short); -BOOST_PYTHON_DECL unsigned short from_python(PyObject*, boost::python::type); -unsigned short from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(char); -BOOST_PYTHON_DECL char from_python(PyObject*, boost::python::type); -char from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(signed char); -BOOST_PYTHON_DECL signed char from_python(PyObject*, boost::python::type); -signed char from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(unsigned char); -BOOST_PYTHON_DECL unsigned char from_python(PyObject*, boost::python::type); -unsigned char from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL float from_python(PyObject*, boost::python::type); -BOOST_PYTHON_DECL double from_python(PyObject*, boost::python::type); - -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 -PyObject* to_python(float); -PyObject* to_python(double); -# else -BOOST_PYTHON_DECL PyObject* to_python(float); -BOOST_PYTHON_DECL PyObject* to_python(double); -# endif -float from_python(PyObject*, boost::python::type); - -double from_python(PyObject*, boost::python::type); - -PyObject* to_python(bool); -BOOST_PYTHON_DECL bool from_python(PyObject*, boost::python::type); -bool from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(void); -BOOST_PYTHON_DECL void from_python(PyObject*, boost::python::type); - -PyObject* to_python(const char* s); -BOOST_PYTHON_DECL const char* from_python(PyObject*, boost::python::type); - -BOOST_PYTHON_DECL PyObject* to_python(const std::string& s); -BOOST_PYTHON_DECL std::string from_python(PyObject*, boost::python::type); -std::string from_python(PyObject*, boost::python::type); - -inline PyObject* to_python(const std::complex& x) -{ - return boost::python::detail::complex_to_python(x); -} - -inline PyObject* to_python(const std::complex& x) -{ - return boost::python::detail::complex_to_python(x); -} - -inline std::complex from_python(PyObject* p, - boost::python::type >) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -inline std::complex from_python(PyObject* p, - boost::python::type&>) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -inline std::complex from_python(PyObject* p, - boost::python::type >) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -inline std::complex from_python(PyObject* p, - boost::python::type&>) { - return boost::python::detail::complex_from_python(p, boost::python::type()); -} - -// For when your C++ function really wants to pass/return a PyObject* -PyObject* to_python(PyObject*); -PyObject* from_python(PyObject*, boost::python::type); - -// Some standard conversions to/from smart pointer types. You can add your own -// from these examples. These are not generated using the friend technique from -// wrapped_pointer because: -// -// 1. We want to be able to extend conversion to/from WrappedPointers using -// arbitrary smart pointer types. -// -// 2. It helps with compilation independence. This way, code which creates -// wrappers for functions accepting and returning smart_ptr does not -// have to have already seen the invocation of wrapped_type. -// - -// Unfortunately, MSVC6 is so incredibly lame that we have to rely on the friend -// technique to auto_generate standard pointer conversions for wrapped -// types. This means that you need to write a non-templated function for each -// specific smart_ptr which you want to convert from_python. For example, -// -// namespace boost { namespace python { -// #ifdef MUST_SUPPORT_MSVC -// -// MyPtr from_python(PyObject*p, type >) -// { return smart_ptr_from_python(p, type >(), type());} -// } -// -// MyPtr from_python(PyObject*p, type >) -// { return smart_ptr_from_python(p, type >(), type());} -// -// ... // definitions for MyPtr, MyPtr, etc. -// -// #else -// -// // Just once for all MyPtr -// template -// MyPtr from_python(PyObject*p, type >) -// { -// return smart_ptr_from_python(p, type >(), type()); -// } -// -// #endif -// }} // namespace boost::python - -#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) -template -boost::shared_ptr from_python(PyObject*p, boost::python::type >) -{ - return smart_ptr_from_python(p, boost::python::type >(), boost::python::type()); -} -#endif - -#if 0 -template -PyObject* to_python(std::auto_ptr p) -{ - return new boost::python::wrapped_pointer, T>(p); -} - -template -PyObject* to_python(boost::shared_ptr p) -{ - return new boost::python::wrapped_pointer, T>(p); -} -#endif - -// -// inline implementations -// - -#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 -inline PyObject* to_python(double d) -{ - return PyFloat_FromDouble(d); -} - -inline PyObject* to_python(float f) -{ - return PyFloat_FromDouble(f); -} -#endif - -inline PyObject* to_python(long l) -{ - return PyInt_FromLong(l); -} - -inline PyObject* to_python(int x) -{ - return PyInt_FromLong(x); -} - -inline PyObject* to_python(short x) -{ - return PyInt_FromLong(x); -} - -inline PyObject* to_python(bool b) -{ - return PyInt_FromLong(b); -} - -inline PyObject* to_python(void) -{ - return boost::python::detail::none(); -} - -inline PyObject* to_python(const char* s) -{ - return PyString_FromString(s); -} - -inline std::string from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline PyObject* to_python(PyObject* p) -{ - Py_INCREF(p); - return p; -} - -inline PyObject* from_python(PyObject* p, boost::python::type) -{ - return p; -} - -inline const char* from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline double from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline float from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline int from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline short from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline long from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline bool from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned int from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned short from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline char from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline signed char from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned char from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -inline unsigned long from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -#endif // METHOD_DWA122899_H_ diff --git a/include/boost/python/converter/arg_from_python.hpp b/include/boost/python/converter/arg_from_python.hpp deleted file mode 100755 index 1e3dfa26..00000000 --- a/include/boost/python/converter/arg_from_python.hpp +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ARG_FROM_PYTHON_DWA2002127_HPP -# define ARG_FROM_PYTHON_DWA2002127_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python -{ - template struct arg_from_python; -}} - -// This header defines Python->C++ function argument converters, -// parametrized on the argument type. - -namespace boost { namespace python { namespace converter { - -// -// lvalue converters -// -// These require that an lvalue of the type U is stored somewhere in -// the Python object being converted. - -// Used when T == U*const& -template -struct pointer_cref_arg_from_python -{ - typedef T result_type; - - pointer_cref_arg_from_python(PyObject*); - T operator()(PyObject*) const; - bool convertible() const; - - private: // storage for a U* - // needed because not all compilers will let us declare U* as the - // return type of operator() -- we return U*const& instead - typename python::detail::referent_storage::type m_result; -}; - -// Base class for pointer and reference converters -struct arg_lvalue_from_python_base -{ - public: // member functions - arg_lvalue_from_python_base(void* result); - bool convertible() const; - - protected: // member functions - void*const& result() const; - - private: // data members - void* m_result; -}; - -// Used when T == U* -template -struct pointer_arg_from_python : arg_lvalue_from_python_base -{ - typedef T result_type; - - pointer_arg_from_python(PyObject*); - T operator()(PyObject*) const; -}; - -// Used when T == U& and (T != V const& or T == W volatile&) -template -struct reference_arg_from_python : arg_lvalue_from_python_base -{ - typedef T result_type; - - reference_arg_from_python(PyObject*); - T operator()(PyObject*) const; -}; - -// =================== - -// -// rvalue converters -// -// These require only that an object of type T can be created from -// the given Python object, but not that the T object exist -// somewhere in storage. -// - -// Used when T is a plain value (non-pointer, non-reference) type or -// a (non-volatile) const reference to a plain value type. -template -struct arg_rvalue_from_python -{ - typedef typename boost::add_reference< - typename boost::add_const::type - >::type result_type; - - arg_rvalue_from_python(PyObject*); - bool convertible() const; - - result_type operator()(PyObject*); - - private: - rvalue_from_python_data m_data; -}; - - -// ================== - -// Converts to a (PyObject*,T) bundle, for when you need a reference -// back to the Python object -template -struct back_reference_arg_from_python - : boost::python::arg_from_python -{ - typedef T result_type; - - back_reference_arg_from_python(PyObject*); - T operator()(PyObject*); - private: - typedef boost::python::arg_from_python base; -}; - - -// ================== - -// This metafunction selects the appropriate arg_from_python converter -// type for an argument of type T. -template -struct select_arg_from_python -{ - BOOST_STATIC_CONSTANT( - bool, obj_mgr = is_object_manager::value); - - BOOST_STATIC_CONSTANT( - bool, obj_mgr_ref = is_reference_to_object_manager::value); - - BOOST_STATIC_CONSTANT( - bool, ptr = is_pointer::value); - - BOOST_STATIC_CONSTANT( - bool, ptr_cref - = boost::python::detail::is_reference_to_pointer::value - && boost::python::detail::is_reference_to_const::value - && !boost::python::detail::is_reference_to_volatile::value); - - - BOOST_STATIC_CONSTANT( - bool, ref = - boost::python::detail::is_reference_to_non_const::value - || boost::python::detail::is_reference_to_volatile::value); - - BOOST_STATIC_CONSTANT( - bool, back_ref = - boost::python::is_back_reference::value); - - typedef typename mpl::if_c< - obj_mgr - , object_manager_value_arg_from_python - , typename mpl::if_c< - obj_mgr_ref - , object_manager_ref_arg_from_python - , typename mpl::if_c< - ptr - , pointer_arg_from_python - , typename mpl::if_c< - ptr_cref - , pointer_cref_arg_from_python - , typename mpl::if_c< - ref - , reference_arg_from_python - , typename mpl::if_c< - back_ref - , back_reference_arg_from_python - , arg_rvalue_from_python - >::type - >::type - >::type - >::type - >::type - >::type type; -}; - -// ================== - -// -// implementations -// - -// arg_lvalue_from_python_base -// -inline arg_lvalue_from_python_base::arg_lvalue_from_python_base(void* result) - : m_result(result) -{ -} - -inline bool arg_lvalue_from_python_base::convertible() const -{ - return m_result != 0; -} - -inline void*const& arg_lvalue_from_python_base::result() const -{ - return m_result; -} - -// pointer_cref_arg_from_python -// -namespace detail -{ - // null_ptr_reference -- a function returning a reference to a null - // pointer of type U. Needed so that extractors for T*const& can - // convert Python's None. - template - struct null_ptr_owner - { - static T value; - }; - template T null_ptr_owner::value = 0; - - template - inline U& null_ptr_reference(U&(*)()) - { - return null_ptr_owner::value; - } -} - -template -inline pointer_cref_arg_from_python::pointer_cref_arg_from_python(PyObject* p) -{ - // T == U*const&: store a U* in the m_result storage. Nonzero - // indicates success. If find returns nonzero, it's a pointer to - // a U object. - python::detail::write_void_ptr_reference( - m_result.bytes - , p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee::converters) - , (T(*)())0); -} - -template -inline bool pointer_cref_arg_from_python::convertible() const -{ - return python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0) != 0; -} -template -inline T pointer_cref_arg_from_python::operator()(PyObject* p) const -{ - return (p == Py_None) // None ==> 0 - ? detail::null_ptr_reference((T(*)())0) - // Otherwise, return a U*const& to the m_result storage. - : python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0); -} - -// pointer_arg_from_python -// -template -inline pointer_arg_from_python::pointer_arg_from_python(PyObject* p) - : arg_lvalue_from_python_base( - p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee::converters)) -{ -} - -template -inline T pointer_arg_from_python::operator()(PyObject* p) const -{ - return (p == Py_None) ? 0 : T(result()); -} - -// reference_arg_from_python -// -template -inline reference_arg_from_python::reference_arg_from_python(PyObject* p) - : arg_lvalue_from_python_base(converter::get_lvalue_from_python(p,registered::converters)) -{ -} - -template -inline T reference_arg_from_python::operator()(PyObject*) const -{ - return python::detail::void_ptr_to_reference(result(), (T(*)())0); -} - - -// arg_rvalue_from_python -// -template -inline arg_rvalue_from_python::arg_rvalue_from_python(PyObject* obj) - : m_data(converter::rvalue_from_python_stage1(obj, registered::converters)) -{ -} - -template -inline bool arg_rvalue_from_python::convertible() const -{ - return m_data.stage1.convertible != 0; -} - -template -inline typename arg_rvalue_from_python::result_type -arg_rvalue_from_python::operator()(PyObject* p) -{ - if (m_data.stage1.construct != 0) - m_data.stage1.construct(p, &m_data.stage1); - - return python::detail::void_ptr_to_reference(m_data.stage1.convertible, (result_type(*)())0); -} - -// back_reference_arg_from_python -// -template -back_reference_arg_from_python::back_reference_arg_from_python(PyObject* x) - : base(x) -{ -} - -template -inline T -back_reference_arg_from_python::operator()(PyObject* x) -{ - return T(x, base::operator()(x)); -} - -}}} // namespace boost::python::converter - -#endif // ARG_FROM_PYTHON_DWA2002127_HPP diff --git a/include/boost/python/converter/arg_to_python.hpp b/include/boost/python/converter/arg_to_python.hpp deleted file mode 100755 index deab7964..00000000 --- a/include/boost/python/converter/arg_to_python.hpp +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ARG_TO_PYTHON_DWA200265_HPP -# define ARG_TO_PYTHON_DWA200265_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -// Bring in specializations -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -template struct is_object_manager; - -namespace detail -{ - BOOST_PYTHON_DECL void throw_no_class_registered(); - - template - struct function_arg_to_python : handle<> - { - function_arg_to_python(T const& x); - }; - - template - struct reference_arg_to_python : handle<> - { - reference_arg_to_python(T& x); - private: - static PyObject* get_object(T& x); - }; - - template - struct value_arg_to_python : arg_to_python_base - { - // Throw an exception if the conversion can't succeed - value_arg_to_python(T const&); - }; - - template - struct pointer_deep_arg_to_python : arg_to_python_base - { - // Throw an exception if the conversion can't succeed - pointer_deep_arg_to_python(Ptr); - }; - - template - struct pointer_shallow_arg_to_python : handle<> - { - // Throw an exception if the conversion can't succeed - pointer_shallow_arg_to_python(Ptr); - private: - static PyObject* get_object(Ptr p); - }; - - // Convert types that manage a Python object to_python - template - struct object_manager_arg_to_python - { - object_manager_arg_to_python(T const& x) : m_src(x) {} - - PyObject* get() const - { - return python::upcast(get_managed_object(m_src, tag)); - } - - private: - T const& m_src; - }; - - template - struct select_arg_to_python - { - // Special handling for char const[N]; interpret them as char - // const* for the sake of conversion - BOOST_STATIC_CONSTANT( - bool, is_string = python::detail::is_string_literal::value); - - BOOST_STATIC_CONSTANT( - bool, function = is_function::value | python::detail::is_pointer_to_function::value | is_member_function_pointer::value); - - BOOST_STATIC_CONSTANT( - bool, manager = is_object_manager::value); - - BOOST_STATIC_CONSTANT( - bool, ptr = is_pointer::value); - - BOOST_STATIC_CONSTANT( - bool, ref_wrapper = is_reference_wrapper::value); - - BOOST_STATIC_CONSTANT( - bool, ptr_wrapper = is_pointer_wrapper::value); - - typedef typename unwrap_reference::type unwrapped_referent; - typedef typename unwrap_pointer::type unwrapped_ptr; - - typedef typename mpl::if_c< - is_string - , arg_to_python - , typename mpl::if_c< - function - , function_arg_to_python - , typename mpl::if_c< - manager - , object_manager_arg_to_python - , typename mpl::if_c< - ptr - , pointer_deep_arg_to_python - , typename mpl::if_c< - ptr_wrapper - , pointer_shallow_arg_to_python - , typename mpl::if_c< - ref_wrapper - , reference_arg_to_python - , value_arg_to_python - >::type - >::type - >::type - >::type - >::type - >::type - type; - }; -} - -template -struct arg_to_python - : detail::select_arg_to_python::type -{ - typedef typename detail::select_arg_to_python::type base; - public: // member functions - // Throw an exception if the conversion can't succeed - arg_to_python(T const& x); -}; - -// -// implementations -// -namespace detail -{ - // reject_raw_object_ptr -- cause a compile-time error if the user - // should pass a raw Python object pointer - using python::detail::yes_convertible; - using python::detail::no_convertible; - using python::detail::unspecialized; - - template struct cannot_convert_raw_PyObject; - - template - struct reject_raw_object_helper - { - static void error(Convertibility) - { - cannot_convert_raw_PyObject::to_python_use_handle_instead(); - } - static void error(...) {} - }; - - template - inline void reject_raw_object_ptr(T*) - { - reject_raw_object_helper::error( - python::detail::convertible::check((T*)0)); - - typedef typename remove_cv::type value_type; - - reject_raw_object_helper::error( - python::detail::convertible::check( - (base_type_traits*)0 - )); - } - // --------- - - template - inline function_arg_to_python::function_arg_to_python(T const& x) - : handle<>(python::objects::make_function_handle(x)) - { - } - - template - inline value_arg_to_python::value_arg_to_python(T const& x) - : arg_to_python_base(&x, registered::converters) - { - } - - template - inline pointer_deep_arg_to_python::pointer_deep_arg_to_python(Ptr x) - : arg_to_python_base(x, registered_pointee::converters) - { - detail::reject_raw_object_ptr((Ptr)0); - } - - template - inline PyObject* reference_arg_to_python::get_object(T& x) - { - to_python_indirect convert; - if (!convert.convertible()) - throw_no_class_registered(); - return convert(x); - } - - template - inline reference_arg_to_python::reference_arg_to_python(T& x) - : handle<>(reference_arg_to_python::get_object(x)) - { - } - - template - inline pointer_shallow_arg_to_python::pointer_shallow_arg_to_python(Ptr x) - : handle<>(pointer_shallow_arg_to_python::get_object(x)) - { - detail::reject_raw_object_ptr((Ptr)0); - } - - template - inline PyObject* pointer_shallow_arg_to_python::get_object(Ptr x) - { - to_python_indirect convert; - if (!convert.convertible()) - throw_no_class_registered(); - return x ? convert(x) : python::detail::none(); - } -} - -template -inline arg_to_python::arg_to_python(T const& x) - : base(x) -{} - -}}} // namespace boost::python::converter - -#endif // ARG_TO_PYTHON_DWA200265_HPP diff --git a/include/boost/python/converter/arg_to_python_base.hpp b/include/boost/python/converter/arg_to_python_base.hpp deleted file mode 100755 index 385a7839..00000000 --- a/include/boost/python/converter/arg_to_python_base.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ARG_TO_PYTHON_BASE_DWA200237_HPP -# define ARG_TO_PYTHON_BASE_DWA200237_HPP -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -struct registration; - -namespace detail -{ - struct BOOST_PYTHON_DECL arg_to_python_base -# if !defined(BOOST_MSVC) || BOOST_MSVC <= 1300 || _MSC_FULL_VER > 13102179 - : handle<> -# endif - { - arg_to_python_base(void const volatile* source, registration const&); -# if defined(BOOST_MSVC) && BOOST_MSVC > 1300 && _MSC_FULL_VER <= 13102179 - PyObject* get() const { return m_ptr.get(); } - PyObject* release() { return m_ptr.release(); } - private: - handle<> m_ptr; -# endif - }; -} - -}}} // namespace boost::python::converter - -#endif // ARG_TO_PYTHON_BASE_DWA200237_HPP diff --git a/include/boost/python/converter/builtin_converters.hpp b/include/boost/python/converter/builtin_converters.hpp deleted file mode 100644 index aebfd459..00000000 --- a/include/boost/python/converter/builtin_converters.hpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef BUILTIN_CONVERTERS_DWA2002124_HPP -# define BUILTIN_CONVERTERS_DWA2002124_HPP -# include -# include -# include -# include -# include - -// Since all we can use to decide how to convert an object to_python -// is its C++ type, there can be only one such converter for each -// type. Therefore, for built-in conversions we can bypass registry -// lookups using explicit specializations of arg_to_python and -// result_to_python. - -namespace boost { namespace python { - -namespace converter -{ - template struct arg_to_python; - BOOST_PYTHON_DECL PyObject* do_return_to_python(char); - BOOST_PYTHON_DECL PyObject* do_return_to_python(char const*); - BOOST_PYTHON_DECL PyObject* do_return_to_python(PyObject*); - BOOST_PYTHON_DECL PyObject* do_arg_to_python(PyObject*); -} - -// Provide specializations of to_python_value -template struct to_python_value; - -namespace detail -{ - // Since there's no registry lookup, always report the existence of - // a converter. - struct builtin_to_python - { - static bool convertible() { return true; } - }; -} - -// Use expr to create the PyObject corresponding to x -# define BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(T, expr) \ - template <> struct to_python_value \ - : detail::builtin_to_python \ - { \ - inline PyObject* operator()(T const& x) const \ - { \ - return (expr); \ - } \ - }; \ - template <> struct to_python_value \ - : detail::builtin_to_python \ - { \ - inline PyObject* operator()(T const& x) const \ - { \ - return (expr); \ - } \ - }; - -# define BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T, expr) \ - namespace converter \ - { \ - template <> struct arg_to_python< T > \ - : handle<> \ - { \ - arg_to_python(T const& x) \ - : python::handle<>(expr) {} \ - }; \ - } - -// Specialize argument and return value converters for T using expr -# define BOOST_PYTHON_TO_PYTHON_BY_VALUE(T, expr) \ - BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(T,expr) \ - BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T,expr) - -// Specialize converters for signed and unsigned T to Python Int -# define BOOST_PYTHON_TO_INT(T) \ - BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, PyInt_FromLong(x)) \ - BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned T, PyInt_FromLong(x)) - -// Bool is not signed. -BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, PyInt_FromLong(x)) - -// note: handles signed char and unsigned char, but not char (see below) -BOOST_PYTHON_TO_INT(char) - -BOOST_PYTHON_TO_INT(short) -BOOST_PYTHON_TO_INT(int) -BOOST_PYTHON_TO_INT(long) - -// using Python's macro instead of Boost's - we don't seem to get the -// config right all the time. -# ifdef HAVE_LONG_LONG -BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed LONG_LONG, PyLong_FromLongLong(x)) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned LONG_LONG, PyLong_FromUnsignedLongLong(x)) -# endif - -# undef BOOST_TO_PYTHON_INT - -BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x)) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x)) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, PyString_FromString(x.c_str())) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, PyFloat_FromDouble(x)) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, PyFloat_FromDouble(x)) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, PyFloat_FromDouble(x)) -BOOST_PYTHON_RETURN_TO_PYTHON_BY_VALUE(PyObject*, converter::do_return_to_python(x)) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex, PyComplex_FromDoubles(x.real(), x.imag())) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex, PyComplex_FromDoubles(x.real(), x.imag())) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex, PyComplex_FromDoubles(x.real(), x.imag())) - -namespace converter -{ - - void initialize_builtin_converters(); - -} - -}} // namespace boost::python::converter - -#endif // BUILTIN_CONVERTERS_DWA2002124_HPP diff --git a/include/boost/python/converter/callback.hpp b/include/boost/python/converter/callback.hpp deleted file mode 100644 index d11dfcb1..00000000 --- a/include/boost/python/converter/callback.hpp +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CALLBACK_DWA2002228_HPP -# define CALLBACK_DWA2002228_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -namespace detail -{ - template - struct pointer_callback_from_python - { - pointer_callback_from_python(); - T operator()(PyObject*) const; - }; - - template - struct reference_callback_from_python - { - reference_callback_from_python(); - T operator()(PyObject*) const; - }; - - template - struct rvalue_callback_from_python - { - rvalue_callback_from_python(); - T const& operator()(PyObject*); - private: - rvalue_data m_data; - }; - - template - struct select_callback_from_python - { - BOOST_STATIC_CONSTANT( - bool, ptr = is_pointer::value); - - BOOST_STATIC_CONSTANT( - bool, ref = is_reference::value); - - typedef typename mpl::select_if_c< - ptr - , pointer_callback_from_python - , typename mpl::select_if_c< - ref - , reference_callback_from_python - , rvalue_callback_from_python - >::type - >::type type; - }; - - - template - struct reference_callback_to_python : callback_to_python_holder - { - reference_callback_to_python(T& x); - private: - static PyObject* get_object(T& x); - }; - - template - struct value_callback_to_python : callback_to_python_base - { - // Throw an exception if the conversion can't succeed - value_callback_to_python(T const&); - }; - - template - struct pointer_deep_callback_to_python : callback_to_python_base - { - // Throw an exception if the conversion can't succeed - pointer_deep_callback_to_python(Ptr); - }; - - template - struct pointer_shallow_callback_to_python : callback_to_python_holder - { - // Throw an exception if the conversion can't succeed - pointer_shallow_callback_to_python(Ptr); - private: - static PyObject* get_object(Ptr p); - }; - - template - struct select_callback_to_python - { - BOOST_STATIC_CONSTANT( - bool, ptr = is_pointer::value); - - BOOST_STATIC_CONSTANT( - bool, ref_wrapper = is_reference_wrapper::value); - - BOOST_STATIC_CONSTANT( - bool, ptr_wrapper = is_pointer_wrapper::value); - - typedef typename unwrap_reference::type unwrapped_referent; - typedef typename unwrap_pointer::type unwrapped_ptr; - - typedef typename mpl::select_if_c< - ptr - , pointer_deep_callback_to_python - , typename mpl::select_if_c< - ptr_wrapper - , pointer_shallow_callback_to_python - , typename mpl::select_if_c< - ref_wrapper - , reference_callback_to_python - , value_callback_to_python - >::type - >::type - >::type type; - }; -} - -template -struct callback_from_python - : detail::select_callback_from_python::type -{ - typedef T result_type; -}; - -struct void_result -{ - private: - void_result() {} - void operator=(void_result const&); - - // I would prefer to make this completely untouchable, but few - // compilers support template friends -# if 0 - void_result(void_result const&); -# endif - friend struct callback_from_python; -}; - -// Specialization as a convenience for call and call_method -template <> -struct callback_from_python -{ - typedef void_result result_type; - result_type operator()(PyObject* x) const - { - Py_DECREF(expect_non_null(x)); - return result_type(); - } -}; - -template -struct callback_to_python - : detail::select_callback_to_python::type -{ - typedef typename detail::select_callback_to_python::type base; - public: // member functions - // Throw an exception if the conversion can't succeed - callback_to_python(T const& x); -}; - -// Convenience macros for call<> and call_method<> code generation -# define BOOST_PYTHON_CALLBACK_TO_PYTHON_GET(index,ignored) \ - converter::callback_to_python( \ - BOOST_PP_CAT(a,index)).get() - -# define BOOST_PYTHON_ARG_STRING(nargs) \ - "(" BOOST_PP_REPEAT(nargs,BOOST_PYTHON_PROJECT_2ND,"O") ")" - -// -// Implementations -// -namespace detail -{ - template - inline rvalue_callback_from_python::rvalue_callback_from_python() - : m_data(rvalue_from_python_chain::value) - { - throw_if_not_registered(m_data.stage1); - } - - template - inline T const& rvalue_callback_from_python::operator()(PyObject* obj) - { - return *(T*)convert_rvalue(obj, m_data.stage1, m_data.storage.bytes); - } - - BOOST_PYTHON_DECL void throw_no_class_registered(); - - template - inline reference_callback_from_python::reference_callback_from_python() - { - detail::throw_if_not_registered(lvalue_from_python_chain::value); - } - - template - inline T reference_callback_from_python::operator()(PyObject* obj) const - { - return python::detail::void_ptr_to_reference( - callback_convert_reference(obj, lvalue_from_python_chain::value) - , (T(*)())0); - } - - template - inline pointer_callback_from_python::pointer_callback_from_python() - { - detail::throw_if_not_registered(lvalue_from_python_chain::value); - } - - template - inline T pointer_callback_from_python::operator()(PyObject* obj) const - { - return T(callback_convert_pointer(obj, lvalue_from_python_chain::value)); - } - - template - inline value_callback_to_python::value_callback_to_python(T const& x) - : callback_to_python_base(&x, to_python_function::value) - { - } - - template - inline pointer_deep_callback_to_python::pointer_deep_callback_to_python(Ptr x) - : callback_to_python_base(x, pointee_to_python_function::value) - { - } - - template - inline PyObject* reference_callback_to_python::get_object(T& x) - { - to_python_indirect convert; - if (!convert.convertible()) - throw_no_class_registered(); - return convert(x); - } - - template - inline reference_callback_to_python::reference_callback_to_python(T& x) - : callback_to_python_holder(get_object(x)) - { - } - - template - inline pointer_shallow_callback_to_python::pointer_shallow_callback_to_python(Ptr x) - : callback_to_python_holder(get_object(x)) - {} - - template - inline PyObject* pointer_shallow_callback_to_python::get_object(Ptr x) - { - to_python_indirect convert; - if (!convert.convertible()) - throw_no_class_registered(); - return x ? convert(x) : python::detail::none(); - } -} - -template -inline callback_to_python::callback_to_python(T const& x) - : base(x) -{} - -}}} // namespace boost::python::converter - -#endif // CALLBACK_DWA2002228_HPP diff --git a/include/boost/python/converter/callback_from_python_base.hpp b/include/boost/python/converter/callback_from_python_base.hpp deleted file mode 100644 index 117ba145..00000000 --- a/include/boost/python/converter/callback_from_python_base.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CALLBACK_FROM_PYTHON_BASE_DWA200237_HPP -# define CALLBACK_FROM_PYTHON_BASE_DWA200237_HPP - -namespace boost { namespace python { namespace converter { - -namespace detail -{ - - // Throw an exception - BOOST_PYTHON_DECL void throw_if_not_registered(rvalue_stage1_data const&); - BOOST_PYTHON_DECL void* convert_rvalue(PyObject*, rvalue_stage1_data& data, void* storage); - - BOOST_PYTHON_DECL void throw_if_not_registered(lvalue_from_python_registration*const&); - BOOST_PYTHON_DECL void* callback_convert_reference(PyObject*, lvalue_from_python_registration*const&); - BOOST_PYTHON_DECL void* callback_convert_pointer(PyObject*, lvalue_from_python_registration*const&); -} - -}}} // namespace boost::python::converter - -#endif // CALLBACK_FROM_PYTHON_BASE_DWA200237_HPP diff --git a/include/boost/python/converter/callback_to_python_base.hpp b/include/boost/python/converter/callback_to_python_base.hpp deleted file mode 100644 index c878850e..00000000 --- a/include/boost/python/converter/callback_to_python_base.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CALLBACK_TO_PYTHON_BASE_DWA200237_HPP -# define CALLBACK_TO_PYTHON_BASE_DWA200237_HPP -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -namespace detail -{ - struct callback_to_python_holder - { - callback_to_python_holder(PyObject* obj); - inline PyObject* get() const; - private: - ref m_held; - }; - - struct BOOST_PYTHON_DECL callback_to_python_base : callback_to_python_holder - { - callback_to_python_base(void const volatile* source, to_python_function_t); - }; - - // - // implmentation - // - inline callback_to_python_holder::callback_to_python_holder(PyObject* obj) - : m_held(obj) - { - } - - inline PyObject* callback_to_python_holder::get() const - { - return m_held.get(); - } -} - -}}} // namespace boost::python::converter - -#endif // CALLBACK_TO_PYTHON_BASE_DWA200237_HPP diff --git a/include/boost/python/converter/constructor_function.hpp b/include/boost/python/converter/constructor_function.hpp deleted file mode 100644 index f3c49bd4..00000000 --- a/include/boost/python/converter/constructor_function.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CONSTRUCTOR_FUNCTION_DWA200278_HPP -# define CONSTRUCTOR_FUNCTION_DWA200278_HPP - -namespace boost { namespace python { namespace converter { - -// Declares the type of functions used to construct C++ objects for -// rvalue from_python conversions. -struct rvalue_from_python_stage1_data; -typedef void (*constructor_function)(PyObject* source, rvalue_from_python_stage1_data*); - -}}} // namespace boost::python::converter - -#endif // CONSTRUCTOR_FUNCTION_DWA200278_HPP diff --git a/include/boost/python/converter/convertible_function.hpp b/include/boost/python/converter/convertible_function.hpp deleted file mode 100644 index 98db1cfb..00000000 --- a/include/boost/python/converter/convertible_function.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CONVERTIBLE_FUNCTION_DWA200278_HPP -# define CONVERTIBLE_FUNCTION_DWA200278_HPP - -namespace boost { namespace python { namespace converter { - -typedef void* (*convertible_function)(PyObject*); - -}}} // namespace boost::python::converter - -#endif // CONVERTIBLE_FUNCTION_DWA200278_HPP diff --git a/include/boost/python/converter/find_from_python.hpp b/include/boost/python/converter/find_from_python.hpp deleted file mode 100644 index 709c5de0..00000000 --- a/include/boost/python/converter/find_from_python.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FIND_FROM_PYTHON_DWA2002223_HPP -# define FIND_FROM_PYTHON_DWA2002223_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -struct lvalue_from_python_registration; -struct rvalue_from_python_registration; - -BOOST_PYTHON_DECL void* find( - PyObject* source, lvalue_from_python_registration const*); - -BOOST_PYTHON_DECL rvalue_stage1_data find( - PyObject* source, rvalue_from_python_registration const*); - -BOOST_PYTHON_DECL rvalue_from_python_registration const* find_chain( - PyObject* source, rvalue_from_python_registration const*); - -}}} // namespace boost::python::converter - -#endif // FIND_FROM_PYTHON_DWA2002223_HPP diff --git a/include/boost/python/converter/from_python.hpp b/include/boost/python/converter/from_python.hpp deleted file mode 100644 index dabafcaa..00000000 --- a/include/boost/python/converter/from_python.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FIND_FROM_PYTHON_DWA2002223_HPP -# define FIND_FROM_PYTHON_DWA2002223_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -struct registration; -struct rvalue_from_python_chain; - -BOOST_PYTHON_DECL void* get_lvalue_from_python( - PyObject* source, registration const&); - -BOOST_PYTHON_DECL rvalue_from_python_chain const* implicit_conversion_chain( - PyObject* source, registration const&); - -BOOST_PYTHON_DECL rvalue_from_python_stage1_data rvalue_from_python_stage1( - PyObject* source, registration const&); - -BOOST_PYTHON_DECL void* rvalue_from_python_stage2( - PyObject* source, rvalue_from_python_stage1_data&, registration const&); - -BOOST_PYTHON_DECL void* rvalue_result_from_python( - PyObject*, rvalue_from_python_stage1_data&); - -BOOST_PYTHON_DECL void* reference_result_from_python(PyObject*, registration const&); -BOOST_PYTHON_DECL void* pointer_result_from_python(PyObject*, registration const&); - -BOOST_PYTHON_DECL void void_result_from_python(PyObject*); - -BOOST_PYTHON_DECL void throw_no_pointer_from_python(PyObject*, registration const&); -BOOST_PYTHON_DECL void throw_no_reference_from_python(PyObject*, registration const&); - -}}} // namespace boost::python::converter - -#endif // FIND_FROM_PYTHON_DWA2002223_HPP diff --git a/include/boost/python/converter/from_python_data.hpp b/include/boost/python/converter/from_python_data.hpp deleted file mode 100644 index a71c6548..00000000 --- a/include/boost/python/converter/from_python_data.hpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FROM_PYTHON_AUX_DATA_DWA2002128_HPP -# define FROM_PYTHON_AUX_DATA_DWA2002128_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -namespace detail -{ - template struct referent_size; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - - template - struct referent_size - { - BOOST_STATIC_CONSTANT( - std::size_t, value = sizeof(T)); - }; - -# else - - template struct referent_size - { - static T f(); - BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(f())); - }; - -# endif - struct alignment_dummy; - typedef void (*function_ptr)(); - typedef int (alignment_dummy::*member_ptr); - typedef int (alignment_dummy::*member_function_ptr)(); - -# define BOOST_PYTHON_ALIGNMENT_TYPES BOOST_PP_TUPLE_TO_LIST( \ - 11, ( \ - char, short, int, long, float, double, long double \ - , void*, function_ptr, member_ptr, member_function_ptr)) - -# define BOOST_PYTHON_CHOOSE_LOWER_SIZE(R,P,I,T) \ - typename mpl::select_if_c< \ - sizeof(T) <= target, T, char>::type BOOST_PP_CAT(t,I); - -# define BOOST_PYTHON_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I); - - template - union lower_size - { - BOOST_PP_LIST_FOR_EACH_I( - BOOST_PYTHON_CHOOSE_LOWER_SIZE - , ignored, BOOST_PYTHON_ALIGNMENT_TYPES) - }; - - template - union aligned_storage - { - Align align; - char bytes[size]; - }; - - template - struct referent_storage - { - typedef lower_size::value> align_t; - typedef aligned_storage::value> type; - }; -} - -template -struct rvalue_base_data -{ - rvalue_stage1_data stage1; - - typename detail::referent_storage< - typename add_reference::type - >::type storage; -}; - -template -struct rvalue_data : rvalue_base_data -{ - rvalue_data(rvalue_stage1_data const&); - rvalue_data(void*); - ~rvalue_data(); - private: - typedef typename add_reference::type>::type ref_type; -}; - -// -// Implementataions -// -template -inline rvalue_data::rvalue_data(rvalue_stage1_data const& stage1) -{ - this->stage1 = stage1; -} - -template -inline rvalue_data::rvalue_data(void* convertible) -{ - this->stage1.convertible = convertible; -} - -template -inline rvalue_data::~rvalue_data() -{ - if (this->stage1.convertible == this->storage.bytes) - python::detail::destroy_reference(this->storage.bytes); -} - -}}} // namespace boost::python::converter - -#endif // FROM_PYTHON_AUX_DATA_DWA2002128_HPP diff --git a/include/boost/python/converter/from_python_function.hpp b/include/boost/python/converter/from_python_function.hpp deleted file mode 100644 index eea96372..00000000 --- a/include/boost/python/converter/from_python_function.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FROM_PYTHON_FUNCTION_DWA2002128_HPP -# define FROM_PYTHON_FUNCTION_DWA2002128_HPP - -# include - -namespace boost { namespace python { namespace converter { - -struct rvalue_stage1_data; -typedef void (*constructor_function)(PyObject* source, rvalue_stage1_data*); - -}}} // namespace boost::python::converter - -#endif // FROM_PYTHON_FUNCTION_DWA2002128_HPP diff --git a/include/boost/python/converter/from_python_stage1_data.hpp b/include/boost/python/converter/from_python_stage1_data.hpp deleted file mode 100644 index 50fd74ad..00000000 --- a/include/boost/python/converter/from_python_stage1_data.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FROM_PYTHON_STAGE1_DATA_DWA2002223_HPP -# define FROM_PYTHON_STAGE1_DATA_DWA2002223_HPP - -# include - -namespace boost { namespace python { namespace converter { - -struct rvalue_stage1_data -{ - void* convertible; - constructor_function construct; -}; - -}}} // namespace boost::python::converter - -#endif // FROM_PYTHON_STAGE1_DATA_DWA2002223_HPP diff --git a/include/boost/python/converter/implicit.hpp b/include/boost/python/converter/implicit.hpp deleted file mode 100644 index 79a398aa..00000000 --- a/include/boost/python/converter/implicit.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef IMPLICIT_DWA2002326_HPP -# define IMPLICIT_DWA2002326_HPP -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -template -struct implicit -{ - static void* convertible(PyObject* obj) - { - // Find a converter chain which can produce a Source instance - // from obj. The user has told us that Source can be converted - // to Target, and instantiating construct() below, ensures - // that at compile-time. - return const_cast( - converter::implicit_conversion_chain(obj, registered::converters)); - } - - static void construct(PyObject* obj, rvalue_from_python_stage1_data* data) - { - // This is the chain we got from the convertible step - rvalue_from_python_chain const* chain - = static_cast(data->convertible); - - // Call the convertible function again - rvalue_from_python_data intermediate_data(chain->convertible(obj)); - - // Use the result to construct the source type if the first - // converter was an rvalue converter. - if (chain->construct != 0) - chain->construct(obj, &intermediate_data.stage1); - - void* storage = ((rvalue_from_python_storage*)data)->storage.bytes; -# if !defined(BOOST_MSVC) || _MSC_FULL_VER != 13012108 // vc7.01 alpha workaround - new (storage) Target(*static_cast(intermediate_data.stage1.convertible)); -# else - Target x(*static_cast(intermediate_data.stage1.convertible)); - new (storage) Target(x); -# endif - - // record successful construction - data->convertible = storage; - - } -}; - -}}} // namespace boost::python::converter - -#endif // IMPLICIT_DWA2002326_HPP diff --git a/include/boost/python/converter/lvalue_from_python_chain.hpp b/include/boost/python/converter/lvalue_from_python_chain.hpp deleted file mode 100644 index a58b4309..00000000 --- a/include/boost/python/converter/lvalue_from_python_chain.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP -# define LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -// Given T == U*cv&, T == U*, or T == U&, lvalue_from_python_chain -// declares a "templated global reference" to the lvalue from_python -// converter chain for U. The optional bool second argument callback, -// when true, removes special treatment for T == U*cv& so that the -// converter for U* is found. -namespace detail -{ - template - struct ptr_or_ptr_ref_lvalue_from_python_chain - { - static lvalue_from_python_registration*const& value; - }; - - template - lvalue_from_python_registration*const& - ptr_or_ptr_ref_lvalue_from_python_chain::value - = registry::lvalue_converters(pointer_type_id()); - - template - struct ref_lvalue_from_python_chain - { - static lvalue_from_python_registration*const& value; - }; - - template - lvalue_from_python_registration*const& - ref_lvalue_from_python_chain::value - = registry::lvalue_converters(undecorated_type_id()); - - template - struct select_lvalue_from_python_chain - { - BOOST_STATIC_CONSTANT( - bool, ptr - = !callback && boost::python::detail::is_reference_to_pointer::value - || is_pointer::value); - - typedef typename add_reference::type>::type normalized; - - typedef typename mpl::select_if_c< - ptr - , ptr_or_ptr_ref_lvalue_from_python_chain - , ref_lvalue_from_python_chain - >::type type; - }; -} - -template -struct lvalue_from_python_chain - : detail::select_lvalue_from_python_chain::type -{ -}; - -}}} // namespace boost::python::converter - -#endif // LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP diff --git a/include/boost/python/converter/obj_mgr_arg_from_python.hpp b/include/boost/python/converter/obj_mgr_arg_from_python.hpp deleted file mode 100644 index 75b0ae43..00000000 --- a/include/boost/python/converter/obj_mgr_arg_from_python.hpp +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP -# define OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP - -# include -# include -# include -# include -# include -# include -# include - -// -// arg_from_python converters for Python type wrappers, to be used as -// base classes for specializations. -// -namespace boost { namespace python { namespace converter { - -template -struct object_manager_value_arg_from_python -{ - typedef T result_type; - - object_manager_value_arg_from_python(PyObject*); - bool convertible() const; - T operator()(PyObject*) const; - private: - PyObject* m_source; -}; - -// Used for converting reference-to-object-manager arguments from -// python. The process used here is a little bit odd. Upon -// construction, we build the object manager object in the m_result -// object, *forcing* it to accept the source Python object by casting -// its pointer to detail::borrowed_reference. This is supposed to -// bypass any type checking of the source object. The convertible -// check then extracts the owned object and checks it. If the check -// fails, nothing else in the program ever gets to touch this strange -// "forced" object. -template -struct object_manager_ref_arg_from_python -{ - typedef Ref result_type; - - object_manager_ref_arg_from_python(PyObject*); - bool convertible() const; - Ref operator()(PyObject*) const; - ~object_manager_ref_arg_from_python(); - private: - typename python::detail::referent_storage::type m_result; -}; - -// -// implementations -// - -template -inline object_manager_value_arg_from_python::object_manager_value_arg_from_python(PyObject* x) - : m_source(x) -{ -} - -template -inline bool object_manager_value_arg_from_python::convertible() const -{ - return object_manager_traits::check(m_source); -} - -template -inline T object_manager_value_arg_from_python::operator()(PyObject* x) const -{ - return T(python::detail::borrowed_reference(x)); -} - -template -inline object_manager_ref_arg_from_python::object_manager_ref_arg_from_python(PyObject* x) -{ - python::detail::construct_referent(&m_result.bytes, python::detail::borrowed_reference(x)); -} - -template -inline object_manager_ref_arg_from_python::~object_manager_ref_arg_from_python() -{ - python::detail::destroy_referent(this->m_result.bytes); -} - -namespace detail -{ - template - inline bool object_manager_ref_check(T const& x) - { - return object_manager_traits::check(get_managed_object(x, tag)); - } -} - -template -inline bool object_manager_ref_arg_from_python::convertible() const -{ - return detail::object_manager_ref_check( - python::detail::void_ptr_to_reference(this->m_result.bytes, (Ref(*)())0)); -} - -template -inline Ref object_manager_ref_arg_from_python::operator()(PyObject*) const -{ - return python::detail::void_ptr_to_reference( - this->m_result.bytes, (Ref(*)())0); -} - -}}} // namespace boost::python::converter - -#endif // OBJ_MGR_ARG_FROM_PYTHON_DWA2002628_HPP diff --git a/include/boost/python/converter/object_manager.hpp b/include/boost/python/converter/object_manager.hpp deleted file mode 100755 index 974c149b..00000000 --- a/include/boost/python/converter/object_manager.hpp +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_MANAGER_DWA2002614_HPP -# define OBJECT_MANAGER_DWA2002614_HPP - -# include -# include -# include -# include -# include -# include - -// Facilities for dealing with types which always manage Python -// objects. Some examples are object, list, str, et. al. Different -// to_python/from_python conversion rules apply here because in -// contrast to other types which are typically embedded inside a -// Python object, these are wrapped around a Python object. For most -// object managers T, a C++ non-const T reference argument does not -// imply the existence of a T lvalue embedded in the corresponding -// Python argument, since mutating member functions on T actually only -// modify the held Python object. -// -// handle is an object manager, though strictly speaking it should -// not be. In other words, even though mutating member functions of -// hanlde actually modify the handle and not the T object, -// handle& arguments of wrapped functions will bind to "rvalues" -// wrapping the actual Python argument, just as with other object -// manager classes. Making an exception for handle is simply not -// worth the trouble. -// -// borrowed cv* is an object manager so that we can use the general -// to_python mechanisms to convert raw Python object pointers to -// python, without the usual semantic problems of using raw pointers. - - -// Object Manager Concept requirements: -// -// T is an Object Manager -// p is a PyObject* -// x is a T -// -// * object_manager_traits::is_specialized == true -// -// * T(detail::borrowed_reference(p)) -// Manages p without checking its type -// -// * get_managed_object(x, boost::python::tag) -// Convertible to PyObject* -// -// Additional requirements if T can be converted from_python: -// -// * T(object_manager_traits::adopt(p)) -// steals a reference to p, or throws a TypeError exception if -// p doesn't have an appropriate type. May assume p is non-null -// -// * X::check(p) -// convertible to bool. True iff T(X::construct(p)) will not -// throw. - -// Forward declarations -// -namespace boost { namespace python -{ - namespace api - { - class object; - } -}} - -namespace boost { namespace python { namespace converter { - - -// Specializations for handle -template -struct handle_object_manager_traits - : pyobject_traits -{ - private: - typedef pyobject_traits base; - - public: - BOOST_STATIC_CONSTANT(bool, is_specialized = true); - - // Initialize with a null_ok pointer for efficiency, bypassing the - // null check since the source is always non-null. - static null_ok* adopt(PyObject* p) - { - return python::allow_null(base::checked_downcast(p)); - } -}; - -template -struct default_object_manager_traits -{ - BOOST_STATIC_CONSTANT( - bool, is_specialized = python::detail::is_borrowed_ptr::value - ); -}; - -template -struct object_manager_traits - : mpl::if_c< - is_handle::value - , handle_object_manager_traits - , default_object_manager_traits - >::type -{ -}; - -// -// Traits for detecting whether a type is an object manager or a -// (cv-qualified) reference to an object manager. -// - -template -struct is_object_manager -{ - BOOST_STATIC_CONSTANT( - bool, value = object_manager_traits::is_specialized); -}; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct is_reference_to_object_manager -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_reference_to_object_manager - : is_object_manager -{ -}; - -template -struct is_reference_to_object_manager - : is_object_manager -{ -}; - -template -struct is_reference_to_object_manager - : is_object_manager -{ -}; - -template -struct is_reference_to_object_manager - : is_object_manager -{ -}; -# else - -namespace detail -{ - typedef char (&yes_reference_to_object_manager)[1]; - typedef char (&no_reference_to_object_manager)[2]; - - // A number of nastinesses go on here in order to work around MSVC6 - // bugs. - template - struct is_object_manager_help - { - typedef typename mpl::if_c< - is_object_manager::value - , yes_reference_to_object_manager - , no_reference_to_object_manager - >::type type; - - // If we just use the type instead of the result of calling this - // function, VC6 will ICE. - static type call(); - }; - - // A set of overloads for each cv-qualification. The same argument - // is passed twice: the first one is used to unwind the cv*, and the - // second one is used to avoid relying on partial ordering for - // overload resolution. - template - typename is_object_manager_help - is_object_manager_helper(U*, void*); - - template - typename is_object_manager_help - is_object_manager_helper(U const*, void const*); - - template - typename is_object_manager_help - is_object_manager_helper(U volatile*, void volatile*); - - template - typename is_object_manager_help - is_object_manager_helper(U const volatile*, void const volatile*); - - template - struct is_reference_to_object_manager_nonref - { - BOOST_STATIC_CONSTANT(bool, value = false); - }; - - template - struct is_reference_to_object_manager_ref - { - static T sample_object; - BOOST_STATIC_CONSTANT( - bool, value - = (sizeof(is_object_manager_helper(&sample_object, &sample_object).call()) - == sizeof(detail::yes_reference_to_object_manager) - ) - ); - }; -} - -template -struct is_reference_to_object_manager -{ - typedef typename mpl::if_c< - is_reference::value - , detail::is_reference_to_object_manager_ref - , detail::is_reference_to_object_manager_nonref - > chooser; - - BOOST_STATIC_CONSTANT(bool, value = chooser::type::value); -}; -# endif - -}}} // namespace boost::python::converter - -#endif // OBJECT_MANAGER_DWA2002614_HPP diff --git a/include/boost/python/converter/pointee_to_python_function.hpp b/include/boost/python/converter/pointee_to_python_function.hpp deleted file mode 100644 index 0f1ae99e..00000000 --- a/include/boost/python/converter/pointee_to_python_function.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef POINTEE_TO_PYTHON_FUNCTION_DWA2002128_HPP -# define POINTEE_TO_PYTHON_FUNCTION_DWA2002128_HPP - -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -// pointee_to_python_function -- -// -// essentially a "templated global reference" which holds the -// converter for converting a type to Python by-value. We "normalize" -// T by adding "const volatile&" so that fewer global variables and -// associated static initializations are generated. -namespace detail -{ - template - struct pointee_to_python_function_base - { - static to_python_function_t const& value; - }; - - template - to_python_function_t const& - pointee_to_python_function_base::value - = converter::registry::get_to_python_function(pointer_type_id()); -} - -template -struct pointee_to_python_function - : detail::pointee_to_python_function_base< - typename add_reference< - typename add_cv::type - >::type - > -{ -}; - -}}} // namespace boost::python::converter - -#endif // POINTEE_TO_PYTHON_FUNCTION_DWA2002128_HPP diff --git a/include/boost/python/converter/pointer_type_id.hpp b/include/boost/python/converter/pointer_type_id.hpp deleted file mode 100644 index 01e55977..00000000 --- a/include/boost/python/converter/pointer_type_id.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef POINTER_TYPE_ID_DWA2002222_HPP -# define POINTER_TYPE_ID_DWA2002222_HPP - -# include -# include - -namespace boost { namespace python { namespace converter { - -namespace detail -{ - template - struct pointer_typeid_select - { - template - static inline type_info execute(T*(*)() = 0) - { - return type_id(); - } - }; - - template <> - struct pointer_typeid_select - { - template - static inline type_info execute(T* const volatile&(*)() = 0) - { - return type_id(); - } - - template - static inline type_info execute(T*volatile&(*)() = 0) - { - return type_id(); - } - - template - static inline type_info execute(T*const&(*)() = 0) - { - return type_id(); - } - - template - static inline type_info execute(T*&(*)() = 0) - { - return type_id(); - } - }; -} - -// Usage: pointer_type_id() -// -// Returns a type_info associated with the type pointed -// to by T, which may be a pointer or a reference to a pointer. -template -type_info pointer_type_id(T(*)() = 0) -{ - return detail::pointer_typeid_select< - is_reference::value - >::execute((T(*)())0); -} - -}}} // namespace boost::python::converter - -#endif // POINTER_TYPE_ID_DWA2002222_HPP diff --git a/include/boost/python/converter/pyobject_traits.hpp b/include/boost/python/converter/pyobject_traits.hpp deleted file mode 100644 index f975360c..00000000 --- a/include/boost/python/converter/pyobject_traits.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef PYOBJECT_TRAITS_DWA2002720_HPP -# define PYOBJECT_TRAITS_DWA2002720_HPP - -# include -# include - -namespace boost { namespace python { namespace converter { - -template struct pyobject_traits; - -template <> -struct pyobject_traits -{ - // All objects are convertible to PyObject - static bool check(PyObject*) { return true; } - static PyObject* checked_downcast(PyObject* x) { return x; } -}; - -// -// Specializations -// - -# define BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(T) \ - template <> struct pyobject_traits \ - : pyobject_type {} - -// This is not an exhaustive list; should be expanded. -BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Type); -BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(List); -BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Int); -BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Long); -BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Dict); -BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Tuple); - -}}} // namespace boost::python::converter - -#endif // PYOBJECT_TRAITS_DWA2002720_HPP diff --git a/include/boost/python/converter/pyobject_type.hpp b/include/boost/python/converter/pyobject_type.hpp deleted file mode 100644 index 63127d5b..00000000 --- a/include/boost/python/converter/pyobject_type.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef PYOBJECT_TYPE_DWA2002720_HPP -# define PYOBJECT_TYPE_DWA2002720_HPP - -# include -# include - -namespace boost { namespace python { namespace converter { - -BOOST_PYTHON_DECL PyObject* checked_downcast_impl(PyObject*, PyTypeObject*); - -// Used as a base class for specializations which need to provide -// Python type checking capability. -template -struct pyobject_type -{ - static bool check(PyObject* x) - { - return ::PyObject_IsInstance(x, (PyObject*)pytype); - } - - static Object* checked_downcast(PyObject* x) - { - return python::downcast( - (checked_downcast_impl)(x, pytype) - ); - } -}; - -}}} // namespace boost::python::converter - -#endif // PYOBJECT_TYPE_DWA2002720_HPP diff --git a/include/boost/python/converter/pytype_arg_from_python.hpp b/include/boost/python/converter/pytype_arg_from_python.hpp deleted file mode 100644 index ade4fd66..00000000 --- a/include/boost/python/converter/pytype_arg_from_python.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP -# define PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP - -# include - -// -// arg_from_python converters for Python type wrappers, to be used as -// base classes for specializations. -// -namespace boost { namespace python { namespace converter { - -template -struct pytype_arg_from_python -{ - pytype_arg_from_python(PyObject*); - bool convertible() const; - private: - PyObject* m_src; -}; - -// rvalue converter base -template -struct pytype_wrapper_value_arg_from_python - : pytype_arg_from_python -{ - typedef Wrapper result_type; - - pytype_wrapper_value_arg_from_python(PyObject*); - Wrapper operator()(PyObject*) const; -}; - -// Special case for Wrapper& - must store an lvalue internally. This -// OK because the entire state of the object is actually in the Python -// object. -template -struct pytype_wrapper_ref_arg_from_python - : pytype_arg_from_python -{ - typedef Wrapper& result_type; - - pytype_wrapper_ref_arg_from_python(PyObject*); - Wrapper& operator()(PyObject*) const; - private: - mutable Wrapper m_result; -}; - -// -// implementations -// - -template -inline pytype_arg_from_python::pytype_arg_from_python(PyObject* x) - : m_src(x) -{ -} - -template -inline bool pytype_arg_from_python::convertible() const -{ - return PyObject_IsInstance(m_src, (PyObject*)python_type); -} - -template -pytype_wrapper_value_arg_from_python::pytype_wrapper_value_arg_from_python( - PyObject* p) - : pytype_arg_from_python(p) -{ -} - -template -Wrapper pytype_wrapper_value_arg_from_python::operator()( - PyObject* x) const -{ - return Wrapper(python::detail::borrowed_reference(x)); -} - -template -pytype_wrapper_ref_arg_from_python::pytype_wrapper_ref_arg_from_python( - PyObject* p) - : pytype_arg_from_python(p) - , m_result(python::detail::borrowed_reference(p)) -{ -} - -template -Wrapper& pytype_wrapper_ref_arg_from_python::operator()( - PyObject* x) const -{ - return m_result; -} - -}}} // namespace boost::python::converter - -#endif // PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP diff --git a/include/boost/python/converter/pytype_object_mgr_traits.hpp b/include/boost/python/converter/pytype_object_mgr_traits.hpp deleted file mode 100644 index 94cbae64..00000000 --- a/include/boost/python/converter/pytype_object_mgr_traits.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP -# define PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP - -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -// Provide a forward declaration as a convenience for clients, who all -// need it. -template struct object_manager_traits; - -// Derive specializations of object_manager_traits from this class -// when T is an object manager for a particular Python type hierarchy. -// -template -struct pytype_object_manager_traits - : pyobject_type // provides check() -{ - BOOST_STATIC_CONSTANT(bool, is_specialized = true); - static inline python::detail::new_reference adopt(PyObject*); -}; - -// -// implementations -// -template -inline python::detail::new_reference pytype_object_manager_traits::adopt(PyObject* x) -{ - return python::detail::new_reference(python::pytype_check(pytype, x)); -} - -}}} // namespace boost::python::converter - -#endif // PYTYPE_OBJECT_MANAGER_TRAITS_DWA2002716_HPP diff --git a/include/boost/python/converter/registered.hpp b/include/boost/python/converter/registered.hpp deleted file mode 100644 index 2d3daa99..00000000 --- a/include/boost/python/converter/registered.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef REGISTERED_DWA2002710_HPP -# define REGISTERED_DWA2002710_HPP -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -struct registration; - -namespace detail -{ - template - struct registered_base - { - static registration const& converters; - }; -} - -template -struct registered - : detail::registered_base< - typename add_reference< - typename add_cv::type - >::type - > -{ -}; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -// collapses a few more types to the same static instance -template -struct registered : registered {}; -# endif - -// -// implementations -// -namespace detail -{ - template - registration const& registered_base::converters - = registry::lookup(type_id()); -} -}}} // namespace boost::python::converter - -#endif // REGISTERED_DWA2002710_HPP diff --git a/include/boost/python/converter/registered_pointee.hpp b/include/boost/python/converter/registered_pointee.hpp deleted file mode 100644 index 861cf724..00000000 --- a/include/boost/python/converter/registered_pointee.hpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef REGISTERED_POINTEE_DWA2002710_HPP -# define REGISTERED_POINTEE_DWA2002710_HPP -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -struct registration; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct registered_pointee - : registered< - typename remove_pointer< - typename remove_cv< - typename remove_reference::type - >::type - >::type - > -{ -}; -# else -namespace detail -{ - template - struct registered_pointee_base - { - static registration const& converters; - }; -} - -template -struct registered_pointee - : detail::registered_pointee_base< - typename add_reference< - typename add_cv::type - >::type - > -{ -}; - -// -// implementations -// -namespace detail -{ - template - registration const& registered_pointee_base::converters - = registry::lookup(pointer_type_id()); -} - -# endif -}}} // namespace boost::python::converter - -#endif // REGISTERED_POINTEE_DWA2002710_HPP diff --git a/include/boost/python/converter/registrations.hpp b/include/boost/python/converter/registrations.hpp deleted file mode 100644 index af2dd510..00000000 --- a/include/boost/python/converter/registrations.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef REGISTRATIONS_DWA2002223_HPP -# define REGISTRATIONS_DWA2002223_HPP - -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -struct lvalue_from_python_chain -{ - convertible_function convert; - lvalue_from_python_chain* next; -}; - -struct rvalue_from_python_chain -{ - convertible_function convertible; - constructor_function construct; - rvalue_from_python_chain* next; -}; - -struct registration -{ - explicit registration(type_info); - - const python::type_info target_type; - - // The chain of eligible from_python converters when an lvalue is required - lvalue_from_python_chain* lvalue_chain; - - // The chain of eligible from_python converters when an rvalue is acceptable - rvalue_from_python_chain* rvalue_chain; - - // The unique to_python converter for the associated C++ type. - to_python_function_t to_python; - - // The class object associated with this type - PyTypeObject* class_object; -}; - -// -// implementations -// -inline registration::registration(type_info target_type) - : target_type(target_type) - , lvalue_chain(0) - , rvalue_chain(0) - , to_python(0) - , class_object(0) -{} - -inline bool operator<(registration const& lhs, registration const& rhs) -{ - return lhs.target_type < rhs.target_type; -} - -}}} // namespace boost::python::converter - -#endif // REGISTRATIONS_DWA2002223_HPP diff --git a/include/boost/python/converter/registry.hpp b/include/boost/python/converter/registry.hpp deleted file mode 100644 index b71c949a..00000000 --- a/include/boost/python/converter/registry.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef REGISTRY_DWA20011127_HPP -# define REGISTRY_DWA20011127_HPP -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -struct registration; - -// This namespace acts as a sort of singleton -namespace registry -{ - // Get the registration corresponding to the type, creating it if neccessary - BOOST_PYTHON_DECL registration const& lookup(type_info); - - // Return a pointer to the corresponding registration, if one exists - BOOST_PYTHON_DECL registration const* query(type_info); - - BOOST_PYTHON_DECL void insert(to_python_function_t, type_info); - - // Insert an lvalue from_python converter - BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), type_info); - - // Insert an rvalue from_python converter - BOOST_PYTHON_DECL void insert( - convertible_function - , constructor_function - , type_info - ); - - // Insert an rvalue from_python converter at the tail of the - // chain. Used for implicit conversions - BOOST_PYTHON_DECL void push_back( - convertible_function - , constructor_function - , type_info - ); -} - -}}} // namespace boost::python::converter - -#endif // REGISTRY_DWA20011127_HPP diff --git a/include/boost/python/converter/return_from_python.hpp b/include/boost/python/converter/return_from_python.hpp deleted file mode 100755 index 58d182f0..00000000 --- a/include/boost/python/converter/return_from_python.hpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef RETURN_FROM_PYTHON_DWA200265_HPP -# define RETURN_FROM_PYTHON_DWA200265_HPP - -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -template struct is_object_manager; - -namespace detail -{ - template - struct return_pointer_from_python - { - typedef T result_type; - T operator()(PyObject*) const; - }; - - template - struct return_reference_from_python - { - typedef T result_type; - T operator()(PyObject*) const; - }; - - template - struct return_rvalue_from_python - { - typedef typename call_traits::param_type result_type; - return_rvalue_from_python(); - result_type operator()(PyObject*); - private: - rvalue_from_python_data m_data; - }; - - template - struct return_object_manager_from_python - { - typedef T result_type; - result_type operator()(PyObject*) const; - }; - - template - struct select_return_from_python - { - BOOST_STATIC_CONSTANT( - bool, obj_mgr = is_object_manager::value); - - BOOST_STATIC_CONSTANT( - bool, ptr = is_pointer::value); - - BOOST_STATIC_CONSTANT( - bool, ref = is_reference::value); - - typedef typename mpl::if_c< - obj_mgr - , return_object_manager_from_python - , typename mpl::if_c< - ptr - , return_pointer_from_python - , typename mpl::if_c< - ref - , return_reference_from_python - , return_rvalue_from_python - >::type - >::type - >::type type; - }; -} - -template -struct return_from_python - : detail::select_return_from_python::type -{ -}; - -// Specialization as a convenience for call and call_method -template <> -struct return_from_python -{ - typedef python::detail::returnable::type result_type; - - result_type operator()(PyObject* x) const - { - (void_result_from_python)(x); -# ifdef BOOST_NO_VOID_RETURNS - return result_type(); -# endif - } -}; - -// -// Implementations -// -namespace detail -{ - template - inline return_rvalue_from_python::return_rvalue_from_python() - : m_data( - const_cast(®istered::converters) - ) - { - } - - template - inline typename return_rvalue_from_python::result_type - return_rvalue_from_python::operator()(PyObject* obj) - { - return *(T*) - (rvalue_result_from_python)(obj, m_data.stage1); - } - - template - inline T return_reference_from_python::operator()(PyObject* obj) const - { - return python::detail::void_ptr_to_reference( - (reference_result_from_python)(obj, registered::converters) - , (T(*)())0); - } - - template - inline T return_pointer_from_python::operator()(PyObject* obj) const - { - return T( - (pointer_result_from_python)(obj, registered_pointee::converters) - ); - } - - template - inline T return_object_manager_from_python::operator()(PyObject* obj) const - { - return T( - object_manager_traits::adopt(obj) - ); - } -} - -}}} // namespace boost::python::converter - -#endif // RETURN_FROM_PYTHON_DWA200265_HPP diff --git a/include/boost/python/converter/rvalue_from_python_chain.hpp b/include/boost/python/converter/rvalue_from_python_chain.hpp deleted file mode 100644 index c57ef564..00000000 --- a/include/boost/python/converter/rvalue_from_python_chain.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP -# define RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -namespace detail -{ - template - struct rvalue_from_python_chain_impl - { - static rvalue_from_python_registration*const& value; - }; - - template - rvalue_from_python_registration*const& rvalue_from_python_chain_impl::value - = registry::rvalue_converters(undecorated_type_id()); -} - -template -struct rvalue_from_python_chain - : detail::rvalue_from_python_chain_impl< - typename add_reference< - typename add_cv::type - >::type - > -{ -}; - -}}} // namespace boost::python::converter - -#endif // RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP diff --git a/include/boost/python/converter/rvalue_from_python_data.hpp b/include/boost/python/converter/rvalue_from_python_data.hpp deleted file mode 100644 index 16c9d44b..00000000 --- a/include/boost/python/converter/rvalue_from_python_data.hpp +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FROM_PYTHON_AUX_DATA_DWA2002128_HPP -# define FROM_PYTHON_AUX_DATA_DWA2002128_HPP - -# include -# include -# include -# include -# include -# include -# include - -// Data management for potential rvalue conversions from Python to C++ -// types. When a client requests a conversion to T* or T&, we -// generally require that an object of type T exists in the source -// Python object, and the code here does not apply**. This implements -// conversions which may create new temporaries of type T. The classic -// example is a conversion which converts a Python tuple to a -// std::vector. Since no std::vector lvalue exists in the Python -// object -- it must be created "on-the-fly" by the converter, and -// which must manage the lifetime of the created object. -// -// Note that the client is not precluded from using a registered -// lvalue conversion to T in this case. In other words, we will -// happily accept a Python object which /does/ contain a std::vector -// lvalue, provided an appropriate converter is registered. So, while -// this is an rvalue conversion from the client's point-of-view, the -// converter registry may serve up lvalue or rvalue conversions for -// the target type. -// -// ** C++ argument from_python conversions to T const& are an -// exception to the rule for references: since in C++, const -// references can bind to temporary rvalues, we allow rvalue -// converters to be chosen when the target type is T const& for some -// T. -namespace boost { namespace python { namespace converter { - -// Conversions begin by filling in and returning a copy of this -// structure. The process looks up a converter in the rvalue converter -// registry for the target type. It calls the convertible() function -// of each registered converter, passing the source PyObject* as an -// argument, until a non-null result is returned. This result goes in -// the convertible field, and the converter's construct() function is -// stored in the construct field. -// -// If no appropriate converter is found, conversion fails and the -// convertible field is null. When used in argument conversion for -// wrapped C++ functions, it causes overload resolution to reject the -// current function but not to fail completely. If an exception is -// thrown, overload resolution stops and the exception propagates back -// through the caller. -// -// If an lvalue converter is matched, its convertible() function is -// expected to return a pointer to the stored T object; its -// construct() function will be NULL. The convertible() function of -// rvalue converters may return any non-singular pointer; the actual -// target object will only be available once the converter's -// construct() function is called. -struct rvalue_from_python_stage1_data -{ - void* convertible; - constructor_function construct; -}; - -// Augments rvalue_from_python_stage1_data by adding storage for -// constructing an object of remove_reference::type. The -// construct() function of rvalue converters (stored in m_construct -// above) will cast the rvalue_from_python_stage1_data to an -// appropriate instantiation of this template in order to access that -// storage. -template -struct rvalue_from_python_storage -{ - rvalue_from_python_stage1_data stage1; - - // Storage for the result, in case an rvalue must be constructed - typename python::detail::referent_storage< - typename add_reference::type - >::type storage; -}; - -// Augments rvalue_from_python_storage with a destructor. If -// stage1.convertible == storage.bytes, it indicates that an object of -// remove_reference::type has been constructed in storage and -// should will be destroyed in ~rvalue_from_python_data(). It is -// crucial that successful rvalue conversions establish this equality -// and that unsuccessful ones do not. -template -struct rvalue_from_python_data : rvalue_from_python_storage -{ -# if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) \ - && (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) \ - && (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014) - // This must always be a POD struct with m_data its first member. - BOOST_STATIC_ASSERT(offsetof(rvalue_from_python_storage,stage1) == 0); -# endif - - // The usual constructor - rvalue_from_python_data(rvalue_from_python_stage1_data const&); - - // This constructor just sets m_convertible -- used by - // implicitly_convertible<> to perform the final step of the - // conversion, where the construct() function is already known. - rvalue_from_python_data(void* convertible); - - // Destroys any object constructed in the storage. - ~rvalue_from_python_data(); - private: - typedef typename add_reference::type>::type ref_type; -}; - -// -// Implementataions -// -template -inline rvalue_from_python_data::rvalue_from_python_data(rvalue_from_python_stage1_data const& stage1) -{ - this->stage1 = stage1; -} - -template -inline rvalue_from_python_data::rvalue_from_python_data(void* convertible) -{ - this->stage1.convertible = convertible; -} - -template -inline rvalue_from_python_data::~rvalue_from_python_data() -{ - if (this->stage1.convertible == this->storage.bytes) - python::detail::destroy_referent(this->storage.bytes); -} - -}}} // namespace boost::python::converter - -#endif // FROM_PYTHON_AUX_DATA_DWA2002128_HPP diff --git a/include/boost/python/converter/smart_ptr.hpp b/include/boost/python/converter/smart_ptr.hpp deleted file mode 100644 index bae4c2b8..00000000 --- a/include/boost/python/converter/smart_ptr.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef SMART_PTR_DWA2002123_HPP -# define SMART_PTR_DWA2002123_HPP - -# include -# include -namespace boost { namespace python { namespace converter { - -template -class smart_ptr_wrapper - : wrapper -{ - smart_ptr_wrapper(ref const& type_) - : m_class_object(type_) - { - assert(type_->ob_type == (PyTypeObject*)class_metatype().get()); - } - - PyObject* convert(Pointer x) const; - - private: - ref m_class_object; - - smart_ptr_converters(); -} - - -// -// implementations -// - -template -PyObject* smart_ptr_wrapper::convert(Pointer x) const -{ - if (x.operator->() == 0) - return detail::none(); - - // Don't call the type to do the construction, since that - // would require the registration of an __init__ copy - // constructor. Instead, just construct the object in place. - PyObject* raw_result = (PyObject*)PyObject_New( - instance, (PyTypeObject*)m_class_object.get()); - - if (raw_result == 0) - return 0; - - // Everything's OK; Bypass NULL checks but guard against - // exceptions. - ref result(raw_result, ref::allow_null()); - - // Build a value_holder to contain the object using the copy - // constructor - objects::pointer_holder* - p = new objects::pointer_holder(x); - - // Install it in the instance - p->install(raw_result); - - // Return the new result - return result.release(); -} - - -}}} // namespace boost::python::converter - -#endif // SMART_PTR_DWA2002123_HPP diff --git a/include/boost/python/converter/to_python_function.hpp b/include/boost/python/converter/to_python_function.hpp deleted file mode 100644 index ff3891e2..00000000 --- a/include/boost/python/converter/to_python_function.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TO_PYTHON_FUNCTION_DWA2002128_HPP -# define TO_PYTHON_FUNCTION_DWA2002128_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace converter { - -// to_python_function -- -// -// essentially a "templated global reference" which holds the -// converter for converting a type to Python by-value. We "normalize" -// T by adding "const volatile&" so that fewer global variables and -// associated static initializations are generated. -namespace detail -{ - template - struct to_python_function_base - { - static to_python_function_t const& value; - }; - - template - to_python_function_t const& - to_python_function_base::value - = converter::registry::get_to_python_function(undecorated_type_id()); -} - -template -struct to_python_function - : detail::to_python_function_base< - typename add_reference< - typename add_cv::type - >::type - > -{ -}; - -}}} // namespace boost::python::converter - -#endif // TO_PYTHON_FUNCTION_DWA2002128_HPP diff --git a/include/boost/python/converter/to_python_function_type.hpp b/include/boost/python/converter/to_python_function_type.hpp deleted file mode 100644 index 197654e5..00000000 --- a/include/boost/python/converter/to_python_function_type.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP -# define TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP -# include - -namespace boost { namespace python { namespace converter { - -// The type of stored function pointers which actually do conversion -// by-value. The void* points to the object to be converted, and -// type-safety is preserved through runtime registration. -typedef PyObject* (*to_python_function_t)(void const*); - -// Given a typesafe to_python conversion function, produces a -// to_python_function_t which can be registered in the usual way. -template -struct as_to_python_function -{ - static PyObject* convert(void const* x) - { - return ToPython::convert(*(T const*)x); - } -}; - -}}} // namespace boost::python::converter - -#endif // TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP diff --git a/include/boost/python/converter/type_id.hpp b/include/boost/python/converter/type_id.hpp deleted file mode 100644 index f1bfa8a3..00000000 --- a/include/boost/python/converter/type_id.hpp +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TYPE_ID_DWA20011127_HPP -# define TYPE_ID_DWA20011127_HPP -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - - -namespace boost { namespace python { namespace converter { - -// for this compiler at least, cross-shared-library type_info -// comparisons don't work, so use typeid(x).name() instead. It's not -// yet clear what the best default strategy is. -# if defined(__GNUC__) && __GNUC__ >= 3 -# define BOOST_PYTHON_TYPE_ID_NAME -# endif - -// type ids which represent the same information as std::type_info -// (i.e. the top-level reference and cv-qualifiers are stripped), but -// which works across shared libraries. -struct undecorated_type_id_t : totally_ordered -{ - undecorated_type_id_t(std::type_info const&); - - // default constructor needed to build arrays, etc. - undecorated_type_id_t(); - - bool operator<(undecorated_type_id_t const& rhs) const; - bool operator==(undecorated_type_id_t const& rhs) const; - - char const* name() const; - friend BOOST_PYTHON_DECL std::ostream& operator<<( - std::ostream&, undecorated_type_id_t const&); - - private: // data members -# ifdef BOOST_PYTHON_TYPE_ID_NAME - typedef char const* base_id_t; -# else - typedef std::type_info const* base_id_t; -# endif - - base_id_t m_base_type; -}; - -struct type_id_t : totally_ordered -{ - enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 }; - - type_id_t(undecorated_type_id_t, decoration = decoration()); - - bool operator<(type_id_t const& rhs) const; - bool operator==(type_id_t const& rhs) const; - - friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&); - - operator undecorated_type_id_t const&() const; - private: // type - typedef undecorated_type_id_t base_id_t; - - private: // data members - decoration m_decoration; - base_id_t m_base_type; -}; - -template -inline undecorated_type_id_t undecorated_type_id(boost::type* = 0) -{ - return undecorated_type_id_t( -# if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600) - typeid(T) -# else // strip the decoration which msvc and Intel mistakenly leave in - python::detail::msvc_typeid() -# endif - ); -} - -template -inline type_id_t type_id(boost::type* = 0) -{ - return type_id_t( - undecorated_type_id() - , type_id_t::decoration( - (is_const::value || python::detail::is_reference_to_const::value - ? type_id_t::const_ : 0) - | (is_volatile::value || python::detail::is_reference_to_volatile::value - ? type_id_t::volatile_ : 0) - | (is_reference::value ? type_id_t::reference : 0) - ) - ); -} - -inline undecorated_type_id_t::undecorated_type_id_t(std::type_info const& id) - : m_base_type( -# ifdef BOOST_PYTHON_TYPE_ID_NAME - id.name() -# else - &id -# endif - ) -{ -} - -inline undecorated_type_id_t::undecorated_type_id_t() - : m_base_type() -{ -} - -inline type_id_t::type_id_t(undecorated_type_id_t base_t, decoration decoration) - : m_decoration(decoration) - , m_base_type(base_t) -{ -} - -inline bool undecorated_type_id_t::operator<(undecorated_type_id_t const& rhs) const -{ -# ifdef BOOST_PYTHON_TYPE_ID_NAME - return std::strcmp(m_base_type, rhs.m_base_type) < 0; -# else - return m_base_type->before(*rhs.m_base_type); -# endif -} - -inline bool type_id_t::operator<(type_id_t const& rhs) const -{ - return m_decoration < rhs.m_decoration - || m_decoration == rhs.m_decoration - && m_base_type < rhs.m_base_type; -} - -inline bool undecorated_type_id_t::operator==(undecorated_type_id_t const& rhs) const -{ -# ifdef BOOST_PYTHON_TYPE_ID_NAME - return !std::strcmp(m_base_type, rhs.m_base_type); -# else - return *m_base_type == *rhs.m_base_type; -# endif -} - -inline bool type_id_t::operator==(type_id_t const& rhs) const -{ - return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type; -} - -inline type_id_t::operator undecorated_type_id_t const&() const -{ - return m_base_type; -} - -inline char const* undecorated_type_id_t::name() const -{ -# ifdef BOOST_PYTHON_TYPE_ID_NAME - return m_base_type; -# else - return m_base_type->name(); -# endif -} - - -BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, undecorated_type_id_t const&); -BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&); - -}}} // namespace boost::python::converter - -#endif // TYPE_ID_DWA20011127_HPP diff --git a/include/boost/python/copy_const_reference.hpp b/include/boost/python/copy_const_reference.hpp deleted file mode 100644 index 8eecd2ce..00000000 --- a/include/boost/python/copy_const_reference.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef COPY_CONST_REFERENCE_DWA2002131_HPP -# define COPY_CONST_REFERENCE_DWA2002131_HPP -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct copy_const_reference_expects_a_const_reference_return_type -# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) - {} -# endif - ; -} - -template struct to_python_value; - -struct copy_const_reference -{ - template - struct apply - { - typedef typename mpl::if_c< - detail::is_reference_to_const::value - , to_python_value - , detail::copy_const_reference_expects_a_const_reference_return_type - >::type type; - }; -}; - - -}} // namespace boost::python - -#endif // COPY_CONST_REFERENCE_DWA2002131_HPP diff --git a/include/boost/python/copy_mutable_reference.hpp b/include/boost/python/copy_mutable_reference.hpp deleted file mode 100644 index acf170d0..00000000 --- a/include/boost/python/copy_mutable_reference.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef COPY_MUTABLE_REFERENCE_DWA2002131_HPP -# define COPY_MUTABLE_REFERENCE_DWA2002131_HPP -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct copy_mutable_reference_expects_a_reference_to_non_const_return_type -# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) - {} -# endif - ; -} - -template struct to_python_value; - -struct copy_mutable_reference -{ - template - struct apply - { - typedef typename mpl::select_if_c< - detail::is_reference_to_non_const::value - , to_python_value - , detail::copy_mutable_reference_expects_a_reference_to_non_const_return_type - >::type type; - }; -}; - -}} // namespace boost::python - -#endif // COPY_MUTABLE_REFERENCE_DWA2002131_HPP diff --git a/include/boost/python/copy_non_const_reference.hpp b/include/boost/python/copy_non_const_reference.hpp deleted file mode 100644 index 53c576e0..00000000 --- a/include/boost/python/copy_non_const_reference.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef COPY_NON_CONST_REFERENCE_DWA2002131_HPP -# define COPY_NON_CONST_REFERENCE_DWA2002131_HPP -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct copy_non_const_reference_expects_a_non_const_reference_return_type -# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) - {} -# endif - ; -} - -template struct to_python_value; - -struct copy_non_const_reference -{ - template - struct apply - { - typedef typename mpl::if_c< - boost::python::detail::is_reference_to_non_const::value - , to_python_value - , detail::copy_non_const_reference_expects_a_non_const_reference_return_type - >::type type; - }; -}; - - -}} // namespace boost::python - -#endif // COPY_NON_CONST_REFERENCE_DWA2002131_HPP diff --git a/include/boost/python/cross_module.hpp b/include/boost/python/cross_module.hpp deleted file mode 100644 index c6ac8c22..00000000 --- a/include/boost/python/cross_module.hpp +++ /dev/null @@ -1,329 +0,0 @@ -/* (C) Copyright Ralf W. Grosse-Kunstleve 2001. Permission to copy, use, - modify, sell and distribute this software is granted provided this - copyright notice appears in all copies. This software is provided - "as is" without express or implied warranty, and with no claim as to - its suitability for any purpose. - - Revision History: - 17 Apr 01 merged into boost CVS trunk (Ralf W. Grosse-Kunstleve) -*/ - -/* Implementation of Boost.Python cross-module support. - See root/libs/python/doc/cross_module.html for details. -*/ - -#ifndef CROSS_MODULE_HPP -# define CROSS_MODULE_HPP - -# include - -namespace boost { namespace python { - -struct BOOST_PYTHON_DECL import_error: error_already_set {}; -struct BOOST_PYTHON_DECL export_error : error_already_set {}; - -void BOOST_PYTHON_DECL throw_import_error(); -void BOOST_PYTHON_DECL throw_export_error(); - -namespace detail -{ - -// Concept: throw exception if api_major is changed -// show warning on stderr if api_minor is changed - const int export_converters_api_major = 4; - const int export_converters_api_minor = 1; - extern BOOST_PYTHON_DECL const char* converters_attribute_name; - BOOST_PYTHON_DECL void* import_converter_object(const std::string& module_name, - const std::string& py_class_name, - const std::string& attribute_name); - BOOST_PYTHON_DECL void check_export_converters_api(const int importing_major, - const int importing_minor, - const int imported_major, - const int imported_minor); - -} - -}} // namespace boost::python - -// forward declaration -namespace boost { namespace python { namespace detail { -template class import_extension_class; -}}} - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE - -/* This class template is instantiated by import_converters. - This class is a look-alike of class python_extension_class_converters. - The converters in this class are wrappers that call converters - imported from another module. - To ensure that the dynamic loader resolves all symbols in the - intended way, the signature of all friend functions is changed with - respect to the original functions in class - python_extension_class_converters by adding an arbitrary additional - parameter with a default value, in this case "bool sig = false". - See also: comments for class export_converter_object_base below. - */ -template -class python_import_extension_class_converters -{ - public: - - friend python_import_extension_class_converters py_extension_class_converters(boost::python::type, bool sig = false) { - return python_import_extension_class_converters(); - } - - PyObject* to_python(const T& x) const { - return boost::python::detail::import_extension_class::get_converters()->to_python(x); - } - - friend T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_Ts(p, t); - } - friend const T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_cTs(p, t); - } - friend const T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_cTscr(p, t); - } - friend T* from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_Tscr(p, t); - } - friend T& from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_Tr(p, t); - } - friend const T& from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_cTr(p, t); - } - friend const T& from_python(PyObject* p, boost::python::type t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_T(p, t); - } - - friend std::auto_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_aTr(p, t); - } - friend std::auto_ptr from_python(PyObject* p, boost::python::type > t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_aT(p, t); - } - friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_caTr(p, t); - } - friend PyObject* to_python(std::auto_ptr x, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->to_python(x); - } - - friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_sTr(p, t); - } - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type > t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_sT(p, t); - } - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->from_python_csTr(p, t); - } - friend PyObject* to_python(boost::shared_ptr x, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->to_python(x); - } -}; - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -namespace boost { namespace python { - -BOOST_PYTHON_IMPORT_CONVERSION(python_import_extension_class_converters); - -/* This class template is instantiated by export_converters(). - A pointer to this class is exported/imported via the Python API. - Using the Python API ensures maximum portability. - All member functions are virtual. This is, what we export/import - is essentially just a pointer to a vtbl. - To work around a deficiency of Visual C++ 6.0, the name of each - from_python() member functions is made unique by appending a few - characters (derived in a ad-hoc manner from the corresponding type). - */ -template -struct export_converter_object_base -{ - virtual int get_api_major() const { return detail::export_converters_api_major; } - virtual int get_api_minor() const { return detail::export_converters_api_minor; } - - virtual PyObject* to_python(const T& x) = 0; - - virtual T* from_python_Ts(PyObject* p, boost::python::type t) = 0; - virtual const T* from_python_cTs(PyObject* p, boost::python::type t) = 0; - virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) = 0; - virtual T* from_python_Tscr(PyObject* p, boost::python::type t) = 0; - virtual T& from_python_Tr(PyObject* p, boost::python::type t) = 0; - virtual const T& from_python_cTr(PyObject* p, boost::python::type t) = 0; - virtual const T& from_python_T(PyObject* p, boost::python::type t) = 0; - - virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) = 0; - virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) = 0; - virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) = 0; - virtual PyObject* to_python(std::auto_ptr x) = 0; - - virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) = 0; - virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) = 0; - virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) = 0; - virtual PyObject* to_python(boost::shared_ptr x) = 0; -}; - -// Converters to be used if T is not copyable. -template -struct export_converter_object_noncopyable : export_converter_object_base -{ - virtual PyObject* to_python(const T& x) { - PyErr_SetString(PyExc_RuntimeError, - "to_python(const T&) converter not exported"); - throw_import_error(); - return 0; - } - - virtual T* from_python_Ts(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T* from_python_cTs(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual T* from_python_Tscr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual T& from_python_Tr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T& from_python_cTr(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const T& from_python_T(PyObject* p, boost::python::type t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - - virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual PyObject* to_python(std::auto_ptr x) { - return BOOST_PYTHON_CONVERSION::to_python(x); - } - - virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) { - return BOOST_PYTHON_CONVERSION::from_python(p, t); - } - virtual PyObject* to_python(boost::shared_ptr x) { - return BOOST_PYTHON_CONVERSION::to_python(x); - } -}; - -// The addditional to_python() converter that can be used if T is copyable. -template -struct export_converter_object : export_converter_object_noncopyable -{ - virtual PyObject* to_python(const T& x) { - return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type()).to_python(x); - } -}; - -namespace detail -{ - -/* This class template is instantiated by import_converters. - Its purpose is to import the converter_object via the Python API. - The actual import is only done once. The pointer to the - imported converter object is kept in the static data member - imported_converters. -*/ - template - class import_extension_class - : public python_import_extension_class_converters - { - public: - inline import_extension_class(const char* module, const char* py_class) { - m_module = module; - m_py_class = py_class; - } - - static boost::python::export_converter_object_base* get_converters(); - - private: - static std::string m_module; - static std::string m_py_class; - static boost::python::export_converter_object_base* imported_converters; - }; - - template std::string import_extension_class::m_module; - template std::string import_extension_class::m_py_class; - template - boost::python::export_converter_object_base* - import_extension_class::imported_converters = 0; - - template - boost::python::export_converter_object_base* - import_extension_class::get_converters() { - if (imported_converters == 0) { - void* cobject - = import_converter_object(m_module, m_py_class, - converters_attribute_name); - imported_converters - = static_cast*>(cobject); - check_export_converters_api( - export_converters_api_major, - export_converters_api_minor, - imported_converters->get_api_major(), - imported_converters->get_api_minor()); - } - return imported_converters; - } -}}} // namespace boost::python::detail - -namespace boost { namespace python { - -// Implementation of export_converters(). -template -void export_converters(class_builder& cb) -{ - static export_converter_object export_cvts; - cb.add( - ref(PyCObject_FromVoidPtr(reinterpret_cast(&export_cvts), NULL)), - detail::converters_attribute_name); -} - -// Implementation of export_converters_noncopyable(). -template -void export_converters_noncopyable(class_builder& cb) -{ - static export_converter_object_noncopyable export_cvts; - cb.add( - ref(PyCObject_FromVoidPtr(reinterpret_cast(&export_cvts), NULL)), - detail::converters_attribute_name); -} - -// Implementation of import_converters. -template -class import_converters - : python_import_extension_class_converters // Works around MSVC6.x/GCC2.95.2 bug described - // at the bottom of class_builder.hpp. -{ - public: - import_converters(const char* module, const char* py_class) - : m_class(new detail::import_extension_class(module, py_class)) - { } - private: - boost::shared_ptr > m_class; -}; - -}} // namespace boost::python - -#endif // CROSS_MODULE_HPP diff --git a/include/boost/python/data_members.hpp b/include/boost/python/data_members.hpp deleted file mode 100644 index 01190811..00000000 --- a/include/boost/python/data_members.hpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef DATA_MEMBERS_DWA2002328_HPP -# define DATA_MEMBERS_DWA2002328_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct member - { - static PyObject* get(Data Class::*pm, PyObject* args_, PyObject*, Policies const& policies) - { - arg_from_python c0(PyTuple_GET_ITEM(args_, 0)); - if (!c0.convertible()) return 0; - - // find the result converter - typedef typename Policies::result_converter result_converter; - typedef typename boost::add_reference::type source; - typename mpl::apply1::type cr; - if (!cr.convertible()) return 0; - - if (!policies.precall(args_)) return 0; - - PyObject* result = cr( (c0(PyTuple_GET_ITEM(args_, 0)))->*pm ); - - return policies.postcall(args_, result); - } - - static PyObject* set(Data Class::*pm, PyObject* args_, PyObject*, Policies const& policies) - { - // check that each of the arguments is convertible - arg_from_python c0(PyTuple_GET_ITEM(args_, 0)); - if (!c0.convertible()) return 0; - - typedef typename add_const::type target1; - typedef typename add_reference::type target; - arg_from_python c1(PyTuple_GET_ITEM(args_, 1)); - - if (!c1.convertible()) return 0; - - if (!policies.precall(args_)) return 0; - - (c0(PyTuple_GET_ITEM(args_, 0)))->*pm = c1(PyTuple_GET_ITEM(args_, 1)); - - return policies.postcall(args_, detail::none()); - } - }; -} - -template -object make_getter(D C::*pm) -{ - typedef return_value_policy default_policy; - - return objects::function_object( - ::boost::bind( - &detail::member::get, pm, _1, _2 - , default_policy()) - , 1); - -} - -template -object make_getter(D C::*pm, Policies const& policies) -{ - return objects::function_object( - ::boost::bind( - &detail::member::get, pm, _1, _2 - , policies) - , 1); -} - -template -object make_setter(D C::*pm) -{ - return objects::function_object( - ::boost::bind( - &detail::member::set, pm, _1, _2 - , default_call_policies()) - , 2); -} - -template -object make_setter(D C::*pm, Policies const& policies) -{ - return objects::function_object( - ::boost::bind( - &detail::member::set, pm, _1, _2 - , policies) - , 2); -} - - -}} // namespace boost::python - -#endif // DATA_MEMBERS_DWA2002328_HPP diff --git a/include/boost/python/def.hpp b/include/boost/python/def.hpp deleted file mode 100644 index c581e7f6..00000000 --- a/include/boost/python/def.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef DEF_DWA200292_HPP -# define DEF_DWA200292_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& obj, char const* doc); - - template - void - dispatch_def( - void const*, - char const* name, - Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc = 0) - { - typedef detail::def_helper helper; - - detail::scope_setattr_doc( - name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)), - helper::get_doc(policy_or_doc, doc)); - } - - template - void dispatch_def( - detail::func_stubs_base const*, - char const* name, - SigT sig, - StubsT const& stubs) - { - // convert sig to a type_list (see detail::get_signature in signature.hpp) - // before calling detail::define_with_defaults. - - scope current; - detail::define_with_defaults( - name, stubs, current, detail::get_signature(sig)); - } -} - -template -void def(char const* name, Fn fn) -{ - detail::scope_setattr_doc(name, boost::python::make_function(fn), 0); -} - -template -void def(char const* name, Arg1T arg1, Arg2T const& arg2) -{ - // The arguments may be: - // def(name, function) - // def(name, function, policy) - // def(name, function, doc_string) - // def(name, signature, stubs) - - detail::dispatch_def(&arg2, name, arg1, arg2); -} - -template -void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3) -{ - // The arguments are definitely: - // def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position - - detail::dispatch_def(&arg2, name, arg1, arg2, arg3); -} - -//template -//void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc) -//{ -// // The arguments are definitely: -// // arg1: signature -// // arg2: stubs -// // arg3: policy -// -// detail::dispatch_def(&arg2, name, arg1, arg2, arg3, doc); -//} - -}} // namespace boost::python - -#endif // DEF_DWA200292_HPP diff --git a/include/boost/python/default_call_policies.hpp b/include/boost/python/default_call_policies.hpp deleted file mode 100644 index f964990f..00000000 --- a/include/boost/python/default_call_policies.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef DEFAULT_CALL_POLICIES_DWA2002131_HPP -# define DEFAULT_CALL_POLICIES_DWA2002131_HPP -# include -# include -# include -# include - -namespace boost { namespace python { - -template struct to_python_value; - -namespace detail -{ -// for "readable" error messages - template struct specify_a_result_policy_to_wrap_functions_returning -# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) - {} -# endif - ; -} - -struct default_result_converter; - -struct default_call_policies -{ - // Nothing to do - static bool precall(PyObject*) - { - return true; - } - - // Pass the result through - static PyObject* postcall(PyObject*, PyObject* result) - { - return result; - } - - typedef default_result_converter result_converter; -}; - -struct default_result_converter -{ - template - struct apply - { - BOOST_STATIC_CONSTANT(bool, is_illegal = is_reference::value || is_pointer::value); - - typedef typename mpl::if_c< - is_illegal - , detail::specify_a_result_policy_to_wrap_functions_returning - , boost::python::to_python_value< - typename add_reference::type>::type - > - >::type type; - }; -}; - -// Exceptions for c strings an PyObject*s -template <> -struct default_result_converter::apply -{ - typedef boost::python::to_python_value type; -}; - -template <> -struct default_result_converter::apply -{ - typedef boost::python::to_python_value type; -}; - -}} // namespace boost::python - -#endif // DEFAULT_CALL_POLICIES_DWA2002131_HPP diff --git a/include/boost/python/detail/aix_init_module.hpp b/include/boost/python/detail/aix_init_module.hpp deleted file mode 100644 index 6eda62ea..00000000 --- a/include/boost/python/detail/aix_init_module.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef AIX_INIT_MODULE_DWA2002529_HPP -# define AIX_INIT_MODULE_DWA2002529_HPP -# ifdef _AIX -# include -# include - -namespace boost { namespace python { namespace detail { - -extern "C" -{ - typedef PyObject* (*so_load_function)(char*,char*,FILE*); -} - -void aix_init_module(so_load_function, char const* name, void (*init_module)()); - -}}} // namespace boost::python::detail -# endif - -#endif // AIX_INIT_MODULE_DWA2002529_HPP diff --git a/include/boost/python/detail/api_placeholder.hpp b/include/boost/python/detail/api_placeholder.hpp deleted file mode 100644 index 9a4672ab..00000000 --- a/include/boost/python/detail/api_placeholder.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef BOOST_PYTHON_API_PLACE_HOLDER_HPP -#define BOOST_PYTHON_API_PLACE_HOLDER_HPP - -namespace boost { namespace python { - - inline long len(object const& obj) - { - long result = PyObject_Length(obj.ptr()); - if (PyErr_Occurred()) throw_error_already_set(); - return result; - } -}} // namespace boost::python - -#endif // BOOST_PYTHON_API_PLACE_HOLDER_HPP diff --git a/include/boost/python/detail/arg_tuple_size.hpp b/include/boost/python/detail/arg_tuple_size.hpp deleted file mode 100644 index 183e957f..00000000 --- a/include/boost/python/detail/arg_tuple_size.hpp +++ /dev/null @@ -1,127 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// This work was funded in part by Lawrence Berkeley National Labs -// -// This file generated for 5-argument member functions and 6-argument free -// functions by gen_arg_tuple_size.python - -#ifndef ARG_TUPLE_SIZE_DWA20011201_HPP -# define ARG_TUPLE_SIZE_DWA20011201_HPP - -# include - -# include -# include - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// Computes (at compile-time) the number of elements that a Python -// argument tuple must have in order to be passed to a wrapped C++ -// (member) function of the given type. -template struct arg_tuple_size; - -// We will use the "sizeof() trick" to work around the lack of -// partial specialization in MSVC6 and its broken-ness in borland. -// See http://opensource.adobe.com or -// http://groups.yahoo.com/group/boost/message/5441 for -// more examples - -// The following helper functions are never actually called, since -// they are only used within a sizeof() expression, but the type of -// their return value is used to discriminate between various free -// and member function pointers at compile-time. - -// Specializations for function pointers -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_MAX_ARITY, , BOOST_PYTHON_FUNCTION_POINTER)) -# include BOOST_PP_ITERATE() - -// Specializations for member function pointers -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_CV_COUNT - 1, , BOOST_PYTHON_POINTER_TO_MEMBER)) -# include BOOST_PP_ITERATE() - -# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - -template -struct arg_tuple_size -{ - // The sizeof() magic happens here - BOOST_STATIC_CONSTANT(std::size_t, value - = sizeof(arg_tuple_size_helper(F(0)).elements) - 1); -}; - -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -}}} // namespace boost::python::detail - -#endif // ARG_TUPLE_SIZE_DWA20011201_HPP - -// --------------- function pointers --------------- // -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER -# line BOOST_PP_LINE(__LINE__, arg_tuple_size.hpp(function pointers)) - -# define N BOOST_PP_ITERATION() - -# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - -template -struct arg_tuple_size -{ - BOOST_STATIC_CONSTANT(std::size_t, value = N); -}; - -# else - -template -char_array arg_tuple_size_helper( - R (*)(BOOST_PYTHON_UNARY_ENUM(N, A))); - -# endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - -# undef N - -// --------------- pointers-to-members --------------- // -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER -// Outer iteration over cv-qualifications - -# define BOOST_PP_ITERATION_PARAMS_2 \ - (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -#elif BOOST_PP_ITERATION_DEPTH() == 2 && BOOST_PP_RELATIVE_FLAGS(1) == BOOST_PYTHON_POINTER_TO_MEMBER -# line BOOST_PP_LINE(__LINE__, arg_tuple_size.hpp(pointers-to-members)) -// Inner iteration over arities - -# define N BOOST_PP_ITERATION() -# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1)) - -# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - -template -struct arg_tuple_size -{ - BOOST_STATIC_CONSTANT(std::size_t, value = N + 1U); -}; - -# else - -template -char_array arg_tuple_size_helper( - R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q); - -# endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - -# undef Q -# undef N - -#endif // !defined(BOOST_PP_IS_ITERATING) diff --git a/include/boost/python/detail/base_object.hpp b/include/boost/python/detail/base_object.hpp deleted file mode 100644 index d92b3972..00000000 --- a/include/boost/python/detail/base_object.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// Revision History: -// Mar 01 01 Use PyObject_INIT() instead of trying to hand-initialize (David Abrahams) - -#ifndef BASE_OBJECT_DWA051600_H_ -# define BASE_OBJECT_DWA051600_H_ - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// base_object - adds a constructor and non-virtual destructor to a -// base Python type (e.g. PyObject, PyTypeObject). -template -struct base_object : PythonType -{ - typedef PythonType base_python_type; - - // Initializes type and reference count. All other fields of base_python_type are 0 - base_object(PyTypeObject* type_obj); - - // Decrements reference count on the type - ~base_object(); -}; - -// Easy typedefs for common usage -typedef base_object python_object; -typedef base_object python_type; - - -// -// base_object member function implementations -// -template -base_object::base_object(PyTypeObject* type_obj) -{ - base_python_type* bp = this; - BOOST_CSTD_::memset(bp, 0, sizeof(base_python_type)); - Py_INCREF(type_obj); - PyObject_INIT(bp, type_obj); -} - -template -inline base_object::~base_object() -{ - Py_DECREF(ob_type); -} - -}}} // namespace boost::python::detail - -#endif // BASE_OBJECT_DWA051600_H_ diff --git a/include/boost/python/detail/borrowed_ptr.hpp b/include/boost/python/detail/borrowed_ptr.hpp deleted file mode 100755 index 6b35c862..00000000 --- a/include/boost/python/detail/borrowed_ptr.hpp +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef BORROWED_PTR_DWA20020601_HPP -# define BORROWED_PTR_DWA20020601_HPP -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -template class borrowed -{ - typedef T type; -}; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct is_borrowed_ptr -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -# if !defined(__MWERKS__) || __MWERKS__ > 0x3000 -template -struct is_borrowed_ptr*> -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_borrowed_ptr const*> -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_borrowed_ptr volatile*> -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_borrowed_ptr const volatile*> -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; -# else -template -struct is_borrowed -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; -template -struct is_borrowed > -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; -template -struct is_borrowed_ptr - : is_borrowed::type> -{ -}; -# endif - -# else // no partial specialization - -typedef char (&yes_borrowed_ptr_t)[1]; -typedef char (&no_borrowed_ptr_t)[2]; - -no_borrowed_ptr_t is_borrowed_ptr_test(...); - -template -typename mpl::if_c< - is_pointer::value - , T - , int - >::type -is_borrowed_ptr_test1(boost::type); - -template -yes_borrowed_ptr_t is_borrowed_ptr_test(borrowed const volatile*); - -template -class is_borrowed_ptr -{ - public: - BOOST_STATIC_CONSTANT( - bool, value = ( - sizeof(detail::is_borrowed_ptr_test(is_borrowed_ptr_test1(boost::type()))) - == sizeof(detail::yes_borrowed_ptr_t))); -}; - -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -} - -template -inline T* get_managed_object(detail::borrowed const volatile* p, tag_t) -{ - return (T*)p; -} - -}} // namespace boost::python::detail - -#endif // #ifndef BORROWED_PTR_DWA20020601_HPP diff --git a/include/boost/python/detail/call_object.hpp b/include/boost/python/detail/call_object.hpp deleted file mode 100644 index 5595e5c0..00000000 --- a/include/boost/python/detail/call_object.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CALL_OBJECT_DWA20011222_HPP -# define CALL_OBJECT_DWA20011222_HPP -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - // A function object adaptor which turns a function returning R into - // an "equivalent" function returning void, but taking an R& in - // which the adapted function's result is stored. - template - struct return_by_reference - { - typedef void return_type; - - return_by_reference(R& result, F f) - : m_result(result) - , m_f(f) - { - } - - void operator()() const - { - m_result = m_f(); - } - - R& m_result; - F m_f; - }; - - // An object generator for the above adaptors - template - return_by_reference bind_return(R& result, F f) - { - return return_by_reference(result, f); - } - - // Given a function object f with signature - // - // R f(PyTypeObject*,PyObject*) - // - // calls f inside of handle_exception_impl, placing f's result in - // ret. Returns true iff an exception is thrown by f, leaving ret - // unmodified. - template - bool call_object(R& ret, PyObject* obj, F f) - { - return handle_exception( - detail::bind_return( - ret - , boost::bind( - f, static_cast(obj->ob_type), obj))); - } -} // namespace detail - -}} // namespace boost::python - -#endif // CALL_OBJECT_DWA20011222_HPP diff --git a/include/boost/python/detail/caller.hpp b/include/boost/python/detail/caller.hpp deleted file mode 100644 index 2ade2a11..00000000 --- a/include/boost/python/detail/caller.hpp +++ /dev/null @@ -1,105 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file generated for 10-argument member functions and 11-argument free -// functions by gen_caller.python - -# ifndef CALLER_DWA20011214_HPP -# define CALLER_DWA20011214_HPP - -# include -# include -# include - -# include -# include - -# include -# include -# include - -namespace boost { namespace python -{ - template struct to_python; -}} - -namespace boost { namespace python { namespace detail { - -struct caller -{ - typedef PyObject* result_type; - - // function pointers -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_MAX_ARITY, , BOOST_PYTHON_FUNCTION_POINTER)) -# include BOOST_PP_ITERATE() - - // pointers-to-members -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, 3, , BOOST_PYTHON_POINTER_TO_MEMBER)) -# include BOOST_PP_ITERATE() - -}; - -}}} // namespace boost::python::detail - -# endif // CALLER_DWA20011214_HPP - -/* ---------- function pointers --------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER -# line BOOST_PP_LINE(__LINE__, detail/caller.hpp(function pointers)) - -# define N BOOST_PP_ITERATION() - -template < - class P, class R - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A) - > -PyObject* operator()( - R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A)) - , PyObject* args - , PyObject* keywords - , P const& policies) const -{ - return returning::call(pf, args, keywords, &policies); -} - -# undef N - -/* ---------- pointers-to-members ---------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER -// outer over cv-qualifiers - -# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -#elif BOOST_PP_ITERATION_DEPTH() == 2 -// inner over arities - -#define N BOOST_PP_ITERATION() -#define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1)) - -template < - class P, class R, class T - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A) - > -PyObject* operator()( - R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q - , PyObject* args, PyObject* keywords - , P const& policies - ) const -{ - return returning::call(pmf, args, keywords, &policies); -} - -#undef N -#undef Q - -#endif diff --git a/include/boost/python/detail/cast.hpp b/include/boost/python/detail/cast.hpp deleted file mode 100644 index 367f1f14..00000000 --- a/include/boost/python/detail/cast.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef CAST_DWA052500_H_ -# define CAST_DWA052500_H_ - -# ifndef BOOST_PYTHON_V2 -# include -# include - -namespace boost { namespace python { - -namespace detail { - inline PyTypeObject* as_base_object(const PyTypeObject*, PyObject* p) - { - return reinterpret_cast(p); - } - - inline PyObject* as_base_object(const PyObject*, PyObject* p) - { - return p; - } - - inline const PyTypeObject* as_base_object(const PyTypeObject*, const PyObject* p) - { - return reinterpret_cast(p); - } - - inline const PyObject* as_base_object(const PyObject*, const PyObject* p) - { - return p; - } -} // namespace detail - -// Convert a pointer to any type derived from PyObject or PyTypeObject to a PyObject* -inline PyObject* as_object(PyObject* p) { return p; } -inline PyObject* as_object(PyTypeObject* p) { return reinterpret_cast(p); } - -// If I didn't have to support stupid MSVC6 we could just use a simple template function: -// template T* downcast(PyObject*). -template -struct downcast -{ - downcast(PyObject* p) - : m_p(static_cast(detail::as_base_object((T*)0, p))) - {} - - downcast(const PyObject* p) - : m_p(static_cast(detail::as_base_object((const T*)0, p))) - {} - - downcast(PyTypeObject* p) - : m_p(static_cast(p)) - {} - - downcast(const PyTypeObject* p) - : m_p(static_cast(p)) - {} - - operator T*() const { return m_p; } - - // MSVC doesn't like boost::dereferencable unless T has a default - // constructor, so operator-> must be defined by hand :( - T* operator->() const { return &**this; } - - T* get() const { return m_p; } - T& operator*() const { return *m_p; } - private: - T* m_p; -}; - -}} // namespace boost::python - -# endif // BOOST_PYTHON_V2 - -#endif // CAST_DWA052500_H_ diff --git a/include/boost/python/detail/char_array.hpp b/include/boost/python/detail/char_array.hpp deleted file mode 100644 index d68aea47..00000000 --- a/include/boost/python/detail/char_array.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CHAR_ARRAY_DWA2002129_HPP -# define CHAR_ARRAY_DWA2002129_HPP - -namespace boost { namespace python { namespace detail { - -// This little package is used to transmit the number of arguments -// from the helper functions below to the sizeof() expression below. -// Because we can never have an array of fewer than 1 element, we -// add 1 to n and then subtract 1 from the result of sizeof() below. -template -struct char_array -{ - char elements[n+1]; -}; - -}}} // namespace boost::python::detail - -#endif // CHAR_ARRAY_DWA2002129_HPP diff --git a/include/boost/python/detail/config.hpp b/include/boost/python/detail/config.hpp deleted file mode 100644 index c3750902..00000000 --- a/include/boost/python/detail/config.hpp +++ /dev/null @@ -1,117 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -// Revision History: -// 04 Mar 01 Some fixes so it will compile with Intel C++ (Dave Abrahams) - -#ifndef CONFIG_DWA052200_H_ -# define CONFIG_DWA052200_H_ - -# include - -# ifdef BOOST_NO_OPERATORS_IN_NAMESPACE - // A gcc bug forces some symbols into the global namespace -# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE -# define BOOST_PYTHON_END_CONVERSION_NAMESPACE -# define BOOST_PYTHON_CONVERSION -# define BOOST_PYTHON_IMPORT_CONVERSION(x) using ::x -# else -# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE namespace boost { namespace python { -# define BOOST_PYTHON_END_CONVERSION_NAMESPACE }} // namespace boost::python -# define BOOST_PYTHON_CONVERSION boost::python -# define BOOST_PYTHON_IMPORT_CONVERSION(x) void never_defined() // so we can follow the macro with a ';' -# endif - -# if defined(BOOST_MSVC) -# if _MSC_VER <= 1200 -# define BOOST_MSVC6_OR_EARLIER 1 -# endif - -# pragma warning (disable : 4786) - -# elif defined(__ICL) && __ICL < 600 // Intel C++ 5 - -# pragma warning(disable: 985) // identifier was truncated in debug information - -# endif - -// The STLport puts all of the standard 'C' library names in std (as far as the -// user is concerned), but without it you need a fix if you're using MSVC or -// Intel C++ -# if defined(BOOST_MSVC_STD_ITERATOR) -# define BOOST_CSTD_ -# else -# define BOOST_CSTD_ std -# endif - -/***************************************************************************** - * - * Set up dll import/export options: - * - ****************************************************************************/ - -// backwards compatibility: -#ifdef BOOST_PYTHON_STATIC_LIB -# define BOOST_PYTHON_STATIC_LINK -# elif !defined(BOOST_PYTHON_DYNAMIC_LIB) -# define BOOST_PYTHON_DYNAMIC_LIB -#endif - -#if defined(__MWERKS__) \ - || (defined(__DECCXX_VER) && __DECCXX_VER <= 60590002) \ - || (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730) -# define BOOST_PYTHON_NO_TEMPLATE_EXPORT -#endif - -#if defined(BOOST_PYTHON_DYNAMIC_LIB) && defined(_WIN32) -# if defined(BOOST_PYTHON_SOURCE) -# define BOOST_PYTHON_DECL __declspec(dllexport) -# define BOOST_PYTHON_BUILD_DLL -# else -# define BOOST_PYTHON_DECL __declspec(dllimport) -# endif - -// MinGW, at least, has some problems exporting template instantiations -# if defined(__GNUC__) && __GNUC__ < 3 && !defined(__CYGWIN__) -# define BOOST_PYTHON_NO_TEMPLATE_EXPORT -# endif - -#endif - -#ifndef BOOST_PYTHON_DECL -# define BOOST_PYTHON_DECL -#endif - -#ifndef BOOST_PYTHON_EXPORT -# define BOOST_PYTHON_EXPORT extern -#endif - -#if !defined(BOOST_PYTHON_NO_TEMPLATE_EXPORT) -# define BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(instantiation) BOOST_PYTHON_EXPORT template class BOOST_PYTHON_DECL instantiation -#else -# define BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(instantiation) struct ThIsTyPeNeVeRuSeD -#endif - -#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730 -// Work around a compiler bug. -// boost::python::detail::function has to be seen by the compiler before the -// boost::function class template. -namespace boost { namespace python { namespace detail { -class function; -}}} -#endif - -#if (defined(__DECCXX_VER) && __DECCXX_VER <= 60590014) -// Replace broken Tru64/cxx offsetof macro -# define BOOST_PYTHON_OFFSETOF(s_name, s_member) \ - ((size_t)__INTADDR__(&(((s_name *)0)->s_member))) -#else -# define BOOST_PYTHON_OFFSETOF offsetof -#endif - -#endif // CONFIG_DWA052200_H_ diff --git a/include/boost/python/detail/construct.hpp b/include/boost/python/detail/construct.hpp deleted file mode 100644 index f7b747f6..00000000 --- a/include/boost/python/detail/construct.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CONSTRUCT_REFERENCE_DWA2002716_HPP -# define CONSTRUCT_REFERENCE_DWA2002716_HPP - -namespace boost { namespace python { namespace detail { - -template -void construct_pointee(void* storage, Arg& x -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 - , T const volatile* -# else - , T const* -# endif - ) -{ - new (storage) T(x); -} - -template -void construct_referent_impl(void* storage, Arg& x, T&(*)()) -{ - construct_pointee(storage, x, (T*)0); -} - -template -void construct_referent(void* storage, Arg const& x, T(*tag)() = 0) -{ - construct_referent_impl(storage, x, tag); -} - -template -void construct_referent(void* storage, Arg& x, T(*tag)() = 0) -{ - construct_referent_impl(storage, x, tag); -} - -}}} // namespace boost::python::detail - -#endif // CONSTRUCT_REFERENCE_DWA2002716_HPP diff --git a/include/boost/python/detail/convertible.hpp b/include/boost/python/detail/convertible.hpp deleted file mode 100755 index 74440090..00000000 --- a/include/boost/python/detail/convertible.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CONVERTIBLE_DWA2002614_HPP -# define CONVERTIBLE_DWA2002614_HPP - -# if defined(__EDG_VERSION__) && __EDG_VERSION__ <= 241 -# include -# include -# endif - -// Supplies a runtime is_convertible check which can be used with tag -// dispatching to work around the Metrowerks Pro7 limitation with boost::is_convertible -namespace boost { namespace python { namespace detail { - -typedef char* yes_convertible; -typedef int* no_convertible; - -template -struct convertible -{ -# if !defined(__EDG_VERSION__) || __EDG_VERSION__ > 241 || __EDG_VERSION__ == 238 - static inline no_convertible check(...) { return 0; } - static inline yes_convertible check(Target) { return 0; } -# else - template - static inline typename mpl::if_c< - is_convertible::value - , yes_convertible - , no_convertible - >::type check(X const&) { return 0; } -# endif -}; - -}}} // namespace boost::python::detail - -#endif // CONVERTIBLE_DWA2002614_HPP diff --git a/include/boost/python/detail/cv_category.hpp b/include/boost/python/detail/cv_category.hpp deleted file mode 100644 index f4ac4b92..00000000 --- a/include/boost/python/detail/cv_category.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CV_CATEGORY_DWA200222_HPP -# define CV_CATEGORY_DWA200222_HPP -# include - -namespace boost { namespace python { namespace detail { - -template -struct cv_tag -{ - BOOST_STATIC_CONSTANT(bool, is_const = is_const_); - BOOST_STATIC_CONSTANT(bool, is_volatile = is_const_); -}; - -typedef cv_tag cv_unqualified; -typedef cv_tag const_; -typedef cv_tag volatile_; -typedef cv_tag const_volatile_; - -template -struct cv_category -{ - BOOST_STATIC_CONSTANT(bool, c = is_const::value); - BOOST_STATIC_CONSTANT(bool, v = is_volatile::value); - typedef cv_tag type; -}; - -}}} // namespace boost::python::detail - -#endif // CV_CATEGORY_DWA200222_HPP diff --git a/include/boost/python/detail/decorated_type_id.hpp b/include/boost/python/detail/decorated_type_id.hpp deleted file mode 100755 index c43a4160..00000000 --- a/include/boost/python/detail/decorated_type_id.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef DECORATED_TYPE_ID_DWA2002517_HPP -# define DECORATED_TYPE_ID_DWA2002517_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -struct decorated_type_info : totally_ordered -{ - enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 }; - - decorated_type_info(type_info, decoration = decoration()); - - inline bool operator<(decorated_type_info const& rhs) const; - inline bool operator==(decorated_type_info const& rhs) const; - - friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&); - - operator type_info const&() const; - private: // type - typedef type_info base_id_t; - - private: // data members - decoration m_decoration; - base_id_t m_base_type; -}; - -template -inline decorated_type_info decorated_type_id(boost::type* = 0) -{ - return decorated_type_info( - type_id() - , decorated_type_info::decoration( - (is_const::value || python::detail::is_reference_to_const::value - ? decorated_type_info::const_ : 0) - | (is_volatile::value || python::detail::is_reference_to_volatile::value - ? decorated_type_info::volatile_ : 0) - | (is_reference::value ? decorated_type_info::reference : 0) - ) - ); -} - -inline decorated_type_info::decorated_type_info(type_info base_t, decoration decoration) - : m_decoration(decoration) - , m_base_type(base_t) -{ -} - -inline bool decorated_type_info::operator<(decorated_type_info const& rhs) const -{ - return m_decoration < rhs.m_decoration - || m_decoration == rhs.m_decoration - && m_base_type < rhs.m_base_type; -} - -inline bool decorated_type_info::operator==(decorated_type_info const& rhs) const -{ - return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type; -} - -inline decorated_type_info::operator type_info const&() const -{ - return m_base_type; -} - -BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&); - -}}} // namespace boost::python::detail - -#endif // DECORATED_TYPE_ID_DWA2002517_HPP diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp deleted file mode 100644 index 1222f71b..00000000 --- a/include/boost/python/detail/def_helper.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef DEF_HELPER_DWA200287_HPP -# define DEF_HELPER_DWA200287_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// -// def_helper -- -// -// A helper for def() functions which determines how to interpret -// an argument of type T which could be either CallPolicies or a -// string literal representing a docstring. -// -// Generates two static functions: -// -// get_policy(x), where x is of type T, returns a policies -// object: either a reference to x or default_call_policies() -// if x is a string literal. -// -// get_doc(x, s), where s convertible to char const*, returns x -// if x is a string literal, s otherwise. - -template -struct def_helper_impl -{ - template - static P const& get_policy(P const& x) { return x; } - - template - static char const* get_doc(P const&, char const* doc) { return doc; } -}; - -template <> -struct def_helper_impl -{ - static python::default_call_policies get_policy(char const*) { return default_call_policies(); } - static char const* get_doc(char const* doc, char const*) { return doc; } -}; - -template -struct def_helper - : def_helper_impl< - type_traits::ice_or< - is_string_literal::value - , is_same::value - , is_same::value ->::value -> -{}; - -}}} // namespace boost::python::detail - -#endif // DEF_HELPER_DWA200287_HPP diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp deleted file mode 100644 index a8e32c8a..00000000 --- a/include/boost/python/detail/defaults_def.hpp +++ /dev/null @@ -1,249 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -// -/////////////////////////////////////////////////////////////////////////////// -#if !defined(BOOST_PP_IS_ITERATING) - -#ifndef DEFAULTS_DEF_JDG20020811_HPP -#define DEFAULTS_DEF_JDG20020811_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/////////////////////////////////////////////////////////////////////////////// -namespace boost { namespace python { - -struct module; - -namespace objects -{ - struct class_base; -} - -namespace detail { - -template -static void name_space_def( - NameSpaceT& name_space, - char const* name, - Func f, - CallPolicies const& policies, - char const* doc, - objects::class_base* - ) -{ - name_space.def( - name, f, policies, doc); -} - -template -static void name_space_def( - object& name_space, - char const* name, - Func f, - CallPolicies const& policies, - char const* doc, - ... - ) -{ - scope within(name_space); - - def(name, f, policies, doc); -} - -// For backward compatibility -template -static void name_space_def( - NameSpaceT& name_space, - char const* name, - Func f, - CallPolicies const& policies, - char const* doc, - module* - ) -{ - name_space.def( - name, f, policies, doc); -} - -/////////////////////////////////////////////////////////////////////////////// -// -// This Boost PP code generates expansions for -// -// template -// inline void -// define_stub_function( -// char const* name, StubsT s, NameSpaceT& name_space, mpl::int_c) -// { -// name_space.def(name, &StubsT::func_N); -// } -// -// where N runs from 0 to BOOST_PYTHON_MAX_ARITY -// -// The set of overloaded functions (define_stub_function) expects: -// -// 1. char const* name: function name that will be visible to python -// 2. StubsT: a function stubs struct (see defaults_gen.hpp) -// 3. NameSpaceT& name_space: a python::class_ or python::module instance -// 4. int_t: the Nth overloaded function (StubsT::func_N) -// (see defaults_gen.hpp) -// 5. char const* name: doc string -// -/////////////////////////////////////////////////////////////////////////////// -template -struct define_stub_function {}; - -#define BOOST_PP_ITERATION_PARAMS_1 \ - (3, (0, BOOST_PYTHON_MAX_ARITY, )) - -#include BOOST_PP_ITERATE() - -/////////////////////////////////////////////////////////////////////////////// -// -// define_with_defaults_helper -// -// This helper template struct does the actual recursive definition. -// There's a generic version define_with_defaults_helper and a -// terminal case define_with_defaults_helper<0>. The struct and its -// specialization has a sole static member function def that expects: -// -// 1. char const* name: function name that will be visible to python -// 2. StubsT: a function stubs struct (see defaults_gen.hpp) -// 3. NameSpaceT& name_space: a python::class_ or python::module instance -// 4. char const* name: doc string -// -// The def static member function calls a corresponding -// define_stub_function. The general case recursively calls -// define_with_defaults_helper::def until it reaches the -// terminal case case define_with_defaults_helper<0>. -// -/////////////////////////////////////////////////////////////////////////////// - template - struct define_with_defaults_helper { - - template - static void - def( - char const* name, - StubsT stubs, - CallPolicies const& policies, - NameSpaceT& name_space, - char const* doc) - { - // define the NTH stub function of stubs - define_stub_function::define(name, stubs, policies, name_space, doc); - // call the next define_with_defaults_helper - define_with_defaults_helper::def(name, stubs, policies, name_space, doc); - } - }; - -/////////////////////////////////////// - template <> - struct define_with_defaults_helper<0> { - - template - static void - def( - char const* name, - StubsT stubs, - CallPolicies const& policies, - NameSpaceT& name_space, - char const* doc) - { - // define the Oth stub function of stubs - define_stub_function<0>::define(name, stubs, policies, name_space, doc); - // return - } - }; - -/////////////////////////////////////////////////////////////////////////////// -// -// define_with_defaults -// -// 1. char const* name: function name that will be visible to python -// 2. StubsT: a function stubs struct (see defaults_gen.hpp) -// 3. CallPolicies& policies: Call policies -// 4. NameSpaceT& name_space: a python::class_ or python::module instance -// 5. SigT sig: Function signature typelist (see defaults_gen.hpp) -// 6. char const* name: doc string -// -// This is the main entry point. This function recursively defines all -// stub functions of StubT (see defaults_gen.hpp) in NameSpaceT name_space which -// can be either a python::class_ or a python::module. The sig argument -// is a typelist that specifies the return type, the class (for member -// functions, and the arguments. Here are some SigT examples: -// -// int foo(int) mpl::list -// void bar(int, int) mpl::list -// void C::foo(int) mpl::list -// -/////////////////////////////////////////////////////////////////////////////// - template - inline void - define_with_defaults( - char const* name, - StubsT const& stubs, - NameSpaceT& name_space, - SigT sig) - { - typedef typename mpl::front::type return_type; - typedef typename StubsT::v_type v_type; - typedef typename StubsT::nv_type nv_type; - - typedef typename mpl::if_c< - boost::is_same::value - , v_type - , nv_type - >::type stubs_type; - - BOOST_STATIC_ASSERT( - (stubs_type::max_args) <= mpl::size::value); - - typedef typename stubs_type::template gen gen_type; - define_with_defaults_helper::def - (name, gen_type(), stubs.call_policies(), name_space, stubs.doc_string()); - } - -} // namespace detail - -}} // namespace boost::python - -/////////////////////////////////////////////////////////////////////////////// -#endif // DEFAULTS_DEF_JDG20020811_HPP - -#else // defined(BOOST_PP_IS_ITERATING) -// PP vertical iteration code - - -template <> -struct define_stub_function { - template - static void define( - char const* name, - StubsT, - CallPolicies const& policies, - NameSpaceT& name_space, - char const* doc) - { - detail::name_space_def(name_space, - name, - &StubsT::BOOST_PP_CAT(func_, BOOST_PP_ITERATION()), - policies, - doc, &name_space); - } -}; - -#endif // !defined(BOOST_PP_IS_ITERATING) diff --git a/include/boost/python/detail/dependent.hpp b/include/boost/python/detail/dependent.hpp deleted file mode 100644 index 4fc48766..00000000 --- a/include/boost/python/detail/dependent.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef DEPENDENT_DWA200286_HPP -# define DEPENDENT_DWA200286_HPP - -namespace boost { namespace python { namespace detail { - -// A way to turn a concrete type T into a type dependent on U. This -// keeps conforming compilers (those implementing proper 2-phase -// name lookup for templates) from complaining about incomplete -// types in situations where it would otherwise be inconvenient or -// impossible to re-order code so that all types are defined in time. - -// One such use is when we must return an incomplete T from a member -// function template (which must be defined in the class body to -// keep MSVC happy). -template -struct dependent -{ - typedef T type; -}; - -}}} // namespace boost::python::detail - -#endif // DEPENDENT_DWA200286_HPP diff --git a/include/boost/python/detail/destroy.hpp b/include/boost/python/detail/destroy.hpp deleted file mode 100644 index 7b107550..00000000 --- a/include/boost/python/detail/destroy.hpp +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef DESTROY_DWA2002221_HPP -# define DESTROY_DWA2002221_HPP - -# include -# include - -namespace boost { namespace python { namespace detail { - -template struct value_destroyer; - -template <> -struct value_destroyer -{ - template - static void execute(T const volatile* p) - { - p->T::~T(); - } -}; - -template <> -struct value_destroyer -{ - template - static void execute(A*, T const volatile* const first) - { - for (T const volatile* p = first; p != first + sizeof(A)/sizeof(T); ++p) - value_destroyer< - boost::is_array::value - ,boost::has_trivial_destructor::value - >::execute(p); - } - - template - static void execute(T const volatile* p) - { - execute(p, *p); - } -}; - -template <> -struct value_destroyer -{ - template - static void execute(T const volatile* p) - { - } -}; - -template <> -struct value_destroyer -{ - template - static void execute(T const volatile* p) - { - } -}; - -template -inline void destroy_referent_impl(void* p, T& (*)()) -{ - // note: cv-qualification needed for MSVC6 - // must come *before* T for metrowerks - value_destroyer< - (boost::is_array::value) - ,(boost::has_trivial_destructor::value) - >::execute((const volatile T*)p); -} - -template -inline void destroy_referent(void* p, T(*)() = 0) -{ - destroy_referent_impl(p, (T(*)())0); -} - -}}} // namespace boost::python::detail - -#endif // DESTROY_DWA2002221_HPP diff --git a/include/boost/python/detail/exception_handler.hpp b/include/boost/python/detail/exception_handler.hpp deleted file mode 100644 index 9a9aa4d2..00000000 --- a/include/boost/python/detail/exception_handler.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef EXCEPTION_HANDLER_DWA2002810_HPP -# define EXCEPTION_HANDLER_DWA2002810_HPP - -# include -# include - -namespace boost { namespace python { namespace detail { - -struct BOOST_PYTHON_DECL exception_handler; - -typedef function2 const&> handler_function; - -struct BOOST_PYTHON_DECL exception_handler -{ - private: // types - - public: - explicit exception_handler(handler_function const& impl); - - inline bool handle(function0 const& f) const; - - bool operator()(function0 const& f) const; - - static exception_handler* chain; - - private: - static exception_handler* tail; - - handler_function m_impl; - exception_handler* m_next; -}; - - -inline bool exception_handler::handle(function0 const& f) const -{ - return this->m_impl(*this, f); -} - -BOOST_PYTHON_DECL void register_exception_handler(handler_function const& f); - -}}} // namespace boost::python::detail - -#endif // EXCEPTION_HANDLER_DWA2002810_HPP diff --git a/include/boost/python/detail/extension_class.hpp b/include/boost/python/detail/extension_class.hpp deleted file mode 100644 index f92bb83b..00000000 --- a/include/boost/python/detail/extension_class.hpp +++ /dev/null @@ -1,1002 +0,0 @@ -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file automatically generated for 10-argument constructors by -// gen_extclass.python - -// Revision History: -// 17 Apr 01 Comment added with reference to cross_module.hpp (R.W. Grosse-Kunstleve) -// 05 Mar 01 Fixed a bug which prevented auto_ptr values from being converted -// to_python (Dave Abrahams) - -#ifndef EXTENSION_CLASS_DWA052000_H_ -# define EXTENSION_CLASS_DWA052000_H_ - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -// forward declarations -template struct operators; -template struct left_operand; -template struct right_operand; - -enum without_downcast_t { without_downcast }; - -namespace detail -{ - -// forward declarations - class extension_instance; - class extension_class_base; - template class instance_holder; - template class instance_value_holder; - template class instance_ptr_holder; - template struct operand_select; - template struct choose_op; - template struct choose_rop; - template struct choose_unary_op; - template struct define_operator; - - class BOOST_PYTHON_DECL extension_instance : public instance - { - public: - extension_instance(PyTypeObject* class_); - ~extension_instance(); - - void add_implementation(std::auto_ptr holder); - - typedef std::vector held_objects; - const held_objects& wrapped_objects() const - { return m_wrapped_objects; } - private: - held_objects m_wrapped_objects; - }; - -} // namespace detail - -BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(class_t); -BOOST_PYTHON_EXPORT_CLASS_TEMPLATE(meta_class); - -namespace detail { - -BOOST_PYTHON_DECL meta_class* extension_meta_class(); -BOOST_PYTHON_DECL extension_instance* get_extension_instance(PyObject* p); -BOOST_PYTHON_DECL void report_missing_instance_data(extension_instance*, class_t*, const std::type_info&); -BOOST_PYTHON_DECL void report_missing_ptr_data(extension_instance*, class_t*, const std::type_info&); -BOOST_PYTHON_DECL void report_missing_class_object(const std::type_info&); -BOOST_PYTHON_DECL void report_released_smart_pointer(const std::type_info&); - -template -T* check_non_null(T* p) -{ - if (p == 0) - report_released_smart_pointer(typeid(T)); - return p; -} - -template class held_instance; - -typedef void* (*conversion_function_ptr)(void*); - -struct BOOST_PYTHON_DECL base_class_info -{ - base_class_info(extension_class_base* t, conversion_function_ptr f) - :class_object(t), convert(f) - {} - - extension_class_base* class_object; - conversion_function_ptr convert; -}; - -typedef base_class_info derived_class_info; - -struct add_operator_base; - -class BOOST_PYTHON_DECL extension_class_base : public class_t -{ - public: - extension_class_base(const char* name); - - public: - // the purpose of try_class_conversions() and its related functions - // is explained in extclass.cpp - void* try_class_conversions(instance_holder_base*) const; - void* try_base_class_conversions(instance_holder_base*) const; - void* try_derived_class_conversions(instance_holder_base*) const; - - void set_attribute(const char* name, PyObject* x); - void set_attribute(const char* name, ref x); - - private: - virtual void* extract_object_from_holder(instance_holder_base* v) const = 0; - virtual std::vector const& base_classes() const = 0; - virtual std::vector const& derived_classes() const = 0; - - protected: - friend struct add_operator_base; - void add_method(reference method, const char* name); - void add_method(function* method, const char* name); - - void add_constructor_object(function*); - void add_setter_method(function*, const char* name); - void add_getter_method(function*, const char* name); -}; - -template -class class_registry -{ - public: - static extension_class_base* class_object() - { return static_class_object; } - - // Register/unregister the Python class object corresponding to T - static void register_class(extension_class_base*); - static void unregister_class(extension_class_base*); - - // Establish C++ inheritance relationships - static void register_base_class(base_class_info const&); - static void register_derived_class(derived_class_info const&); - - // Query the C++ inheritance relationships - static std::vector const& base_classes(); - static std::vector const& derived_classes(); - private: - static extension_class_base* static_class_object; - static std::vector static_base_class_info; - static std::vector static_derived_class_info; -}; - -template -struct is_null_helper -{ - template - static bool test(Ptr x) { return x == 0; } -}; - -template <> -struct is_null_helper -{ - template - static bool test(const Ptr& x) { return x.get() == 0; } -}; - -template -bool is_null(const Ptr& x) -{ - return is_null_helper<(is_pointer::value)>::test(x); -} - -}}} // namespace boost::python::detail - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE - -// This class' only job is to define from_python and to_python converters for T -// and U. T is the class the user really intends to wrap. U is a class derived -// from T with some virtual function overriding boilerplate, or if there are no -// virtual functions, U = held_instance. -// -// A look-alike of this class in root/boost/python/cross_module.hpp -// is used for the implementation of the cross-module support -// (export_converters and import_converters). If from_python -// and to_python converters are added or removed from the class -// below, the class python_import_extension_class_converters has -// to be modified accordingly. -// -template > -class python_extension_class_converters -{ - public: - // Get an object which can be used to convert T to/from python. This is used - // as a kind of concept check by the global template - // - // PyObject* to_python(const T& x) - // - // below this class, to prevent the confusing messages that would otherwise - // pop up. Now, if T hasn't been wrapped as an extension class, the user - // will see an error message about the lack of an eligible - // py_extension_class_converters() function. - friend python_extension_class_converters py_extension_class_converters(boost::python::type) - { - return python_extension_class_converters(); - } - - // This is a member function because in a conforming implementation, friend - // funcitons defined inline in the class body are all instantiated as soon - // as the enclosing class is instantiated. If T is not copyable, that causes - // a compiler error. Instead, we access this function through the global - // template - // - // PyObject* to_python(const T& x) - // - // defined below this class. Since template functions are instantiated only - // on demand, errors will be avoided unless T is noncopyable and the user - // writes code which causes us to try to copy a T. - PyObject* to_python(const T& x) const - { - boost::python::reference result(create_instance()); - result->add_implementation( - std::auto_ptr( - new boost::python::detail::instance_value_holder(result.get(), x))); - return result.release(); - } - - friend - T* non_null_from_python(PyObject* obj, boost::python::type) - { - // downcast to an extension_instance, then find the actual T - boost::python::detail::extension_instance* self = boost::python::detail::get_extension_instance(obj); - typedef std::vector::const_iterator iterator; - for (iterator p = self->wrapped_objects().begin(); - p != self->wrapped_objects().end(); ++p) - { - boost::python::detail::instance_holder* held = dynamic_cast*>(*p); - if (held != 0) - return held->target(); - - // see extclass.cpp for an explanation of try_class_conversions() - void* target = boost::python::detail::class_registry::class_object()->try_class_conversions(*p); - if(target) - return static_cast(target); - } - boost::python::detail::report_missing_instance_data(self, boost::python::detail::class_registry::class_object(), typeid(T)); - boost::python::throw_argument_error(); - return 0; - } - - // Convert to T* - friend T* from_python(PyObject* obj, boost::python::type) - { - if (obj == Py_None) - return 0; - else - return non_null_from_python(obj, boost::python::type()); - } - - // Extract from obj a mutable reference to the PtrType object which is holding a T. - template - static PtrType& smart_ptr_reference(PyObject* obj, boost::python::type) - { - // downcast to an extension_instance, then find the actual T - boost::python::detail::extension_instance* self = boost::python::detail::get_extension_instance(obj); - typedef std::vector::const_iterator iterator; - for (iterator p = self->wrapped_objects().begin(); - p != self->wrapped_objects().end(); ++p) - { - boost::python::detail::instance_ptr_holder* held = - dynamic_cast*>(*p); - if (held != 0) - return held->ptr(); - } - boost::python::detail::report_missing_ptr_data(self, boost::python::detail::class_registry::class_object(), typeid(T)); - boost::python::throw_argument_error(); - - return *(PtrType*)obj; - } - - // Extract from obj a reference to the PtrType object which is holding a - // T. If it weren't for auto_ptr, it would be a constant reference. Do not - // modify the referent except by copying an auto_ptr! If obj is None, the - // reference denotes a default-constructed PtrType - template - static PtrType& smart_ptr_value(PyObject* obj, boost::python::type) - { - if (obj == Py_None) - { - static PtrType null_ptr; - return null_ptr; - } - return smart_ptr_reference(obj, boost::python::type()); - } - - template - static PyObject* smart_ptr_to_python(PtrType x) - { - if (boost::python::detail::is_null(x)) - { - return boost::python::detail::none(); - } - - boost::python::reference result(create_instance()); - result->add_implementation( - std::auto_ptr( - new boost::python::detail::instance_ptr_holder(x))); - return result.release(); - } - - static boost::python::reference create_instance() - { - PyTypeObject* class_object = boost::python::detail::class_registry::class_object(); - if (class_object == 0) - boost::python::detail::report_missing_class_object(typeid(T)); - - return boost::python::reference( - new boost::python::detail::extension_instance(class_object)); - } - - // Convert to const T* - friend const T* from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to const T* const& - friend const T* from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to T* const& - friend T* from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to T& - friend T& from_python(PyObject* p, boost::python::type) - { return *boost::python::detail::check_non_null(non_null_from_python(p, boost::python::type())); } - - // Convert to const T& - friend const T& from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - // Convert to T - friend const T& from_python(PyObject* p, boost::python::type) - { return from_python(p, boost::python::type()); } - - friend std::auto_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_reference(p, boost::python::type >()); } - - friend std::auto_ptr from_python(PyObject* p, boost::python::type >) - { return smart_ptr_value(p, boost::python::type >()); } - - friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_value(p, boost::python::type >()); } - - friend PyObject* to_python(std::auto_ptr x) - { return smart_ptr_to_python(x); } - - friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_reference(p, boost::python::type >()); } - - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type >) - { return smart_ptr_value(p, boost::python::type >()); } - - friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&>) - { return smart_ptr_value(p, boost::python::type >()); } - - friend PyObject* to_python(boost::shared_ptr x) - { return smart_ptr_to_python(x); } -}; - -// Convert T to_python, instantiated on demand and only if there isn't a -// non-template overload for this function. This version is the one invoked when -// T is a wrapped class. See the first 2 functions declared in -// python_extension_class_converters above for more info. -template -PyObject* to_python(const T& x) -{ - return py_extension_class_converters(boost::python::type()).to_python(x); -} - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -namespace boost { namespace python { - -BOOST_PYTHON_IMPORT_CONVERSION(python_extension_class_converters); - -namespace detail { - -template class instance_holder; - -class BOOST_PYTHON_DECL read_only_setattr_function : public function -{ - public: - read_only_setattr_function(const char* name); - PyObject* do_call(PyObject* args, PyObject* keywords) const; - const char* description() const; - private: - string m_name; -}; - - template - struct define_conversion - { - static void* upcast_ptr(void* v) - { - return static_cast(static_cast(v)); - } - - static void* downcast_ptr(void* v) - { - return dynamic_cast(static_cast(v)); - } - }; - -// An easy way to make an extension base class which wraps T. Note that Python -// subclasses of this class will simply be class_t objects. -// -// U should be a class derived from T which overrides virtual functions with -// boilerplate code to call back into Python. See extclass_demo.h for examples. -// -// U is optional, but you won't be able to override any member functions in -// Python which are called from C++ if you don't supply it. If you just want to -// be able to use T in python without overriding member functions, you can omit -// U. -template > -class extension_class - : public python_extension_class_converters, // This generates the to_python/from_python functions - public extension_class_base -{ - public: - typedef T wrapped_type; - typedef U callback_type; - - // Construct with a name that comes from typeid(T).name(). The name only - // affects the objects of this class are represented through repr() - extension_class(); - - // Construct with the given name. The name only affects the objects of this - // class are represented through repr() - extension_class(const char* name); - - ~extension_class(); - - // define constructors - template - inline void def(constructor) - // The following incantation builds a signature1, signature2,... object. It - // should _all_ get optimized away. - { add_constructor( - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - prepend(type::id(), - signature0()))))))))))); - } - - - // export homogeneous operators (type of both lhs and rhs is 'operator') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>()); - - // export homogeneous operators (type of both lhs and rhs is 'T const&') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>()); - template - inline void def(operators) - { - typedef typename operand_select::template wrapped::type true_operand; - def_operators(operators()); - } - - // export heterogeneous operators (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::right_operand()); - - // export heterogeneous operators (type of lhs: 'T const&', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(), - // boost::python::right_operand()); - template - inline void def(operators, right_operand r) - { - typedef typename operand_select::template wrapped::type true_left; - def_operators(operators(), r); - } - - // export heterogeneous reverse-argument operators - // (type of lhs: 'left', of rhs: 'right') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(), - // boost::python::left_operand()); - - // export heterogeneous reverse-argument operators - // (type of lhs: 'left', of rhs: 'T const&') - // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(), - // boost::python::left_operand()); - template - inline void def(operators, left_operand l) - { - typedef typename operand_select::template wrapped::type true_right; - def_operators(operators(), l); - } - - // define a function that passes Python arguments and keywords - // to C++ verbatim (as a 'tuple const&' and 'dictionary const&' - // respectively). This is useful for manual argument passing. - // It's also the only possibility to pass keyword arguments to C++. - // Fn must have a signatur that is compatible to - // PyObject* (*)(PyObject* aTuple, PyObject* aDictionary) - template - inline void def_raw(Fn fn, const char* name) - { - this->add_method(new_raw_arguments_function(fn), name); - } - - // define member functions. In fact this works for free functions, too - - // they act like static member functions, or if they start with the - // appropriate self argument (as a pointer), they can be used just like - // ordinary member functions -- just like Python! - template - inline void def(Fn fn, const char* name) - { - this->add_method(new_wrapped_function(fn), name); - } - - // Define a virtual member function with a default implementation. - // default_fn should be a function which provides the default implementation. - // Be careful that default_fn does not in fact call fn virtually! - template - inline void def(Fn fn, const char* name, DefaultFn default_fn) - { - this->add_method(new_virtual_function(type(), fn, default_fn), name); - } - - // Provide a function which implements x., reading from the given - // member (pm) of the T obj - template - inline void def_getter(MemberType T::*pm, const char* name) - { - this->add_getter_method(new getter_function(pm), name); - } - - // Provide a function which implements assignment to x., writing to - // the given member (pm) of the T obj - template - inline void def_setter(MemberType T::*pm, const char* name) - { - this->add_setter_method(new setter_function(pm), name); - } - - // Expose the given member (pm) of the T obj as a read-only attribute - template - inline void def_readonly(MemberType T::*pm, const char* name) - { - this->add_setter_method(new read_only_setattr_function(name), name); - this->def_getter(pm, name); - } - - // Expose the given member (pm) of the T obj as a read/write attribute - template - inline void def_read_write(MemberType T::*pm, const char* name) - { - this->def_getter(pm, name); - this->def_setter(pm, name); - } - - // define the standard coercion needed for operator overloading - void def_standard_coerce(); - - // declare the given class a base class of this one and register - // up and down conversion functions - template - void declare_base(extension_class* base) - { - // see extclass.cpp for an explanation of why we need to register - // conversion functions - base_class_info baseInfo(base, - &define_conversion::downcast_ptr); - class_registry::register_base_class(baseInfo); - add_base(ref(as_object(base), ref::increment_count)); - - derived_class_info derivedInfo(this, - &define_conversion::upcast_ptr); - class_registry::register_derived_class(derivedInfo); - } - - // declare the given class a base class of this one and register - // only up conversion function - template - void declare_base(extension_class* base, without_downcast_t) - { - // see extclass.cpp for an explanation of why we need to register - // conversion functions - base_class_info baseInfo(base, 0); - class_registry::register_base_class(baseInfo); - add_base(ref(as_object(base), ref::increment_count)); - - derived_class_info derivedInfo(this, - &define_conversion::upcast_ptr); - class_registry::register_derived_class(derivedInfo); - } - - private: // types - typedef instance_value_holder holder; - - private: // extension_class_base virtual function implementations - std::vector const& base_classes() const; - std::vector const& derived_classes() const; - void* extract_object_from_holder(instance_holder_base* v) const; - - private: // Utility functions - template - inline void def_operators(operators) - { - def_standard_coerce(); - - // for some strange reason, this prevents MSVC from having an - // "unrecoverable block scoping error"! - typedef choose_op<(which & op_add)> choose_add; - - choose_op<(which & op_add)>::template args::add(this); - choose_op<(which & op_sub)>::template args::add(this); - choose_op<(which & op_mul)>::template args::add(this); - choose_op<(which & op_div)>::template args::add(this); - choose_op<(which & op_mod)>::template args::add(this); - choose_op<(which & op_divmod)>::template args::add(this); - choose_op<(which & op_pow)>::template args::add(this); - choose_op<(which & op_lshift)>::template args::add(this); - choose_op<(which & op_rshift)>::template args::add(this); - choose_op<(which & op_and)>::template args::add(this); - choose_op<(which & op_xor)>::template args::add(this); - choose_op<(which & op_or)>::template args::add(this); - choose_op<(which & op_gt)>::template args::add(this); - choose_op<(which & op_ge)>::template args::add(this); - choose_op<(which & op_lt)>::template args::add(this); - choose_op<(which & op_le)>::template args::add(this); - choose_op<(which & op_eq)>::template args::add(this); - choose_op<(which & op_ne)>::template args::add(this); - choose_unary_op<(which & op_neg)>::template args::add(this); - choose_unary_op<(which & op_pos)>::template args::add(this); - choose_unary_op<(which & op_abs)>::template args::add(this); - choose_unary_op<(which & op_invert)>::template args::add(this); - choose_unary_op<(which & op_int)>::template args::add(this); - choose_unary_op<(which & op_long)>::template args::add(this); - choose_unary_op<(which & op_float)>::template args::add(this); - choose_op<(which & op_cmp)>::template args::add(this); - choose_unary_op<(which & op_str)>::template args::add(this); - } - - template - inline void def_operators(operators, right_operand) - { - def_standard_coerce(); - - choose_op<(which & op_add)>::template args::add(this); - choose_op<(which & op_sub)>::template args::add(this); - choose_op<(which & op_mul)>::template args::add(this); - choose_op<(which & op_div)>::template args::add(this); - choose_op<(which & op_mod)>::template args::add(this); - choose_op<(which & op_divmod)>::template args::add(this); - choose_op<(which & op_pow)>::template args::add(this); - choose_op<(which & op_lshift)>::template args::add(this); - choose_op<(which & op_rshift)>::template args::add(this); - choose_op<(which & op_and)>::template args::add(this); - choose_op<(which & op_xor)>::template args::add(this); - choose_op<(which & op_or)>::template args::add(this); - choose_op<(which & op_cmp)>::template args::add(this); - choose_op<(which & op_gt)>::template args::add(this); - choose_op<(which & op_ge)>::template args::add(this); - choose_op<(which & op_lt)>::template args::add(this); - choose_op<(which & op_le)>::template args::add(this); - choose_op<(which & op_eq)>::template args::add(this); - choose_op<(which & op_ne)>::template args::add(this); - } - - template - inline void def_operators(operators, left_operand) - { - def_standard_coerce(); - - choose_rop<(which & op_add)>::template args::add(this); - choose_rop<(which & op_sub)>::template args::add(this); - choose_rop<(which & op_mul)>::template args::add(this); - choose_rop<(which & op_div)>::template args::add(this); - choose_rop<(which & op_mod)>::template args::add(this); - choose_rop<(which & op_divmod)>::template args::add(this); - choose_rop<(which & op_pow)>::template args::add(this); - choose_rop<(which & op_lshift)>::template args::add(this); - choose_rop<(which & op_rshift)>::template args::add(this); - choose_rop<(which & op_and)>::template args::add(this); - choose_rop<(which & op_xor)>::template args::add(this); - choose_rop<(which & op_or)>::template args::add(this); - choose_rop<(which & op_cmp)>::template args::add(this); - } - - template - void add_constructor(signature sig) - { - this->add_constructor_object(init_function::create(sig)); - } -}; - -// A simple wrapper over a T which allows us to use extension_class with a -// single template parameter only. See extension_class, above. -template -class held_instance : public Held -{ - // There are no member functions: we want to avoid inadvertently overriding - // any virtual functions in Held. -public: - held_instance(PyObject*) : Held() {} - template - held_instance(PyObject*, A1 a1) : Held( - typename unwrap_parameter::type(a1)) {} - template - held_instance(PyObject*, A1 a1, A2 a2) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7) - , typename unwrap_parameter::type(a8)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7) - , typename unwrap_parameter::type(a8) - , typename unwrap_parameter::type(a9)) {} - template - held_instance(PyObject*, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) : Held( - typename unwrap_parameter::type(a1) - , typename unwrap_parameter::type(a2) - , typename unwrap_parameter::type(a3) - , typename unwrap_parameter::type(a4) - , typename unwrap_parameter::type(a5) - , typename unwrap_parameter::type(a6) - , typename unwrap_parameter::type(a7) - , typename unwrap_parameter::type(a8) - , typename unwrap_parameter::type(a9) - , typename unwrap_parameter::type(a10)) {} -}; - -// Abstract base class for all obj holders. Base for template class -// instance_holder<>, below. -class BOOST_PYTHON_DECL instance_holder_base -{ -public: - virtual ~instance_holder_base() {} - virtual bool held_by_value() = 0; -}; - -// Abstract base class which holds a Held, somehow. Provides a uniform way to -// get a pointer to the held object -template -class instance_holder : public instance_holder_base -{ -public: - virtual Held*target() = 0; -}; - -// Concrete class which holds a Held by way of a wrapper class Wrapper. If Held -// can be constructed with arguments (A1...An), Wrapper must have a -// corresponding constructor for arguments (PyObject*, A1...An). Wrapper is -// neccessary to implement virtual function callbacks (there must be a -// back-pointer to the actual Python object so that we can call any -// overrides). held_instance (above) is used as a default Wrapper class when -// there are no virtual functions. -template -class instance_value_holder : public instance_holder -{ -public: - Held* target() { return &m_held; } - Wrapper* value_target() { return &m_held; } - - instance_value_holder(extension_instance* p) : - m_held(p) {} - template - instance_value_holder(extension_instance* p, A1 a1) : - m_held(p, a1) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2) : - m_held(p, a1, a2) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3) : - m_held(p, a1, a2, a3) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4) : - m_held(p, a1, a2, a3, a4) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) : - m_held(p, a1, a2, a3, a4, a5) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) : - m_held(p, a1, a2, a3, a4, a5, a6) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) : - m_held(p, a1, a2, a3, a4, a5, a6, a7) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) : - m_held(p, a1, a2, a3, a4, a5, a6, a7, a8) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) : - m_held(p, a1, a2, a3, a4, a5, a6, a7, a8, a9) {} - template - instance_value_holder(extension_instance* p, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) : - m_held(p, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} - - public: // implementation of instance_holder_base required interface - bool held_by_value() { return true; } - - private: - Wrapper m_held; -}; - -// Concrete class which holds a HeldType by way of a (possibly smart) pointer -// PtrType. By default, these are only generated for PtrType == -// std::auto_ptr and PtrType == boost::shared_ptr. -template -class instance_ptr_holder : public instance_holder -{ - public: - HeldType* target() { return &*m_ptr; } - PtrType& ptr() { return m_ptr; } - - instance_ptr_holder(PtrType ptr) : m_ptr(ptr) {} - - public: // implementation of instance_holder_base required interface - bool held_by_value() { return false; } - private: - PtrType m_ptr; -}; - -// -// Template function implementations -// - -template -extension_class::extension_class() - : extension_class_base(typeid(T).name()) -{ - class_registry::register_class(this); -} - -template -extension_class::extension_class(const char* name) - : extension_class_base(name) -{ - class_registry::register_class(this); -} - -template -void extension_class::def_standard_coerce() -{ - ref coerce_fct = dict().get_item(string("__coerce__")); - - if(coerce_fct.get() == 0) // not yet defined - this->def(&standard_coerce, "__coerce__"); -} - -template -inline -std::vector const& -extension_class::base_classes() const -{ - return class_registry::base_classes(); -} - -template -inline -std::vector const& -extension_class::derived_classes() const -{ - return class_registry::derived_classes(); -} - -template -void* extension_class::extract_object_from_holder(instance_holder_base* v) const -{ - instance_holder* held = dynamic_cast*>(v); - if(held) - return held->target(); - return 0; -} - -template -extension_class::~extension_class() -{ - class_registry::unregister_class(this); -} - -template -inline void class_registry::register_class(extension_class_base* p) -{ - // You're not expected to create more than one of these! - assert(static_class_object == 0); - static_class_object = p; -} - -template -inline void class_registry::unregister_class(extension_class_base* p) -{ - // The user should be destroying the same object they created. - assert(static_class_object == p); - (void)p; // unused in shipping version - static_class_object = 0; -} - -template -void class_registry::register_base_class(base_class_info const& i) -{ - static_base_class_info.push_back(i); -} - -template -void class_registry::register_derived_class(derived_class_info const& i) -{ - static_derived_class_info.push_back(i); -} - -template -std::vector const& class_registry::base_classes() -{ - return static_base_class_info; -} - -template -std::vector const& class_registry::derived_classes() -{ - return static_derived_class_info; -} - -// -// Static data member declaration. -// -template -extension_class_base* class_registry::static_class_object; -template -std::vector class_registry::static_base_class_info; -template -std::vector class_registry::static_derived_class_info; - -}}} // namespace boost::python::detail - -#endif // EXTENSION_CLASS_DWA052000_H_ diff --git a/include/boost/python/detail/force_instantiate.hpp b/include/boost/python/detail/force_instantiate.hpp deleted file mode 100755 index 62446c32..00000000 --- a/include/boost/python/detail/force_instantiate.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FORCE_INSTANTIATE_DWA200265_HPP -# define FORCE_INSTANTIATE_DWA200265_HPP - -namespace boost { namespace python { namespace detail { - -// Allows us to force the argument to be instantiated without -// incurring unused variable warnings - -# if !defined(BOOST_MSVC) || BOOST_MSVC == 1200 || _MSC_FULL_VER > 13102196 - -template -inline void force_instantiate(T const&) {} - -# else - -# pragma optimize("g", off) -inline void force_instantiate_impl(...) {} -# pragma optimize("", on) -template -inline void force_instantiate(T const& x) -{ - detail::force_instantiate_impl(&x); -} -# endif - -}}} // namespace boost::python::detail - -#endif // FORCE_INSTANTIATE_DWA200265_HPP diff --git a/include/boost/python/detail/functions.hpp b/include/boost/python/detail/functions.hpp deleted file mode 100644 index 486d73f9..00000000 --- a/include/boost/python/detail/functions.hpp +++ /dev/null @@ -1,311 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef FUNCTIONS_DWA051400_H_ -# define FUNCTIONS_DWA051400_H_ - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// forward declaration -class extension_instance; - - -// function -- -// the common base class for all overloadable function and method objects -// supplied by the library. -class BOOST_PYTHON_DECL function : public python_object -{ - public: - function(); - // function objects are reasonably rare, so we guess we can afford a virtual table. - // This cuts down on the number of distinct type objects which need to be defined. - virtual ~function() {} - - PyObject* call(PyObject* args, PyObject* keywords) const; - static void add_to_namespace(reference f, const char* name, PyObject* dict); - - private: - virtual PyObject* do_call(PyObject* args, PyObject* keywords) const = 0; - virtual const char* description() const = 0; - private: - struct type_object; - private: - reference m_overloads; // A linked list of the function overloads -}; - -// wrapped_function_pointer<> -- -// A single function or member function pointer wrapped and presented to -// Python as a callable object. -// -// Template parameters: -// R - the return type of the function pointer -// F - the complete type of the wrapped function pointer -template -struct wrapped_function_pointer : function -{ - typedef F ptr_fun; // pointer-to--function or pointer-to-member-function - - wrapped_function_pointer(ptr_fun pf) - : m_pf(pf) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const - { - // This is where the boundary between the uniform Python function - // interface and the statically-checked C++ function interface is - // crossed. - return caller::call(m_pf, args, keywords); - } - - const char* description() const - { return typeid(F).name(); } - - private: - const ptr_fun m_pf; -}; - -// raw_arguments_function -// A function that passes the Python argument tuple and keyword dictionary -// verbatim to C++ (useful for customized argument parsing and variable -// argument lists) -template -struct raw_arguments_function : function -{ - typedef Ret (*ptr_fun)(Args, Keywords); - - raw_arguments_function(ptr_fun pf) - : m_pf(pf) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const - { - ref dict(keywords ? - ref(keywords, ref::increment_count) : - ref(PyDict_New())); - - return to_python( - (*m_pf)(from_python(args, boost::python::type()), - from_python(dict.get(), boost::python::type()))); - } - - const char* description() const - { return typeid(ptr_fun).name(); } - - private: - const ptr_fun m_pf; -}; - -// virtual_function<> -- -// A virtual function with a default implementation wrapped and presented -// to Python as a callable object. -// -// Template parameters: -// T - the type of the target class -// R - the return type of the function pointer -// V - the virtual function pointer being wrapped -// (should be of the form R(T::*)(), or R (*)(T, )) -// D - a function which takes a T&, const T&, T*, or const T* first -// parameter and calls T::f on it /non-virtually/, where V -// approximates &T::f. -template -class virtual_function : public function -{ - public: - virtual_function(V virtual_function_ptr, D default_implementation) - : m_virtual_function_ptr(virtual_function_ptr), - m_default_implementation(default_implementation) - {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const; - - const char* description() const - { return typeid(V).name(); } - - private: - const V m_virtual_function_ptr; - const D m_default_implementation; -}; - -// A helper function for new_member_function(), below. Implements the core -// functionality once the return type has already been deduced. R is expected to -// be type, where X is the actual return type of pmf. -template -function* new_wrapped_function_aux(R, F pmf) -{ - // We can't just use "typename R::Type" below because MSVC (incorrectly) pukes. - typedef typename R::type return_type; - return new wrapped_function_pointer(pmf); -} - -// Create and return a new member function object wrapping the given -// pointer-to-member function -template -inline function* new_wrapped_function(F pmf) -{ - // Deduce the return type and pass it off to the helper function above - return new_wrapped_function_aux(return_value(pmf), pmf); -} - -template -function* new_raw_arguments_function(R (*pmf)(Args, keywords)) -{ - return new raw_arguments_function(pmf); -} - - -// A helper function for new_virtual_function(), below. Implements the core -// functionality once the return type has already been deduced. R is expected to -// be type, where X is the actual return type of V. -template -inline function* new_virtual_function_aux( - type, R, V virtual_function_ptr, D default_implementation - ) -{ - // We can't just use "typename R::Type" below because MSVC (incorrectly) pukes. - typedef typename R::type return_type; - return new virtual_function( - virtual_function_ptr, default_implementation); -} - -// Create and return a new virtual_function object wrapping the given -// virtual_function_ptr and default_implementation -template -inline function* new_virtual_function( - type, V virtual_function_ptr, D default_implementation - ) -{ - // Deduce the return type and pass it off to the helper function above - return new_virtual_function_aux( - type(), return_value(virtual_function_ptr), - virtual_function_ptr, default_implementation); -} - -// A function with a bundled "bound target" object. This is what is produced by -// the expression a.b where a is an instance or extension_instance object and b -// is a callable object not found in the obj namespace but on its class or -// a base class. -class BOOST_PYTHON_DECL bound_function : public python_object -{ - public: - static bound_function* create(const ref& target, const ref& fn); - - bound_function(const ref& target, const ref& fn); - PyObject* call(PyObject*args, PyObject* keywords) const; - PyObject* getattr(const char* name) const; - - private: - struct type_object; - friend struct type_object; - - ref m_target; - ref m_unbound_function; - - private: // data members for allocation/deallocation optimization - bound_function* m_free_list_link; - - static bound_function* free_list; -}; - -// Special functions designed to access data members of a wrapped C++ object. -template -class getter_function : public function -{ - public: - typedef MemberType ClassType::* pointer_to_member; - - getter_function(pointer_to_member pm) - : m_pm(pm) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const; - - const char* description() const - { return typeid(MemberType (*)(const ClassType&)).name(); } - private: - pointer_to_member m_pm; -}; - -template -class setter_function : public function -{ - public: - typedef MemberType ClassType::* pointer_to_member; - - setter_function(pointer_to_member pm) - : m_pm(pm) {} - - private: - PyObject* do_call(PyObject* args, PyObject* keywords) const; - - const char* description() const - { return typeid(void (*)(const ClassType&, const MemberType&)).name(); } - private: - pointer_to_member m_pm; -}; - -template -PyObject* getter_function::do_call( - PyObject* args, PyObject* /* keywords */) const -{ - PyObject* self; - if (!PyArg_ParseTuple(args, const_cast("O"), &self)) - return 0; - - return to_python( - from_python(self, type())->*m_pm); -} - -template -PyObject* setter_function::do_call( - PyObject* args, PyObject* /* keywords */) const -{ - PyObject* self; - PyObject* value; - if (!PyArg_ParseTuple(args, const_cast("OO"), &self, &value)) - return 0; - - typedef typename boost::call_traits::const_reference extract_type; - from_python(self, type())->*m_pm - = from_python(value, type()); - - return none(); -} - -template -PyObject* virtual_function::do_call(PyObject* args, PyObject* keywords) const -{ - // If the target object is held by pointer, we must call through the virtual - // function pointer to the most-derived override. - PyObject* target = PyTuple_GetItem(args, 0); - if (target != 0) - { - extension_instance* self = get_extension_instance(target); - if (self->wrapped_objects().size() == 1 - && !self->wrapped_objects()[0]->held_by_value()) - { - return caller::call(m_virtual_function_ptr, args, keywords); - } - } - return caller::call(m_default_implementation, args, keywords); -} - -}}} // namespace boost::python::detail - -#endif // FUNCTIONS_DWA051400_H_ diff --git a/include/boost/python/detail/if_else.hpp b/include/boost/python/detail/if_else.hpp deleted file mode 100644 index 6668617c..00000000 --- a/include/boost/python/detail/if_else.hpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef IF_ELSE_DWA2002322_HPP -# define IF_ELSE_DWA2002322_HPP -# include - -namespace boost { namespace python { namespace detail { - -template struct elif_selected; - -template -struct if_selected -{ - template - struct elif : elif_selected - { - }; - - template - struct else_ - { - typedef T type; - }; -}; - -# if defined(BOOST_MSVC) && (BOOST_MSVC == 1300) -namespace msvc70_aux { - -template< bool > struct inherit_from -{ - template< typename T > struct result - { - typedef T type; - }; -}; - -template<> struct inherit_from -{ - template< typename T > struct result - { - struct type {}; - }; -}; - -template< typename T > -struct never_true -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -} // namespace msvc70_aux - -#endif // # if defined(BOOST_MSVC) && (BOOST_MSVC == 1300) - -template -struct elif_selected -{ -# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407) - template class then; -# elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300) - template - struct then : msvc70_aux::inherit_from< msvc70_aux::never_true::value > - ::template result< if_selected >::type - { - }; -# else - template - struct then : if_selected - { - }; -# endif -}; - -# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407) -template -template -class elif_selected::then : public if_selected -{ -}; -# endif - -template struct if_ -{ - template - struct then : if_selected - { - }; -}; - -struct if_unselected -{ - template struct elif : if_ - { - }; - - template - struct else_ - { - typedef U type; - }; -}; - -template <> -struct if_ -{ - template - struct then : if_unselected - { - }; -}; - -}}} // namespace boost::python::detail - -#endif // IF_ELSE_DWA2002322_HPP diff --git a/include/boost/python/detail/indirect_traits.hpp b/include/boost/python/detail/indirect_traits.hpp deleted file mode 100644 index c6f8bcc7..00000000 --- a/include/boost/python/detail/indirect_traits.hpp +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef INDIRECT_TRAITS_DWA2002131_HPP -# define INDIRECT_TRAITS_DWA2002131_HPP -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct is_reference_to_const -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_reference_to_const -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -# if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround -template -struct is_reference_to_const -{ - static const bool value = true; -}; -# endif - -# if 0 // Corresponding code doesn't work on MSVC yet -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; - -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; - -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; - -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; -# endif - -template -struct is_pointer_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_pointer_to_function -{ - // There's no such thing as a pointer-to-cv-function, so we don't need specializations for those - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; - -template -struct is_reference_to_non_const -{ - BOOST_STATIC_CONSTANT( - bool, value = ( - ::boost::type_traits::ice_and< - ::boost::is_reference::value - , ::boost::type_traits::ice_not< - ::boost::python::detail::is_reference_to_const::value>::value - >::value) - ); -}; - -template -struct is_reference_to_volatile -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_reference_to_volatile -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -# if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround -template -struct is_reference_to_volatile -{ - static const bool value = true; -}; -# endif - - -template -struct is_reference_to_pointer -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_reference_to_pointer -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_reference_to_pointer -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_reference_to_pointer -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_reference_to_pointer -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_reference_to_class -{ - BOOST_STATIC_CONSTANT( - bool, value - = (boost::type_traits::ice_and< - is_reference::value - , is_class< - typename remove_cv< - typename remove_reference::type - >::type - >::value - >::value) - ); -}; - -template -struct is_pointer_to_class -{ - BOOST_STATIC_CONSTANT( - bool, value - = (boost::type_traits::ice_and< - is_pointer::value - , is_class< - typename remove_cv< - typename remove_pointer::type - >::type - >::value - >::value) - ); -}; - -# else - -typedef char (&inner_yes_type)[3]; -typedef char (&inner_no_type)[2]; -typedef char (&outer_no_type)[1]; - -template -struct is_const_help -{ - typedef typename mpl::if_c< - is_const::value - , inner_yes_type - , inner_no_type - >::type type; -}; - -template -struct is_volatile_help -{ - typedef typename mpl::if_c< - is_volatile::value - , inner_yes_type - , inner_no_type - >::type type; -}; - -template -struct is_pointer_help -{ - typedef typename mpl::if_c< - is_pointer::value - , inner_yes_type - , inner_no_type - >::type type; -}; - -template -struct is_class_help -{ - typedef typename mpl::if_c< - is_class::value - , inner_yes_type - , inner_no_type - >::type type; -}; - -# if 0 // doesn't seem to work yet -template -struct is_reference_to_function -{ - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = sizeof(::boost::type_traits::is_function_ptr_tester(t)) == sizeof(::boost::type_traits::yes_type)); -# endif - -template -struct is_pointer_to_function -{ - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = sizeof(::boost::type_traits::is_function_ptr_tester(t)) == sizeof(::boost::type_traits::yes_type)); -}; - -struct false_helper1 -{ - template - struct apply - { - BOOST_STATIC_CONSTANT(bool, value = false); - }; -}; - -template -typename is_const_help::type reference_to_const_helper(V&); -outer_no_type -reference_to_const_helper(...); - -template -struct is_reference_to_const_helper1 -{ - template - struct apply - { - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type)); - }; -}; - -template <> -struct is_reference_to_const_helper1 : false_helper1 -{ -}; - - -template -struct is_reference_to_const - : is_reference_to_const_helper1::value>::template apply -{ -}; - - - -template -struct is_reference_to_non_const_helper1 -{ - template - struct apply - { - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type)); - }; -}; - -template <> -struct is_reference_to_non_const_helper1 : false_helper1 -{ -}; - - -template -struct is_reference_to_non_const - : is_reference_to_non_const_helper1::value>::template apply -{ -}; - - -template -typename is_volatile_help::type reference_to_volatile_helper(V&); -outer_no_type -reference_to_volatile_helper(...); - -template -struct is_reference_to_volatile_helper1 -{ - template - struct apply - { - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type)); - }; -}; - -template <> -struct is_reference_to_volatile_helper1 : false_helper1 -{ -}; - - -template -struct is_reference_to_volatile - : is_reference_to_volatile_helper1::value>::template apply -{ -}; - - -template -typename is_pointer_help::type reference_to_pointer_helper(V&); -outer_no_type reference_to_pointer_helper(...); - -template -struct is_reference_to_pointer -{ - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = (is_reference::value - && sizeof(reference_to_pointer_helper(t)) == sizeof(inner_yes_type)) - ); -}; - -template -typename is_class_help::type reference_to_class_helper(V const volatile&); -outer_no_type reference_to_class_helper(...); - -template -struct is_reference_to_class -{ - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = (is_reference::value - && sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type)) - ); -}; - -template -typename is_class_help::type pointer_to_class_helper(V const volatile*); -outer_no_type pointer_to_class_helper(...); - -template -struct is_pointer_to_class -{ - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = (is_pointer::value - && sizeof(pointer_to_class_helper(t)) == sizeof(inner_yes_type)) - ); -}; -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -}}} // namespace boost::python::detail - -#endif // INDIRECT_TRAITS_DWA2002131_HPP diff --git a/include/boost/python/detail/init_function.hpp b/include/boost/python/detail/init_function.hpp deleted file mode 100644 index 928159c2..00000000 --- a/include/boost/python/detail/init_function.hpp +++ /dev/null @@ -1,562 +0,0 @@ -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file was generated for %d-argument constructors by gen_init_function.python - -#ifndef INIT_FUNCTION_DWA052000_H_ -# define INIT_FUNCTION_DWA052000_H_ - -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail { - - // parameter_traits - so far, this is a way to pass a const T& when we can be - // sure T is not a reference type, and a raw T otherwise. This should be - // rolled into boost::call_traits. Ordinarily, parameter_traits would be - // written: - // - // template struct parameter_traits - // { - // typedef const T& const_reference; - // }; - // - // template struct parameter_traits - // { - // typedef T& const_reference; - // }; - // - // template <> struct parameter_traits - // { - // typedef void const_reference; - // }; - // - // ...but since we can't partially specialize on reference types, we need this - // long-winded but equivalent incantation. - - // const_ref_selector -- an implementation detail of parameter_traits (below). This uses - // the usual "poor man's partial specialization" hack for MSVC. - template - struct const_ref_selector - { - template - struct const_ref - { - typedef const T& type; - }; - }; - - template <> - struct const_ref_selector - { - template - struct const_ref - { - typedef T type; - }; - }; - -# ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable: 4181) -# endif // BOOST_MSVC - template - struct parameter_traits - { - private: - enum { is_ref = boost::is_reference::value }; - typedef const_ref_selector selector; - public: - typedef typename selector::template const_ref::type const_reference; - }; -# ifdef BOOST_MSVC -# pragma warning(pop) -# endif // BOOST_MSVC - - // Full spcialization for void - template <> - struct parameter_traits - { - typedef void const_reference; - }; - - struct reference_parameter_base {}; - - template - class reference_parameter - : public reference_parameter_base - { - public: - typedef typename parameter_traits::const_reference const_reference; - reference_parameter(const_reference value) - : value(value) {} - operator const_reference() { return value; } - private: - const_reference value; - }; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct unwrap_parameter - { - typedef typename boost::add_reference::type type; - }; - - template - struct unwrap_parameter > - { - typedef typename reference_parameter::const_reference type; - }; -# else - template - struct unwrap_parameter_helper - { - template - struct apply - { - typedef typename T::const_reference type; - }; - }; - - template <> - struct unwrap_parameter_helper - { - template - struct apply - { - typedef typename add_reference::type type; - }; - }; - - template - struct unwrap_parameter - { - BOOST_STATIC_CONSTANT( - bool, is_wrapped = (is_base_and_derived::value)); - - typedef typename unwrap_parameter_helper< - is_wrapped - >::template apply::type type; - }; -# endif - -class extension_instance; -class instance_holder_base; - -class init; -template struct init0; -template struct init1; -template struct init2; -template struct init3; -template struct init4; -template struct init5; -template struct init6; -template struct init7; -template struct init8; -template struct init9; -template struct init10; - -template -struct init_function -{ -# ifdef BOOST_MSVC6_OR_EARLIER -# define typename -# endif - static init* create(signature0) { - return new init0; - } - - template - static init* create(signature1) { - return new init1::const_reference>; - } - - template - static init* create(signature2) { - return new init2::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature3) { - return new init3::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature4) { - return new init4::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature5) { - return new init5::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature6) { - return new init6::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature7) { - return new init7::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature8) { - return new init8::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature9) { - return new init9::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } - - template - static init* create(signature10) { - return new init10::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference, - typename detail::parameter_traits::const_reference>; - } -#ifdef BOOST_MSVC6_OR_EARLIER -# undef typename -#endif -}; - -class BOOST_PYTHON_DECL init : public function -{ -private: // override function hook - PyObject* do_call(PyObject* args, PyObject* keywords) const; -private: - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* tail_args, PyObject* keywords) const = 0; -}; - - -template -struct init0 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - if (!PyArg_ParseTuple(args, const_cast(""))) - throw_argument_error(); - return new T(self - ); - } - const char* description() const - { return typeid(void (*)(T&)).name(); } -}; - -template -struct init1 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1)).name(); } -}; - -template -struct init2 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2)).name(); } -}; - -template -struct init3 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3)).name(); } -}; - -template -struct init4 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4)).name(); } -}; - -template -struct init5 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5)).name(); } -}; - -template -struct init6 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6)).name(); } -}; - -template -struct init7 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7)).name(); } -}; - -template -struct init8 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())), - boost::python::detail::reference_parameter(from_python(a8, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7, A8)).name(); } -}; - -template -struct init9 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())), - boost::python::detail::reference_parameter(from_python(a8, type())), - boost::python::detail::reference_parameter(from_python(a9, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7, A8, A9)).name(); } -}; - -template -struct init10 : init -{ - virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const - { - PyObject* a1; - PyObject* a2; - PyObject* a3; - PyObject* a4; - PyObject* a5; - PyObject* a6; - PyObject* a7; - PyObject* a8; - PyObject* a9; - PyObject* a10; - if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - throw_argument_error(); - return new T(self, - boost::python::detail::reference_parameter(from_python(a1, type())), - boost::python::detail::reference_parameter(from_python(a2, type())), - boost::python::detail::reference_parameter(from_python(a3, type())), - boost::python::detail::reference_parameter(from_python(a4, type())), - boost::python::detail::reference_parameter(from_python(a5, type())), - boost::python::detail::reference_parameter(from_python(a6, type())), - boost::python::detail::reference_parameter(from_python(a7, type())), - boost::python::detail::reference_parameter(from_python(a8, type())), - boost::python::detail::reference_parameter(from_python(a9, type())), - boost::python::detail::reference_parameter(from_python(a10, type())) - ); - } - const char* description() const - { return typeid(void (*)(T&, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)).name(); } -}; - -}}} // namespace boost::python::detail - -#endif // INIT_FUNCTION_DWA052000_H_ diff --git a/include/boost/python/detail/make_tuple.hpp b/include/boost/python/detail/make_tuple.hpp deleted file mode 100644 index 07cd9903..00000000 --- a/include/boost/python/detail/make_tuple.hpp +++ /dev/null @@ -1,31 +0,0 @@ -# // Copyright David Abrahams 2002. Permission to copy, use, -# // modify, sell and distribute this software is granted provided this -# // copyright notice appears in all copies. This software is provided -# // "as is" without express or implied warranty, and with no claim as -# // to its suitability for any purpose. - -#if !defined(BOOST_PP_IS_ITERATING) -# error Boost.Python - do not include this file! -#endif - -#define N BOOST_PP_ITERATION() - -#define BOOST_PYTHON_MAKE_TUPLE_ARG(z, N, ignored) \ - PyTuple_SET_ITEM( \ - result.ptr() \ - , N \ - , python::incref(python::object(a##N).ptr()) \ - ); - - template - tuple - make_tuple(BOOST_PYTHON_BINARY_ENUM(N, A, const& a)) - { - tuple result((detail::new_reference)::PyTuple_New(N)); - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_MAKE_TUPLE_ARG, _) - return result; - } - -#undef BOOST_PYTHON_MAKE_TUPLE_ARG - -#undef N diff --git a/include/boost/python/detail/map_entry.hpp b/include/boost/python/detail/map_entry.hpp deleted file mode 100644 index 9249523a..00000000 --- a/include/boost/python/detail/map_entry.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MAP_ENTRY_DWA2002118_HPP -# define MAP_ENTRY_DWA2002118_HPP - -namespace boost { namespace python { namespace detail { - -// A trivial type that works well as the value_type of associative -// vector maps -template -struct map_entry -{ - map_entry() {} - map_entry(Key k) : key(k), value() {} - map_entry(Key k, Value v) : key(k), value(v) {} - - bool operator<(map_entry const& rhs) const - { - return this->key < rhs.key; - } - - Key key; - Value value; -}; - -template -bool operator<(map_entry const& e, Key const& k) -{ - return e.key < k; -} - -template -bool operator<(Key const& k, map_entry const& e) -{ - return k < e.key; -} - - -}}} // namespace boost::python::detail - -#endif // MAP_ENTRY_DWA2002118_HPP diff --git a/include/boost/python/detail/member_function_cast.hpp b/include/boost/python/detail/member_function_cast.hpp deleted file mode 100644 index f143abd0..00000000 --- a/include/boost/python/detail/member_function_cast.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# ifndef MEMBER_FUNCTION_CAST_DWA2002311_HPP -# define MEMBER_FUNCTION_CAST_DWA2002311_HPP - -# include - -# include -# include - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -template -struct cast_helper -{ - struct yes_helper - { - static FT stage3(FT x) { return x; } - }; - - struct no_helper - { - template - static T stage3(T x) { return x; } - }; - - static yes_helper stage2(S*) { return yes_helper(); } - static no_helper stage2(void*) { return no_helper(); } -}; - -struct non_member_function_cast_impl -{ - template - static non_member_function_cast_impl stage1(T) { return non_member_function_cast_impl(); } - - template - static non_member_function_cast_impl stage2(T) { return non_member_function_cast_impl(); } - - template - T stage3(T x) { return x; } -}; - -template -struct member_function_cast_impl -{ -# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING - template - static non_member_function_cast_impl stage1(U) - { - return non_member_function_cast_impl(); - } -# endif - -// Member functions -# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 3, )) -# include BOOST_PP_ITERATE() -}; - -template -struct member_function_cast -# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING - : member_function_cast_impl -# else - : mpl::if_c< - is_member_function_pointer::value - , member_function_cast_impl - , non_member_function_cast_impl - >::type -# endif -{ -}; - -}}} // namespace boost::python::detail - -# endif // MEMBER_FUNCTION_CAST_DWA2002311_HPP - -#elif BOOST_PP_ITERATION_DEPTH() == 1 -// outer over cv-qualifiers - -# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -#elif BOOST_PP_ITERATION_DEPTH() == 2 -# line BOOST_PP_LINE(__LINE__, member_function_cast.hpp) -// inner over arities - -# define N BOOST_PP_ITERATION() -# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1)) - - template < - class S, class R - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A) - > - static cast_helper - stage1(R (S::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q) - { - return cast_helper(); - } - -# undef N -# undef Q - -#endif diff --git a/include/boost/python/detail/module_base.hpp b/include/boost/python/detail/module_base.hpp deleted file mode 100644 index 144c1d93..00000000 --- a/include/boost/python/detail/module_base.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MODULE_BASE_DWA2002227_HPP -# define MODULE_BASE_DWA2002227_HPP -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -class BOOST_PYTHON_DECL module_base -{ - public: - // Create a module. REQUIRES: only one module is created per module. - module_base(char const* name, char const* doc = 0); - ~module_base(); - - // Add elements to the module - void add(type_handle const&); // just use the type's name - - // Return a reference to the Python module object being built - inline handle<> object() const; - - protected: - void setattr_doc(const char* name, python::object const&, char const* doc); - - private: - handle<> m_module; - static PyMethodDef initial_methods[1]; -}; - -// -// inline implementations -// -inline handle<> module_base::object() const -{ - return m_module; -} - -}}} // namespace boost::python::detail - -#endif // MODULE_BASE_DWA2002227_HPP diff --git a/include/boost/python/detail/module_info.hpp b/include/boost/python/detail/module_info.hpp deleted file mode 100644 index ba3f91cc..00000000 --- a/include/boost/python/detail/module_info.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright David Hawkes 2002. -// Permission is hereby granted to copy, use and modify this software -// for any purpose, including commercial distribution, provided this -// copyright notice is not removed. No warranty WHATSOEVER is provided with this -// software. Any user(s) accepts this software "as is" and as such they will not -// bind the author(s) to any claim of suitabilty for any purpose. - -#ifndef MODULE_INFO -# define MODULE_INFO - -#include - -namespace boost { namespace python { namespace detail { - -class module_info -{ -public: - module_info(const char *name) - { - m_module_name = name; - } - void set_module(object const& m) - { - if(!m_primary_module) - m_primary_module = m; - } - object const& get_module() const - { - return m_primary_module; - } - void set_prior_module(object const& m) - { - m_prior_module = m; - } - object const& get_prior_module() const - { - return m_prior_module; - } - const char* get_module_name() const - { - return m_module_name; - } -private: - object m_primary_module; - object m_prior_module; - const char* m_module_name; -}; - -}}} - -#endif // MODULE_INFO diff --git a/include/boost/python/detail/module_init.hpp b/include/boost/python/detail/module_init.hpp deleted file mode 100644 index 5b2366f6..00000000 --- a/include/boost/python/detail/module_init.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifdef BOOST_PYTHON_V2 -# error obsolete -#endif -#ifndef MODULE_INIT_DWA2002529_HPP -# define MODULE_INIT_DWA2002529_HPP - -# ifndef BOOST_PYTHON_MODULE_INIT - -# if defined(_WIN32) || defined(__CYGWIN__) - -# define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ -extern "C" __declspec(dllexport) void init##name() \ -{ \ - boost::python::handle_exception(&init_module_##name); \ -} \ -void init_module_##name() - -# elif defined(_AIX) - -# include -# define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ -extern "C" \ -{ \ - extern PyObject* _PyImport_LoadDynamicModule(char*, char*, FILE *); \ - void init##name() \ - { \ - boost::python::detail::aix_init_module(_PyImport_LoadDynamicModule, &init_module_##name); \ - } \ -} \ -void init_module_##name() - -# else - -# define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ -extern "C" void init##name() \ -{ \ - boost::python::handle_exception(&init_module_##name); \ -} \ -void init_module_##name() - -# endif - -# endif - -#endif // MODULE_INIT_DWA2002529_HPP diff --git a/include/boost/python/detail/msvc_typeinfo.hpp b/include/boost/python/detail/msvc_typeinfo.hpp deleted file mode 100644 index b50922b7..00000000 --- a/include/boost/python/detail/msvc_typeinfo.hpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MSVC_TYPEINFO_DWA200222_HPP -# define MSVC_TYPEINFO_DWA200222_HPP - -#include -#include -#include -#include -#include -#include -// -// Fix for MSVC's broken typeid() implementation which doesn't strip -// decoration. This fix doesn't handle cv-qualified array types. It -// could probably be done, but I haven't figured it out yet. -// - -# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(BOOST_INTEL_CXX_VERSION) && BOOST_INTEL_CXX_VERSION <= 600 - -namespace boost { namespace python { namespace detail { - -typedef std::type_info const& typeinfo; - -templatestruct value_id_accessor; - -template<> -struct value_id_accessor<0> -{ - template - static typeinfo get(T*) { return typeid(T); } -}; - -template<> -struct value_id_accessor<1> -{ - template - static typeinfo get(T const*) { return typeid(T); } -}; - -template<> -struct value_id_accessor<2> -{ - template - static typeinfo get(T volatile*) { return typeid(T); } -}; - -template<> -struct value_id_accessor<3> -{ - template - static typeinfo get(T const volatile*) { return typeid(T); } -}; - -template struct bool_t{}; - -template -inline typeinfo typeid_nonref(boost::type* = 0) -{ - bool const c = is_const::value; - bool const v = is_volatile::value; - return value_id_accessor<(2 * v + c)>::get((T*)0); -} - -template -inline typeinfo typeid_ref(T&(*)()) -{ - return typeid_nonref(); -} - -template -inline typeinfo array_ref_typeid(bool_t, bool_t, boost::type* = 0) -{ - return typeid_ref((T&(*)())0); -} - -template -inline typeinfo array_ref_typeid(bool_t, bool_t, boost::type* = 0) -{ - return typeid_ref((T(*)())0); -} - -template -inline typeinfo array_ref_typeid(bool_t, bool_t, boost::type* = 0) -{ - return typeid_ref((T&(*)())0); -} - -template -inline typeinfo msvc_typeid(boost::type* = 0) -{ - typedef bool_t::value> array_tag; - typedef bool_t::value> ref_tag; - return array_ref_typeid(array_tag(), ref_tag(), (boost::type*)0); -} - -}}} // namespace boost::python::detail - -# endif // BOOST_MSVC -#endif // MSVC_TYPEINFO_DWA200222_HPP diff --git a/include/boost/python/detail/none.hpp b/include/boost/python/detail/none.hpp deleted file mode 100644 index 8cb21004..00000000 --- a/include/boost/python/detail/none.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef NONE_DWA_052000_H_ -# define NONE_DWA_052000_H_ - -# include -# include - -namespace boost { namespace python { namespace detail { - -inline PyObject* none() { Py_INCREF(Py_None); return Py_None; } - -}}} // namespace boost::python::detail - -#endif // NONE_DWA_052000_H_ diff --git a/include/boost/python/detail/not_specified.hpp b/include/boost/python/detail/not_specified.hpp deleted file mode 100644 index ce1b280d..00000000 --- a/include/boost/python/detail/not_specified.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef NOT_SPECIFIED_DWA2002321_HPP -# define NOT_SPECIFIED_DWA2002321_HPP - -namespace boost { namespace python { namespace detail { - - struct not_specified {}; - -}}} // namespace boost::python::detail - -#endif // NOT_SPECIFIED_DWA2002321_HPP diff --git a/include/boost/python/detail/operator_id.hpp b/include/boost/python/detail/operator_id.hpp deleted file mode 100755 index 8edb310b..00000000 --- a/include/boost/python/detail/operator_id.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OPERATOR_ID_DWA2002531_HPP -# define OPERATOR_ID_DWA2002531_HPP - -namespace boost { namespace python { namespace detail { - -enum operator_id -{ - op_add, - op_sub, - op_mul, - op_div, - op_mod, - op_divmod, - op_pow, - op_lshift, - op_rshift, - op_and, - op_xor, - op_or, - op_neg, - op_pos, - op_abs, - op_invert, - op_int, - op_long, - op_float, - op_str, - op_cmp, - op_gt, - op_ge, - op_lt, - op_le, - op_eq, - op_ne, - op_iadd, - op_isub, - op_imul, - op_idiv, - op_imod, - op_ilshift, - op_irshift, - op_iand, - op_ixor, - op_ior, - op_complex -}; - -}}} // namespace boost::python::detail - -#endif // OPERATOR_ID_DWA2002531_HPP diff --git a/include/boost/python/detail/pointee.hpp b/include/boost/python/detail/pointee.hpp deleted file mode 100644 index 2af1535f..00000000 --- a/include/boost/python/detail/pointee.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef POINTEE_DWA2002323_HPP -# define POINTEE_DWA2002323_HPP - -# include - -namespace boost { namespace python { namespace detail { - -template -struct pointee_impl -{ - template struct apply : remove_pointer {}; -}; - -template <> -struct pointee_impl -{ - template struct apply - { - typedef typename T::element_type type; - }; -}; - -template -struct pointee - : pointee_impl::value>::template apply -{ -}; - -}}} // namespace boost::python::detail - -#endif // POINTEE_DWA2002323_HPP diff --git a/include/boost/python/detail/preprocessor.hpp b/include/boost/python/detail/preprocessor.hpp deleted file mode 100644 index 45e307d4..00000000 --- a/include/boost/python/detail/preprocessor.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef PREPROCESSOR_DWA200247_HPP -# define PREPROCESSOR_DWA200247_HPP - -# include -# include -# include -# include - -// stuff that should be in the preprocessor library - -# define BOOST_PYTHON_APPLY(x) BOOST_PP_CAT(BOOST_PYTHON_APPLY_, x) - -# define BOOST_PYTHON_APPLY_BOOST_PYTHON_ITEM(v) v -# define BOOST_PYTHON_APPLY_BOOST_PYTHON_NIL - -// cv-qualifiers - -# if !defined(__MWERKS__) || __MWERKS__ > 0x2407 -# define BOOST_PYTHON_CV_COUNT 4 -# else -# define BOOST_PYTHON_CV_COUNT 1 -# endif - -# ifndef BOOST_PYTHON_MAX_ARITY -# define BOOST_PYTHON_MAX_ARITY 15 -# endif - -# ifndef BOOST_PYTHON_MAX_BASES -# define BOOST_PYTHON_MAX_BASES 10 -# endif - -# define BOOST_PYTHON_CV_QUALIFIER(i) \ - BOOST_PYTHON_APPLY( \ - BOOST_PP_TUPLE_ELEM(4, i, BOOST_PYTHON_CV_QUALIFIER_I) \ - ) - -# define BOOST_PYTHON_CV_QUALIFIER_I \ - ( \ - BOOST_PYTHON_NIL, \ - BOOST_PYTHON_ITEM(const), \ - BOOST_PYTHON_ITEM(volatile), \ - BOOST_PYTHON_ITEM(const volatile) \ - ) - -// enumerators -# define BOOST_PYTHON_UNARY_ENUM(c, text) BOOST_PP_REPEAT(c, BOOST_PYTHON_UNARY_ENUM_I, text) -# define BOOST_PYTHON_UNARY_ENUM_I(z, n, text) BOOST_PP_COMMA_IF(n) text ## n - -# define BOOST_PYTHON_BINARY_ENUM(c, a, b) BOOST_PP_REPEAT(c, BOOST_PYTHON_BINARY_ENUM_I, (a, b)) -# define BOOST_PYTHON_BINARY_ENUM_I(z, n, _) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, _), n) BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, _), n) - -# define BOOST_PYTHON_ENUM_WITH_DEFAULT(c, text, def) BOOST_PP_REPEAT(c, BOOST_PYTHON_ENUM_WITH_DEFAULT_I, (text, def)) -# define BOOST_PYTHON_ENUM_WITH_DEFAULT_I(z, n, _) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, _), n) = BOOST_PP_TUPLE_ELEM(2, 1, _) - -// fixed text (no commas) -# define BOOST_PYTHON_FIXED(z, n, text) text - -// flags -# define BOOST_PYTHON_FUNCTION_POINTER 0x0001 -# define BOOST_PYTHON_POINTER_TO_MEMBER 0x0002 - -#endif // PREPROCESSOR_DWA200247_HPP diff --git a/include/boost/python/detail/python22_fixed.h b/include/boost/python/detail/python22_fixed.h deleted file mode 100644 index 3caff6dd..00000000 --- a/include/boost/python/detail/python22_fixed.h +++ /dev/null @@ -1,140 +0,0 @@ -// Copy of Python 2.2/2.2.1 Python.h . -// Changes marked with "Boost.Python modification" -#ifndef Py_PYTHON_H -#define Py_PYTHON_H -/* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */ - - -/* Enable compiler features; switching on C lib defines doesn't work - here, because the symbols haven't necessarily been defined yet. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -/* Forcing SUSv2 compatibility still produces problems on some - platforms, True64 and SGI IRIX begin two of them, so for now the - define is switched off. */ -#if 0 -#ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 500 -#endif -#endif - -/* Include nearly all Python header files */ - -#include "patchlevel.h" -#include "pyconfig.h" - -#ifdef HAVE_LIMITS_H -#include -#endif - -/* pyconfig.h may or may not define DL_IMPORT */ -#ifndef DL_IMPORT /* declarations for DLL import/export */ -#define DL_IMPORT(RTYPE) RTYPE -#endif -#ifndef DL_EXPORT /* declarations for DLL import/export */ -#define DL_EXPORT(RTYPE) RTYPE -#endif - -#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE) -#define _SGI_MP_SOURCE -#endif - -#include -#ifndef NULL -# error "Python.h requires that stdio.h define NULL." -#endif - -#include -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#if PY_MICRO_VERSION == 1 // Boost.Python modification: emulate Python 2.2 -#ifdef HAVE_UNISTD_H -#include -#endif -#endif // Boost.Python modification: emulate Python 2.2 - -/* CAUTION: Build setups should ensure that NDEBUG is defined on the - * compiler command line when building Python in release mode; else - * assert() calls won't be removed. - */ -#include - -#include "pyport.h" - -#include "pymem.h" - -#include "object.h" -#include "objimpl.h" - -#include "pydebug.h" - -#include "unicodeobject.h" -#include "intobject.h" -#include "longobject.h" -#include "floatobject.h" -#ifndef WITHOUT_COMPLEX -#include "complexobject.h" -#endif -#include "rangeobject.h" -#include "stringobject.h" -#include "bufferobject.h" -#include "tupleobject.h" -#include "listobject.h" -#include "dictobject.h" -#include "methodobject.h" -#include "moduleobject.h" -#include "funcobject.h" -#include "classobject.h" -#include "fileobject.h" -#include "cobject.h" -#include "traceback.h" -#include "sliceobject.h" -#include "cellobject.h" -extern "C" { // Boost.Python modification: provide missing extern "C" -#include "iterobject.h" -#include "descrobject.h" -} // Boost.Python modification: provide missing extern "C" -#include "weakrefobject.h" - -#include "codecs.h" -#include "pyerrors.h" - -#include "pystate.h" - -#include "modsupport.h" -#include "pythonrun.h" -#include "ceval.h" -#include "sysmodule.h" -#include "intrcheck.h" -#include "import.h" - -#include "abstract.h" - -#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a)) -#define PyArg_NoArgs(v) PyArg_Parse(v, "") - -/* Convert a possibly signed character to a nonnegative int */ -/* XXX This assumes characters are 8 bits wide */ -#ifdef __CHAR_UNSIGNED__ -#define Py_CHARMASK(c) (c) -#else -#define Py_CHARMASK(c) ((c) & 0xff) -#endif - -#include "pyfpe.h" - -/* These definitions must match corresponding definitions in graminit.h. - There's code in compile.c that checks that they are the same. */ -#define Py_single_input 256 -#define Py_file_input 257 -#define Py_eval_input 258 - -#ifdef HAVE_PTH -/* GNU pth user-space thread support */ -#include -#endif -#endif /* !Py_PYTHON_H */ diff --git a/include/boost/python/detail/python_library_include.hpp b/include/boost/python/detail/python_library_include.hpp deleted file mode 100644 index d2b78c6e..00000000 --- a/include/boost/python/detail/python_library_include.hpp +++ /dev/null @@ -1,183 +0,0 @@ -#error obsolete -/* - * - * Copyright (c) 1998-2000 - * Dr John Maddock - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Dr John Maddock makes no representations - * about the suitability of this software for any purpose. - * It is provided "as is" without express or implied warranty. - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE regex_libary_include.hpp - * VERSION see - * DESCRIPTION: Automatic library inclusion for Borland/Microsoft compilers. - * Note this is an internal header file included - * by regex.hpp, do not include on its own. - */ - - -#ifndef BOOST_REGEX_LIBRARY_INCLUDE_HPP -#define BOOST_REGEX_LIBRARY_INCLUDE_HPP -#ifndef BOOST_REGEX_NO_LIB - -#if defined(BOOST_MSVC) && !defined(BOOST_REGEX_BUILD_DLL) -#ifdef __SGI_STL_PORT - #ifdef _DLL - // All these are multithreaded: - #if defined(_DEBUG) && defined(__STL_DEBUG) - #pragma comment(lib, "vc6-stlport-re300ddl.lib") - #elif defined(_DEBUG) - #pragma comment(lib, "vc6-stlport-re300dl.lib") - #elif defined(BOOST_REGEX_STATIC_LINK) - // static regex lib, dll runtime - #pragma comment(lib, "vc6-stlport-re300ls.lib") - #else // DEBUG - #pragma comment(lib, "vc6-stlport-re300l.lib") - #endif // _DEBUG - #else // _DLL - #ifdef _MT - #if defined(_DEBUG) && defined(__STL_DEBUG) - #pragma comment(lib, "vc6-stlport-re300ddm.lib") - #elif defined(_DEBUG) - #pragma comment(lib, "vc6-stlport-re300dm.lib") - #else //_DEBUG - #pragma comment(lib, "vc6-stlport-re300m.lib") - #endif //_DEBUG - #else //_MT - // STLPort does not support single threaded builds: - #error STLPort does not support single threaded builds - #endif //_MT - #endif //_DLL -#elif _MSC_VER < 1300 - #ifdef _DLL - // All these are multithreaded: - #ifdef _DEBUG - #pragma comment(lib, "vc6-re300dl.lib") - #elif defined(BOOST_REGEX_STATIC_LINK) - // static regex lib, dll runtime - #pragma comment(lib, "vc6-re300ls.lib") - #else // DEBUG - #pragma comment(lib, "vc6-re300l.lib") - #endif // _DEBUG - #else // _DLL - #ifdef _MT - #ifdef _DEBUG - #pragma comment(lib, "vc6-re300dm.lib") - #else //_DEBUG - #pragma comment(lib, "vc6-re300m.lib") - #endif //_DEBUG - #else //_MT - #ifdef _DEBUG - #pragma comment(lib, "vc6-re300d.lib") - #else //_DEBUG - #pragma comment(lib, "vc6-re300.lib") - #endif //_DEBUG - #endif //_MT - #endif //_DLL -#else - #ifdef _DLL - // All these are multithreaded: - #ifdef _DEBUG - #pragma comment(lib, "vc7-re300dl.lib") - #elif defined(BOOST_REGEX_STATIC_LINK) - // static regex lib, dll runtime - #pragma comment(lib, "vc7-re300ls.lib") - #else // DEBUG - #pragma comment(lib, "vc7-re300l.lib") - #endif // _DEBUG - #else // _DLL - #ifdef _MT - #ifdef _DEBUG - #pragma comment(lib, "vc7-re300dm.lib") - #else //_DEBUG - #pragma comment(lib, "vc7-re300m.lib") - #endif //_DEBUG - #else //_MT - #ifdef _DEBUG - #pragma comment(lib, "vc7-re300d.lib") - #else //_DEBUG - #pragma comment(lib, "vc7-re300.lib") - #endif //_DEBUG - #endif //_MT - #endif //_DLL -#endif // __SGI_STL_PORT -#endif //BOOST_MSVC - - -#if defined(__BORLANDC__) && !defined(BOOST_REGEX_BUILD_DLL) - - #if __BORLANDC__ < 0x550 - - #ifdef BOOST_REGEX_USE_VCL - - #ifdef _RTLDLL - #pragma comment(lib, "bcb4re300lv.lib") - #else - #pragma comment(lib, "bcb4re300v.lib") - #endif - - #else // VCL - - #ifdef _RTLDLL - #ifdef __MT__ - #pragma comment(lib, "bcb4re300lm.lib") - #else // __MT__ - #pragma comment(lib, "bcb4re300l.lib") - #endif // __MT__ - #else //_RTLDLL - #ifdef __MT__ - #pragma comment(lib, "bcb4re300m.lib") - #else // __MT__ - #pragma comment(lib, "bcb4re300.lib") - #endif // __MT__ - #endif // _RTLDLL - - #endif // VCL - - #else // C++ Builder 5: - - #ifdef BOOST_REGEX_USE_VCL - - #ifdef _RTLDLL - #pragma comment(lib, "bcb5re300lv.lib") - #else - #pragma comment(lib, "bcb5re300v.lib") - #endif - - #else // VCL - - #ifdef _RTLDLL - #ifdef __MT__ - #pragma comment(lib, "bcb5re300lm.lib") - #else // __MT__ - #pragma comment(lib, "bcb5re300l.lib") - #endif // __MT__ - #else //_RTLDLL - #ifdef __MT__ - #pragma comment(lib, "bcb5re300m.lib") - #else // __MT__ - #pragma comment(lib, "bcb5re300.lib") - #endif // __MT__ - #endif // _RTLDLL - - #endif // VCL - - #endif - -#endif //__BORLANDC__ - -#endif //BOOST_REGEX_NO_LIB - -#endif // BOOST_REGEX_LIBRARY_INCLUDE_HPP - - - - diff --git a/include/boost/python/detail/raw_pyobject.hpp b/include/boost/python/detail/raw_pyobject.hpp deleted file mode 100644 index e9d36901..00000000 --- a/include/boost/python/detail/raw_pyobject.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef RAW_PYOBJECT_DWA2002628_HPP -# define RAW_PYOBJECT_DWA2002628_HPP - -namespace boost { namespace python { namespace detail { - -// -// Define some types which we can use to get around the vagaries of -// PyObject*. We will use these to initialize object instances, and -// keep them in namespace detail to make sure they stay out of the -// hands of users. That is much simpler than trying to grant -// friendship to all the appropriate parties. -// - -// New references are normally checked for null -struct new_reference_t; -typedef new_reference_t* new_reference; - -// Borrowed references are assumed to be non-null -struct borrowed_reference_t; -typedef borrowed_reference_t* borrowed_reference; - -// New references which aren't checked for null -struct new_non_null_reference_t; -typedef new_non_null_reference_t* new_non_null_reference; - -}}} // namespace boost::python::detail - -#endif // RAW_PYOBJECT_DWA2002628_HPP diff --git a/include/boost/python/detail/referent_storage.hpp b/include/boost/python/detail/referent_storage.hpp deleted file mode 100644 index b93d888f..00000000 --- a/include/boost/python/detail/referent_storage.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef REFERENT_STORAGE_DWA200278_HPP -# define REFERENT_STORAGE_DWA200278_HPP -# include -# include - -namespace boost { namespace python { namespace detail { - -struct alignment_dummy; -typedef void (*function_ptr)(); -typedef int (alignment_dummy::*member_ptr); -typedef int (alignment_dummy::*member_function_ptr)(); - -# define BOOST_PYTHON_ALIGNER(T, n) \ - typename mpl::if_c< \ - sizeof(T) <= size, T, char>::type t##n - -// Storage for size bytes, aligned to all fundamental types no larger than size -template -union aligned_storage -{ - BOOST_PYTHON_ALIGNER(char, 0); - BOOST_PYTHON_ALIGNER(short, 1); - BOOST_PYTHON_ALIGNER(int, 2); - BOOST_PYTHON_ALIGNER(long, 3); - BOOST_PYTHON_ALIGNER(float, 4); - BOOST_PYTHON_ALIGNER(double, 5); - BOOST_PYTHON_ALIGNER(long double, 6); - BOOST_PYTHON_ALIGNER(void*, 7); - BOOST_PYTHON_ALIGNER(function_ptr, 8); - BOOST_PYTHON_ALIGNER(member_ptr, 9); - BOOST_PYTHON_ALIGNER(member_function_ptr, 10); - char bytes[size]; -}; - -# undef BOOST_PYTHON_ALIGNER - - // Compute the size of T's referent. We wouldn't need this at all, - // but sizeof() is broken in CodeWarriors <= 8.0 - template struct referent_size; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - - template - struct referent_size - { - BOOST_STATIC_CONSTANT( - std::size_t, value = sizeof(T)); - }; - -# else - - template struct referent_size - { - static T f(); - BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(f())); - }; - -# endif - -// A metafunction returning a POD type which can store U, where T == -// U&. If T is not a reference type, returns a POD which can store T. -template -struct referent_storage -{ - typedef aligned_storage::value> type; -}; - -}}} // namespace boost::python::detail - -#endif // REFERENT_STORAGE_DWA200278_HPP diff --git a/include/boost/python/detail/result.hpp b/include/boost/python/detail/result.hpp deleted file mode 100755 index 6ec95fb7..00000000 --- a/include/boost/python/detail/result.hpp +++ /dev/null @@ -1,124 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# ifndef RESULT_DWA2002521_HPP -# define RESULT_DWA2002521_HPP - -# include - -# include - -# include -# include - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// Defines a family of overloaded function which, given x, a function -// pointer, member [function] pointer, or an AdaptableFunction object, -// returns a pointer to type*, where R is the result type of -// invoking the result of bind(x). -// -// In order to work around bugs in deficient compilers, if x might be -// an AdaptableFunction object, you must pass OL as a second argument -// to get this to work portably. - -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_MAX_ARITY, , BOOST_PYTHON_FUNCTION_POINTER)) -# include BOOST_PP_ITERATE() - -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_CV_COUNT - 1, , BOOST_PYTHON_POINTER_TO_MEMBER)) -# include BOOST_PP_ITERATE() - -template -boost::type* result(R (T::*), int = 0) { return 0; } - -# if (defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140) \ - || (defined(__GNUC__) && __GNUC__ < 3) \ - || (defined(__MWERKS__) && __MWERKS__ < 0x3000) -// This code actually works on all implementations, but why use it when we don't have to? -template -struct get_result_type -{ - typedef boost::type type; -}; - -struct void_type -{ - typedef void type; -}; - -template -struct result_result -{ - typedef typename mpl::if_c< - is_class::value - , get_result_type - , void_type - >::type t1; - - typedef typename t1::type* type; -}; - -template -typename result_result::type -result(X const&, short) { return 0; } - -# else // Simpler code for more-capable compilers -template -boost::type* -result(X const&, short = 0) { return 0; } - -# endif - -}}} // namespace boost::python::detail - -# endif // RESULT_DWA2002521_HPP - -/* --------------- function pointers --------------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER -# line BOOST_PP_LINE(__LINE__, result.hpp(function pointers)) - -# define N BOOST_PP_ITERATION() - -template -boost::type* result(R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A)), int = 0) -{ - return 0; -} - -# undef N - -/* --------------- pointers-to-members --------------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER -// Outer over cv-qualifiers - -# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -#elif BOOST_PP_ITERATION_DEPTH() == 2 -# line BOOST_PP_LINE(__LINE__, result.hpp(pointers-to-members)) -// Inner over arities - -# define N BOOST_PP_ITERATION() -# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1)) - -template -boost::type* result(R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q, int = 0) -{ - return 0; -} - -# undef N -# undef Q - -#endif diff --git a/include/boost/python/detail/returning.hpp b/include/boost/python/detail/returning.hpp deleted file mode 100644 index 9ab87c43..00000000 --- a/include/boost/python/detail/returning.hpp +++ /dev/null @@ -1,215 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// (C) Copyright David Abrahams 2001,2002. Permission to copy, use, modify, sell -// and distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// This work was funded in part by Lawrence Berkeley National Labs -// -// This file generated for 5-argument member functions and 6-argument free -// functions by gen_returning.py - -# ifndef RETURNING_DWA20011201_HPP -# define RETURNING_DWA20011201_HPP - -# include - -# include -# include -# include -# include - -# include -# include -# include -# include -# include - -# include - -namespace boost { namespace python { namespace detail { - -# define BOOST_PYTHON_RETURNING_NON_VOID 0x0004 -# define BOOST_PYTHON_RETURNING_VOID 0x0008 - -template -struct returning -{ - // Specializations for function pointers -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_MAX_ARITY, , \ - BOOST_PYTHON_FUNCTION_POINTER | BOOST_PYTHON_RETURNING_NON_VOID)) -# include BOOST_PP_ITERATE() - - // Specializations for member function pointers -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, 3, , \ - BOOST_PYTHON_POINTER_TO_MEMBER | BOOST_PYTHON_RETURNING_NON_VOID)) -# include BOOST_PP_ITERATE() -}; - -template <> -struct returning -{ - typedef void R; - // Specializations for function pointers -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_MAX_ARITY, , \ - BOOST_PYTHON_FUNCTION_POINTER | BOOST_PYTHON_RETURNING_VOID)) -# include BOOST_PP_ITERATE() - - // Specializations for member function pointers -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, 3, , \ - BOOST_PYTHON_POINTER_TO_MEMBER | BOOST_PYTHON_RETURNING_VOID)) -# include BOOST_PP_ITERATE() -}; - -}}} // namespace boost::python::detail - -# undef BOOST_PYTHON_RETURNING_NON_VOID -# undef BOOST_PYTHON_RETURNING_VOID - -# endif // RETURNING_DWA20011201_HPP - -// --------------- function pointers --------------- // -#elif BOOST_PP_ITERATION_DEPTH() == 1 && (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_FUNCTION_POINTER) -# line BOOST_PP_LINE(__LINE__, returning.hpp(function pointers)) - -# define N BOOST_PP_ITERATION() - -# define BOOST_PYTHON_CALL_ARGS(z, n, _) \ - BOOST_PP_COMMA_IF(n) c##n(PyTuple_GET_ITEM(args_, n)) - -# define BOOST_PYTHON_CHECK_CONVERSION(z, n, _) \ - arg_from_python c##n(PyTuple_GET_ITEM(args_, n)); \ - if (!c##n.convertible()) \ - return 0; - -# if (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_RETURNING_NON_VOID) - - template - static PyObject* call( - R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A)) - , PyObject* args_ - , PyObject*, P const* policies) - { - // check that each of the arguments is convertible - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) - - // find the result converter - typedef typename P::result_converter result_converter; - typename mpl::apply1::type cr; - if (!cr.convertible() || !policies->precall(args_)) - return 0; - PyObject* result = cr( - (*pf)(BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)) - ); - return policies->postcall(args_, result); - } -# elif (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_RETURNING_VOID) - - template - static PyObject* call( - R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A)) - , PyObject* args_ - , PyObject*, P const* policies) - { - // check that each of the arguments is convertible - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) - - if (!policies->precall(args_)) - return 0; - (*pf)(BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)); - return policies->postcall(args_, detail::none()); - } -# endif // returning void / non-void - -# undef N -# undef BOOST_PYTHON_CALL_ARGS -# undef BOOST_PYTHON_CHECK_CONVERSION - -// --------------- pointers to members --------------- // -#elif BOOST_PP_ITERATION_DEPTH() == 1 && (BOOST_PP_ITERATION_FLAGS() & BOOST_PYTHON_POINTER_TO_MEMBER) - - // Outer iteration over cv-qualifications -# define BOOST_PP_ITERATION_PARAMS_2 \ - (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -#elif BOOST_PP_ITERATION_DEPTH() == 2 && BOOST_PP_RELATIVE_FLAGS(1) & BOOST_PYTHON_POINTER_TO_MEMBER -# line BOOST_PP_LINE(__LINE__, returning.hpp(pointers-to-members)) - - // Inner iteration over arities -# define N BOOST_PP_ITERATION() -# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1)) - -# define BOOST_PYTHON_CALL_ARGS(z, n, _) \ - BOOST_PP_COMMA_IF(n) c##n(PyTuple_GET_ITEM(args_, BOOST_PP_INC(n))) - -# define BOOST_PYTHON_CHECK_CONVERSION(z, n, _) \ - arg_from_python c##n(PyTuple_GET_ITEM(args_, BOOST_PP_INC(n))); \ - if (!c##n.convertible()) \ - return 0; - -# if (BOOST_PP_RELATIVE_FLAGS(1) & BOOST_PYTHON_RETURNING_NON_VOID) - - template - static PyObject* call( - R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q - , PyObject* args_ - , PyObject*, P const* policies) - { - // check that each of the arguments is convertible - // self is special - arg_from_python ct(PyTuple_GET_ITEM(args_, 0)); - if (!ct.convertible()) - return 0; - - // unroll a loop for the rest of them - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) - - // find the result converter - typedef typename P::result_converter result_converter; - typename mpl::apply1::type cr; - if (!cr.convertible() || !policies->precall(args_)) - return 0; - PyObject* result = cr( - ((ct(PyTuple_GET_ITEM(args_, 0))).*pmf)( - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)) - ); - return policies->postcall(args_, result); - } -# elif (BOOST_PP_RELATIVE_FLAGS(1) & BOOST_PYTHON_RETURNING_VOID) - - template - static PyObject* call( - R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q - , PyObject* args_ - , PyObject*, P const* policies) - { - // check that each of the arguments is convertible - // self is special - arg_from_python ct(PyTuple_GET_ITEM(args_, 0)); - if (!ct.convertible()) - return 0; - - // unroll a loop for the rest of them - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) - - if (!policies->precall(args_)) - return 0; - - ((ct(PyTuple_GET_ITEM(args_, 0))).*pmf)( - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)); - return policies->postcall(args_, detail::none()); - } -# endif - -# undef N -# undef Q -# undef BOOST_PYTHON_CALL_ARGS -# undef BOOST_PYTHON_CHECK_CONVERSION - -#endif diff --git a/include/boost/python/detail/signatures.hpp b/include/boost/python/detail/signatures.hpp deleted file mode 100644 index e216f688..00000000 --- a/include/boost/python/detail/signatures.hpp +++ /dev/null @@ -1,251 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. -// -// This file automatically generated by gen_signatures.python for 10 arguments. -#ifndef SIGNATURES_DWA050900_H_ -# define SIGNATURES_DWA050900_H_ - -# include - -namespace boost { namespace python { - -namespace detail { -// A stand-in for the built-in void. This one can be passed to functions and -// (under MSVC, which has a bug, be used as a default template type parameter). -struct BOOST_PYTHON_DECL void_t {}; -} - -// An envelope in which type information can be delivered for the purposes -// of selecting an overloaded from_python() function. This is needed to work -// around MSVC's lack of partial specialiation/ordering. Where normally we'd -// want to form a function call like void f(), We instead pass -// type as one of the function parameters to select a particular -// overload. -// -// The id typedef helps us deal with the lack of partial ordering by generating -// unique types for constructor signatures. In general, type::id is type, -// but type::id is just void_t. -template -struct type -{ - typedef type id; -}; - -template <> -struct type -{ - typedef boost::python::detail::void_t id; -}; - -namespace detail { -// These basically encapsulate a chain of types, , used to make the syntax of -// add(constructor()) work. We need to produce a unique type for each number -// of non-default parameters to constructor<>. Q: why not use a recursive -// formulation for infinite extensibility? A: MSVC6 seems to choke on constructs -// that involve recursive template nesting. -// -// signature chaining -template -struct signature10 {}; - -template -struct signature9 {}; - -template -inline signature10 prepend(type, signature9) - { return signature10(); } - -template -struct signature8 {}; - -template -inline signature9 prepend(type, signature8) - { return signature9(); } - -template -struct signature7 {}; - -template -inline signature8 prepend(type, signature7) - { return signature8(); } - -template -struct signature6 {}; - -template -inline signature7 prepend(type, signature6) - { return signature7(); } - -template -struct signature5 {}; - -template -inline signature6 prepend(type, signature5) - { return signature6(); } - -template -struct signature4 {}; - -template -inline signature5 prepend(type, signature4) - { return signature5(); } - -template -struct signature3 {}; - -template -inline signature4 prepend(type, signature3) - { return signature4(); } - -template -struct signature2 {}; - -template -inline signature3 prepend(type, signature2) - { return signature3(); } - -template -struct signature1 {}; - -template -inline signature2 prepend(type, signature1) - { return signature2(); } - -struct signature0 {}; - -template -inline signature1 prepend(type, signature0) - { return signature1(); } - - -// This one terminates the chain. Prepending void_t to the head of a void_t -// signature results in a void_t signature again. -inline signature0 prepend(void_t, signature0) { return signature0(); } - -} // namespace detail - -template -struct constructor -{ -}; - -namespace detail { -// Return value extraction: - -// This is just another little envelope for carrying a typedef (see type, -// above). I could have re-used type, but that has a very specific purpose. I -// thought this would be clearer. -template -struct return_value_select { typedef T type; }; - -// free functions -template -return_value_select return_value(R (*)()) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7, A8)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) { return return_value_select(); } - -template -return_value_select return_value(R (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) { return return_value_select(); } - -// TODO(?): handle 'const void' - -// member functions -template -return_value_select return_value(R (T::*)()) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)() const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const) { return return_value_select(); } - -template -return_value_select return_value(R (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const) { return return_value_select(); } - -}}} // namespace boost::python::detail - -#endif diff --git a/include/boost/python/detail/singleton.hpp b/include/boost/python/detail/singleton.hpp deleted file mode 100644 index 3e7d91af..00000000 --- a/include/boost/python/detail/singleton.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef SINGLETON_DWA051900_H_ -# define SINGLETON_DWA051900_H_ - -# include - -namespace boost { namespace python { namespace detail { - -struct BOOST_PYTHON_DECL empty {}; -template -struct singleton : Base -{ - typedef singleton singleton_base; // Convenience type for derived class constructors - - static Derived* instance(); - - // Pass-through constructors - singleton() : Base() {} - - template - singleton(const A1& a1) : Base(a1) {} - - template - singleton(const A1& a1, const A2& a2) : Base(a1, a2) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3) : Base(a1, a2, a3) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4) : Base(a1, a2, a3, a4) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) : Base(a1, a2, a3, a4, a5) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) : Base(a1, a2, a3, a4, a5, a6) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : Base(a1, a2, a3, a4, a5, a6, a7) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : Base(a1, a2, a3, a4, a5, a6, a7, a8) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9) : Base(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} - - template - singleton(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10) : Base(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} - -}; - -template -Derived* singleton::instance() -{ - static Derived x; - return &x; -} - -}}} // namespace boost::python::detail - -#endif diff --git a/include/boost/python/detail/string_literal.hpp b/include/boost/python/detail/string_literal.hpp deleted file mode 100644 index dc8b0791..00000000 --- a/include/boost/python/detail/string_literal.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef STRING_LITERAL_DWA2002629_HPP -# define STRING_LITERAL_DWA2002629_HPP - -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct is_string_literal -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -# if !defined(__MWERKS__) || __MWERKS__ > 0x2407 -template -struct is_string_literal -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -# if (defined(__DECCXX_VER) && __DECCXX_VER <= 60590014) \ - || (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730) -// This compiler mistakenly gets the type of string literals as char* -// instead of char[NN]. -template <> -struct is_string_literal -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; -# endif - -# else - -// CWPro7 has trouble with the array type deduction above -template -struct is_string_literal - : is_same -{ -}; -# endif -# else -template -struct string_literal_helper -{ - typedef char (&yes_string_literal)[1]; - typedef char (&no_string_literal)[2]; - - template - struct apply - { - typedef apply self; - static T x; - static yes_string_literal check(char const*); - static no_string_literal check(char*); - static no_string_literal check(void const volatile*); - - BOOST_STATIC_CONSTANT( - bool, value = sizeof(self::check(x)) == sizeof(yes_string_literal)); - }; -}; - -template <> -struct string_literal_helper -{ - template - struct apply - { - BOOST_STATIC_CONSTANT(bool, value = false); - }; -}; - -template -struct is_string_literal - : string_literal_helper::value>::apply -{ -}; -# endif - -}}} // namespace boost::python::detail - -#endif // STRING_LITERAL_DWA2002629_HPP diff --git a/include/boost/python/detail/target.hpp b/include/boost/python/detail/target.hpp deleted file mode 100644 index bbaec740..00000000 --- a/include/boost/python/detail/target.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# ifndef TARGET_DWA2002521_HPP -# define TARGET_DWA2002521_HPP - -# include - -# include - -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_MAX_ARITY, , BOOST_PYTHON_FUNCTION_POINTER)) -# include BOOST_PP_ITERATE() - -# define BOOST_PP_ITERATION_PARAMS_1 \ - (4, (0, BOOST_PYTHON_CV_COUNT - 1, , BOOST_PYTHON_POINTER_TO_MEMBER)) -# include BOOST_PP_ITERATE() - -template -boost::type* target(R (T::*)) { return 0; } - -}}} // namespace boost::python::detail - -# endif // TARGET_DWA2002521_HPP - -/* --------------- function pointers --------------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER -# line BOOST_PP_LINE(__LINE__, target.hpp(function_pointers)) - -# define N BOOST_PP_ITERATION() - -template -boost::type* target(R (*)(BOOST_PYTHON_UNARY_ENUM(N, A))) -{ - return 0; -} - -# undef N - -/* --------------- pointers-to-members --------------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER -// Outer over cv-qualifiers - -# define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -#elif BOOST_PP_ITERATION_DEPTH() == 2 -# line BOOST_PP_LINE(__LINE__, target.hpp(pointers-to-members)) -// Inner over arities - -# define N BOOST_PP_ITERATION() -# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1)) - -template -boost::type* target(R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q) -{ - return 0; -} - -# undef N -# undef Q - -#endif diff --git a/include/boost/python/detail/translate_exception.hpp b/include/boost/python/detail/translate_exception.hpp deleted file mode 100644 index aa617a2a..00000000 --- a/include/boost/python/detail/translate_exception.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TRANSLATE_EXCEPTION_DWA2002810_HPP -# define TRANSLATE_EXCEPTION_DWA2002810_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// A ternary function object used to translate C++ exceptions of type -// ExceptionType into Python exceptions by invoking an object of type -// Translate. Typically the translate function will be curried with -// boost::bind(). -template -struct translate_exception -{ - typedef typename add_reference< - typename add_const::type - >::type exception_cref; - - inline bool operator()( - exception_handler const& handler - , function0 const& f - , typename call_traits::param_type translate) const - { - try - { - return handler(f); - } - catch(exception_cref e) - { - translate(e); - return true; - } - } -}; - -}}} // namespace boost::python::detail - -#endif // TRANSLATE_EXCEPTION_DWA2002810_HPP diff --git a/include/boost/python/detail/type_list.hpp b/include/boost/python/detail/type_list.hpp deleted file mode 100644 index 4a09c0be..00000000 --- a/include/boost/python/detail/type_list.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TYPE_LIST_DWA2002913_HPP -# define TYPE_LIST_DWA2002913_HPP - -# include -# include -# include - -# if BOOST_PYTHON_MAX_ARITY + 2 > BOOST_PYTHON_MAX_BASES -# define BOOST_PYTHON_LIST_SIZE BOOST_PP_INC(BOOST_PP_INC(BOOST_PYTHON_MAX_ARITY)) -# else -# define BOOST_PYTHON_BASE_LIST_SIZE BOOST_PYTHON_MAX_BASES -# endif - -// Compute the MPL list header to use for lists up to BOOST_PYTHON_LIST_SIZE in length -# if BOOST_PYTHON_LIST_SIZE > 48 -# error Arities above 48 not supported by Boost.Python due to MPL internal limit -# elif BOOST_PYTHON_LIST_SIZE > 38 -# include -# elif BOOST_PYTHON_LIST_SIZE > 28 -# include -# elif BOOST_PYTHON_LIST_SIZE > 18 -# include -# elif BOOST_PYTHON_LIST_SIZE > 8 -# include -# else -# include -# endif - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -# include -# else -# include -# endif - -#endif // TYPE_LIST_DWA2002913_HPP diff --git a/include/boost/python/detail/type_list_impl.hpp b/include/boost/python/detail/type_list_impl.hpp deleted file mode 100644 index 2a02851f..00000000 --- a/include/boost/python/detail/type_list_impl.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef BOOST_PP_IS_ITERATING -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -# ifndef TYPE_LIST_IMPL_DWA2002913_HPP -# define TYPE_LIST_IMPL_DWA2002913_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -template -struct type_list - : BOOST_PP_CAT(mpl::list,BOOST_PYTHON_LIST_SIZE) -{ -}; - -# define BOOST_PP_ITERATION_PARAMS_1 \ - (3, (0, BOOST_PP_DEC(BOOST_PYTHON_LIST_SIZE), )) -# include BOOST_PP_ITERATE() - - -}}} // namespace boost::python::detail - -# endif // TYPE_LIST_IMPL_DWA2002913_HPP - -#else // BOOST_PP_IS_ITERATING - -# define N BOOST_PP_ITERATION() -# define BOOST_PYTHON_VOID_ARGS BOOST_PP_SUB_D(1,BOOST_PYTHON_LIST_SIZE,N) - -template < - BOOST_PP_ENUM_PARAMS(N, class T) - > -struct type_list< - BOOST_PP_ENUM_PARAMS(N, T) - BOOST_PP_COMMA_IF(N) - BOOST_PP_ENUM( - BOOST_PYTHON_VOID_ARGS, BOOST_PYTHON_FIXED, mpl::void_) - > - : BOOST_PP_CAT(mpl::list,N) -{ -}; - -# undef BOOST_PYTHON_VOID_ARGS -# undef N - -#endif // BOOST_PP_IS_ITERATING diff --git a/include/boost/python/detail/type_list_impl_no_pts.hpp b/include/boost/python/detail/type_list_impl_no_pts.hpp deleted file mode 100644 index 1c4d392c..00000000 --- a/include/boost/python/detail/type_list_impl_no_pts.hpp +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef BOOST_PP_IS_ITERATING -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -# ifndef TYPE_LIST_IMPL_NO_PTS_DWA2002913_HPP -# define TYPE_LIST_IMPL_NO_PTS_DWA2002913_HPP - -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -template< typename T > -struct is_list_arg -{ - enum { value = true }; -}; - -template<> -struct is_list_arg -{ - enum { value = false }; -}; - -template struct type_list_impl_chooser; - -# define BOOST_PP_ITERATION_PARAMS_1 \ - (3, (0, BOOST_PYTHON_LIST_SIZE, )) -# include BOOST_PP_ITERATE() - -# define BOOST_PYTHON_PLUS() + -# define BOOST_PYTHON_IS_LIST_ARG(z, n, data) \ - BOOST_PP_IF(n, BOOST_PYTHON_PLUS, BOOST_PP_EMPTY)() \ - is_list_arg< BOOST_PP_CAT(T,n) >::value - -template< - BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE, class T) - > -struct type_list_count_args -{ - enum { value = - BOOST_PP_REPEAT_1(BOOST_PYTHON_LIST_SIZE, BOOST_PYTHON_IS_LIST_ARG, _) - }; -}; - -# undef BOOST_PYTHON_IS_LIST_ARG -# undef BOOST_PYTHON_PLUS - -template< - BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE, class T) - > -struct type_list_impl -{ - typedef type_list_count_args< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) > arg_num_; - typedef typename detail::type_list_impl_chooser< arg_num_::value > - ::template result_< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) >::type type; -}; - -template< - BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PYTHON_LIST_SIZE, class T, mpl::void_) - > -struct type_list - : detail::type_list_impl< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) >::type -{ - typedef typename detail::type_list_impl< - BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) - >::type type; -}; - -}}} // namespace boost::python::detail - -# endif // TYPE_LIST_IMPL_NO_PTS_DWA2002913_HPP - -#else // BOOST_PP_IS_ITERATING - -# define N BOOST_PP_ITERATION() - -template<> -struct type_list_impl_chooser -{ - template< - BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE, class T) - > - struct result_ - { - typedef BOOST_PP_CAT(mpl::list,N)< - BOOST_PP_ENUM_PARAMS(N, T) - > type; - }; -}; - -# undef N - -#endif // BOOST_PP_IS_ITERATING diff --git a/include/boost/python/detail/type_list_utils.hpp b/include/boost/python/detail/type_list_utils.hpp deleted file mode 100644 index ebb5488b..00000000 --- a/include/boost/python/detail/type_list_utils.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#error obsolete -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TYPE_LIST_UTILS_JDG20020826_HPP -# define TYPE_LIST_UTILS_JDG20020826_HPP - - -# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -namespace boost { namespace python { namespace detail { - -template< typename T > -struct is_list_arg -{ - enum { value = true }; -}; - -template<> -struct is_list_arg -{ - enum { value = false }; -}; - -}}} -# endif -#endif // TYPE_LIST_UTILS_JDG20020826_HPP diff --git a/include/boost/python/detail/types.hpp b/include/boost/python/detail/types.hpp deleted file mode 100644 index 2e69d24e..00000000 --- a/include/boost/python/detail/types.hpp +++ /dev/null @@ -1,413 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef TYPES_DWA051800_H_ -# define TYPES_DWA051800_H_ - -// Usage: -// class X : public -// boost::python::callable< -// boost::python::getattrable < -// boost::python::setattrable > > -// { -// public: -// ref call(args, kw); -// ref getattr(args, kw); -// ref setattr(args, kw); -// }; - -# include -# include // really just for type<> -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail { - -class BOOST_PYTHON_DECL type_object_base : public python_type -{ - public: - explicit type_object_base(PyTypeObject* type_type); - virtual ~type_object_base(); - - public: - enum capability { - hash, call, str, getattr, setattr, compare, repr, richcompare, - - mapping_length, mapping_subscript, mapping_ass_subscript, - - sequence_length, sequence_item, sequence_ass_item, - sequence_concat, sequence_repeat, sequence_slice, sequence_ass_slice, - - number_add, number_subtract, number_multiply, number_divide, - number_remainder, number_divmod, number_power, number_negative, - number_positive, number_absolute, number_nonzero, number_invert, - number_lshift, number_rshift, number_and, number_xor, number_or, - number_coerce, number_int, number_long, number_float, number_oct, - number_hex, number_inplace_add, number_inplace_subtract, - number_inplace_multiply, number_inplace_divide, - number_inplace_remainder, number_inplace_power, - number_inplace_lshift, number_inplace_rshift, - number_inplace_and, number_inplace_or, number_inplace_xor - }; - - void enable(capability); - - // - // type behaviors - // - public: // Callbacks for basic type functionality. - virtual PyObject* instance_repr(PyObject*) const; - virtual int instance_compare(PyObject*, PyObject* other) const; - virtual PyObject* instance_str(PyObject*) const; - virtual long instance_hash(PyObject*) const; - virtual PyObject* instance_call(PyObject* obj, PyObject* args, PyObject* kw) const; - virtual PyObject* instance_getattr(PyObject* obj, const char* name) const; - virtual int instance_setattr(PyObject* obj, const char* name, PyObject* value) const; - - // Dealloc is a special case, since every type needs a nonzero tp_dealloc slot. - virtual void instance_dealloc(PyObject*) const = 0; - - public: // Callbacks for mapping methods - virtual int instance_mapping_length(PyObject*) const; - virtual PyObject* instance_mapping_subscript(PyObject*, PyObject*) const ; - virtual int instance_mapping_ass_subscript(PyObject*, PyObject*, PyObject*) const; - - public: // Callbacks for sequence methods - virtual int instance_sequence_length(PyObject* obj) const; - virtual PyObject* instance_sequence_concat(PyObject* obj, PyObject* other) const; - virtual PyObject* instance_sequence_repeat(PyObject* obj, int n) const; - virtual PyObject* instance_sequence_item(PyObject* obj, int n) const; - virtual PyObject* instance_sequence_slice(PyObject* obj, int start, int finish) const; - virtual int instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const; - virtual int instance_sequence_ass_slice(PyObject* obj, int start, int finish, PyObject* value) const; - - public: // Callbacks for number methods - virtual PyObject* instance_number_add(PyObject*, PyObject*) const; - virtual PyObject* instance_number_subtract(PyObject*, PyObject*) const; - virtual PyObject* instance_number_multiply(PyObject*, PyObject*) const; - virtual PyObject* instance_number_divide(PyObject*, PyObject*) const; - virtual PyObject* instance_number_remainder(PyObject*, PyObject*) const; - virtual PyObject* instance_number_divmod(PyObject*, PyObject*) const; - virtual PyObject* instance_number_power(PyObject*, PyObject*, PyObject*) const; - virtual PyObject* instance_number_negative(PyObject*) const; - virtual PyObject* instance_number_positive(PyObject*) const; - virtual PyObject* instance_number_absolute(PyObject*) const; - virtual int instance_number_nonzero(PyObject*) const; - virtual PyObject* instance_number_invert(PyObject*) const; - virtual PyObject* instance_number_lshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_rshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_and(PyObject*, PyObject*) const; - virtual PyObject* instance_number_xor(PyObject*, PyObject*) const; - virtual PyObject* instance_number_or(PyObject*, PyObject*) const; - virtual int instance_number_coerce(PyObject*, PyObject**, PyObject**) const; - virtual PyObject* instance_number_int(PyObject*) const; - virtual PyObject* instance_number_long(PyObject*) const; - virtual PyObject* instance_number_float(PyObject*) const; - virtual PyObject* instance_number_oct(PyObject*) const; - virtual PyObject* instance_number_hex(PyObject*) const; - - virtual PyObject* instance_number_inplace_add(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_subtract(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_multiply(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_divide(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_remainder(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_power(PyObject*, PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_lshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_rshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_and(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_or(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_xor(PyObject*, PyObject*) const; - - public: // Callbacks for rich comparisons - virtual PyObject* instance_lt(PyObject*, PyObject*) const; - virtual PyObject* instance_le(PyObject*, PyObject*) const; - virtual PyObject* instance_eq(PyObject*, PyObject*) const; - virtual PyObject* instance_ne(PyObject*, PyObject*) const; - virtual PyObject* instance_gt(PyObject*, PyObject*) const; - virtual PyObject* instance_ge(PyObject*, PyObject*) const; -}; - -template -class type_object : public type_object_base -{ - public: - typedef T instance; - - type_object(PyTypeObject* type_type, const char* name) - : type_object_base(type_type) - { - assert(name != 0); - this->tp_name = const_cast(name); - } - - type_object(PyTypeObject* type_type) - : type_object_base(type_type) - { - this->tp_name = const_cast(typeid(instance).name()); - } - - private: // Overridable behaviors. - // Called when the reference count goes to zero. The default implementation - // is "delete p". If you have not allocated your object with operator new or - // you have other constraints, you'll need to override this - virtual void dealloc(T* p) const; - - private: // Implementation of type_object_base hooks. Do not reimplement in derived classes. - void instance_dealloc(PyObject*) const; -}; - -// -// type objects -// -template -class callable : public Base -{ - public: - typedef callable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - callable(PyTypeObject* type_type, const char* name); - callable(PyTypeObject* type_type); - private: - PyObject* instance_call(PyObject* obj, PyObject* args, PyObject* kw) const; -}; - -template -class getattrable : public Base -{ - public: - typedef getattrable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - getattrable(PyTypeObject* type_type, const char* name); - getattrable(PyTypeObject* type_type); - private: - PyObject* instance_getattr(PyObject* obj, const char* name) const; -}; - -template -class setattrable : public Base -{ - public: - typedef setattrable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - setattrable(PyTypeObject* type_type, const char* name); - setattrable(PyTypeObject* type_type); - private: - int instance_setattr(PyObject* obj, const char* name, PyObject* value) const; -}; - -template -class reprable : public Base -{ - public: - typedef reprable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - reprable(PyTypeObject* type_type, const char* name); - reprable(PyTypeObject* type_type); - private: - PyObject* instance_repr(PyObject* obj) const; -}; - -// -// Member function definitions -// - -// type_object<> -template -void type_object::instance_dealloc(PyObject* obj) const -{ - this->dealloc(downcast(obj).get()); -} - -template -void type_object::dealloc(T* obj) const -{ - delete obj; -} - -// callable -template -callable::callable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(call); -} - -template -callable::callable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(call); -} - -template -PyObject* callable::instance_call(PyObject* obj, PyObject* args, PyObject* kw) const -{ - return downcast(obj)->call(args, kw); -} - -// getattrable -template -getattrable::getattrable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(getattr); -} - -template -getattrable::getattrable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(getattr); -} - -template -PyObject* getattrable::instance_getattr(PyObject* obj, const char* name) const -{ - return downcast(obj)->getattr(name); -} - -// setattrable -template -setattrable::setattrable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(setattr); -} - -template -setattrable::setattrable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(setattr); -} - -template -int setattrable::instance_setattr(PyObject* obj, const char* name, PyObject* value) const -{ - return downcast(obj)->setattr(name, value); -} - -// reprable -template -reprable::reprable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(repr); -} - -template -reprable::reprable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(repr); -} - -template -PyObject* reprable::instance_repr(PyObject* obj) const -{ - return downcast(obj)->repr(); -} - - // Helper class for optimized allocation of PODs: If two PODs - // happen to contain identical byte patterns, they may share their - // memory. Reference counting is used to free unused memory. - // This is useful because method tables of related extension classes tend - // to be identical, so less memory is needed for them. - class BOOST_PYTHON_DECL shared_pod_manager - { - typedef std::pair holder; - typedef std::vector storage; - - public: - static shared_pod_manager& obj(); - ~shared_pod_manager(); - - // Allocate memory for POD T and fill it with zeros. - // This memory is initially not shared. - template - static void create(T*& t) - { - t = reinterpret_cast(obj().create(sizeof(T))); - } - - // Decrement the refcount for the memory t points to. If the count - // goes to zero, the memory is freed. - template - static void dispose(T* t) - { - obj().dec_ref(t, sizeof(T)); - } - - // Attempt to share the memory t points to. If memory with the same - // contents already exists, t is replaced by a pointer to this memory, - // and t's old memory is disposed. Otherwise, t will be registered for - // potential future sharing. - template - static void replace_if_equal(T*& t) - { - t = reinterpret_cast(obj().replace_if_equal(t, sizeof(T))); - } - - // Create a copy of t's memory that is guaranteed to be private to t. - // Afterwards t points to the new memory, unless it was already private, in - // which case there is no change (except that t's memory will no longer - // be considered for future sharing - see raplade_if_equal()) - // This function *must* be called before the contents of (*t) can - // be overwritten. Otherwise, inconsistencies and crashes may result. - template - static void make_unique_copy(T*& t) - { - t = reinterpret_cast(obj().make_unique_copy(t, sizeof(T))); - } - - private: - void* replace_if_equal(void* pod, std::size_t size); - void* make_unique_copy(void* pod, std::size_t size); - void* create(std::size_t size); - void dec_ref(void* pod, std::size_t size); - void erase_from_list(void* pod); - - struct compare; - struct identical; - - private: - shared_pod_manager() {} // instance - -#ifdef TYPE_OBJECT_BASE_STANDALONE_TEST - public: -#endif - storage m_storage; - }; - - - BOOST_PYTHON_DECL void add_capability(type_object_base::capability capability, - PyTypeObject* dest); - -// This macro gets the length of an array as a compile-time constant, and will -// fail to compile if the parameter is a pointer. -#ifdef __BORLANDC__ // smart implementation doesn't work for borland; maybe someone knows a workaround? -# define PY_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0])) -#else -# define PY_ARRAY_LENGTH(a) \ - (sizeof(::boost::python::detail::countof_validate(a, &(a))) ? sizeof(a) / sizeof((a)[0]) : 0) -#endif - - template - inline void countof_validate(T* const, T* const*); - - template - inline int countof_validate(const void*, T); - -}}} // namespace boost::python::detail - -#endif // TYPES_DWA051800_H_ diff --git a/include/boost/python/detail/unwind_type.hpp b/include/boost/python/detail/unwind_type.hpp deleted file mode 100644 index 878b6cc1..00000000 --- a/include/boost/python/detail/unwind_type.hpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef UNWIND_TYPE_DWA200222_HPP -# define UNWIND_TYPE_DWA200222_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -template -inline typename Generator::result_type -unwind_type_cv(U* p, cv_unqualified, Generator* = 0) -{ - return Generator::execute(p); -} - -template -inline typename Generator::result_type -unwind_type_cv(U const* p, const_, Generator* = 0) -{ - return unwind_type(const_cast(p), (Generator*)0); -} - -template -inline typename Generator::result_type -unwind_type_cv(U volatile* p, volatile_, Generator* = 0) -{ - return unwind_type(const_cast(p), (Generator*)0); -} - -template -inline typename Generator::result_type -unwind_type_cv(U const volatile* p, const_volatile_, Generator* = 0) -{ - return unwind_type(const_cast(p), (Generator*)0); -} - -template -inline typename Generator::result_type -unwind_ptr_type(U* p, Generator* = 0) -{ - typedef typename cv_category::type tag; - return unwind_type_cv(p, tag()); -} - -template -struct unwind_helper -{ - template - static typename Generator::result_type - execute(U p, Generator* = 0) - { - return unwind_ptr_type(p, (Generator*)0); - } -}; - -template <> -struct unwind_helper -{ - template - static typename Generator::result_type - execute(U& p, Generator* = 0) - { - return unwind_ptr_type(&p, (Generator*)0); - } -}; - -template -inline typename Generator::result_type -unwind_type(U const& p, Generator* = 0) -{ - return unwind_helper::value>::execute(p, (Generator*)0); -} - -enum { direct_ = 0, pointer_ = 1, reference_ = 2, reference_to_pointer_ = 3 }; -template struct unwind_helper2; - -template <> -struct unwind_helper2 -{ - template - static typename Generator::result_type - execute(U(*)(), Generator* = 0) - { - return unwind_ptr_type((U*)0, (Generator*)0); - } -}; - -template <> -struct unwind_helper2 -{ - template - static typename Generator::result_type - execute(U*(*)(), Generator* = 0) - { - return unwind_ptr_type((U*)0, (Generator*)0); - } -}; - -template <> -struct unwind_helper2 -{ - template - static typename Generator::result_type - execute(U&(*)(), Generator* = 0) - { - return unwind_ptr_type((U*)0, (Generator*)0); - } -}; - -template <> -struct unwind_helper2 -{ - template - static typename Generator::result_type - execute(U&(*)(), Generator* = 0) - { - return unwind_ptr_type(U(0), (Generator*)0); - } -}; - -// Call this one with both template parameters explicitly specified -// and no function arguments: -// -// return unwind_type(); -// -// Doesn't work if T is an array type; we could handle that case, but -// why bother? -template -inline typename Generator::result_type -unwind_type(boost::type*p = 0, Generator* = 0) -{ - BOOST_STATIC_CONSTANT(int, indirection - = (is_pointer::value ? pointer_ : 0) - + (is_reference_to_pointer::value - ? reference_to_pointer_ - : is_reference::value - ? reference_ - : 0)); - - return unwind_helper2::execute((U(*)())0,(Generator*)0); -} - -}}} // namespace boost::python::detail - -#endif // UNWIND_TYPE_DWA200222_HPP diff --git a/include/boost/python/detail/void_adaptor.hpp b/include/boost/python/detail/void_adaptor.hpp deleted file mode 100644 index 3b4b2124..00000000 --- a/include/boost/python/detail/void_adaptor.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. - -#ifndef VOID_ADAPTOR_DWA20011112_HPP -# define VOID_ADAPTOR_DWA20011112_HPP - -namespace boost { namespace python { namespace detail { - - extern BOOST_PYTHON_DECL PyObject arbitrary_object; - - template - struct void_adaptor - { - typedef PyObject* result_type; - - void_adaptor(T const& f) - : m_f(f) - {} - - PyObject* operator()() const - { - m_f(); - return &arbitrary_object; - } - private: - T m_f; - }; - - template - void_adaptor make_void_adaptor(T const& f) - { - return void_adaptor(f); - } -}}} // namespace boost::python::detail - -#endif // VOID_ADAPTOR_DWA20011112_HPP - diff --git a/include/boost/python/detail/void_ptr.hpp b/include/boost/python/detail/void_ptr.hpp deleted file mode 100644 index 676a5cac..00000000 --- a/include/boost/python/detail/void_ptr.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef VOID_PTR_DWA200239_HPP -# define VOID_PTR_DWA200239_HPP - -namespace boost { namespace python { namespace detail { - -template -inline U& void_ptr_to_reference(void const volatile* p, U&(*)()) -{ - return *(U*)p; -} - -template -inline void write_void_ptr(void const volatile* storage, void* ptr, T*) -{ - *(T**)storage = (T*)ptr; -} - -// writes U(ptr) into the storage -template -inline void write_void_ptr_reference(void const volatile* storage, void* ptr, U&(*)()) -{ - // stripping CV qualification suppresses warnings on older EDGs - typedef typename remove_cv::type u_stripped; - write_void_ptr(storage, ptr, u_stripped(0)); -} - -}}} // namespace boost::python::detail - -#endif // VOID_PTR_DWA200239_HPP diff --git a/include/boost/python/detail/void_return.hpp b/include/boost/python/detail/void_return.hpp deleted file mode 100644 index 512aa636..00000000 --- a/include/boost/python/detail/void_return.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef VOID_RETURN_DWA200274_HPP -# define VOID_RETURN_DWA200274_HPP - -# include - -namespace boost { namespace python { namespace detail { - -struct void_return -{ - void_return() {} - private: - void operator=(void_return const&); -}; - -template -struct returnable -{ - typedef T type; -}; - -# ifdef BOOST_NO_VOID_RETURNS -template <> -struct returnable -{ - typedef void_return type; -}; - -# ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS -template <> struct returnable : returnable {}; -template <> struct returnable : returnable {}; -template <> struct returnable : returnable {}; -# endif - -# endif // BOOST_NO_VOID_RETURNS - -}}} // namespace boost::python::detail - -#endif // VOID_RETURN_DWA200274_HPP diff --git a/include/boost/python/detail/wrap_function.hpp b/include/boost/python/detail/wrap_function.hpp deleted file mode 100644 index 488f939e..00000000 --- a/include/boost/python/detail/wrap_function.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef WRAP_FUNCTION_DWA2002118_HPP -# define WRAP_FUNCTION_DWA2002118_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace detail { - -// A function which converts its argument into a Python callable -// object. Not very general yet! - -// This should eventually be replaced with a mechanism for specialized -// wrap/unwrap objects. In other words, to_python(f), where f is a -// function pointer or function type, should produce a callable Python -// object. - -template -inline PyObject* wrap_function_aux(F f, PyObject*) { return f; } - -template -inline PyObject* wrap_function_aux(F f, ...) { return make_function(f); } - -template -PyObject* wrap_function(F f) -{ - return wrap_function_aux(f, f); -} - -}}} // namespace boost::python::detail - -#endif // WRAP_FUNCTION_DWA2002118_HPP diff --git a/include/boost/python/detail/wrap_python.hpp b/include/boost/python/detail/wrap_python.hpp deleted file mode 100644 index 6cb8dee2..00000000 --- a/include/boost/python/detail/wrap_python.hpp +++ /dev/null @@ -1,157 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -// This file serves as a wrapper around which allows it to be -// compiled with GCC 2.95.2 under Win32 and which disables the default MSVC -// behavior so that a program may be compiled in debug mode without requiring a -// special debugging build of the Python library. - - -// To use the Python debugging library, #define BOOST_DEBUG_PYTHON on the -// compiler command-line. - -// Revision History: -// 05 Mar 01 Suppress warnings under Cygwin with Python 2.0 (Dave Abrahams) -// 04 Mar 01 Rolled in some changes from the Dragon fork (Dave Abrahams) -// 01 Mar 01 define PyObject_INIT() for Python 1.x (Dave Abrahams) - -// -// Python's LongObject.h helpfully #defines ULONGLONG_MAX for us, -// which confuses Boost's config -// -#include -#ifndef ULONG_MAX -# define BOOST_PYTHON_ULONG_MAX_UNDEFINED -#endif -#ifndef LONGLONG_MAX -# define BOOST_PYTHON_LONGLONG_MAX_UNDEFINED -#endif -#ifndef ULONGLONG_MAX -# define BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED -#endif - -// -// Get ahold of Python's version number -// -#include - -#ifdef _DEBUG -# ifndef BOOST_DEBUG_PYTHON -# undef _DEBUG // Don't let Python force the debug library just because we're debugging. -# define DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H -# endif -#endif - -// -// Some things we need in order to get Python.h to work with compilers other -// than MSVC on Win32 -// -#if defined(_WIN32) || defined(__CYGWIN__) -# if defined(__GNUC__) && defined(__CYGWIN__) - -# define SIZEOF_LONG 4 - -# if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 2 - -typedef int pid_t; - -# define WORD_BIT 32 -# define hypot _hypot -# include - -# if PY_MAJOR_VERSION < 2 -# define HAVE_CLOCK -# define HAVE_STRFTIME -# define HAVE_STRERROR -# endif - -# define NT_THREADS - -# ifndef NETSCAPE_PI -# define USE_SOCKET -# endif - -# ifdef USE_DL_IMPORT -# define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE -# endif - -# ifdef USE_DL_EXPORT -# define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE -# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE -# endif - -# define HAVE_LONG_LONG 1 -# define LONG_LONG long long -# endif - -# elif defined(__MWERKS__) - -# ifndef _MSC_VER -# define PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H 1 -# define _MSC_VER 900 -# endif - -# if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2 -# include -# else -# include -# endif -# undef hypot // undo the evil #define left by Python. - -# elif defined(__BORLANDC__) -# if PY_MAJOR_VERSION < 2 || PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2 -# include -# else -# include -# endif -# undef HAVE_HYPOT -# define HAVE_HYPOT 1 -# endif - -#endif // _WIN32 - -#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 2 -# include -#else -# include -#endif - -#ifdef BOOST_PYTHON_ULONG_MAX_UNDEFINED -# undef ULONG_MAX -# undef BOOST_PYTHON_ULONG_MAX_UNDEFINED -#endif - -#ifdef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED -# undef LONGLONG_MAX -# undef BOOST_PYTHON_LONGLONG_MAX_UNDEFINED -#endif - -#ifdef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED -# undef ULONGLONG_MAX -# undef BOOST_PYTHON_ULONGLONG_MAX_UNDEFINED -#endif - -#ifdef PY_MSC_VER_DEFINED_FROM_WRAP_PYTHON_H -# undef _MSC_VER -#endif - -#ifdef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H -# undef DEBUG_UNDEFINED_FROM_WRAP_PYTHON_H -# define _DEBUG -#endif - -#if !defined(PY_MAJOR_VERSION) || PY_MAJOR_VERSION < 2 -# define PyObject_INIT(op, typeobj) \ - ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) ) -#endif - -#ifdef __MWERKS__ -# pragma warn_possunwant off -#elif _MSC_VER -# pragma warning(disable:4786) -#endif diff --git a/include/boost/python/dict.hpp b/include/boost/python/dict.hpp deleted file mode 100644 index b593f902..00000000 --- a/include/boost/python/dict.hpp +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef DICT_20020706_HPP -#define DICT_20020706_HPP - -#include -#include -#include -#include - -namespace boost { namespace python { - -class dict : public object -{ - public: - // dict() -> new empty dictionary. - // dict(mapping) -> new dictionary initialized from a mapping object's - // (key, value) pairs. - // dict(seq) -> new dictionary initialized as if via: - BOOST_PYTHON_DECL dict(); // new dict - explicit BOOST_PYTHON_DECL dict(object_cref data); - - template - explicit dict(T const& data) - : object(dict::call(object(data))) - { - } - - // D.clear() -> None. Remove all items from D. - BOOST_PYTHON_DECL void clear(); - - // D.copy() -> a shallow copy of D - BOOST_PYTHON_DECL dict copy(); - - // D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None. - BOOST_PYTHON_DECL object get(object_cref k) const; - - template - object get(T const& k) const - { - return this->get(object(k)); - } - - BOOST_PYTHON_DECL object get(object_cref k, object_cref d) const; - - template - object get(T1 const& k, T2 const& d) const - { - return this->get(object(k),object(d)); - } - - // D.has_key(k) -> 1 if D has a key k, else 0 - BOOST_PYTHON_DECL bool has_key(object_cref k) const; - - template - bool has_key(T const& k) const - { - return this->has_key(object(k)); - } - - // D.items() -> list of D's (key, value) pairs, as 2-tuples - BOOST_PYTHON_DECL list items() const; - - // D.iteritems() -> an iterator over the (key, value) items of D - BOOST_PYTHON_DECL object iteritems() const; - - // D.iterkeys() -> an iterator over the keys of D - BOOST_PYTHON_DECL object iterkeys() const; - - // D.itervalues() -> an iterator over the values of D - BOOST_PYTHON_DECL object itervalues() const; - - // D.keys() -> list of D's keys - BOOST_PYTHON_DECL list keys() const; - - // D.popitem() -> (k, v), remove and return some (key, value) pair as a - // 2-tuple; but raise KeyError if D is empty - BOOST_PYTHON_DECL tuple popitem(); - - // D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k) - BOOST_PYTHON_DECL object setdefault(object_cref k); - - template - object setdefault(T const& k) - { - return this->setdefault(object(k)); - } - - BOOST_PYTHON_DECL object setdefault(object_cref k, object_cref d); - - template - object setdefault(T1 const& k, T2 const& d) - { - return this->setdefault(object(k),object(d)); - } - - // D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k] - BOOST_PYTHON_DECL void update(object_cref E); - - template - void update(T const& E) - { - this->update(object(E)); - } - - // D.values() -> list of D's values - BOOST_PYTHON_DECL list values() const; - - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict) - - private: - static BOOST_PYTHON_DECL detail::new_reference call(object const&); -}; - - -// -// Converter Specializations -// -namespace converter -{ - template <> - struct object_manager_traits - : pytype_object_manager_traits<&PyDict_Type,dict> - { - }; -} - -}} // namespace boost::python - -#endif - diff --git a/include/boost/python/enum.hpp b/include/boost/python/enum.hpp deleted file mode 100644 index 072a0626..00000000 --- a/include/boost/python/enum.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ENUM_DWA200298_HPP -# define ENUM_DWA200298_HPP - -# include -# include -# include - -namespace boost { namespace python { - -template -struct enum_ : public objects::enum_base -{ - typedef objects::enum_base base; - - enum_(char const* name); - inline enum_& value(char const* name, T); - - private: - static PyObject* to_python(void const* x); - static void* convertible(PyObject* obj); - static void construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data); -}; - -template -inline enum_::enum_(char const* name) - : base( - name - , &enum_::to_python - , &enum_::convertible - , &enum_::construct - , type_id()) -{ -} - -// This is the conversion function that gets registered for converting -template -PyObject* enum_::to_python(void const* x) -{ - return base::to_python( - converter::registered::converters.class_object - , static_cast(*(T const*)x)); -} - -template -void* enum_::convertible(PyObject* obj) -{ - return PyObject_IsInstance( - obj - , upcast( - converter::registered::converters.class_object)) - - ? obj : 0; -} - -template -void enum_::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data) -{ - T x = static_cast(PyInt_AS_LONG(obj)); - void* const storage = ((converter::rvalue_from_python_storage*)data)->storage.bytes; - new (storage) T(x); - data->convertible = storage; -} - -template -inline enum_& enum_::value(char const* name, T x) -{ - this->add_value(name, static_cast(x)); - return *this; -} - -}} // namespace boost::python - -#endif // ENUM_DWA200298_HPP diff --git a/include/boost/python/errors.hpp b/include/boost/python/errors.hpp deleted file mode 100644 index 4c47aca8..00000000 --- a/include/boost/python/errors.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef ERRORS_DWA052500_H_ -# define ERRORS_DWA052500_H_ - -# include -# include -# include - -namespace boost { namespace python { - -struct BOOST_PYTHON_DECL error_already_set {}; -struct BOOST_PYTHON_DECL argument_error : error_already_set {}; - -// Handles exceptions caught just before returning to Python code. -// Returns true iff an exception was caught. -BOOST_PYTHON_DECL bool handle_exception_impl(function0); - -template -bool handle_exception(T f) -{ - return handle_exception_impl(function0(boost::ref(f))); -} - -namespace detail { inline void rethrow() { throw; } } - -inline void handle_exception() -{ - handle_exception(detail::rethrow); -} - -BOOST_PYTHON_DECL void throw_argument_error(); -BOOST_PYTHON_DECL void throw_error_already_set(); - -template -inline T* expect_non_null(T* x) -{ - if (x == 0) - throw_error_already_set(); - return x; -} - -# ifdef BOOST_PYTHON_V2 -// Return source if it is an instance of pytype; throw an appropriate -// exception otherwise. -BOOST_PYTHON_DECL PyObject* pytype_check(PyTypeObject* pytype, PyObject* source); -# endif - -}} // namespace boost::python - -#endif // ERRORS_DWA052500_H_ diff --git a/include/boost/python/exception_translator.hpp b/include/boost/python/exception_translator.hpp deleted file mode 100644 index 830d50d2..00000000 --- a/include/boost/python/exception_translator.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef EXCEPTION_TRANSLATOR_DWA2002810_HPP -# define EXCEPTION_TRANSLATOR_DWA2002810_HPP -# include -# include -# include -# include - -namespace boost { namespace python { - -template -void register_exception_translator(Translate const& translate, boost::type* = 0) -{ - detail::register_exception_handler( - bind(detail::translate_exception(), _1, _2, translate) - ); -} - -}} // namespace boost::python - -#endif // EXCEPTION_TRANSLATOR_DWA2002810_HPP diff --git a/include/boost/python/extract.hpp b/include/boost/python/extract.hpp deleted file mode 100644 index 598fe249..00000000 --- a/include/boost/python/extract.hpp +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef EXTRACT_DWA200265_HPP -# define EXTRACT_DWA200265_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace converter -{ - template - struct extract_pointer - { - typedef Ptr result_type; - extract_pointer(PyObject*); - - bool check() const; - Ptr operator()() const; - - private: - PyObject* m_source; - void* m_result; - }; - - template - struct extract_reference - { - typedef Ref result_type; - extract_reference(PyObject*); - - bool check() const; - Ref operator()() const; - - private: - PyObject* m_source; - void* m_result; - }; - - template - struct extract_rvalue : private noncopyable - { - typedef typename call_traits::param_type result_type; - extract_rvalue(PyObject*); - - bool check() const; - result_type operator()() const; - private: - PyObject* m_source; - mutable rvalue_from_python_data m_data; - }; - - template - struct extract_object_manager - { - typedef T result_type; - extract_object_manager(PyObject*); - - bool check() const; - result_type operator()() const; - private: - PyObject* m_source; - }; - - template - struct select_extract - { - BOOST_STATIC_CONSTANT( - bool, obj_mgr = is_object_manager::value); - - BOOST_STATIC_CONSTANT( - bool, ptr = is_pointer::value); - - BOOST_STATIC_CONSTANT( - bool, ref = is_reference::value); - - typedef typename mpl::if_c< - obj_mgr - , extract_object_manager - , typename mpl::if_c< - ptr - , extract_pointer - , typename mpl::if_c< - ref - , extract_reference - , extract_rvalue - >::type - >::type - >::type type; - }; -} - -template -struct extract - : converter::select_extract::type -{ - private: - typedef typename converter::select_extract::type base; - public: - typedef typename base::result_type result_type; - - operator result_type() const - { - return (*this)(); - } - - extract(PyObject*); - extract(object const&); -}; - -// -// Implementations -// -template -inline extract::extract(PyObject* o) - : base(o) -{ -} - -template -inline extract::extract(object const& o) - : base(o.ptr()) -{ -} - -namespace converter -{ - template - inline extract_rvalue::extract_rvalue(PyObject* x) - : m_source(x) - , m_data( - (rvalue_from_python_stage1)(x, registered::converters) - ) - { - } - - template - inline bool - extract_rvalue::check() const - { - return m_data.stage1.convertible; - } - - template - inline typename extract_rvalue::result_type - extract_rvalue::operator()() const - { - return *(T*)( - // Only do the stage2 conversion once - m_data.stage1.convertible == m_data.storage.bytes - ? m_data.storage.bytes - : (rvalue_from_python_stage2)(m_source, m_data.stage1, registered::converters) - ); - } - - template - inline extract_reference::extract_reference(PyObject* obj) - : m_source(obj) - , m_result( - (get_lvalue_from_python)(obj, registered::converters) - ) - { - } - - template - inline bool extract_reference::check() const - { - return m_result != 0; - } - - template - inline Ref extract_reference::operator()() const - { - if (m_result == 0) - (throw_no_reference_from_python)(m_source, registered::converters); - - return python::detail::void_ptr_to_reference(m_result, (Ref(*)())0); - } - - template - inline extract_pointer::extract_pointer(PyObject* obj) - : m_source(obj) - , m_result( - obj == Py_None ? 0 : (get_lvalue_from_python)(obj, registered_pointee::converters) - ) - { - } - - template - inline bool extract_pointer::check() const - { - return m_source == Py_None || m_result != 0; - } - - template - inline Ptr extract_pointer::operator()() const - { - if (m_result == 0 && m_source != Py_None) - (throw_no_pointer_from_python)(m_source, registered_pointee::converters); - - return Ptr(m_result); - } - - template - inline extract_object_manager::extract_object_manager(PyObject* obj) - : m_source(obj) - { - } - - template - inline bool extract_object_manager::check() const - { - return object_manager_traits::check(m_source); - } - - template - inline T extract_object_manager::operator()() const - { - return T( - object_manager_traits::adopt(python::incref(m_source)) - ); - } -} - -}} // namespace boost::python::converter - -#endif // EXTRACT_DWA200265_HPP diff --git a/include/boost/python/from_python.hpp b/include/boost/python/from_python.hpp deleted file mode 100644 index 726928ac..00000000 --- a/include/boost/python/from_python.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FROM_PYTHON_DWA2002128_HPP -# define FROM_PYTHON_DWA2002128_HPP - -# include - -namespace boost { namespace python { - -template -struct from_python - : converter::select_from_python::type -{ - typedef typename converter::select_from_python::type base; - from_python(PyObject*); -}; - -// specialization for PyObject* -template <> -struct from_python -{ - from_python(PyObject*) {} - bool convertible() const { return true; } - PyObject* operator()(PyObject* source) const { return source; } -}; - -template <> -struct from_python -{ - from_python(PyObject*) {} - bool convertible() const { return true; } - PyObject*const& operator()(PyObject*const& source) const { return source; } -}; - -// -// implementations -// -template -inline from_python::from_python(PyObject* source) - : base(source) -{ -} - -}} // namespace boost::python - -#endif // FROM_PYTHON_DWA2002128_HPP diff --git a/include/boost/python/handle.hpp b/include/boost/python/handle.hpp deleted file mode 100755 index 7fea1134..00000000 --- a/include/boost/python/handle.hpp +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef HANDLE_DWA200269_HPP -# define HANDLE_DWA200269_HPP - -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -template struct null_ok; - -template -inline null_ok* allow_null(T* p) -{ - return (null_ok*)p; -} - -namespace detail -{ - template - inline T* manage_ptr(detail::borrowed >* p, int) - { - return python::xincref((T*)p); - } - - template - inline T* manage_ptr(null_ok >* p, int) - { - return python::xincref((T*)p); - } - - template - inline T* manage_ptr(detail::borrowed* p, long) - { - return python::incref(expect_non_null((T*)p)); - } - - template - inline T* manage_ptr(null_ok* p, long) - { - return (T*)p; - } - - template - inline T* manage_ptr(T* p, ...) - { - return expect_non_null(p); - } -} - -template -class handle -{ - typedef T* (handle::* bool_type )() const; - - public: // types - typedef T element_type; - - public: // member functions - handle(); - ~handle(); - - template - explicit handle(Y* p) - : m_p( - python::upcast( - detail::manage_ptr(p, 0) - ) - ) - { - } - - handle& operator=(handle const& r); - -#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1200) - - template - handle& operator=(handle const & r) // never throws - { - python::xdecref(m_p); - m_p = python::xincref(python::upcast(r.get())); - return *this; - } - -#endif - - template - handle(handle const& r) - : m_p(python::xincref(python::upcast(r.get()))) - { - } - - handle(handle const& r) - : m_p(python::xincref(r.m_p)) - { - } - - T* operator-> () const; - T& operator* () const; - T* get() const; - T* release(); - - operator bool_type() const // never throws - { - return m_p ? &handle::get : 0; - } - bool operator! () const; // never throws - - public: // implementation details -- do not touch - // Defining this in the class body suppresses a VC7 link failure - inline handle(detail::borrowed_reference x) - : m_p( - python::incref( - downcast((PyObject*)x) - )) - { - } - - private: // data members - T* m_p; -}; - -typedef handle type_handle; - -// -// Compile-time introspection -// -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -class is_handle -{ - public: - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -class is_handle > -{ - public: - BOOST_STATIC_CONSTANT(bool, value = true); -}; -# else -namespace detail -{ - typedef char (&yes_handle_t)[1]; - typedef char (&no_handle_t)[2]; - - no_handle_t is_handle_test(...); - - template - yes_handle_t is_handle_test(boost::type< handle >); -} - -template -class is_handle -{ - public: - BOOST_STATIC_CONSTANT( - bool, value = ( - sizeof(detail::is_handle_test(boost::type())) - == sizeof(detail::yes_handle_t))); -}; -# endif - -// -// implementations -// -template -inline handle::handle() - : m_p(0) -{ -} - -template -inline handle::~handle() -{ - python::xdecref(m_p); -} - -template -inline handle& handle::operator=(handle const& r) -{ - python::xdecref(m_p); - m_p = python::xincref(r.m_p); - return *this; -} - -template -inline T* handle::operator->() const -{ - return m_p; -} - -template -inline T& handle::operator*() const -{ - return *m_p; -} - -template -inline T* handle::get() const -{ - return m_p; -} - -template -inline bool handle::operator!() const -{ - return m_p == 0; -} - -template -inline T* handle::release() -{ - T* result = m_p; - m_p = 0; - return result; -} - -// Because get_managed_object must return a non-null PyObject*, we -// return Py_None if the handle is null. -template -inline PyObject* get_managed_object(handle const& h, tag_t) -{ - return h.get() ? python::upcast(h.get()) : Py_None; -} - -}} // namespace boost::python - - -#endif // HANDLE_DWA200269_HPP diff --git a/include/boost/python/handle_fwd.hpp b/include/boost/python/handle_fwd.hpp deleted file mode 100755 index afcce163..00000000 --- a/include/boost/python/handle_fwd.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef HANDLE_FWD_DWA2002615_HPP -# define HANDLE_FWD_DWA2002615_HPP - -# include - -namespace boost { namespace python { - -template class handle; - -}} // namespace boost::python - -#endif // HANDLE_FWD_DWA2002615_HPP diff --git a/include/boost/python/has_back_reference.hpp b/include/boost/python/has_back_reference.hpp deleted file mode 100644 index 95a3ae9a..00000000 --- a/include/boost/python/has_back_reference.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef HAS_BACK_REFERENCE_DWA2002323_HPP -# define HAS_BACK_REFERENCE_DWA2002323_HPP - -namespace boost { namespace python { - -// traits class which users can specialize to indicate that a class -// contains a back-reference to its owning PyObject* -template -struct has_back_reference -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - - -}} // namespace boost::python - -#endif // HAS_BACK_REFERENCE_DWA2002323_HPP diff --git a/include/boost/python/implicit.hpp b/include/boost/python/implicit.hpp deleted file mode 100644 index a6e73eba..00000000 --- a/include/boost/python/implicit.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef IMPLICIT_DWA2002325_HPP -# define IMPLICIT_DWA2002325_HPP -# include -# include -# include -# include - -namespace boost { namespace python { - -template -void implicitly_convertible(boost::type* = 0, boost::type* = 0) -{ - typedef converter::implicit functions; - - converter::registry::push_back( - &functions::convertible - , &functions::construct - , type_id()); -} - -}} // namespace boost::python - -#endif // IMPLICIT_DWA2002325_HPP diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp deleted file mode 100644 index 824b72f0..00000000 --- a/include/boost/python/init.hpp +++ /dev/null @@ -1,368 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -// -/////////////////////////////////////////////////////////////////////////////// -#ifndef INIT_JDG20020820_HPP -#define INIT_JDG20020820_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -/////////////////////////////////////////////////////////////////////////////// -#define BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT \ - BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( \ - BOOST_PYTHON_MAX_ARITY, \ - class T, \ - mpl::void_) \ - -#define BOOST_PYTHON_TEMPLATE_TYPES \ - BOOST_PP_ENUM_PARAMS( \ - BOOST_PYTHON_MAX_ARITY, \ - class T) \ - -#define BOOST_PYTHON_TEMPLATE_ARGS \ - BOOST_PP_ENUM_PARAMS( \ - BOOST_PYTHON_MAX_ARITY, \ - T) \ - -/////////////////////////////////////////////////////////////////////////////// -namespace boost { namespace python { - -template -struct init; // forward declaration - -/////////////////////////////////////// -template -struct optional; // forward declaration - -namespace detail { - - /////////////////////////////////////////////////////////////////////////// - // - // is_optional::value - // - // This metaprogram checks if T is an optional - // - /////////////////////////////////////////////////////////////////////////// - #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - - template - struct is_optional { - - private: - - template - static boost::type_traits::yes_type f(optional); - static boost::type_traits::no_type f(...); - static T t(); - - public: - - BOOST_STATIC_CONSTANT( - bool, value = - sizeof(f(t())) == sizeof(::boost::type_traits::yes_type)); - typedef mpl::bool_c type; - - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) // needed for MSVC & Borland - }; - - /////////////////////////////////////// - #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - - template - struct is_optional_impl { - - BOOST_STATIC_CONSTANT(bool, value = false); - }; - - template - struct is_optional_impl > { - - BOOST_STATIC_CONSTANT(bool, value = true); - }; - - template - struct is_optional : is_optional_impl - { - typedef mpl::bool_c::value> type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) // needed for MSVC & Borland - }; - #endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - -} // namespace detail - -template -struct init_base { - - DerivedT const& derived() const - { return *static_cast(this); } -}; - -template -struct init_with_call_policies -: public init_base > -{ - BOOST_STATIC_CONSTANT(int, n_arguments = InitT::n_arguments); - BOOST_STATIC_CONSTANT(int, n_defaults = InitT::n_defaults); - - typedef typename InitT::reversed_args reversed_args; - - init_with_call_policies(CallPoliciesT const& policies_, char const* doc_) - : policies(policies_), doc(doc_) {} - - char const* doc_string() const - { return doc; } - - CallPoliciesT - call_policies() const - { return policies; } - - CallPoliciesT policies; - char const* doc; -}; - -template -struct init : public init_base > -{ - typedef init self_t; - - init(char const* doc_ = 0) - : doc(doc_) {} - - char const* doc_string() const - { return doc; } - - default_call_policies - call_policies() const - { return default_call_policies(); } - - template - init_with_call_policies - operator[](CallPoliciesT const& policies) const - { return init_with_call_policies(policies, doc); } - - typedef detail::type_list signature_; - typedef typename mpl::end::type finish; - - // Find the optional<> element, if any - typedef typename mpl::find_if< - signature_, detail::is_optional - >::type opt; - - - // Check to make sure the optional<> element, if any, is the last one - typedef typename mpl::apply_if< - is_same - , mpl::identity - , mpl::next - >::type expected_finish; - BOOST_STATIC_ASSERT((is_same::value)); - - typedef typename mpl::apply_if< - is_same - , mpl::list0<> - , opt - >::type optional_args; - - // Count the number of default args - BOOST_STATIC_CONSTANT(int, n_defaults = mpl::size::value); - - typedef typename mpl::iterator_range< - typename mpl::begin::type - , opt - >::type required_args; - - // Build a reverse image of all the args, including optionals - typedef typename mpl::fold< - required_args - , mpl::list0<> - , mpl::push_front - >::type reversed_required; - - typedef typename mpl::fold< - optional_args - , reversed_required - , mpl::push_front - >::type reversed_args; - - // Count the maximum number of arguments - BOOST_STATIC_CONSTANT(int, n_arguments = mpl::size::value); - - char const* doc; -}; - -template <> // specialization for zero args -struct init<> : public init_base > -{ - typedef init<> self_t; - - init(char const* doc_ = 0) - : doc(doc_) {} - - char const* doc_string() const - { return doc; } - - default_call_policies - call_policies() const - { return default_call_policies(); } - - template - init_with_call_policies - operator[](CallPoliciesT const& policies) const - { return init_with_call_policies(policies, doc); } - - BOOST_STATIC_CONSTANT(int, n_defaults = 0); - BOOST_STATIC_CONSTANT(int, n_arguments = 0); - - typedef detail::type_list<> reversed_args; - - char const* doc; -}; - -/////////////////////////////////////////////////////////////////////////////// -// -// optional -// -// optional::type returns a typelist. -// -/////////////////////////////////////////////////////////////////////////////// -template -struct optional - : detail::type_list -{ -}; - -namespace detail -{ - template - void def_init_reversed(ClassT& cl, ReversedArgs const&, CallPoliciesT const& policies, char const* doc) - { - typedef typename mpl::fold< - ReversedArgs - , mpl::list0<> - , mpl::push_front - >::type args; - - cl.def_init(args(), policies, doc); - } - - /////////////////////////////////////////////////////////////////////////////// - // - // define_class_init_helper::apply - // - // General case - // - // Accepts a class_ and an arguments list. Defines a constructor - // for the class given the arguments and recursively calls - // define_class_init_helper::apply with one less arguments (the - // rightmost argument is shaved off) - // - /////////////////////////////////////////////////////////////////////////////// - template - struct define_class_init_helper { - - template - static void apply(ClassT& cl, CallPoliciesT const& policies, ReversedArgs const& args, char const* doc) - { - def_init_reversed(cl, args, policies, doc); - - typename mpl::pop_front::type next; - define_class_init_helper::apply(cl, policies, next, doc); - } - }; - - /////////////////////////////////////////////////////////////////////////////// - // - // define_class_init_helper<0>::apply - // - // Terminal case - // - // Accepts a class_ and an arguments list. Defines a constructor - // for the class given the arguments. - // - /////////////////////////////////////////////////////////////////////////////// - template <> - struct define_class_init_helper<0> { - - template - static void apply(ClassT& cl, CallPoliciesT const& policies, ReversedArgs const& args, char const* doc) - { - def_init_reversed(cl, args, policies, doc); - } - }; -} - -/////////////////////////////////////////////////////////////////////////////// -// -// define_init -// -// Accepts a class_ and an init-list. Defines a set of constructors for -// the class given the arguments. The init list (see init above) has -// n_defaults (number of default arguments and n_arguments (number of -// actual arguments). This function defines n_defaults + 1 constructors -// for the class. Each constructor after the first has one less argument -// to its right. Example: -// -// init -// -// Defines: -// -// __init__(int, char, long, double) -// __init__(int, char, long) -// __init__(int, char) -// __init__(int) -// -/////////////////////////////////////////////////////////////////////////////// -template -void -define_init(ClassT& cl, InitT const& i) -{ - typedef typename InitT::reversed_args reversed_args; - detail::define_class_init_helper::apply( - cl, i.call_policies(), reversed_args(), i.doc_string()); -} - -}} // namespace boost::python - -#undef BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT -#undef BOOST_PYTHON_TEMPLATE_TYPES -#undef BOOST_PYTHON_TEMPLATE_ARGS -#undef BOOST_PYTHON_IS_OPTIONAL_VALUE -#undef BOOST_PYTHON_APPEND_TO_INIT - -/////////////////////////////////////////////////////////////////////////////// -#endif // INIT_JDG20020820_HPP - - - - - - - - diff --git a/include/boost/python/instance_holder.hpp b/include/boost/python/instance_holder.hpp deleted file mode 100755 index 28aa02e8..00000000 --- a/include/boost/python/instance_holder.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef INSTANCE_HOLDER_DWA2002517_HPP -# define INSTANCE_HOLDER_DWA2002517_HPP - -# include -# include -# include -# include - -namespace boost { namespace python { - -// Base class for all holders -struct BOOST_PYTHON_DECL instance_holder : private noncopyable -{ - public: - instance_holder(); - virtual ~instance_holder(); - - // return the next holder in a chain - instance_holder* next() const; - - virtual void* holds(type_info) = 0; - - void install(PyObject* inst) throw(); - - // These functions should probably be located elsewhere. - - // Allocate storage for an object of the given size at the given - // offset in the Python instance<> object if bytes are available - // there. Otherwise allocate size bytes of heap memory. - static void* allocate(PyObject*, std::size_t offset, std::size_t size); - - // Deallocate storage from the heap if it was not carved out of - // the given Python object by allocate(), above. - static void deallocate(PyObject*, void* storage) throw(); - private: - instance_holder* m_next; -}; - -// This macro is needed for implementation of derived holders -# define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward::type)(a##N) - -// -// implementation -// -inline instance_holder* instance_holder::next() const -{ - return m_next; -} - -}} // namespace boost::python - -#endif // INSTANCE_HOLDER_DWA2002517_HPP diff --git a/include/boost/python/iterator.hpp b/include/boost/python/iterator.hpp deleted file mode 100644 index 3f477034..00000000 --- a/include/boost/python/iterator.hpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ITERATOR_DWA2002512_HPP -# define ITERATOR_DWA2002512_HPP - -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - // Adds an additional layer of binding to - // objects::make_iterator(...), which allows us to pass member - // function and member data pointers. - template - inline object make_iterator( - Accessor1 get_start, Accessor2 get_finish, boost::type* target = 0, NextPolicies* = 0) - { - return objects::make_iterator_function( - boost::protect(boost::bind(get_start, _1)) - , boost::protect(boost::bind(get_finish, _1)) - ); - } - - // Guts of template class iterators<>, below. - template - struct iterators_impl - { - template - struct apply - { - typedef typename T::iterator iterator; - static iterator begin(T& x) { return x.begin(); } - static iterator end(T& x) { return x.end(); } - }; - }; - - template <> - struct iterators_impl - { - template - struct apply - { - typedef typename T::const_iterator iterator; - static iterator begin(T& x) { return x.begin(); } - static iterator end(T& x) { return x.end(); } - }; - }; -} - -// An "ordinary function generator" which contains static begin(x) and -// end(x) functions that invoke T::begin() and T::end(), respectively. -template -struct iterators - : detail::iterators_impl< - boost::is_const::value - >::template apply -{ -}; - -// Create an iterator-building function which uses the given -// accessors. Deduce the Target type from the accessors. The iterator -// returns copies of the inderlying elements. -template -object range(Accessor1 start, Accessor2 finish) -{ - return detail::make_iterator( - start, finish - , detail::target(start)); -} - -// Create an iterator-building function which uses the given accessors -// and next() policies. Deduce the Target type. -template -object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0) -{ - return detail::make_iterator(start, finish, detail::target(start)); -} - -// Create an iterator-building function which uses the given accessors -// and next() policies, operating on the given Target type -template -object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type* = 0) -{ - typedef typename add_reference::type target; - return detail::make_iterator(start, finish); -} - -// A Python callable object which produces an iterator traversing -// [x.begin(), x.end()), where x is an instance of the Container -// type. NextPolicies are used as the CallPolicies for the iterator's -// next() function. -template -struct iterator : object -{ - iterator() - : object( - python::range( - &iterators::begin, &iterators::end - )) - { - } -}; - -}} // namespace boost::python - -#endif // ITERATOR_DWA2002512_HPP diff --git a/include/boost/python/list.hpp b/include/boost/python/list.hpp deleted file mode 100644 index 501eeed5..00000000 --- a/include/boost/python/list.hpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef LIST_DWA2002627_HPP -# define LIST_DWA2002627_HPP - -# include -# include - -namespace boost { namespace python { - -class list : public object -{ - public: - BOOST_PYTHON_DECL list(); // new list - explicit BOOST_PYTHON_DECL list(object_cref sequence); // new list initialized from sequence's items - - template - explicit list(T const& sequence) - : object(list::call(object(sequence))) - { - } - - BOOST_PYTHON_DECL void append(object_cref); // append object to end - - template - void append(T const& x) - { - this->append(object(x)); - } - - BOOST_PYTHON_DECL long count(object_cref value) const; // return number of occurrences of value - - template - long count(T const& value) const - { - return this->count(object(value)); - } - - BOOST_PYTHON_DECL void extend(object_cref sequence); // extend list by appending sequence elements - - template - void extend(T const& x) - { - this->extend(object(x)); - } - - BOOST_PYTHON_DECL long index(object_cref value) const; // return index of first occurrence of value - - template - long index(T const& x) const - { - return this->index(object(x)); - } - - BOOST_PYTHON_DECL void insert(int index, object_cref); // insert object before index - BOOST_PYTHON_DECL void insert(object const& index, object_cref); - - template - void insert(int index, T const& x) // insert object before index - { - this->insert(index, object(x)); - } - - template - void insert(object const& index, T const& x) // insert object before index - { - this->insert(index, object(x)); - } - - BOOST_PYTHON_DECL object pop(); // remove and return item at index (default last) - BOOST_PYTHON_DECL object pop(long index); - BOOST_PYTHON_DECL object pop(object const& index); - - BOOST_PYTHON_DECL void remove(object_cref value); // remove first occurrence of value - - template - void remove(T const& value) - { - this->remove(object(value)); - } - - BOOST_PYTHON_DECL void reverse(); // reverse *IN PLACE* - - BOOST_PYTHON_DECL void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1 - BOOST_PYTHON_DECL void sort(object_cref cmpfunc); - - template - void sort(T const& value) - { - this->sort(object(value)); - } - - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list) - - private: - static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&); -}; - -// -// Converter Specializations -// -namespace converter -{ - template <> - struct object_manager_traits - : pytype_object_manager_traits<&PyList_Type,list> - { - }; -} - -}} // namespace boost::python - -#endif // LIST_DWA2002627_HPP diff --git a/include/boost/python/long.hpp b/include/boost/python/long.hpp deleted file mode 100644 index 3ba4f434..00000000 --- a/include/boost/python/long.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef LONG_DWA2002627_HPP -# define LONG_DWA2002627_HPP - -# include -# include - -namespace boost { namespace python { - -class long_ : public object -{ - public: - BOOST_PYTHON_DECL long_(); // new long_ - explicit BOOST_PYTHON_DECL long_(object_cref rhs); - - template - explicit long_(T const& rhs) - : object(long_::call(object(rhs))) - { - } - - explicit BOOST_PYTHON_DECL long_(object_cref rhs, object_cref base); - - template - explicit long_(T const& rhs, U const& base) - : object(long_::call(object(rhs), object(base))) - { - } - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_) - - private: - static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&); - static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&, object const&); -}; - -// -// Converter Specializations -// -namespace converter -{ - template <> - struct object_manager_traits - : pytype_object_manager_traits<&PyLong_Type,long_> - { - }; -} - -}} // namespace boost::python - -#endif // LONG_DWA2002627_HPP diff --git a/include/boost/python/lvalue_from_pytype.hpp b/include/boost/python/lvalue_from_pytype.hpp deleted file mode 100755 index ae01a6bd..00000000 --- a/include/boost/python/lvalue_from_pytype.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef LVALUE_FROM_PYTYPE_DWA2002130_HPP -# define LVALUE_FROM_PYTYPE_DWA2002130_HPP - -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - // Given a pointer-to-function of 1 parameter returning a reference - // type, return the type_id of the function's return type. - template - inline type_info extractor_type_id(T&(*)(U)) - { - return type_id(); - } - - // A function generator whose static execute() function is an lvalue - // from_python converter using the given Extractor. U is expected to - // be the actual type of the PyObject instance from which the result - // is being extracted. - template - struct normalized_extractor - { - static inline void* execute(PyObject* op) - { - typedef typename boost::add_reference::type param; - return &Extractor::execute( - boost::python::detail::void_ptr_to_reference( - op, (param(*)())0 ) - ); - } - }; - - // Given an Extractor type and a pointer to its execute function, - // return a new object whose static execute function does the same - // job but is a conforming lvalue from_python conversion function. - // - // usage: normalize(&Extractor::execute) - template - inline normalized_extractor - normalize(T(*)(U), Extractor* = 0) - { - return normalized_extractor(); - } -} - -// An Extractor which extracts the given member from a Python object -// whose instances are stored as InstanceType. -template -struct extract_member -{ - static MemberType& execute(InstanceType& c) - { - (void)c.ob_type; // static assertion - return c.*member; - } -}; - -// An Extractor which simply extracts the entire python object -// instance of InstanceType. -template -struct extract_identity -{ - static InstanceType& execute(InstanceType& c) - { - (void)c.ob_type; // static assertion - return c; - } -}; - -// Registers a from_python conversion which extracts lvalues using -// Extractor's static execute function from Python objects whose type -// object is python_type. -template -struct lvalue_from_pytype -{ - lvalue_from_pytype() - { - converter::registry::insert( - &extract, detail::extractor_type_id(&Extractor::execute)); - } - private: - static void* extract(PyObject* op) - { - return PyObject_TypeCheck(op, const_cast(python_type)) - ? const_cast( - static_cast( - detail::normalize(&Extractor::execute).execute(op))) - : 0 - ; - } -}; - -}} // namespace boost::python - -#endif // LVALUE_FROM_PYTYPE_DWA2002130_HPP diff --git a/include/boost/python/make_function.hpp b/include/boost/python/make_function.hpp deleted file mode 100644 index decdf5b4..00000000 --- a/include/boost/python/make_function.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MAKE_FUNCTION_DWA20011221_HPP -# define MAKE_FUNCTION_DWA20011221_HPP - -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -template -object make_function(F f) -{ - return objects::function_object( - ::boost::bind(detail::caller(), f, _1, _2, default_call_policies()) - , detail::arg_tuple_size::value); -} - -template -object make_function(F f, Policies const& policies) -{ - return objects::function_object( - ::boost::bind(detail::caller(), f, _1, _2, policies) - , detail::arg_tuple_size::value); -} - -template -object make_constructor(HolderGenerator* = 0, ArgList* = 0) -{ - enum { nargs = mpl::size::value }; - - return objects::function_object( - ::boost::bind( - detail::caller() - , objects::make_holder - ::template apply::execute - , _1, _2, default_call_policies()) - , nargs + 1); -} - -template -object make_constructor(Policies const& policies, HolderGenerator* = 0, ArgList* = 0) -{ - enum { nargs = mpl::size::value }; - - return objects::function_object( - ::boost::bind(detail::caller(), - objects::make_holder - ::template apply::execute - , _1, _2, policies) - , nargs + 1); -} - -}} // namespace boost::python - -#endif // MAKE_FUNCTION_DWA20011221_HPP diff --git a/include/boost/python/manage_new_object.hpp b/include/boost/python/manage_new_object.hpp deleted file mode 100644 index 0acbbec8..00000000 --- a/include/boost/python/manage_new_object.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MANAGE_NEW_OBJECT_DWA200222_HPP -# define MANAGE_NEW_OBJECT_DWA200222_HPP -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct manage_new_object_requires_a_pointer_return_type -# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) - {} -# endif - ; -} - -struct manage_new_object -{ - template - struct apply - { - typedef typename mpl::if_c< - boost::is_pointer::value - , to_python_indirect - , detail::manage_new_object_requires_a_pointer_return_type - >::type type; - }; -}; - -}} // namespace boost::python - -#endif // MANAGE_NEW_OBJECT_DWA200222_HPP diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp deleted file mode 100644 index 9f5f4d21..00000000 --- a/include/boost/python/module.hpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MODULE_DWA2001128_HPP -# define MODULE_DWA2001128_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -class module : public detail::module_base -{ - public: - typedef detail::module_base base; - - module(char const* name, char const* doc = 0) - : base(name, doc) {} - - // Add elements to the module - template - module& setattr(const char* name, T const& x) - { - this->base::setattr_doc(name, python::object(x), 0); - return *this; - } - - module& add(type_handle x); // just use the type's name - - template - module& add(class_ const& c) - { - // Soon to disappear... - return *this; - } - - template - module& def(char const* name, Fn fn) - { - this->setattr_doc( - name, boost::python::make_function(fn), 0); - - return *this; - } - - template - module& def(char const* name, Arg1T arg1, Arg2T const& arg2, char const* doc = 0) - { - dispatch_def(name, arg1, arg2, doc, &arg2); - return *this; - } - - private: - - template - void - dispatch_def( - char const* name, - Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc, - void const*) - { - typedef detail::def_helper helper; - - this->setattr_doc( - name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)), - helper::get_doc(policy_or_doc, doc)); - } - - template - void - dispatch_def( - char const* name, - SigT sig, - StubsT const& stubs, - char const* doc, - detail::func_stubs_base const*) - { - // convert sig to a type_list (see detail::get_signature in signature.hpp) - // before calling detail::define_with_defaults. - detail::define_with_defaults( - name, stubs, *this, detail::get_signature(sig)); - } -}; - -// -// inline implementations -// -inline module& module::add(type_handle x) -{ - this->base::add(x); - return *this; -} - -}} // namespace boost::python - -#endif // MODULE_DWA20011221_HPP diff --git a/include/boost/python/module_builder.hpp b/include/boost/python/module_builder.hpp deleted file mode 100644 index 222b28d7..00000000 --- a/include/boost/python/module_builder.hpp +++ /dev/null @@ -1,76 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef MODULE_DWA051000_H_ -# define MODULE_DWA051000_H_ - -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -class BOOST_PYTHON_DECL module_builder_base -{ - public: - // Create a module. REQUIRES: only one module_builder is created per module. - module_builder_base(const char* name); - ~module_builder_base(); - - // Add elements to the module - void add(detail::function* x, const char* name); - void add(PyTypeObject* x, const char* name = 0); - void add(ref x, const char*name); - - // Return true iff a module is currently being built. - static bool initializing(); - - // Return the name of the module currently being built. - // REQUIRES: initializing() == true - static string name(); - - // Return a pointer to the Python module object being built - PyObject* module() const; - - private: - PyObject* m_module; - static PyMethodDef initial_methods[1]; -}; - -class module_builder : public module_builder_base -{ - public: - module_builder(const char* name) - : module_builder_base(name) {} - - template - void def_raw(Fn fn, const char* name) - { - add(detail::new_raw_arguments_function(fn), name); - } - - template - void def(Fn fn, const char* name) - { - add(detail::new_wrapped_function(fn), name); - } -}; - -// -// inline implementations -// -inline PyObject* module_builder_base::module() const -{ - return m_module; -} - -}} // namespace boost::python - -#endif diff --git a/include/boost/python/module_init.hpp b/include/boost/python/module_init.hpp deleted file mode 100644 index 1d65308a..00000000 --- a/include/boost/python/module_init.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MODULE_INIT_DWA20020722_HPP -# define MODULE_INIT_DWA20020722_HPP - -# include -# include - -# ifndef BOOST_PYTHON_MODULE_INIT - -namespace boost { namespace python { namespace detail { - -BOOST_PYTHON_DECL void init_module(char const* name, void(*)()); - -}}} - -# if defined(_WIN32) || defined(__CYGWIN__) - -# define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ -extern "C" __declspec(dllexport) void init##name() \ -{ \ - boost::python::detail::init_module( \ - #name,&init_module_##name); \ -} \ -void init_module_##name() - -# elif defined(_AIX) - -# include -# define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ -extern "C" \ -{ \ - extern PyObject* _PyImport_LoadDynamicModule(char*, char*, FILE *); \ - void init##name() \ - { \ - boost::python::detail::aix_init_module( \ - _PyImport_LoadDynamicModule, #name, &init_module_##name); \ - } \ -} \ -void init_module_##name() - -# else - -# define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ -extern "C" void init##name() \ -{ \ - boost::python::detail::init_module(#name, &init_module_##name); \ -} \ -void init_module_##name() - -# endif - -# endif - -#endif // MODULE_INIT_DWA20020722_HPP diff --git a/include/boost/python/object.hpp b/include/boost/python/object.hpp deleted file mode 100755 index dbdb7c0a..00000000 --- a/include/boost/python/object.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_DWA2002612_HPP -# define OBJECT_DWA2002612_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - - class type_; // XXX temporary work-around - class string; - -}} // namespace boost::python - -#endif // OBJECT_DWA2002612_HPP diff --git a/include/boost/python/object/add_to_namespace.hpp b/include/boost/python/object/add_to_namespace.hpp deleted file mode 100644 index 6a862b3d..00000000 --- a/include/boost/python/object/add_to_namespace.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ADD_TO_NAMESPACE_DWA200286_HPP -# define ADD_TO_NAMESPACE_DWA200286_HPP - -# include - -namespace boost { namespace python { namespace objects { - -// -// A setattr that's "smart" about function overloading (and docstrings). -// -BOOST_PYTHON_DECL void add_to_namespace( - object const& name_space, char const* name, object const& attribute); - -BOOST_PYTHON_DECL void add_to_namespace( - object const& name_space, char const* name, object const& attribute, char const* doc); - -}}} // namespace boost::python::objects - -#endif // ADD_TO_NAMESPACE_DWA200286_HPP diff --git a/include/boost/python/object/auto_ptr_generator.hpp b/include/boost/python/object/auto_ptr_generator.hpp deleted file mode 100644 index 9c13e436..00000000 --- a/include/boost/python/object/auto_ptr_generator.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef AUTO_PTR_GENERATOR_DWA2002123_HPP -# define AUTO_PTR_GENERATOR_DWA2002123_HPP -# include - -namespace boost { namespace python { namespace object { - -struct auto_ptr_generator -{ - template - struct apply - { - typedef std::auto_ptr type; - }; -}; - -}}} // namespace boost::python::object - -#endif // AUTO_PTR_GENERATOR_DWA2002123_HPP diff --git a/include/boost/python/object/class.hpp b/include/boost/python/object/class.hpp deleted file mode 100644 index e97f8edd..00000000 --- a/include/boost/python/object/class.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CLASS_DWA20011214_HPP -# define CLASS_DWA20011214_HPP - -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace objects { - -struct BOOST_PYTHON_DECL class_base : python::api::object -{ - // constructor - class_base( - char const* name // The name of the class - - , std::size_t num_types // A list of class_ids. The first is the type - , type_info const*const types // this is wrapping. The rest are the types of - // any bases. - - , char const* doc = 0 // Docstring, if any. - ); - - // Retrieve the underlying object - void add_property(char const* name, object const& fget); - void add_property(char const* name, object const& fget, object const& fset); - void setattr(char const* name, object const&); - void enable_pickling(bool getstate_manages_dict); - - // Set a special attribute in the class which tells Boost.Python - // to allocate extra bytes for embedded C++ objects in Python - // instances. - void set_instance_size(std::size_t bytes); - - // Set an __init__ function which throws an appropriate exception - // for abstract classes. - void def_no_init(); -}; - -}}} // namespace boost::python::objects - -#endif // CLASS_DWA20011214_HPP diff --git a/include/boost/python/object/class_converters.hpp b/include/boost/python/object/class_converters.hpp deleted file mode 100644 index 79119ef7..00000000 --- a/include/boost/python/object/class_converters.hpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CLASS_CONVERTERS_DWA2002119_HPP -# define CLASS_CONVERTERS_DWA2002119_HPP - -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -////////////////////////////////////////////////////////////////////// -// -// register_base_of - -// A BinaryMetaFunction object which registers a single base -// class of T, and the corresponding cast(s) -// - - -// register_downcast/do_nothing - -// Helpers for register_base_of<> which take care of registering -// down-casts -template -struct register_downcast -{ - static void execute() - { - register_conversion(true); - } -}; - -struct do_nothing -{ - static void execute() { } -}; - -// Here's where the real work gets done: -template -struct register_base_of -{ - // Here's the runtime part: - template - void operator()(Base*) const - { - // Register the Base class - register_dynamic_id(); - // Register the up-cast - register_conversion(false); - - // Register the down-cast, if appropriate. - mpl::if_c< - is_polymorphic::value - , register_downcast - , do_nothing - >::type::execute(); - } -}; - -// Brings into existence all converters associated with a class Bases -// is expected to be an mpl sequence of base types. -template -inline void register_class_from_python(Derived* = 0, Bases* = 0) -{ - // cause the static registration to be instantiated. - python::detail::force_instantiate(instance_finder::registration); - - // register all up/downcasts here - register_dynamic_id(); - - // register each base in the sequence - mpl::for_each(register_base_of(), (Bases*)0, (add_pointer*)0); -} - -}}} // namespace boost::python::object - -#endif // CLASS_CONVERTERS_DWA2002119_HPP diff --git a/include/boost/python/object/class_detail.hpp b/include/boost/python/object/class_detail.hpp deleted file mode 100644 index f4d4d51e..00000000 --- a/include/boost/python/object/class_detail.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CLASS_DETAIL_DWA200295_HPP -# define CLASS_DETAIL_DWA200295_HPP - -# include -# include - -namespace boost { namespace python { namespace objects { - -BOOST_PYTHON_DECL type_handle registered_class_object(type_info id); -BOOST_PYTHON_DECL type_handle class_metatype(); -BOOST_PYTHON_DECL type_handle class_type(); - -}}} // namespace boost::python::object - -#endif // CLASS_DETAIL_DWA200295_HPP diff --git a/include/boost/python/object/class_object.hpp b/include/boost/python/object/class_object.hpp deleted file mode 100644 index 76960762..00000000 --- a/include/boost/python/object/class_object.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CLASS_OBJECT_DWA200222_HPP -# define CLASS_OBJECT_DWA200222_HPP - -# include -# include - -namespace boost { namespace python { namespace objects { - -template -struct class_object -{ - static PyTypeObject*& reference; -}; - -template -PyTypeObject*& class_object::reference = converter::registry::class_object( - converter::undecorated_type_id()); - -}}} // namespace boost::python::objects - -#endif // CLASS_OBJECT_DWA200222_HPP diff --git a/include/boost/python/object/class_wrapper.hpp b/include/boost/python/object/class_wrapper.hpp deleted file mode 100644 index 61364d9d..00000000 --- a/include/boost/python/object/class_wrapper.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CLASS_WRAPPER_DWA20011221_HPP -# define CLASS_WRAPPER_DWA20011221_HPP - -# include -# include - -namespace boost { namespace python { namespace objects { - -// Used to convert objects of type Src to wrapped C++ classes by -// building a new instance object and installing a Holder constructed -// from the Src object. -template -struct class_wrapper - : to_python_converter > -{ - static PyObject* convert(Src const& x) - { - return MakeInstance::execute(cref(x)); - } -}; - -}}} // namespace boost::python::objects - -#endif // CLASS_WRAPPER_DWA20011221_HPP diff --git a/include/boost/python/object/construct.hpp b/include/boost/python/object/construct.hpp deleted file mode 100644 index 1eb73e4a..00000000 --- a/include/boost/python/object/construct.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef CONSTRUCT_DWA20011215_HPP -# define CONSTRUCT_DWA20011215_HPP - -namespace boost { namespace python { namespace objects { - -template -struct construct -{ - static - template -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -struct BOOST_PYTHON_DECL enum_base : python::api::object -{ - protected: - enum_base( - char const* name - , converter::to_python_function_t - , converter::convertible_function - , converter::constructor_function - , type_info); - - void add_value(char const* name, long value); - - static PyObject* to_python(PyTypeObject* type, long x); -}; - -}}} // namespace boost::python::object - -#endif // ENUM_BASE_DWA200298_HPP diff --git a/include/boost/python/object/find_instance.hpp b/include/boost/python/object/find_instance.hpp deleted file mode 100644 index 44c79550..00000000 --- a/include/boost/python/object/find_instance.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FIND_INSTANCE_DWA2002312_HPP -# define FIND_INSTANCE_DWA2002312_HPP - -# include -# include - -namespace boost { namespace python { namespace objects { - -// Given a type_id, find the instance data which corresponds to it, or -// return 0 in case no such type is held. -BOOST_PYTHON_DECL void* find_instance_impl(PyObject*, type_info); - -// This produces a function with the right signature for use in from_python conversions -template -struct instance_finder -{ - instance_finder() - { - converter::registry::insert(&execute, python::type_id()); - } - - static instance_finder const registration; - private: - static inline void* execute(PyObject* p) - { - return find_instance_impl(p, python::type_id()); - } -}; - -template -instance_finder const instance_finder::registration; - -}}} // namespace boost::python::objects - -#endif // FIND_INSTANCE_DWA2002312_HPP diff --git a/include/boost/python/object/forward.hpp b/include/boost/python/object/forward.hpp deleted file mode 100644 index 93c1ed21..00000000 --- a/include/boost/python/object/forward.hpp +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FORWARD_DWA20011215_HPP -# define FORWARD_DWA20011215_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -template -struct reference_to_value -{ - typedef typename add_reference::type>::type reference; - - reference_to_value(reference x) : m_value(x) {} - operator reference() const { return m_value; } - private: - reference m_value; -}; - -// A little metaprogram which selects the type to pass through an -// intermediate forwarding function when the destination argument type -// is T. -template -struct forward - : mpl::if_c< - is_scalar::value - , T - , reference_to_value > -{ -}; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -class unforward -{ - public: - typedef typename unwrap_reference::type& type; -}; - -template -class unforward > -{ - public: - typedef T type; -}; -# else // no partial specialization - -namespace detail -{ - typedef char (&yes_reference_to_value_t)[1]; - typedef char (&no_reference_to_value_t)[2]; - - no_reference_to_value_t is_reference_to_value_test(...); - - template - yes_reference_to_value_t is_reference_to_value_test(boost::type< reference_to_value >); - - template - struct unforwarder - { - template - struct apply - { - typedef typename unwrap_reference::type& type; - }; - }; - - template<> - struct unforwarder - { - template - struct apply - { - typedef typename T::reference type; - }; - }; - - template - class is_reference_to_value - { - public: - BOOST_STATIC_CONSTANT( - bool, value = ( - sizeof(is_reference_to_value_test(boost::type())) - == sizeof(yes_reference_to_value_t))); - }; -} - -template -class unforward - : public detail::unforwarder< - detail::is_reference_to_value::value - >::template apply -{}; - -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -}}} // namespace boost::python::objects - -#endif // FORWARD_DWA20011215_HPP diff --git a/include/boost/python/object/function.hpp b/include/boost/python/object/function.hpp deleted file mode 100644 index c14f57e3..00000000 --- a/include/boost/python/object/function.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FUNCTION_DWA20011214_HPP -# define FUNCTION_DWA20011214_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -struct BOOST_PYTHON_DECL function : PyObject -{ - function(py_function const&, unsigned min_args, unsigned max_args = 0); - ~function(); - - PyObject* call(PyObject*, PyObject*) const; - - // Add an attribute to the name_space with the given name. If it is - // a function object (this class), and an existing function is - // already there, add it as an overload. - static void add_to_namespace( - object const& name_space, char const* name, object const& attribute); - - static void add_to_namespace( - object const& name_space, char const* name, object const& attribute, char const* doc); - - object const& doc() const; - void doc(object const& x); - - object const& name() const; - - private: // helper functions - void argument_error(PyObject* args, PyObject* keywords) const; - void add_overload(handle const&); - - private: // data members - py_function m_fn; - unsigned m_min_args; - unsigned m_max_args; - handle m_overloads; - object m_name; - object m_doc; -}; - -// -// implementations -// -inline object const& function::doc() const -{ - return this->m_doc; -} - -inline void function::doc(object const& x) -{ - this->m_doc = x; -} - -inline object const& function::name() const -{ - return this->m_name; -} - -}}} // namespace boost::python::objects - -#endif // FUNCTION_DWA20011214_HPP diff --git a/include/boost/python/object/function_handle.hpp b/include/boost/python/object/function_handle.hpp deleted file mode 100644 index f29c2e35..00000000 --- a/include/boost/python/object/function_handle.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FUNCTION_HANDLE_DWA2002725_HPP -# define FUNCTION_HANDLE_DWA2002725_HPP -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -BOOST_PYTHON_DECL handle<> function_handle_impl(py_function const& f, unsigned min_args, unsigned max_args = 0); - -// Just like function_object, but returns a handle<> instead. Using -// this for arg_to_python<> allows us to break a circular dependency -// between object and arg_to_python. -template -inline handle<> function_handle(F const& f, unsigned min_args, unsigned max_args = 0) -{ - return objects::function_handle_impl(objects::py_function(f), min_args, max_args); -} - -// Just like make_function, but returns a handle<> intead. Same -// reasoning as above. -template -handle<> make_function_handle(F f) -{ - return objects::function_handle( - ::boost::bind(python::detail::caller(), f, _1, _2, default_call_policies()) - , python::detail::arg_tuple_size::value); -} - -}}} // namespace boost::python::objects - -#endif // FUNCTION_HANDLE_DWA2002725_HPP diff --git a/include/boost/python/object/function_object.hpp b/include/boost/python/object/function_object.hpp deleted file mode 100644 index 03535ec3..00000000 --- a/include/boost/python/object/function_object.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef FUNCTION_OBJECT_DWA2002725_HPP -# define FUNCTION_OBJECT_DWA2002725_HPP -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -BOOST_PYTHON_DECL api::object function_object_impl(boost::function2 const& f, unsigned min_args, unsigned max_args = 0); - -template -inline object function_object(F const& f, unsigned min_args, unsigned max_args = 0) -{ - return objects::function_object_impl(boost::function2(f), min_args, max_args); -} - -}}} // namespace boost::python::objects - -#endif // FUNCTION_OBJECT_DWA2002725_HPP diff --git a/include/boost/python/object/inheritance.hpp b/include/boost/python/object/inheritance.hpp deleted file mode 100644 index 88b556ff..00000000 --- a/include/boost/python/object/inheritance.hpp +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef INHERITANCE_DWA200216_HPP -# define INHERITANCE_DWA200216_HPP - -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -typedef type_info class_id; -using python::type_id; - -// Types used to get address and id of most derived type -typedef std::pair dynamic_id_t; -typedef dynamic_id_t (*dynamic_id_function)(void*); - -BOOST_PYTHON_DECL void register_dynamic_id_aux( - class_id static_id, dynamic_id_function get_dynamic_id); - -BOOST_PYTHON_DECL void add_cast( - class_id src_t, class_id dst_t, void* (*cast)(void*), bool polymorphic); - -BOOST_PYTHON_DECL void* find_static_type(void* p, class_id src, class_id dst); - -BOOST_PYTHON_DECL void* find_dynamic_type(void* p, class_id src, class_id dst); - -// is_polymorphic test from John Maddock -template -struct is_polymorphic -{ - struct d1 : public T - { - d1(); - char padding[256]; - }; - struct d2 : public T - { - d2(); - virtual ~d2(); - virtual void foo(); - char padding[256]; - }; - BOOST_STATIC_CONSTANT(bool, value = (sizeof(d2) == sizeof(d1))); -}; - -// -// a generator with an execute() function which, given a source type -// and a pointer to an object of that type, returns its most-derived -// /reachable/ type identifier and object pointer. -// - -// first, the case where T has virtual functions -template -struct polymorphic_id_generator -{ - static dynamic_id_t execute(void* p_) - { - T* p = static_cast(p_); - return std::make_pair(dynamic_cast(p), class_id(typeid(*p))); - } -}; - -// now, the non-polymorphic case. -template -struct non_polymorphic_id_generator -{ - static dynamic_id_t execute(void* p_) - { - return std::make_pair(p_, python::type_id()); - } -}; - -// Now the generalized selector -template -struct dynamic_id_generator -{ - typedef typename mpl::if_c< - is_polymorphic::value - , polymorphic_id_generator - , non_polymorphic_id_generator >::type type; -}; - -// Register the dynamic id function for T with the type-conversion -// system. -template -void register_dynamic_id(T* = 0) -{ - typedef typename dynamic_id_generator::type generator; - register_dynamic_id_aux( - python::type_id(), &generator::execute); -} - -// -// a generator with an execute() function which, given a void* -// pointing to an object of type Source will attempt to convert it to -// an object of type Target. -// - -template -struct dynamic_cast_generator -{ - static void* execute(void* source) - { - return dynamic_cast( - static_cast(source)); - } - -}; - -template -struct implicit_cast_generator -{ - static void* execute(void* source) - { - Target* result = static_cast(source); - return result; - } -}; - -template -struct cast_generator -{ - // CWPro7 will return false sometimes, but that's OK since we can - // always cast up with dynamic_cast<> - BOOST_STATIC_CONSTANT( - bool, is_upcast = ( - is_base_and_derived::value - )); - - typedef typename mpl::if_c< - is_upcast -# if defined(__MWERKS__) && __MWERKS__ <= 0x2406 - // grab a few more implicit_cast cases for CodeWarrior - || !is_polymorphic::value - || !is_polymorphic::value -# endif - , implicit_cast_generator - , dynamic_cast_generator - >::type type; -}; - -template -inline void register_conversion( - // We need this parameter because CWPro7 can't determine - // which is the base reliably. - bool is_downcast = !cast_generator::is_upcast - - // These parameters shouldn't be used, they're an MSVC bug workaround - , Source* = 0, Target* = 0) -{ - typedef typename cast_generator::type generator; - - add_cast(python::type_id() - , python::type_id() - , &generator::execute - , is_downcast); -} - -}}} // namespace boost::python::object - -#endif // INHERITANCE_DWA200216_HPP diff --git a/include/boost/python/object/instance.hpp b/include/boost/python/object/instance.hpp deleted file mode 100644 index 4cddcc99..00000000 --- a/include/boost/python/object/instance.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef INSTANCE_DWA200295_HPP -# define INSTANCE_DWA200295_HPP - -# include -# include -# include - -namespace boost { namespace python -{ - struct instance_holder; -}} // namespace boost::python - -namespace boost { namespace python { namespace objects { - -// Each extension instance will be one of these -template -struct instance -{ - PyObject_VAR_HEAD - PyObject* dict; - PyObject* weakrefs; - instance_holder* objects; - - BOOST_STATIC_CONSTANT(std::size_t, alignment = alignment_of::value); - typedef typename type_with_alignment::type align_t; - - union - { - align_t align; - char bytes[sizeof(Data)]; - } storage; -}; - -template -struct additional_instance_size -{ - typedef instance instance_data; - typedef instance instance_char; - BOOST_STATIC_CONSTANT( - std::size_t, value = sizeof(instance_data) - - BOOST_PYTHON_OFFSETOF(instance_char,storage)); -}; - -}}} // namespace boost::python::object - -#endif // INSTANCE_DWA200295_HPP diff --git a/include/boost/python/object/iterator.hpp b/include/boost/python/object/iterator.hpp deleted file mode 100644 index 74af64c9..00000000 --- a/include/boost/python/object/iterator.hpp +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ITERATOR_DWA2002510_HPP -# define ITERATOR_DWA2002510_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -// CallPolicies for the next() method of iterators. We don't want -// users to have to explicitly specify that the references returned by -// iterators are copied, so we just replace the result_converter from -// the default_iterator_call_policies with a permissive one which -// always copies the result. -struct default_iterator_call_policies - : default_call_policies -{ - struct result_converter - { - template - struct apply - { - typedef to_python_value type; - }; - }; -}; - -// Instantiations of these are wrapped to produce Python iterators. -template -struct iterator_range -{ - iterator_range(object sequence, Iterator start, Iterator finish); - - object m_sequence; // Keeps the sequence alive while iterating. - Iterator m_start; - Iterator m_finish; -}; - -namespace detail -{ - // Guts of the iterator's next() function. We can't just wrap an - // ordinary function because we don't neccessarily know the result - // type of dereferencing the iterator. This also saves us from - // throwing C++ exceptions to indicate end-of-sequence. - template - struct iterator_next - { - static PyObject* execute(PyObject* args_, PyObject* kw, Policies const& policies) - { - typedef iterator_range range_; - - PyObject* py_self = PyTuple_GET_ITEM(args_, 0); - arg_from_python c0(py_self); - range_* self = c0(py_self); - - // Done iterating? - if (self->m_start == self->m_finish) - { - objects::set_stop_iteration_error(); - return 0; - } - - // note: precall happens before we can check for the result - // converter in this case, to ensure it happens before the - // iterator is dereferenced. However, the arity is 1 so - // there's not much risk that this will amount to anything. - if (!policies.precall(args_)) return 0; - - PyObject* result = iterator_next::convert_result(*self->m_start); - ++self->m_start; - - return policies.postcall(args_, result); - } - private: - // Convert the result of dereferencing the iterator. Dispatched - // here because we can't neccessarily get the value_type of the - // iterator without PTS. This way, we deduce the value type by - // dereferencing. - template - static PyObject* convert_result(ValueType& x) - { - typedef typename Policies::result_converter result_converter; - typename mpl::apply1::type cr; - if (!cr.convertible()) return 0; - - return cr(x); - } - template - static PyObject* convert_result(ValueType const& x) - { - typedef typename Policies::result_converter result_converter; - typename mpl::apply1::type cr; - if (!cr.convertible()) return 0; - - return cr(x); - } - }; - - // Get a Python class which contains the given iterator and - // policies, creating it if neccessary. Requires: NextPolicies is - // default-constructible. - template - object demand_iterator_class(char const* name, Iterator* = 0, NextPolicies const& policies = NextPolicies()) - { - typedef iterator_range range_; - - // Check the registry. If one is already registered, return it. - handle<> class_obj( - objects::registered_class_object(python::type_id())); - - if (class_obj.get() != 0) - return object(class_obj); - - // Make a callable object which can be used as the iterator's next() function. - object next_function = - objects::function_object( - bind(&detail::iterator_next::execute, _1, _2, policies) - , 1); - - return class_(name, no_init) - .def("__iter__", identity_function()) - .setattr("next", next_function) - ; - } - - // This class template acts as a generator for an ordinary function - // which builds a Python iterator. - template - struct make_iterator_help - { - // Extract an object x of the Target type from the first Python - // argument, and invoke get_start(x)/get_finish(x) to produce - // iterators, which are used to construct a new iterator_range<> - // object that gets wrapped into a Python iterator. - static PyObject* create( - Accessor1 const& get_start, Accessor2 const& get_finish - , PyObject* args_, PyObject* /*kw*/) - { - // Make sure the Python class is instantiated. - demand_iterator_class("iterator"); - - to_python_value > cr; - - // This check is probably redundant, since we ensure the - // type is registered above. - if (!cr.convertible()) - return 0; - - // Extract x from the first argument - PyObject* arg0 = PyTuple_GET_ITEM(args_, 0); - arg_from_python c0(arg0); - if (!c0.convertible()) return 0; - typename arg_from_python::result_type x = c0(arg0); - - // Build and convert the iterator_range<>. - return cr( - iterator_range( - object((python::detail::borrowed_reference)arg0) - , get_start(x), get_finish(x))); - } - }; -} - -// Create a Python callable object which accepts a single argument -// convertible to the C++ Target type and returns a Python -// iterator. The Python iterator uses get_start(x) and get_finish(x) -// (where x is an instance of Target) to produce begin and end -// iterators for the range, and an instance of NextPolicies is used as -// CallPolicies for the Python iterator's next() function. -template -inline object make_iterator_function( - Accessor1 const& get_start, Accessor2 const& get_finish - , boost::type* = 0, NextPolicies* = 0) -{ - typedef typename Accessor1::result_type result_type; - - return - objects::function_object( - boost::bind( - &detail::make_iterator_help< - Target,result_type,Accessor1,Accessor2,NextPolicies - >::create - , get_start, get_finish, _1, _2) - , 1 ); -} - -// -// implementation -// -template -inline iterator_range::iterator_range( - object sequence, Iterator start, Iterator finish) - : m_sequence(sequence), m_start(start), m_finish(finish) -{ -} - -}}} // namespace boost::python::objects - -#endif // ITERATOR_DWA2002510_HPP diff --git a/include/boost/python/object/iterator_core.hpp b/include/boost/python/object/iterator_core.hpp deleted file mode 100644 index 655fc71e..00000000 --- a/include/boost/python/object/iterator_core.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef ITERATOR_CORE_DWA2002512_HPP -# define ITERATOR_CORE_DWA2002512_HPP - -# include -# include - -namespace boost { namespace python { namespace objects { - -BOOST_PYTHON_DECL object const& identity_function(); -BOOST_PYTHON_DECL void set_stop_iteration_error(); - -}}} // namespace boost::python::object - -#endif // ITERATOR_CORE_DWA2002512_HPP diff --git a/include/boost/python/object/life_support.hpp b/include/boost/python/object/life_support.hpp deleted file mode 100644 index 5d9587db..00000000 --- a/include/boost/python/object/life_support.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef LIFE_SUPPORT_DWA200222_HPP -# define LIFE_SUPPORT_DWA200222_HPP -# include -# include - -namespace boost { namespace python { namespace objects { - -BOOST_PYTHON_DECL PyObject* make_nurse_and_patient(PyObject* nurse, PyObject* patient); - -}}} // namespace boost::python::object - -#endif // LIFE_SUPPORT_DWA200222_HPP diff --git a/include/boost/python/object/make_holder.hpp b/include/boost/python/object/make_holder.hpp deleted file mode 100644 index 2a9e4e58..00000000 --- a/include/boost/python/object/make_holder.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# ifndef MAKE_HOLDER_DWA20011215_HPP -# define MAKE_HOLDER_DWA20011215_HPP - -# include - -# include -# include -# include - -# include -# include -# include - -# include -# include -# include -# include - -# include - -namespace boost { namespace python { namespace objects { - -template struct make_holder; - -# define BOOST_PYTHON_FORWARD_ARG(z, index, _) \ - typedef typename iter##index::type t##index; \ - typedef typename forward::type f##index; \ - typedef typename mpl::next::type \ - BOOST_PP_CAT(iter,BOOST_PP_INC(index)); - -# define BOOST_PYTHON_DO_FORWARD_ARG(z, index, _) , f##index(a##index) - -// specializations... -# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -# undef BOOST_PYTHON_FORWARD_ARG -# undef BOOST_PYTHON_DO_FORWARD_ARG - -}}} // namespace boost::python::objects - -# endif // MAKE_HOLDER_DWA20011215_HPP - -#elif BOOST_PP_ITERATION_DEPTH() == 1 -# line BOOST_PP_LINE(__LINE__, make_holder.hpp) - -# define N BOOST_PP_ITERATION() - -template <> -struct make_holder -{ - template - struct apply - { - typedef typename mpl::begin::type iter0; - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FORWARD_ARG, nil) - static void execute( - PyObject* p - BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, t, a)) - { - typedef instance instance_t; - - void* memory = Holder::allocate(p, offsetof(instance_t, storage), sizeof(Holder)); - try { - (new (memory) Holder( - p BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_DO_FORWARD_ARG, nil)))->install(p); - } - catch(...) { - Holder::deallocate(p, memory); - throw; - } - } - }; -}; - -# undef N - -#endif diff --git a/include/boost/python/object/make_instance.hpp b/include/boost/python/object/make_instance.hpp deleted file mode 100644 index d5e153b9..00000000 --- a/include/boost/python/object/make_instance.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef MAKE_INSTANCE_DWA200296_HPP -# define MAKE_INSTANCE_DWA200296_HPP - -# include -# include - -namespace boost { namespace python { namespace objects { - -template -struct make_instance -{ - typedef objects::instance instance_t; - - template - static PyObject* execute(Arg& x) - { - BOOST_STATIC_ASSERT(is_class::value); - PyTypeObject* type = converter::registered::converters.class_object; - - PyObject* raw_result = type->tp_alloc( - type, objects::additional_instance_size::value); - - if (raw_result != 0) - { - instance_t* result = (instance_t*)raw_result; - try - { - // construct the new C++ object and install the pointer - // in the Python object. - construct(result, x)->install(raw_result); - } - catch(...) - { - Py_DECREF(raw_result); // reclaim the Python object - throw; - } - - // Note the position of the internally-stored Holder, - // for the sake of destruction - result->ob_size = offsetof(instance_t, storage); - } - return raw_result; - } - - private: - // Kind of a hack to support code re-use. The first form is used - // to construct holders around pointers or smart pointers. The - // second form is used to construct holders around by-value - // returns. We have to pass a pointer to the owning Python object - // to the second form in order to make it forward the 2nd argument - // on to the constructor of its embedded T object. - template - static Holder* construct(instance_t* result, Arg& x) - { - return new ((void*)&result->storage) Holder(x); - } - - static Holder* construct(instance_t* result, reference_wrapper x) - { - return new ((void*)&result->storage) Holder((PyObject*)result, x); - } -}; - - -}}} // namespace boost::python::object - -#endif // MAKE_INSTANCE_DWA200296_HPP diff --git a/include/boost/python/object/pickle_support.hpp b/include/boost/python/object/pickle_support.hpp deleted file mode 100644 index a5a67cc2..00000000 --- a/include/boost/python/object/pickle_support.hpp +++ /dev/null @@ -1,123 +0,0 @@ -// (C) Copyright R.W. Grosse-Kunstleve 2002. -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. This -// software is provided "as is" without express or implied warranty, and -// with no claim as to its suitability for any purpose. -#ifndef BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP -#define BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP - -namespace boost { namespace python { - -namespace api -{ - class object; -} -using api::object; -class tuple; - -BOOST_PYTHON_DECL object const& make_instance_reduce_function(); - -struct pickle_suite; - -namespace error_messages { - - template - struct missing_pickle_suite_function_or_incorrect_signature {}; - - inline void must_be_derived_from_pickle_suite(pickle_suite const&) {} -} - -namespace detail { struct pickle_suite_registration; } - -struct pickle_suite -{ - private: - struct inaccessible {}; - friend struct detail::pickle_suite_registration; - public: - static inaccessible* getinitargs() { return 0; } - static inaccessible* getstate() { return 0; } - static inaccessible* setstate() { return 0; } - static bool getstate_manages_dict() { return false; } -}; - -namespace detail { - - struct pickle_suite_registration - { - typedef pickle_suite::inaccessible inaccessible; - - template - static - void - register_( - Class_& cl, - tuple (*getinitargs_fn)(Tgetinitargs), - inaccessible* (*getstate_fn)(), - inaccessible* (*setstate_fn)(), - bool) - { - cl.enable_pickling(false); - cl.def("__getinitargs__", getinitargs_fn); - } - - template - static - void - register_( - Class_& cl, - inaccessible* (*getinitargs_fn)(), - Rgetstate (*getstate_fn)(Tgetstate), - void (*setstate_fn)(Tsetstate, Ttuple), - bool getstate_manages_dict) - { - cl.enable_pickling(getstate_manages_dict); - cl.def("__getstate__", getstate_fn); - cl.def("__setstate__", setstate_fn); - } - - template - static - void - register_( - Class_& cl, - tuple (*getinitargs_fn)(Tgetinitargs), - Rgetstate (*getstate_fn)(Tgetstate), - void (*setstate_fn)(Tsetstate, Ttuple), - bool getstate_manages_dict) - { - cl.enable_pickling(getstate_manages_dict); - cl.def("__getinitargs__", getinitargs_fn); - cl.def("__getstate__", getstate_fn); - cl.def("__setstate__", setstate_fn); - } - - template - static - void - register_( - Class_&, - ...) - { - typedef typename - error_messages::missing_pickle_suite_function_or_incorrect_signature< - Class_>::error_type error_type; - } - }; - - template - struct pickle_suite_finalize - : PickleSuiteType, - pickle_suite_registration - {}; - -} // namespace detail - -}} // namespace boost::python - -#endif // BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP diff --git a/include/boost/python/object/pointer_holder.hpp b/include/boost/python/object/pointer_holder.hpp deleted file mode 100644 index 0dca4ae3..00000000 --- a/include/boost/python/object/pointer_holder.hpp +++ /dev/null @@ -1,158 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# ifndef POINTER_HOLDER_DWA20011215_HPP -# define POINTER_HOLDER_DWA20011215_HPP - -# include - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -# include -# include - -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -# define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) (typename unforward::type)(a##n) - -template -struct pointer_holder : instance_holder -{ - typedef Value value_type; - - pointer_holder(Pointer); - - // Forward construction to the held object - -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 1)) -# include BOOST_PP_ITERATE() - - private: // types - - private: // required holder implementation - void* holds(type_info); - - private: // data members - Pointer m_p; -}; - -template -struct pointer_holder_back_reference : instance_holder -{ - private: - typedef typename python::pointee::type held_type; - public: - typedef Value value_type; - - // Not sure about this one -- can it work? The source object - // undoubtedly does not carry the correct back reference pointer. - pointer_holder_back_reference(Pointer); - - // Forward construction to the held object -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 2)) -# include BOOST_PP_ITERATE() - - private: // required holder implementation - void* holds(type_info); - - private: // data members - Pointer m_p; -}; - -# undef BOOST_PYTHON_UNFORWARD_LOCAL - -template -inline pointer_holder::pointer_holder(Pointer p) - : m_p(p) -{ -} - -template -inline pointer_holder_back_reference::pointer_holder_back_reference(Pointer p) - : m_p(p) -{ -} - -template -void* pointer_holder::holds(type_info dst_t) -{ - if (dst_t == python::type_id()) - return &this->m_p; - - type_info src_t = python::type_id(); - return src_t == dst_t ? &*this->m_p - : find_dynamic_type(&*this->m_p, src_t, dst_t); -} - -template -void* pointer_holder_back_reference::holds(type_info dst_t) -{ - if (dst_t == python::type_id()) - return &this->m_p; - - if (dst_t == python::type_id()) - return &*this->m_p; - - type_info src_t = python::type_id(); - Value* p = &*this->m_p; - return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t); -} - -}}} // namespace boost::python::objects - -# endif // POINTER_HOLDER_DWA20011215_HPP - -/* --------------- pointer_holder --------------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1 -# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp) - -# define N BOOST_PP_ITERATION() - -# if (N != 0) - template< BOOST_PYTHON_UNARY_ENUM(N, class A) > -# endif - pointer_holder(PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) - : m_p(new Value( - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) - )) - {} - -# undef N - -/* --------------- pointer_holder_back_reference --------------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2 -# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference)) - -# define N BOOST_PP_ITERATION() - -# if (N != 0) - template < BOOST_PYTHON_UNARY_ENUM(N, class A) > -# endif - pointer_holder_back_reference( - PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) - : m_p(new held_type( - p BOOST_PP_COMMA_IF(N) BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) - )) - {} - -# undef N - -#endif diff --git a/include/boost/python/object/py_function.hpp b/include/boost/python/object/py_function.hpp deleted file mode 100644 index 0682d692..00000000 --- a/include/boost/python/object/py_function.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef PY_FUNCTION_DWA200286_HPP -# define PY_FUNCTION_DWA200286_HPP -# include - -namespace boost { namespace python { namespace objects { - -// This type is used as a "generalized Python callback", wrapping the -// function signature: -// -// PyObject* (PyObject* args, PyObject* keywords) -// -// We use boost::function to avoid generating lots of virtual tables -typedef boost::function2 py_function; - -}}} // namespace boost::python::objects - -#endif // PY_FUNCTION_DWA200286_HPP diff --git a/include/boost/python/object/select_holder.hpp b/include/boost/python/object/select_holder.hpp deleted file mode 100644 index 3535fd29..00000000 --- a/include/boost/python/object/select_holder.hpp +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef SELECT_HOLDER_DWA2002322_HPP -# define SELECT_HOLDER_DWA2002322_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -namespace detail -{ - template - struct select_value_holder - { - BOOST_STATIC_CONSTANT(bool, selector = (!is_same::value) | has_back_reference::value); - - typedef typename mpl::if_c< - selector - , value_holder_back_reference - , value_holder - >::type type; - - static inline void register_() - { - select_value_holder::register_(mpl::bool_c()); - } - - static type* get() { return 0; } - - private: - static inline void register_(mpl::bool_c) - { - python::detail::force_instantiate(instance_finder::registration); - } - - static inline void register_(mpl::bool_c) - { - } - }; - - template - struct select_pointer_holder - { - typedef typename python::pointee::type pointee; - BOOST_STATIC_CONSTANT(bool, selector = (!is_same::value) | has_back_reference::value); - - typedef typename mpl::if_c< - selector - , pointer_holder_back_reference - , pointer_holder - >::type type; - - static inline void register_() - { - select_pointer_holder::register_(mpl::bool_c()); - } - - static type* get() { return 0; } - - private: - static inline void register_(mpl::bool_c) - { - // not implemented at least until we solve the back - // reference issue mentioned in pointer_holder.hpp. - // - // python::detail::force_instantiate( - // class_wrapper >()); - - python::detail::force_instantiate(instance_finder::registration); - python::detail::force_instantiate(instance_finder::registration); - } - - struct construct_from_pointer - { - static type* execute(PyObject*, Ptr x) - { - return new type(x); - } - }; - - static inline void register_(mpl::bool_c) - { - python::detail::force_instantiate( - objects::class_wrapper< - Ptr - , type - , make_instance >()); - - python::detail::force_instantiate( - instance_finder::registration); - } - }; -} - -template -struct select_holder -{ - static inline std::size_t additional_size() - { - return additional_size_helper(execute((Held*)0)); - } - - static inline detail::select_value_holder - execute(python::detail::not_specified*) - { - return detail::select_value_holder(); - } - - static inline detail::select_value_holder - execute(T*) - { - return detail::select_value_holder(); - } - - static inline detail::select_pointer_holder - execute(void*) - { - return detail::select_pointer_holder(); - } - - private: - template - static inline std::size_t additional_size_helper(Selector const&) - { - typedef typename Selector::type holder; - return additional_instance_size::value; - } -}; - -}}} // namespace boost::python::objects - -#endif // SELECT_HOLDER_DWA2002322_HPP diff --git a/include/boost/python/object/value_holder.hpp b/include/boost/python/object/value_holder.hpp deleted file mode 100644 index d40d058d..00000000 --- a/include/boost/python/object/value_holder.hpp +++ /dev/null @@ -1,131 +0,0 @@ -#if !defined(BOOST_PP_IS_ITERATING) - -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# ifndef VALUE_HOLDER_DWA20011215_HPP -# define VALUE_HOLDER_DWA20011215_HPP - -# include -# include -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include - -namespace boost { namespace python { namespace objects { - -# define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) (typename unforward::type)(a##n) - -template -struct value_holder : instance_holder -{ - typedef Held value_type; - - // Forward construction to the held object -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 1)) -# include BOOST_PP_ITERATE() - - private: // required holder implementation - void* holds(type_info); - - private: // data members - Held m_held; -}; - -template -struct value_holder_back_reference : instance_holder -{ - typedef Held value_type; - - // Forward construction to the held object -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 2)) -# include BOOST_PP_ITERATE() - -private: // required holder implementation - void* holds(type_info); - - private: // data members - BackReferenceType m_held; -}; - -# undef BOOST_PYTHON_UNFORWARD_LOCAL - -template -void* value_holder::holds(type_info dst_t) -{ - type_info src_t = python::type_id(); - return src_t == dst_t ? &m_held - : find_static_type(&m_held, src_t, dst_t); -} - -template -void* value_holder_back_reference::holds( - type_info dst_t) -{ - type_info src_t = python::type_id(); - Held* x = &m_held; - - if (dst_t == src_t) - return x; - else if (dst_t == python::type_id()) - return &m_held; - else - return find_static_type(x, src_t, dst_t); -} - -}}} // namespace boost::python::objects - -# endif // VALUE_HOLDER_DWA20011215_HPP - -// --------------- value_holder --------------- - -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1 -# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder)) - -# define N BOOST_PP_ITERATION() - -# if (N != 0) - template -# endif - value_holder( - PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) - : m_held( - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) - ) - {} - -# undef N - -// --------------- value_holder_back_reference --------------- - -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2 -# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference)) - -# define N BOOST_PP_ITERATION() - -# if (N != 0) - template -# endif - value_holder_back_reference( - PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) - : m_held( - p BOOST_PP_COMMA_IF(N) - BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) - ) - { - } - -# undef N - -#endif diff --git a/include/boost/python/object/value_holder_fwd.hpp b/include/boost/python/object/value_holder_fwd.hpp deleted file mode 100644 index 6cb2a0f5..00000000 --- a/include/boost/python/object/value_holder_fwd.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef VALUE_HOLDER_FWD_DWA2002311_HPP -# define VALUE_HOLDER_FWD_DWA2002311_HPP - -namespace boost { namespace python { namespace objects { - -struct no_back_reference; - -template struct value_holder_generator; - -}}} // namespace boost::python::object - -#endif // VALUE_HOLDER_FWD_DWA2002311_HPP diff --git a/include/boost/python/object_attributes.hpp b/include/boost/python/object_attributes.hpp deleted file mode 100755 index 4d3c2a7d..00000000 --- a/include/boost/python/object_attributes.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_ATTRIBUTES_DWA2002615_HPP -# define OBJECT_ATTRIBUTES_DWA2002615_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace api { - -struct const_attribute_policies -{ - typedef char const* key_type; - static object get(object const& target, char const* key); -}; - -struct attribute_policies : const_attribute_policies -{ - static object const& set(object const& target, char const* key, object const& value); - static void del(object const&target, char const* key); -}; - -// -// implementation -// -template -inline object_attribute object_operators::attr(char const* name) -{ - object_cref2 x = *static_cast(this); - return object_attribute(x, name); -} - -template -inline const_object_attribute object_operators::attr(char const* name) const -{ - object_cref2 x = *static_cast(this); - return const_object_attribute(x, name); -} - -inline object const_attribute_policies::get(object const& target, char const* key) -{ - return python::getattr(target, key); -} - -inline object const& attribute_policies::set( - object const& target - , char const* key - , object const& value) -{ - python::setattr(target, key, value); - return value; -} - -inline void attribute_policies::del( - object const& target - , char const* key) -{ - python::delattr(target, key); -} - -}}} // namespace boost::python::api - -#endif // OBJECT_ATTRIBUTES_DWA2002615_HPP diff --git a/include/boost/python/object_call.hpp b/include/boost/python/object_call.hpp deleted file mode 100644 index 31b2eff9..00000000 --- a/include/boost/python/object_call.hpp +++ /dev/null @@ -1,22 +0,0 @@ -# // Copyright David Abrahams 2002. Permission to copy, use, -# // modify, sell and distribute this software is granted provided this -# // copyright notice appears in all copies. This software is provided -# // "as is" without express or implied warranty, and with no claim as -# // to its suitability for any purpose. - -#if !defined(BOOST_PP_IS_ITERATING) -# error Boost.Python - do not include this file! -#endif - -#define N BOOST_PP_ITERATION() - - template - typename detail::dependent::type - operator()(BOOST_PYTHON_BINARY_ENUM(N, A, const& a)) const - { - typedef typename detail::dependent::type obj; - U const& self = *static_cast(this); - return call(get_managed_object(self, tag), BOOST_PYTHON_UNARY_ENUM(N, a)); - } - -#undef N diff --git a/include/boost/python/object_core.hpp b/include/boost/python/object_core.hpp deleted file mode 100755 index ebdfeac1..00000000 --- a/include/boost/python/object_core.hpp +++ /dev/null @@ -1,386 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_CORE_DWA2002615_HPP -# define OBJECT_CORE_DWA2002615_HPP - -# include - -# include -# include -# include -# include -# include -# include -# include -# include -# include - -# include -# include - -namespace boost { namespace python { - -namespace converter -{ - template struct arg_to_python; -} - -// Put this in an inner namespace so that the generalized operators won't take over -namespace api -{ - -// This file contains the definition of the object class and enough to -// construct/copy it, but not enough to do operations like -// attribute/item access or addition. - - template class proxy; - - struct const_attribute_policies; - struct attribute_policies; - struct const_item_policies; - struct item_policies; - struct const_slice_policies; - struct slice_policies; - - typedef proxy const_object_attribute; - typedef proxy object_attribute; - typedef proxy const_object_item; - typedef proxy object_item; - typedef proxy const_object_slice; - typedef proxy object_slice; - - // - // is_proxy -- proxy type detection - // -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct is_proxy - { - BOOST_STATIC_CONSTANT(bool, value = false); - }; - template - struct is_proxy > - { - BOOST_STATIC_CONSTANT(bool, value = true); - }; -# else - typedef char yes_proxy; - typedef char (&no_proxy)[2]; - template - yes_proxy is_proxy_helper(boost::type >*); - no_proxy is_proxy_helper(...); - template - struct is_proxy - { - BOOST_STATIC_CONSTANT( - bool, value = (sizeof(is_proxy_helper((boost::type*)0)) - == sizeof(yes_proxy))); - }; -# endif - - template struct object_initializer; - - class object; - typedef PyObject* (object::*bool_type)() const; - - template - class object_operators - { - protected: -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1200 - typedef object const& object_cref; -# else - typedef object object_cref; -# endif - public: - // function call - // - object operator()() const; - -# define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - - // truth value testing - // - operator bool_type() const; - bool operator!() const; // needed for vc6 - - // Attribute access - // - const_object_attribute attr(char const*) const; - object_attribute attr(char const*); - - // item access - // - const_object_item operator[](object_cref) const; - object_item operator[](object_cref); - - template - const_object_item - operator[](T const& key) const -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 - ; -# else - { - return (*this)[object(key)]; - } -# endif - - template - object_item - operator[](T const& key) -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 - ; -# else - { - return (*this)[object(key)]; - } -# endif - - // slicing - // - const_object_slice slice(object_cref, object_cref) const; - object_slice slice(object_cref, object_cref); - - const_object_slice slice(slice_nil, object_cref) const; - object_slice slice(slice_nil, object_cref); - - const_object_slice slice(object_cref, slice_nil) const; - object_slice slice(object_cref, slice_nil); - - template - const_object_slice - slice(T const& start, V const& end) const -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 - ; -# else - { - return this->slice( - slice_bound::type(start) - , slice_bound::type(end)); - } -# endif - - template - object_slice - slice(T const& start, V const& end) -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 - ; -# else - { - return this->slice( - slice_bound::type(start) - , slice_bound::type(end)); - } -# endif - private: - // there is a confirmed CWPro8 codegen bug here. We prevent the - // early destruction of a temporary by binding a named object - // instead. -# if __MWERKS__ < 0x3000 || __MWERKS__ > 0x3002 - typedef object const& object_cref2; -# else - typedef object const object_cref2; -# endif - }; - - // VC6 and VC7 require this base class in order to generate the - // correct copy constructor for object. We can't define it there - // explicitly or it will complain of ambiguity. - struct object_base : object_operators - { - // copy constructor without NULL checking, for efficiency. - inline object_base(object_base const&); - inline object_base(PyObject* ptr); - - object_base& operator=(object_base const& rhs); - ~object_base(); - - // Underlying object access -- returns a borrowed reference - PyObject* ptr() const; - - private: - PyObject* m_ptr; - }; - - class object : public object_base - { - public: - // default constructor creates a None object - object(); - // explicit conversion from any C++ object to Python - template - explicit object(T const& x) - : object_base( - object_initializer< - is_proxy::value - , converter::is_object_manager::value - >::get(&x, detail::convertible::check(&x))) - { - } - - // Throw error_already_set() if the handle is null. - BOOST_PYTHON_DECL explicit object(handle<> const&); - - public: // implementation detail -- for internal use only - explicit object(detail::borrowed_reference); - explicit object(detail::new_reference); - explicit object(detail::new_non_null_reference); - }; - - // Macros for forwarding constructors in classes derived from - // object. Derived classes will usually want these as an - // implementation detail -# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived) \ - inline explicit derived(python::detail::borrowed_reference p) \ - : object(p) {} \ - inline explicit derived(python::detail::new_reference p) \ - : object(p) {} \ - inline explicit derived(python::detail::new_non_null_reference p) \ - : object(p) {} - -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1200 -# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_ -# else - // MSVC6 has a bug which causes an explicit template constructor to - // be preferred over an appropriate implicit conversion operator - // declared on the argument type. Normally, that would cause a - // runtime failure when using extract to extract a type with a - // templated constructor. This additional constructor will turn that - // runtime failure into an ambiguity error at compile-time due to - // the lack of partial ordering, or at least a link-time error if no - // generalized template constructor is declared. -# define BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(derived) \ - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS_(derived) \ - template \ - explicit derived(extract const&); -# endif - - // - // object_initializer -- get the handle to construct the object with, - // based on whether T is a proxy or derived from object - // - template - struct object_initializer - { - static PyObject* - get(object const* x, detail::yes_convertible) - { - return python::incref(x->ptr()); - } - - template - static PyObject* - get(T const* x, detail::no_convertible) - { - return python::incref(converter::arg_to_python(*x).get()); - } - }; - - template <> - struct object_initializer - { - template - static PyObject* - get(proxy const* x, detail::no_convertible) - { - return python::incref(x->operator object().ptr()); - } - }; - - template <> - struct object_initializer - { - template - static PyObject* - get(T const* x, ...) - { - return python::incref(get_managed_object(*x, tag)); - } - }; - - template <> - struct object_initializer - {}; // empty implementation should cause an error -} -using api::object; -template struct extract; - -// -// implementation -// - -inline object::object() - : object_base(python::incref(Py_None)) -{} - -// copy constructor without NULL checking, for efficiency -inline api::object_base::object_base(object_base const& rhs) - : m_ptr(python::incref(rhs.m_ptr)) -{} - -inline api::object_base::object_base(PyObject* p) - : m_ptr(p) -{} - -inline api::object_base& api::object_base::operator=(api::object_base const& rhs) -{ - Py_INCREF(rhs.m_ptr); - Py_DECREF(this->m_ptr); - this->m_ptr = rhs.m_ptr; - return *this; -} - -inline api::object_base::~object_base() -{ - Py_DECREF(m_ptr); -} - -inline object::object(detail::borrowed_reference p) - : object_base(python::incref((PyObject*)p)) -{} - -inline object::object(detail::new_reference p) - : object_base(expect_non_null((PyObject*)p)) -{} - -inline object::object(detail::new_non_null_reference p) - : object_base((PyObject*)p) -{} - -inline PyObject* api::object_base::ptr() const -{ - return m_ptr; -} - -// -// Converter specialization implementations -// -namespace converter -{ - template struct object_manager_traits; - - template <> - struct object_manager_traits - { - BOOST_STATIC_CONSTANT(bool, is_specialized = true); - static bool check(PyObject*) { return true; } - - static python::detail::new_non_null_reference adopt(PyObject* x) - { - return python::detail::new_non_null_reference(x); - } - }; -} - -inline PyObject* get_managed_object(object const& x, tag_t) -{ - return x.ptr(); -} - -}} // namespace boost::python - -#endif // OBJECT_CORE_DWA2002615_HPP diff --git a/include/boost/python/object_fwd.hpp b/include/boost/python/object_fwd.hpp deleted file mode 100644 index 8b0c093e..00000000 --- a/include/boost/python/object_fwd.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_FWD_DWA2002724_HPP -# define OBJECT_FWD_DWA2002724_HPP - -namespace boost { namespace python { -namespace api -{ - class object; -} -using api::object; -}} // namespace boost::python - -#endif // OBJECT_FWD_DWA2002724_HPP diff --git a/include/boost/python/object_items.hpp b/include/boost/python/object_items.hpp deleted file mode 100755 index 436a671f..00000000 --- a/include/boost/python/object_items.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_ITEMS_DWA2002615_HPP -# define OBJECT_ITEMS_DWA2002615_HPP - -# include -# include -# include - -namespace boost { namespace python { namespace api { - -struct const_item_policies -{ - typedef object key_type; - static object get(object const& target, object const& key); -}; - -struct item_policies : const_item_policies -{ - static object const& set(object const& target, object const& key, object const& value); - static void del(object const& target, object const& key); -}; - -// -// implementation -// -template -inline object_item -object_operators::operator[](object_cref key) -{ - object_cref2 x = *static_cast(this); - return object_item(x, key); -} - -template -inline const_object_item -object_operators::operator[](object_cref key) const -{ - object_cref2 x = *static_cast(this); - return const_object_item(x, key); -} - -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 -template -template -inline const_object_item -object_operators::operator[](T const& key) const -{ - return (*this)[object(key)]; -} - -template -template -inline object_item -object_operators::operator[](T const& key) -{ - return (*this)[object(key)]; -} -# endif - - -inline object const_item_policies::get(object const& target, object const& key) -{ - return getitem(target, key); -} - -inline object const& item_policies::set( - object const& target - , object const& key - , object const& value) -{ - setitem(target, key, value); - return value; -} - -inline void item_policies::del( - object const& target - , object const& key) -{ - delitem(target, key); -} - -}}} // namespace boost::python::api - -#endif // OBJECT_ITEMS_DWA2002615_HPP diff --git a/include/boost/python/object_operators.hpp b/include/boost/python/object_operators.hpp deleted file mode 100644 index fb14d484..00000000 --- a/include/boost/python/object_operators.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_OPERATORS_DWA2002617_HPP -# define OBJECT_OPERATORS_DWA2002617_HPP - -# include -# include - -namespace boost { namespace python { namespace api { - -template -object object_operators::operator()() const -{ - object_cref2 f = *static_cast(this); - return call(f.ptr()); -} - - -template -inline -object_operators::operator bool_type() const -{ - object_cref2 x = *static_cast(this); - return PyObject_IsTrue(x.ptr()) ? &object::ptr : 0; -} - -template -inline bool -object_operators::operator!() const -{ - object_cref2 x = *static_cast(this); - return !PyObject_IsTrue(x.ptr()); -} - -# define BOOST_PYTHON_COMPARE_OP(op, opid) \ -template \ -bool operator op(L const& l, R const& r) \ -{ \ - return PyObject_RichCompareBool( \ - object(l).ptr(), object(r).ptr(), opid); \ -} -BOOST_PYTHON_COMPARE_OP(>, Py_GT) -BOOST_PYTHON_COMPARE_OP(>=, Py_GE) -BOOST_PYTHON_COMPARE_OP(<, Py_LT) -BOOST_PYTHON_COMPARE_OP(<=, Py_LE) -BOOST_PYTHON_COMPARE_OP(==, Py_EQ) -BOOST_PYTHON_COMPARE_OP(!=, Py_NE) -# undef BOOST_PYTHON_COMPARE_OP - -# define BOOST_PYTHON_BINARY_OPERATOR(op) \ -BOOST_PYTHON_DECL object operator op(object const& l, object const& r); \ -template \ -object operator op(L const& l, R const& r) \ -{ \ - return object(l) op object(r); \ -} -BOOST_PYTHON_BINARY_OPERATOR(+) -BOOST_PYTHON_BINARY_OPERATOR(-) -BOOST_PYTHON_BINARY_OPERATOR(*) -BOOST_PYTHON_BINARY_OPERATOR(/) -BOOST_PYTHON_BINARY_OPERATOR(%) -BOOST_PYTHON_BINARY_OPERATOR(<<) -BOOST_PYTHON_BINARY_OPERATOR(>>) -BOOST_PYTHON_BINARY_OPERATOR(&) -BOOST_PYTHON_BINARY_OPERATOR(^) -BOOST_PYTHON_BINARY_OPERATOR(|) -# undef BOOST_PYTHON_BINARY_OPERATOR - - -# define BOOST_PYTHON_INPLACE_OPERATOR(op) \ -BOOST_PYTHON_DECL object& operator op(object& l, object const& r); \ -template \ -object& operator op(object& l, R const& r) \ -{ \ - return l op object(r); \ -} -BOOST_PYTHON_INPLACE_OPERATOR(+=) -BOOST_PYTHON_INPLACE_OPERATOR(-=) -BOOST_PYTHON_INPLACE_OPERATOR(*=) -BOOST_PYTHON_INPLACE_OPERATOR(/=) -BOOST_PYTHON_INPLACE_OPERATOR(%=) -BOOST_PYTHON_INPLACE_OPERATOR(<<=) -BOOST_PYTHON_INPLACE_OPERATOR(>>=) -BOOST_PYTHON_INPLACE_OPERATOR(&=) -BOOST_PYTHON_INPLACE_OPERATOR(^=) -BOOST_PYTHON_INPLACE_OPERATOR(|=) -# undef BOOST_PYTHON_INPLACE_OPERATOR - -}}} // namespace boost::python - -#endif // OBJECT_OPERATORS_DWA2002617_HPP diff --git a/include/boost/python/object_protocol.hpp b/include/boost/python/object_protocol.hpp deleted file mode 100755 index 975c9379..00000000 --- a/include/boost/python/object_protocol.hpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_PROTOCOL_DWA2002615_HPP -# define OBJECT_PROTOCOL_DWA2002615_HPP - -# include -# include -# include -# include - -namespace boost { namespace python { namespace api { - -template -object getattr(Target const& target, Key const& key) -{ - return getattr(object(target), object(key)); -} - -template -object getattr(Target const& target, Key const& key, Default const& default_) -{ - return getattr(object(target), object(key), object(default_)); -} - - -template -void setattr(object const& target, Key const& key, Value const& value) -{ - return setattr(target, object(key), object(value)); -} - -template -void delattr(object const& target, Key const& key) -{ - delattr(target, object(key)); -} - -template -object getitem(Target const& target, Key const& key) -{ - return getitem(object(target), object(key)); -} - - -template -void setitem(object const& target, Key const& key, Value const& value) -{ - return setitem(target, object(key), object(value)); -} - -template -void delitem(object const& target, Key const& key) -{ - delitem(target, object(key)); -} - -template -object getslice(Target const& target, Begin const& begin, End const& end) -{ - return getslice(object(target), object(begin), object(end)); -} - -template -void setslice(object const& target, Begin const& begin, End const& end, Value const& value) -{ - return setslice(target, object(begin), object(end), object(value)); -} - -template -void delslice(object const& target, Begin const& begin, End const& end) -{ - delslice(target, object(begin), object(end)); -} - -}}} // namespace boost::python::api - -#endif // OBJECT_PROTOCOL_DWA2002615_HPP diff --git a/include/boost/python/object_protocol_core.hpp b/include/boost/python/object_protocol_core.hpp deleted file mode 100755 index c5c41c6a..00000000 --- a/include/boost/python/object_protocol_core.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_PROTOCOL_CORE_DWA2002615_HPP -# define OBJECT_PROTOCOL_CORE_DWA2002615_HPP - -# include - -namespace boost { namespace python { - -namespace api -{ - class object; - - BOOST_PYTHON_DECL object getattr(object const& target, object const& key); - BOOST_PYTHON_DECL object getattr(object const& target, object const& key, object const& default_); - BOOST_PYTHON_DECL void setattr(object const& target, object const& key, object const& value); - BOOST_PYTHON_DECL void delattr(object const& target, object const& key); - - // These are defined for efficiency, since attributes are commonly - // accessed through literal strings. - BOOST_PYTHON_DECL object getattr(object const& target, char const* key); - BOOST_PYTHON_DECL object getattr(object const& target, char const* key, object const& default_); - BOOST_PYTHON_DECL void setattr(object const& target, char const* key, object const& value); - BOOST_PYTHON_DECL void delattr(object const& target, char const* key); - - BOOST_PYTHON_DECL object getitem(object const& target, object const& key); - BOOST_PYTHON_DECL void setitem(object const& target, object const& key, object const& value); - BOOST_PYTHON_DECL void delitem(object const& target, object const& key); - - BOOST_PYTHON_DECL object getslice(object const& target, handle<> const& begin, handle<> const& end); - BOOST_PYTHON_DECL void setslice(object const& target, handle<> const& begin, handle<> const& end, object const& value); - BOOST_PYTHON_DECL void delslice(object const& target, handle<> const& begin, handle<> const& end); -} - -using api::getattr; -using api::setattr; -using api::delattr; - -using api::getitem; -using api::setitem; -using api::delitem; - -using api::getslice; -using api::setslice; -using api::delslice; - -}} // namespace boost::python - -#endif // OBJECT_PROTOCOL_CORE_DWA2002615_HPP diff --git a/include/boost/python/object_slices.hpp b/include/boost/python/object_slices.hpp deleted file mode 100644 index eb8dcb0b..00000000 --- a/include/boost/python/object_slices.hpp +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OBJECT_SLICES_DWA2002615_HPP -# define OBJECT_SLICES_DWA2002615_HPP - -# include -# include -# include -# include -# include - -namespace boost { namespace python { namespace api { - -struct const_slice_policies -{ - typedef std::pair, handle<> > key_type; - static object get(object const& target, key_type const& key); -}; - -struct slice_policies : const_slice_policies -{ - static object const& set(object const& target, key_type const& key, object const& value); - static void del(object const& target, key_type const& key); -}; - -// -// implementation -// -template -object_slice -object_operators::slice(object_cref start, object_cref finish) -{ - object_cref2 x = *static_cast(this); - return object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr()))); -} - -template -const_object_slice -object_operators::slice(object_cref start, object_cref finish) const -{ - object_cref2 x = *static_cast(this); - return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr()))); -} - -template -object_slice -object_operators::slice(slice_nil, object_cref finish) -{ - object_cref2 x = *static_cast(this); - return object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr()))); -} - -template -const_object_slice -object_operators::slice(slice_nil, object_cref finish) const -{ - object_cref2 x = *static_cast(this); - return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr()))); -} - -template -object_slice -object_operators::slice(object_cref start, slice_nil) -{ - object_cref2 x = *static_cast(this); - return object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0))); -} - -template -const_object_slice -object_operators::slice(object_cref start, slice_nil) const -{ - object_cref2 x = *static_cast(this); - return const_object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0))); -} -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 -template -template -inline const_object_slice -object_operators::slice(T const& start, V const& end) const -{ - return this->slice( - typename slice_bound::type(start) - , typename slice_bound::type(end)); -} - -template -template -inline object_slice -object_operators::slice(T const& start, V const& end) -{ - return this->slice( - typename slice_bound::type(start) - , typename slice_bound::type(end)); -} -# endif - - -inline object const_slice_policies::get(object const& target, key_type const& key) -{ - return getslice(target, key.first, key.second); -} - -inline object const& slice_policies::set( - object const& target - , key_type const& key - , object const& value) -{ - setslice(target, key.first, key.second, value); - return value; -} - -inline void slice_policies::del( - object const& target - , key_type const& key) -{ - delslice(target, key.first, key.second); -} - -}}} // namespace boost::python::api - -#endif // OBJECT_SLICES_DWA2002615_HPP diff --git a/include/boost/python/objects.hpp b/include/boost/python/objects.hpp deleted file mode 100644 index f2adb65b..00000000 --- a/include/boost/python/objects.hpp +++ /dev/null @@ -1,396 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef OBJECTS_DWA051100_H_ -# define OBJECTS_DWA051100_H_ - -# ifdef BOOST_PYTHON_V2 -# error obsolete -# else -# include -# include -# include -# include "boost/operators.hpp" -# include - -namespace boost { namespace python { - -class BOOST_PYTHON_DECL object -{ - public: - explicit object(ref p); - - // Return a reference to the held object - ref reference() const; - - // Return a raw pointer to the held object - PyObject* get() const; - - private: - ref m_p; -}; - -class tuple; - -class BOOST_PYTHON_DECL tuple_base : public object -{ - public: - explicit tuple_base(std::size_t n = 0); - explicit tuple_base(ref p); - - static PyTypeObject* type_obj(); - static bool accepts(ref p); - std::size_t size() const; - ref operator[](std::size_t pos) const; - - void set_item(std::size_t pos, const ref& rhs); - - tuple slice(int low, int high) const; - - friend BOOST_PYTHON_DECL tuple operator+(const tuple&, const tuple&); - friend BOOST_PYTHON_DECL tuple& operator+=(tuple&, const tuple&); -}; - -class tuple : public tuple_base -{ - public: - explicit tuple(std::size_t n = 0) : tuple_base(n) {} - explicit tuple(ref p) : tuple_base(p) {} - - template - tuple(const std::pair& x) - : tuple_base(ref(PyTuple_New(2))) - { - set_item(0, x.first); - set_item(1, x.second); - } - - template - tuple(const First& first, const Second& second) - : tuple_base(ref(PyTuple_New(2))) - { - set_item(0, first); - set_item(1, second); - } - - template - tuple(const First& first, const Second& second, const Third& third) - : tuple_base(ref(PyTuple_New(3))) - { - set_item(0, first); - set_item(1, second); - set_item(2, third); - } - - template - tuple(const First& first, const Second& second, const Third& third, const Fourth& fourth) - : tuple_base(ref(PyTuple_New(4))) - { - set_item(0, first); - set_item(1, second); - set_item(2, third); - set_item(3, fourth); - } - - template - void set_item(std::size_t pos, const T& rhs) - { - this->set_item(pos, make_ref(rhs)); - } - - void set_item(std::size_t pos, const ref& rhs) - { - tuple_base::set_item(pos, rhs); - } -}; - -class list; - -struct BOOST_PYTHON_DECL list_proxy; -struct BOOST_PYTHON_DECL list_slice_proxy; - -class BOOST_PYTHON_DECL list_base : public object -{ - protected: - typedef list_proxy proxy; - typedef list_slice_proxy slice_proxy; - public: - explicit list_base(ref p); - explicit list_base(std::size_t sz = 0); - static PyTypeObject* type_obj(); - static bool accepts(ref p); - std::size_t size() const; - ref operator[](std::size_t pos) const; - proxy operator[](std::size_t pos); - ref get_item(std::size_t pos) const; - - void set_item(std::size_t pos, const ref& ); - -// void set_item(std::size_t pos, const object& ); - - void insert(std::size_t index, const ref& item); - - void push_back(const ref& item); - - void append(const ref& item); - - list slice(int low, int high) const; - slice_proxy slice(int low, int high); - void sort(); - void reverse(); - tuple as_tuple() const; -}; - -class list : public list_base -{ - public: - explicit list(ref p) : list_base(p) {} - explicit list(std::size_t sz = 0) : list_base(sz) {} - template - void set_item(std::size_t pos, const T& x) - { this->set_item(pos, make_ref(x)); } - template - void insert(std::size_t index, const T& x) - { this->insert(index, make_ref(x)); } - template - void push_back(const T& item) - { this->push_back(make_ref(item)); } - template - void append(const T& item) - { this->append(make_ref(item)); } - - void set_item(std::size_t pos, const ref& x) { list_base::set_item(pos, x); } - void insert(std::size_t index, const ref& item) { list_base::insert(index, item); } - void push_back(const ref& item) { list_base::push_back(item); } - void append(const ref& item) { list_base::append(item); } -}; - -class BOOST_PYTHON_DECL string - : public object, public boost::multipliable2 -{ - public: - // Construct from an owned PyObject*. - // Precondition: p must point to a python string. - explicit string(ref p); - explicit string(const char* s); - string(const char* s, std::size_t length); - string(const string& rhs); - - enum interned_t { interned }; - string(const char* s, interned_t); - - // Get the type object for Strings - static PyTypeObject* type_obj(); - - // Return true if the given object is a python string - static bool accepts(ref o); - - // Return the length of the string. - std::size_t size() const; - - // Returns a null-terminated representation of the contents of string. - // The pointer refers to the internal buffer of string, not a copy. - // The data must not be modified in any way. It must not be de-allocated. - const char* c_str() const; - - string& operator*=(unsigned int repeat_count); - string& operator+=(const string& rhs); - friend string operator+(string x, string y); - string& operator+=(const char* rhs); - friend string operator+(string x, const char* y); - friend string operator+(const char* x, string y); - - void intern(); - - friend string operator%(const string& format, const tuple& args); -}; - -class dictionary; - -struct BOOST_PYTHON_DECL dictionary_proxy; - -class BOOST_PYTHON_DECL dictionary_base : public object -{ - protected: - typedef dictionary_proxy proxy; - - public: - explicit dictionary_base(ref p); - dictionary_base(); - void clear(); - - static PyTypeObject* type_obj(); - static bool accepts(ref p); - - public: - proxy operator[](ref key); - ref operator[](ref key) const; - ref get_item(const ref& key) const; - ref get_item(const ref& key, const ref& default_) const; - - void set_item(const ref& key, const ref& value); - - void erase(ref key); - -// proxy operator[](const object& key); -// ref operator[](const object& key) const; - -// ref get_item(const object& key, ref default_ = ref()) const; -// void set_item(const object& key, const ref& value); - -// void erase(const object& key); - - list items() const; - list keys() const; - list values() const; - - std::size_t size() const; - // TODO: iterator support -}; - -struct BOOST_PYTHON_DECL dictionary_proxy -{ - template - const ref& operator=(const T& rhs) - { return (*this) = make_ref(rhs); } - const ref& operator=(const ref& rhs); - - operator ref() const; - private: - friend class dictionary_base; - dictionary_proxy(const ref& dict, const ref& key); - - // This is needed to work around the very strange MSVC error report that the - // return type of the built-in operator= differs from that of the ones - // defined above. Couldn't hurt to make these un-assignable anyway, though. - const ref& operator=(const dictionary_proxy&); // Not actually implemented - private: - ref m_dict; - ref m_key; -}; - -class dictionary : public dictionary_base -{ - typedef dictionary_proxy proxy; - public: - explicit dictionary(ref p) : dictionary_base(p) {} - dictionary() : dictionary_base() {} - - template - proxy operator[](const Key& key) - { return this->operator[](make_ref(key)); } - proxy operator[](ref key) - { return dictionary_base::operator[](key); } - - template - ref operator[](const Key& key) const - { return this->operator[](make_ref(key)); } - ref operator[](ref key) const - { return dictionary_base::operator[](key); } - - template - ref get_item(const Key& key) const - { return this->get_item(make_ref(key)); } - ref get_item(const ref& key) const - { return dictionary_base::get_item(key); } - - template - ref get_item(const Key& key, const Default& default_) const - { return this->get_item(make_ref(key), make_ref(default_)); } - ref get_item(const ref& key, const ref& default_) const - { return dictionary_base::get_item(key, default_); } - - template - void set_item(const Key& key, const Value& value) - { this->set_item(make_ref(key), make_ref(value)); } - void set_item(const ref& key, const ref& value) - { dictionary_base::set_item(key, value); } - - template - void erase(const Key& key) - { this->erase(make_ref(key)); } - void erase(ref key) - { dictionary_base::erase(key); } -}; - -struct BOOST_PYTHON_DECL list_proxy -{ - template - const ref& operator=(const T& rhs) - { return (*this) = make_ref(rhs); } - const ref& operator=(const ref& rhs); - - operator ref() const; - - private: - friend class list_base; - list_proxy(const ref& list, std::size_t index); - - // This is needed to work around the very strange MSVC error report that the - // return type of the built-in operator= differs from that of the ones - // defined above. Couldn't hurt to make these un-assignable anyway, though. - const ref& operator=(const list_proxy&); // Not actually implemented - private: - list m_list; - std::size_t m_index; -}; - -struct BOOST_PYTHON_DECL list_slice_proxy -{ - const list& operator=(const list& rhs); - operator ref() const; - operator list() const; - std::size_t size() const; - ref operator[](std::size_t pos) const; - private: - friend class list_base; - list_slice_proxy(const ref& list, int low, int high); - private: - ref m_list; - int m_low, m_high; -}; - -}} // namespace boost::python - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE - -BOOST_PYTHON_DECL PyObject* to_python(const boost::python::tuple&); -BOOST_PYTHON_DECL boost::python::tuple from_python(PyObject* p, boost::python::type); - -inline boost::python::tuple from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -BOOST_PYTHON_DECL PyObject* to_python(const boost::python::list&); -BOOST_PYTHON_DECL boost::python::list from_python(PyObject* p, boost::python::type); - -inline boost::python::list from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -BOOST_PYTHON_DECL PyObject* to_python(const boost::python::string&); -BOOST_PYTHON_DECL boost::python::string from_python(PyObject* p, boost::python::type); - -inline boost::python::string from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -BOOST_PYTHON_DECL PyObject* to_python(const boost::python::dictionary&); -BOOST_PYTHON_DECL boost::python::dictionary from_python(PyObject* p, boost::python::type); - -inline boost::python::dictionary from_python(PyObject* p, boost::python::type) -{ - return from_python(p, boost::python::type()); -} - -BOOST_PYTHON_END_CONVERSION_NAMESPACE -# endif // !BOOST_PYTHON_V2 -#endif // OBJECTS_DWA051100_H_ diff --git a/include/boost/python/operators.hpp b/include/boost/python/operators.hpp deleted file mode 100644 index df401f85..00000000 --- a/include/boost/python/operators.hpp +++ /dev/null @@ -1,555 +0,0 @@ -// (C) Copyright Ullrich Koethe and David Abrahams 2000-2001. Permission to -// copy, use, modify, sell and distribute this software is granted provided -// this copyright notice appears in all copies. This software is provided "as -// is" without express or implied warranty, and with no claim as to its -// suitability for any purpose. -// -// The authors gratefully acknowlege the support of Dragon Systems, Inc., in -// producing this work. -// -// Revision History: -// 23 Jan 2001 - Another stupid typo fix by Ralf W. Grosse-Kunstleve (David Abrahams) -// 20 Jan 2001 - Added a fix from Ralf W. Grosse-Kunstleve (David Abrahams) -#ifndef OPERATORS_UK112000_H_ -# define OPERATORS_UK112000_H_ -# ifdef BOOST_PYTHON_V2 - -# include - -# else - -# include -# include - -// When STLport is used with native streams, _STL::ostringstream().str() is not -// _STL::string, but std::string. This confuses to_python(), so we'll use -// strstream instead. Also, GCC 2.95.2 doesn't have sstream. -# if defined(__SGI_STL_PORT) ? defined(__SGI_STL_OWN_IOSTREAMS) : (!defined(__GNUC__) || __GNUC__ > 2) -# define BOOST_PYTHON_USE_SSTREAM -# endif - -# if defined(BOOST_PYTHON_USE_SSTREAM) -# include -# else -# include -# endif - -namespace boost { namespace python { - -BOOST_PYTHON_DECL tuple standard_coerce(ref l, ref r); - -namespace detail { - - // helper class for automatic operand type detection - // during operator wrapping. - struct auto_operand {}; -} - -// Define operator ids that can be or'ed together -// (boost::python::op_add | boost::python::op_sub | boost::python::op_mul). -// This allows to wrap several operators in one line. -enum operator_id -{ - op_add = 0x1, - op_sub = 0x2, - op_mul = 0x4, - op_div = 0x8, - op_mod = 0x10, - op_divmod =0x20, - op_pow = 0x40, - op_lshift = 0x80, - op_rshift = 0x100, - op_and = 0x200, - op_xor = 0x400, - op_or = 0x800, - op_neg = 0x1000, - op_pos = 0x2000, - op_abs = 0x4000, - op_invert = 0x8000, - op_int = 0x10000, - op_long = 0x20000, - op_float = 0x40000, - op_str = 0x80000, - op_cmp = 0x100000, - op_gt = 0x200000, - op_ge = 0x400000, - op_lt = 0x800000, - op_le = 0x1000000, - op_eq = 0x2000000, - op_ne = 0x4000000 -}; - -// Wrap the operators given by "which". Usage: -// foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>()); -template -struct operators {}; - -// Wrap heterogeneous operators with given left operand type. Usage: -// foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(), -// boost::python::left_operand()); -template -struct left_operand {}; - -// Wrap heterogeneous operators with given right operand type. Usage: -// foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub)>(), -// boost::python::right_operand()); -template -struct right_operand {}; - -namespace detail -{ - template - struct operand_select - { - template - struct wrapped - { - typedef Specified type; - }; - }; - - template <> - struct operand_select - { - template - struct wrapped - { - typedef const wrapped_type& type; - }; - }; - - template struct define_operator; - - // Base class which grants access to extension_class_base::add_method() to its derived classes - struct add_operator_base - { - protected: - static inline void add_method(extension_class_base* target, function* method, const char* name) - { target->add_method(method, name); } - }; - -// -// choose_op, choose_unary_op, and choose_rop -// -// These templates use "poor man's partial specialization" to generate the -// appropriate add_method() call (if any) for a given operator and argument set. -// -// Usage: -// choose_op<(which & op_add)>::template args::add(ext_class); -// -// (see extension_class<>::def_operators() for more examples). -// - template - struct choose_op - { - template - struct args : add_operator_base - { - static inline void add(extension_class_base* target) - { - typedef define_operator def_op; - add_method(target, - new typename def_op::template operator_function(), - def_op::name()); - } - - }; - }; - - // specialization for 0 has no effect - template <> - struct choose_op<0> - { - template - struct args - { - static inline void add(extension_class_base*) - { - } - - }; - }; - - template - struct choose_unary_op - { - template - struct args : add_operator_base - { - static inline void add(extension_class_base* target) - { - typedef define_operator def_op; - add_method(target, - new typename def_op::template operator_function(), - def_op::name()); - } - - }; - }; - - // specialization for 0 has no effect - template <> - struct choose_unary_op<0> - { - template - struct args - { - static inline void add(extension_class_base*) - { - } - - }; - }; - - template - struct choose_rop - { - template - struct args : add_operator_base - { - static inline void add(extension_class_base* target) - { - typedef define_operator def_op; - add_method(target, - new typename def_op::template roperator_function(), - def_op::rname()); - } - - }; - }; - - // specialization for 0 has no effect - template <> - struct choose_rop<0> - { - template - struct args - { - static inline void add(extension_class_base*) - { - } - - }; - }; - - -// Fully specialize define_operator for all operators defined in operator_id above. -// Every specialization defines one function object for normal operator calls and one -// for operator calls with operands reversed ("__r*__" function variants). -// Specializations for most operators follow a standard pattern: execute the expression -// that uses the operator in question. This standard pattern is realized by the following -// macros so that the actual specialization can be done by just calling a macro. -# define PY_DEFINE_BINARY_OPERATORS(id, oper) \ - template <> \ - struct define_operator \ - { \ - template \ - struct operator_function : function \ - { \ - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \ - { \ - tuple args(ref(arguments, ref::increment_count)); \ - \ - return BOOST_PYTHON_CONVERSION::to_python( \ - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) oper \ - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type())); \ - } \ - \ - const char* description() const \ - { return "__" #id "__"; } \ - }; \ - \ - template \ - struct roperator_function : function \ - { \ - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \ - { \ - tuple args(ref(arguments, ref::increment_count)); \ - \ - return BOOST_PYTHON_CONVERSION::to_python( \ - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) oper \ - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type())); \ - } \ - \ - const char* description() const \ - { return "__r" #id "__"; } \ - \ - }; \ - \ - static const char * name() { return "__" #id "__"; } \ - static const char * rname() { return "__r" #id "__"; } \ - } - -# define PY_DEFINE_UNARY_OPERATORS(id, oper) \ - template <> \ - struct define_operator \ - { \ - template \ - struct operator_function : function \ - { \ - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \ - { \ - tuple args(ref(arguments, ref::increment_count)); \ - \ - return BOOST_PYTHON_CONVERSION::to_python( \ - oper(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()))); \ - } \ - \ - const char* description() const \ - { return "__" #id "__"; } \ - }; \ - \ - static const char * name() { return "__" #id "__"; } \ - } - - PY_DEFINE_BINARY_OPERATORS(add, +); - PY_DEFINE_BINARY_OPERATORS(sub, -); - PY_DEFINE_BINARY_OPERATORS(mul, *); - PY_DEFINE_BINARY_OPERATORS(div, /); - PY_DEFINE_BINARY_OPERATORS(mod, %); - PY_DEFINE_BINARY_OPERATORS(lshift, <<); - PY_DEFINE_BINARY_OPERATORS(rshift, >>); - PY_DEFINE_BINARY_OPERATORS(and, &); - PY_DEFINE_BINARY_OPERATORS(xor, ^); - PY_DEFINE_BINARY_OPERATORS(or, |); - PY_DEFINE_BINARY_OPERATORS(gt, >); - PY_DEFINE_BINARY_OPERATORS(ge, >=); - PY_DEFINE_BINARY_OPERATORS(lt, <); - PY_DEFINE_BINARY_OPERATORS(le, <=); - PY_DEFINE_BINARY_OPERATORS(eq, ==); - PY_DEFINE_BINARY_OPERATORS(ne, !=); - - PY_DEFINE_UNARY_OPERATORS(neg, -); - PY_DEFINE_UNARY_OPERATORS(pos, +); - PY_DEFINE_UNARY_OPERATORS(abs, abs); - PY_DEFINE_UNARY_OPERATORS(invert, ~); - PY_DEFINE_UNARY_OPERATORS(int, long); - PY_DEFINE_UNARY_OPERATORS(long, PyLong_FromLong); - PY_DEFINE_UNARY_OPERATORS(float, double); - -# undef PY_DEFINE_BINARY_OPERATORS -# undef PY_DEFINE_UNARY_OPERATORS - -// Some operators need special treatment, e.g. because there is no corresponding -// expression in C++. These are specialized manually. - -// pow(): Manual specialization needed because an error message is required if this -// function is called with three arguments. The "power modulo" operator is not -// supported by define_operator, but can be wrapped manually (see special.html). - template <> - struct define_operator - { - template - struct operator_function : function - { - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const - { - tuple args(ref(arguments, ref::increment_count)); - - if (args.size() == 3 && args[2]->ob_type != Py_None->ob_type) - { - PyErr_SetString(PyExc_TypeError, "expected 2 arguments, got 3"); - throw_argument_error(); - } - - return BOOST_PYTHON_CONVERSION::to_python( - pow(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()), - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()))); - } - - const char* description() const - { return "__pow__"; } - - }; - - template - struct roperator_function : function - { - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const - { - tuple args(ref(arguments, ref::increment_count)); - - if (args.size() == 3 && args[2]->ob_type != Py_None->ob_type) - { - PyErr_SetString(PyExc_TypeError, "bad operand type(s) for pow()"); - throw_argument_error(); - } - - return BOOST_PYTHON_CONVERSION::to_python( - pow(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()), - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()))); - } - - const char* description() const - { return "__rpow__"; } - - }; - - static const char * name() { return "__pow__"; } - static const char * rname() { return "__rpow__"; } - }; - -// divmod(): Manual specialization needed because we must actually call two operators and -// return a tuple containing both results - template <> - struct define_operator - { - template - struct operator_function : function - { - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const - { - tuple args(ref(arguments, ref::increment_count)); - PyObject * res = PyTuple_New(2); - - PyTuple_SET_ITEM(res, 0, - BOOST_PYTHON_CONVERSION::to_python( - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) / - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()))); - PyTuple_SET_ITEM(res, 1, - BOOST_PYTHON_CONVERSION::to_python( - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) % - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()))); - - return res; - } - - const char* description() const - { return "__divmod__"; } - - }; - - template - struct roperator_function : function - { - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const - { - tuple args(ref(arguments, ref::increment_count)); - PyObject * res = PyTuple_New(2); - - PyTuple_SET_ITEM(res, 0, - BOOST_PYTHON_CONVERSION::to_python( - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) / - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()))); - PyTuple_SET_ITEM(res, 1, - BOOST_PYTHON_CONVERSION::to_python( - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) % - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()))); - - return res; - } - - const char* description() const - { return "__rdivmod__"; } - - }; - - static const char * name() { return "__divmod__"; } - static const char * rname() { return "__rdivmod__"; } - }; - -// cmp(): Manual specialization needed because there is no three-way compare in C++. -// It is implemented by two one-way comparisons with operators reversed in the second. - template <> - struct define_operator - { - template - struct operator_function : function - { - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const - { - tuple args(ref(arguments, ref::increment_count)); - - return BOOST_PYTHON_CONVERSION::to_python( - (BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) < - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type())) ? - - 1 : - (BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) < - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type())) ? - 1 : - 0) ; - } - - const char* description() const - { return "__cmp__"; } - - }; - - template - struct roperator_function : function - { - PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const - { - tuple args(ref(arguments, ref::increment_count)); - - return BOOST_PYTHON_CONVERSION::to_python( - (BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) < - BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type())) ? - - 1 : - (BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) < - BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type())) ? - 1 : - 0) ; - } - - const char* description() const - { return "__rcmp__"; } - - }; - - static const char * name() { return "__cmp__"; } - static const char * rname() { return "__rcmp__"; } - }; - -# ifndef BOOST_PYTHON_USE_SSTREAM - class unfreezer { - public: - unfreezer(std::ostrstream& s) : m_stream(s) {} - ~unfreezer() { m_stream.freeze(false); } - private: - std::ostrstream& m_stream; - }; -# endif - -// str(): Manual specialization needed because the string conversion does not follow -// the standard pattern relized by the macros. - template <> - struct define_operator - { - template - struct operator_function : function - { - PyObject* do_call(PyObject* arguments, PyObject*) const - { - tuple args(ref(arguments, ref::increment_count)); - -// When STLport is used with native streams, _STL::ostringstream().str() is not -// _STL::string, but std::string. -# ifdef BOOST_PYTHON_USE_SSTREAM - std::ostringstream s; - s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()); - return BOOST_PYTHON_CONVERSION::to_python(s.str()); -# else - std::ostrstream s; - s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) << char(); - auto unfreezer unfreeze(s); - return BOOST_PYTHON_CONVERSION::to_python(const_cast(s.str())); -# endif - } - - const char* description() const - { return "__str__"; } - - }; - - static const char * name() { return "__str__"; } - }; - - -} // namespace detail - -}} // namespace boost::python - -# undef BOOST_PYTHON_USE_SSTREAM -# endif -#endif /* OPERATORS_UK112000_H_ */ diff --git a/include/boost/python/operators2.hpp b/include/boost/python/operators2.hpp deleted file mode 100755 index 3f06eb46..00000000 --- a/include/boost/python/operators2.hpp +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef OPERATORS2_DWA2002530_HPP -# define OPERATORS2_DWA2002530_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - // This is essentially the old v1 to_python(). It will be eliminated - // once the public interface for to_python is settled on. - template - PyObject* convert_result(T const& x) - { - return converter::arg_to_python(x).release(); - } - - // Operator implementation template declarations. The nested apply - // declaration here keeps MSVC6 happy. - template struct operator_l - { - template struct apply; - }; - - template struct operator_r - { - template struct apply; - }; - - template struct operator_1 - { - template struct apply; - }; - - // MSVC6 doesn't want us to do this sort of inheritance on a nested - // class template, so we use this layer of indirection to avoid - // ::template<...> on the nested apply functions below - template - struct operator_l_inner - : operator_l::template apply - {}; - - template - struct operator_r_inner - : operator_r::template apply - {}; - - template - struct operator_1_inner - : operator_1::template apply - {}; - - // Define three different binary_op templates which take care of - // these cases: - // self op self - // self op R - // L op self - // - // The inner apply metafunction is used to adjust the operator to - // the class type being defined. Inheritance of the outer class is - // simply used to provide convenient access to the operation's - // name(). - - // self op self - template - struct binary_op : operator_l - { - template - struct apply : operator_l_inner - { - }; - }; - - // self op R - template - struct binary_op_l : operator_l - { - template - struct apply : operator_l_inner - { - }; - }; - - // L op self - template - struct binary_op_r : operator_r - { - template - struct apply : operator_r_inner - { - }; - }; - - template - struct unary_op : operator_1 - { - template - struct apply : operator_1_inner - { - }; - }; - - // This type is what actually gets returned from operators used on - // self_t - template - struct operator_ - : mpl::if_< - is_same - , typename mpl::if_< - is_same - , binary_op - , binary_op_l::type> - >::type - , typename mpl::if_< - is_same - , unary_op - , binary_op_r::type> - >::type - >::type - { - }; -} - -# define BOOST_PYTHON_BINARY_OPERATION(id, rid, expr) \ -namespace detail \ -{ \ - template <> \ - struct operator_l \ - { \ - template \ - struct apply \ - { \ - static inline PyObject* execute(L const& l, R const& r) \ - { \ - return detail::convert_result(expr); \ - } \ - }; \ - static char const* name() { return "__" #id "__"; } \ - }; \ - \ - template <> \ - struct operator_r \ - { \ - template \ - struct apply \ - { \ - static inline PyObject* execute(R const& r, L const& l) \ - { \ - return detail::convert_result(expr); \ - } \ - }; \ - static char const* name() { return "__" #rid "__"; } \ - }; \ -} - -# define BOOST_PYTHON_BINARY_OPERATOR(id, rid, op) \ -BOOST_PYTHON_BINARY_OPERATION(id, rid, l op r) \ -namespace self_ns \ -{ \ - template \ - inline detail::operator_ \ - operator##op(L const&, R const&) \ - { \ - return detail::operator_(); \ - } \ -} - -BOOST_PYTHON_BINARY_OPERATOR(add, radd, +) -BOOST_PYTHON_BINARY_OPERATOR(sub, rsub, -) -BOOST_PYTHON_BINARY_OPERATOR(mul, rmul, *) -BOOST_PYTHON_BINARY_OPERATOR(div, rdiv, /) -BOOST_PYTHON_BINARY_OPERATOR(mod, rmod, %) -BOOST_PYTHON_BINARY_OPERATOR(lshift, rlshift, <<) -BOOST_PYTHON_BINARY_OPERATOR(rshift, rrshift, >>) -BOOST_PYTHON_BINARY_OPERATOR(and, rand, &) -BOOST_PYTHON_BINARY_OPERATOR(xor, rxor, ^) -BOOST_PYTHON_BINARY_OPERATOR(or, ror, |) -BOOST_PYTHON_BINARY_OPERATOR(gt, lt, >) -BOOST_PYTHON_BINARY_OPERATOR(ge, le, >=) -BOOST_PYTHON_BINARY_OPERATOR(lt, gt, <) -BOOST_PYTHON_BINARY_OPERATOR(le, ge, <=) -BOOST_PYTHON_BINARY_OPERATOR(eq, eq, ==) -BOOST_PYTHON_BINARY_OPERATOR(ne, ne, !=) -# undef BOOST_PYTHON_BINARY_OPERATOR - -// pow isn't an operator in C++; handle it specially. -BOOST_PYTHON_BINARY_OPERATION(pow, rpow, pow(l,r)) -# undef BOOST_PYTHON_BINARY_OPERATION - -namespace self_ns -{ -# ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP - template - inline detail::operator_ - pow(L const&, R const&) - { - return detail::operator_(); - } -# else - // When there's no argument-dependent lookup, we need these - // overloads to handle the case when everything is imported into the - // global namespace. Note that the plain overload below does /not/ - // take const& arguments. This is needed by MSVC6 at least, or it - // complains of ambiguities, since there's no partial ordering. - inline detail::operator_ - pow(self_t, self_t) - { - return detail::operator_(); - } - template - inline detail::operator_ - pow(self_t const&, R const&) - { - return detail::operator_(); - } - template - inline detail::operator_ - pow(L const&, self_t const&) - { - return detail::operator_(); - } -# endif -} - - -# define BOOST_PYTHON_INPLACE_OPERATOR(id, op) \ -namespace detail \ -{ \ - template <> \ - struct operator_l \ - { \ - template \ - struct apply \ - { \ - static inline PyObject* \ - execute(back_reference l, R const& r) \ - { \ - l.get() op r; \ - return python::incref(l.source().ptr()); \ - } \ - }; \ - static char const* name() { return "__" #id "__"; } \ - }; \ -} \ -namespace self_ns \ -{ \ - template \ - inline detail::operator_ \ - operator##op(self_t const&, R const&) \ - { \ - return detail::operator_(); \ - } \ -} - -BOOST_PYTHON_INPLACE_OPERATOR(iadd,+=) -BOOST_PYTHON_INPLACE_OPERATOR(isub,-=) -BOOST_PYTHON_INPLACE_OPERATOR(imul,*=) -BOOST_PYTHON_INPLACE_OPERATOR(idiv,/=) -BOOST_PYTHON_INPLACE_OPERATOR(imod,%=) -BOOST_PYTHON_INPLACE_OPERATOR(ilshift,<<=) -BOOST_PYTHON_INPLACE_OPERATOR(irshift,>>=) -BOOST_PYTHON_INPLACE_OPERATOR(iand,&=) -BOOST_PYTHON_INPLACE_OPERATOR(ixor,^=) -BOOST_PYTHON_INPLACE_OPERATOR(ior,|=) - -# define BOOST_PYTHON_UNARY_OPERATOR(id, op, func_name) \ -namespace detail \ -{ \ - template <> \ - struct operator_1 \ - { \ - template \ - struct apply \ - { \ - static PyObject* execute(T const& x) \ - { \ - return detail::convert_result(op(x)); \ - } \ - }; \ - static char const* name() { return "__" #id "__"; } \ - }; \ -} \ -namespace self_ns \ -{ \ - inline detail::operator_ \ - func_name(self_t const&) \ - { \ - return detail::operator_(); \ - } \ -} -# undef BOOST_PYTHON_INPLACE_OPERATOR - -BOOST_PYTHON_UNARY_OPERATOR(neg, -, operator-) -BOOST_PYTHON_UNARY_OPERATOR(pos, +, operator+) -BOOST_PYTHON_UNARY_OPERATOR(abs, abs, abs) -BOOST_PYTHON_UNARY_OPERATOR(invert, ~, operator~) -BOOST_PYTHON_UNARY_OPERATOR(int, long, int_) -BOOST_PYTHON_UNARY_OPERATOR(long, PyLong_FromLong, long_) -BOOST_PYTHON_UNARY_OPERATOR(float, double, float_) -BOOST_PYTHON_UNARY_OPERATOR(complex, std::complex, complex_) -BOOST_PYTHON_UNARY_OPERATOR(str, lexical_cast, str) -# undef BOOST_PYTHON_UNARY_OPERATOR - -}} // namespace boost::python - -# ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP -using boost::python::self_ns::abs; -using boost::python::self_ns::int_; -using boost::python::self_ns::long_; -using boost::python::self_ns::float_; -using boost::python::self_ns::complex_; -using boost::python::self_ns::str; -using boost::python::self_ns::pow; -# endif - -#endif // OPERATORS2_DWA2002530_HPP - - - - - - - - diff --git a/include/boost/python/other.hpp b/include/boost/python/other.hpp deleted file mode 100755 index 0142da34..00000000 --- a/include/boost/python/other.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef OTHER_DWA20020601_HPP -# define OTHER_DWA20020601_HPP -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -# if _MSC_VER+0 >= 1020 -# pragma once -# endif - -# include - -namespace boost { namespace python { - -template struct other -{ - typedef T type; -}; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -namespace detail -{ - template - class is_other - { - public: - BOOST_STATIC_CONSTANT(bool, value = false); - }; - - template - class is_other > - { - public: - BOOST_STATIC_CONSTANT(bool, value = true); - }; - - template - class unwrap_other - { - public: - typedef T type; - }; - - template - class unwrap_other > - { - public: - typedef T type; - }; -} -# else // no partial specialization - -}} // namespace boost::python - -#include - -namespace boost { namespace python { - -namespace detail -{ - typedef char (&yes_other_t)[1]; - typedef char (&no_other_t)[2]; - - no_other_t is_other_test(...); - - template - yes_other_t is_other_test(type< other >); - - template - struct other_unwrapper - { - template - struct apply - { - typedef T type; - }; - }; - - template<> - struct other_unwrapper - { - template - struct apply - { - typedef typename T::type type; - }; - }; - - template - class is_other - { - public: - BOOST_STATIC_CONSTANT( - bool, value = ( - sizeof(detail::is_other_test(type())) - == sizeof(detail::yes_other_t))); - }; - - template - class unwrap_other - : public detail::other_unwrapper< - is_other::value - >::template apply - {}; -} - -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -}} // namespace boost::python - -#endif // #ifndef OTHER_DWA20020601_HPP diff --git a/include/boost/python/pointee.hpp b/include/boost/python/pointee.hpp deleted file mode 100644 index d62bab54..00000000 --- a/include/boost/python/pointee.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef POINTEE_DWA2002323_HPP -# define POINTEE_DWA2002323_HPP - -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct pointee_impl - { - template struct apply : remove_pointer {}; - }; - - template <> - struct pointee_impl - { - template struct apply - { - typedef typename T::element_type type; - }; - }; -} - -template -struct pointee - : detail::pointee_impl::value>::template apply -{ -}; - -}} // namespace boost::python::detail - -#endif // POINTEE_DWA2002323_HPP diff --git a/include/boost/python/proxy.hpp b/include/boost/python/proxy.hpp deleted file mode 100755 index 1818fa27..00000000 --- a/include/boost/python/proxy.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef PROXY_DWA2002615_HPP -# define PROXY_DWA2002615_HPP -# include -# include - -namespace boost { namespace python { namespace api { - -template -class proxy : public object_operators > -{ - typedef typename Policies::key_type key_type; - -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1200 - typedef proxy const& assignment_self; -# else - typedef proxy assignment_self; -# endif - public: - proxy(object const& target, key_type const& key); - operator object() const; - - // to support a[b] = c[d] - proxy const& operator=(assignment_self) const; - - template - inline proxy const& operator=(T const& rhs) const - { - Policies::set(m_target, m_key, object(rhs)); - return *this; - } - - public: // implementation detail - void del() const; - - private: - object m_target; - key_type m_key; -}; - - -template -inline void del(proxy const& x) -{ - x.del(); -} - -// -// implementation -// - -template -inline proxy::proxy(object const& target, key_type const& key) - : m_target(target), m_key(key) -{} - -template -inline proxy::operator object() const -{ - return Policies::get(m_target, m_key); -} - -// to support a[b] = c[d] -template -inline proxy const& proxy::operator=(typename proxy::assignment_self rhs) const -{ - return *this = python::object(rhs); -} - -# define BOOST_PYTHON_PROXY_INPLACE(op) \ -template \ -proxy const& operator op(proxy const& lhs, R const& rhs) \ -{ \ - object old(lhs); \ - return lhs = (old op rhs); \ -} -BOOST_PYTHON_PROXY_INPLACE(+=) -BOOST_PYTHON_PROXY_INPLACE(-=) -BOOST_PYTHON_PROXY_INPLACE(*=) -BOOST_PYTHON_PROXY_INPLACE(/=) -BOOST_PYTHON_PROXY_INPLACE(%=) -BOOST_PYTHON_PROXY_INPLACE(<<=) -BOOST_PYTHON_PROXY_INPLACE(>>=) -BOOST_PYTHON_PROXY_INPLACE(&=) -BOOST_PYTHON_PROXY_INPLACE(^=) -BOOST_PYTHON_PROXY_INPLACE(|=) -# undef BOOST_PYTHON_PROXY_INPLACE - -template -inline void proxy::del() const -{ - Policies::del(m_target, m_key); -} - -}}} // namespace boost::python::api - -#endif // PROXY_DWA2002615_HPP diff --git a/include/boost/python/ptr.hpp b/include/boost/python/ptr.hpp deleted file mode 100644 index 5f8ad2d0..00000000 --- a/include/boost/python/ptr.hpp +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef PTR_DWA20020601_HPP -# define PTR_DWA20020601_HPP -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -// -// Based on boost/ref.hpp, thus: -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) -// Copyright (C) 2001 Peter Dimov - -# if _MSC_VER+0 >= 1020 -# pragma once -# endif - -# include - -namespace boost { namespace python { - -template class pointer_wrapper -{ - public: - typedef Ptr type; - - explicit pointer_wrapper(Ptr x): p_(x) {} - operator Ptr() const { return p_; } - Ptr get() const { return p_; } - private: - Ptr p_; -}; - -template -inline pointer_wrapper ptr(T t) -{ - return pointer_wrapper(t); -} - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -class is_pointer_wrapper -{ - public: - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -class is_pointer_wrapper > -{ - public: - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -class unwrap_pointer -{ - public: - typedef T type; -}; - -template -class unwrap_pointer > -{ - public: - typedef T type; -}; -# else // no partial specialization - -}} // namespace boost::python - -#include - -namespace boost { namespace python { - -namespace detail -{ - typedef char (&yes_pointer_wrapper_t)[1]; - typedef char (&no_pointer_wrapper_t)[2]; - - no_pointer_wrapper_t is_pointer_wrapper_test(...); - - template - yes_pointer_wrapper_t is_pointer_wrapper_test(boost::type< pointer_wrapper >); - - template - struct pointer_unwrapper - { - template - struct apply - { - typedef T type; - }; - }; - - template<> - struct pointer_unwrapper - { - template - struct apply - { - typedef typename T::type type; - }; - }; -} - -template -class is_pointer_wrapper -{ - public: - BOOST_STATIC_CONSTANT( - bool, value = ( - sizeof(detail::is_pointer_wrapper_test(boost::type())) - == sizeof(detail::yes_pointer_wrapper_t))); -}; - -template -class unwrap_pointer - : public detail::pointer_unwrapper< - is_pointer_wrapper::value - >::template apply -{}; - -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -}} // namespace boost::python - -#endif // #ifndef PTR_DWA20020601_HPP diff --git a/include/boost/python/py_interface.hpp b/include/boost/python/py_interface.hpp deleted file mode 100644 index c1416d5c..00000000 --- a/include/boost/python/py_interface.hpp +++ /dev/null @@ -1,700 +0,0 @@ -// Automatically generated from py_api_gen.py -#ifndef PY_INTERFACE_HPP -#define PY_INTERFACE_HPP - -#include -#include - -namespace boost { namespace python { namespace api { - -enum call_dict_usage { use_new_dict, use_local_dict, use_global_dict }; - -namespace api_detail { - -BOOST_PYTHON_DECL object get_func(const char* name); -BOOST_PYTHON_DECL object call_statement(const char *stmt, int n, ...); -BOOST_PYTHON_DECL object call_statement_du(const char *stmt, call_dict_usage cdu, int n, ...); - -template -struct get_arg -{ - get_arg(A const &a) : h(a) {} - object h; - operator object const& () { return h; } - operator object const* () { return &h; } -}; - -template<> -struct get_arg -{ - get_arg(object const &a) : h(a) {} - object const &h; - operator object const& () { return h; } - operator object const* () { return &h; } -}; - -template<> -struct get_arg -{ - get_arg(PyObject* a) : h((python::detail::borrowed_reference)a) {} - object h; - operator object const& () { return h; } - operator object const* () { return &h; } -}; - -} - -BOOST_PYTHON_DECL object locals(); - - -template -object abs(A0 const& a0) -{ - return api_detail::get_func("abs")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object abs(object const& a0); -BOOST_PYTHON_DECL object abs(short a0); -BOOST_PYTHON_DECL object abs(int a0); -BOOST_PYTHON_DECL object abs(long a0); -BOOST_PYTHON_DECL object abs(double const & a0); -BOOST_PYTHON_DECL object apply(object const& a0, object const& a1); -BOOST_PYTHON_DECL object apply(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL bool callable(object const& a0); -template -object chr(A0 const& a0) -{ - return api_detail::get_func("chr")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object chr(object const& a0); -BOOST_PYTHON_DECL object chr(short a0); -BOOST_PYTHON_DECL object chr(int a0); -BOOST_PYTHON_DECL object chr(long a0); -template -int cmp(A0 const& a0, A1 const& a1) -{ - int rslt; - int r = ::PyObject_Cmp(api_detail::get_arg(a0), api_detail::get_arg(a1), &rslt); - if(r == -1) - throw_error_already_set(); - return rslt; -} -BOOST_PYTHON_DECL int cmp(object const& a0, object const& a1); -BOOST_PYTHON_DECL object coerce(object const& a0, object const& a1); -BOOST_PYTHON_DECL object compile(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object compile(const char* a0, const char* a1, const char* a2); -BOOST_PYTHON_DECL object compile(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object compile(const char* a0, const char* a1, const char* a2, int a3); -BOOST_PYTHON_DECL object compile(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object compile(const char* a0, const char* a1, const char* a2, int a3, int a4); -template -object complex(A0 const& a0) -{ - return api_detail::get_func("complex")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object complex(object const& a0); -BOOST_PYTHON_DECL object complex(double const& a0); -template -object complex(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("complex")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object complex(object const& a0, object const& a1); -BOOST_PYTHON_DECL object complex(double const& a0, double const& a1); -BOOST_PYTHON_DECL object dict(); -BOOST_PYTHON_DECL object dict(object const& a0); -BOOST_PYTHON_DECL object dir(); -BOOST_PYTHON_DECL object dir(object const& a0); -template -object divmod(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("divmod")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object divmod(object const& a0, object const& a1); -BOOST_PYTHON_DECL object divmod(int a0, int a1); -BOOST_PYTHON_DECL object divmod(long a0, long a1); -BOOST_PYTHON_DECL object divmod(double const& a0, double const& a1); -BOOST_PYTHON_DECL object eval(const char* a0); -BOOST_PYTHON_DECL object eval(const char* a0, object const& a2); -BOOST_PYTHON_DECL object eval(const char* a0, object const& a2, object const& a3); -BOOST_PYTHON_DECL object exec(const char* a0); -BOOST_PYTHON_DECL object exec(const char* a0, object const& a2); -BOOST_PYTHON_DECL object exec(const char* a0, object const& a2, object const& a3); -BOOST_PYTHON_DECL object execfile(object const& a0); -BOOST_PYTHON_DECL object execfile(object const& a0, object const& a1); -BOOST_PYTHON_DECL object execfile(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object file(object const& a0); -BOOST_PYTHON_DECL object file(const char* a0); -BOOST_PYTHON_DECL object file(object const& a0, object const& a1); -BOOST_PYTHON_DECL object file(const char* a0, const char* a1); -BOOST_PYTHON_DECL object file(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object file(const char* a0, const char* a1, int a2); -BOOST_PYTHON_DECL object filter(object const& a0, object const& a1); -BOOST_PYTHON_DECL object float_(object const& a0); -BOOST_PYTHON_DECL object float_(const char* a0); -BOOST_PYTHON_DECL object float_(double const& a0); -BOOST_PYTHON_DECL object getattr(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object getattr(object const& a0, const char * a1, object const& a2); -BOOST_PYTHON_DECL object globals(); -BOOST_PYTHON_DECL bool hasattr(object const& a0, object const& a1); -BOOST_PYTHON_DECL bool hasattr(object const& a0, const char* a1); -BOOST_PYTHON_DECL long hash(object const& a0); -template -object hex(A0 const& a0) -{ - return api_detail::get_func("hex")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object hex(object const& a0); -BOOST_PYTHON_DECL object hex(char a0); -BOOST_PYTHON_DECL object hex(short a0); -BOOST_PYTHON_DECL object hex(int a0); -BOOST_PYTHON_DECL object hex(long a0); -BOOST_PYTHON_DECL long id(object const& a0); -BOOST_PYTHON_DECL object input(); -BOOST_PYTHON_DECL object input(object const& a0); -BOOST_PYTHON_DECL object input(const char* a0); -BOOST_PYTHON_DECL object int_(object const& a0); -BOOST_PYTHON_DECL object int_(long a0); -BOOST_PYTHON_DECL object int_(const char* a0); -BOOST_PYTHON_DECL object intern(object const& a0); -BOOST_PYTHON_DECL object intern(const char* a0); -BOOST_PYTHON_DECL bool isinstance(object const& a0, object const& a1); -BOOST_PYTHON_DECL bool issubclass(object const& a0, object const& a1); -BOOST_PYTHON_DECL object iter(object const& a0); -BOOST_PYTHON_DECL object iter(object const& a0, object const& a1); -BOOST_PYTHON_DECL long len(object const& a0); -BOOST_PYTHON_DECL object list(); -BOOST_PYTHON_DECL object list(object const& a0); -BOOST_PYTHON_DECL object long_(object const& a0); -BOOST_PYTHON_DECL object long_(long a0); -BOOST_PYTHON_DECL object long_(const char* a0); -BOOST_PYTHON_DECL object map(object const& a0); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object max(A0 const& a0) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0)); -} -template -object max(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8), api_detail::get_arg(a9)); -} -BOOST_PYTHON_DECL object max(object const& a0); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object min(A0 const& a0) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0)); -} -template -object min(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8), api_detail::get_arg(a9)); -} -BOOST_PYTHON_DECL object min(object const& a0); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object oct(A0 const& a0) -{ - return api_detail::get_func("oct")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object oct(object const& a0); -BOOST_PYTHON_DECL object oct(char a0); -BOOST_PYTHON_DECL object oct(short a0); -BOOST_PYTHON_DECL object oct(int a0); -BOOST_PYTHON_DECL object oct(long a0); -BOOST_PYTHON_DECL object open(object const& a0); -BOOST_PYTHON_DECL object open(const char* a0); -BOOST_PYTHON_DECL object open(object const& a0, object const& a1); -BOOST_PYTHON_DECL object open(const char* a0, const char* a1); -BOOST_PYTHON_DECL object open(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object open(const char* a0, const char* a1, int a2); -BOOST_PYTHON_DECL long ord(object const& a0); -BOOST_PYTHON_DECL long ord(const char* a0); -template -object pow(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("pow")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object pow(object const& a0, object const& a1); -BOOST_PYTHON_DECL object pow(double const& a0, double const& a1); -BOOST_PYTHON_DECL object pow(double const& a0, double const& a1, double const& a2); -template -object print(A0 const& a0) -{ - return api_detail::call_statement_du("print _1", use_new_dict, 1, (object const*)api_detail::get_arg(a0)); -} -template -object print(A0 const& a0, A1 const& a1) -{ - return api_detail::call_statement_du("print _1, _2", use_new_dict, 2, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::call_statement_du("print _1, _2, _3", use_new_dict, 3, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4", use_new_dict, 4, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5", use_new_dict, 5, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6", use_new_dict, 6, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7", use_new_dict, 7, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7, _8", use_new_dict, 8, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7, _8, _9", use_new_dict, 9, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7, _8, _9, _10", use_new_dict, 10, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -BOOST_PYTHON_DECL object print(object const& a0); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object print_file(object const& a0, A1 const& a1) -{ - return api_detail::call_statement_du("print >>_1, _2", use_new_dict, 2, a0, (object const*)api_detail::get_arg(a1)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::call_statement_du("print >>_1, _2, _3", use_new_dict, 3, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4", use_new_dict, 4, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5", use_new_dict, 5, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6", use_new_dict, 6, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7", use_new_dict, 7, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8", use_new_dict, 8, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8, _9", use_new_dict, 9, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8, _9, _10", use_new_dict, 10, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11", use_new_dict, 11, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10)); -} -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10); -template -object range(A0 const& a0) -{ - return api_detail::get_func("range")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object range(object const& a0); -BOOST_PYTHON_DECL object range(int a0); -template -object range(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("range")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object range(object const& a0, object const& a1); -BOOST_PYTHON_DECL object range(int a0, int a1); -template -object range(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("range")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -BOOST_PYTHON_DECL object range(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object range(int a0, int a1, int a2); -BOOST_PYTHON_DECL object raw_input(); -BOOST_PYTHON_DECL object raw_input(object const& a0); -BOOST_PYTHON_DECL object raw_input(const char* a0); -BOOST_PYTHON_DECL object reduce(object const& a0, object const& a1); -BOOST_PYTHON_DECL object reduce(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object reload(object const& a0); -BOOST_PYTHON_DECL object repr(object const& a0); -template -object round(A0 const& a0) -{ - return api_detail::get_func("round")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object round(object const& a0); -BOOST_PYTHON_DECL object round(double const& a0); -template -object round(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("round")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object round(object const& a0, object const& a1); -BOOST_PYTHON_DECL object round(double const& a0, double const& a1); -template -object slice(A0 const& a0) -{ - return api_detail::get_func("slice")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object slice(object const& a0); -BOOST_PYTHON_DECL object slice(int a0); -template -object slice(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("slice")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object slice(object const& a0, object const& a1); -BOOST_PYTHON_DECL object slice(int a0, int a1); -template -object slice(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("slice")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -BOOST_PYTHON_DECL object slice(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object slice(int a0, int a1, int a2); -BOOST_PYTHON_DECL object str(object const& a0); -BOOST_PYTHON_DECL object tuple(); -BOOST_PYTHON_DECL object tuple(object const& a0); -BOOST_PYTHON_DECL object type_(object const& a0); -template -object unichr(A0 const& a0) -{ - return api_detail::get_func("unichr")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object unichr(object const& a0); -BOOST_PYTHON_DECL object unichr(short a0); -BOOST_PYTHON_DECL object unichr(int a0); -BOOST_PYTHON_DECL object unichr(long a0); -BOOST_PYTHON_DECL object unicode(object const& a0); -BOOST_PYTHON_DECL object unicode(object const& a0, object const& a1); -BOOST_PYTHON_DECL object unicode(object const& a0, const char* a1); -BOOST_PYTHON_DECL object unicode(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object unicode(object const& a0, const char* a1, const char* a2); -BOOST_PYTHON_DECL object vars(); -BOOST_PYTHON_DECL object vars(object const& a0); -template -object xrange(A0 const& a0) -{ - return api_detail::get_func("xrange")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object xrange(object const& a0); -BOOST_PYTHON_DECL object xrange(int a0); -template -object xrange(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("xrange")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object xrange(object const& a0, object const& a1); -BOOST_PYTHON_DECL object xrange(int a0, int a1); -template -object xrange(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("xrange")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -BOOST_PYTHON_DECL object xrange(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object xrange(int a0, int a1, int a2); -BOOST_PYTHON_DECL object zip(object const& a0); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object compile_string(const char* a0, const char* a1, int a2); -BOOST_PYTHON_DECL int import_append_inittab(const char* a0, void(*a1)(void)); -BOOST_PYTHON_DECL object import_add_module(const char* a0); -BOOST_PYTHON_DECL object import_get_module_dict(); -BOOST_PYTHON_DECL object import_import(object const& a0); -BOOST_PYTHON_DECL object import_import(const char* a0); -BOOST_PYTHON_DECL object import_import_module(const char* a0); -BOOST_PYTHON_DECL object import_import_module_ex(const char* a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object module_get_dict(object const& a0); -BOOST_PYTHON_DECL int object_print(object const& a0, FILE* a1, int a2); -BOOST_PYTHON_DECL object run_file(FILE* a0, const char* a1, int a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL int run_simple_file(FILE* a0, const char* a1); -BOOST_PYTHON_DECL int run_simple_string(const char* a0); -BOOST_PYTHON_DECL object run_string(const char* a0, int a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object call_statement(const char* a0); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1); -template -object call_statement(const char* a0, A1 const& a1) -{ - return api_detail::call_statement(a0, 1, (object const*)api_detail::get_arg(a1)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2) -{ - return api_detail::call_statement(a0, 2, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement(a0, 3, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement(a0, 4, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement(a0, 5, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement(a0, 6, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement(a0, 7, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement(a0, 8, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement(a0, 9, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10) -{ - return api_detail::call_statement(a0, 10, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10)); -} -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10); -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2) -{ - return api_detail::call_statement_du(a0, a1, 1, (object const*)api_detail::get_arg(a2)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement_du(a0, a1, 2, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement_du(a0, a1, 3, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement_du(a0, a1, 4, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement_du(a0, a1, 5, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement_du(a0, a1, 6, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement_du(a0, a1, 7, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement_du(a0, a1, 8, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10) -{ - return api_detail::call_statement_du(a0, a1, 9, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10, A11 const& a11) -{ - return api_detail::call_statement_du(a0, a1, 10, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10), (object const*)api_detail::get_arg(a11)); -} -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10, object const& a11); - -}}} - -#endif // PY_INTERFACE_HPP - diff --git a/include/boost/python/refcount.hpp b/include/boost/python/refcount.hpp deleted file mode 100755 index dce6b266..00000000 --- a/include/boost/python/refcount.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef REFCOUNT_DWA2002615_HPP -# define REFCOUNT_DWA2002615_HPP - -# include -# include - -namespace boost { namespace python { - -template -inline T* incref(T* p) -{ - Py_INCREF(python::upcast(p)); - return p; -} - -template -inline T* xincref(T* p) -{ - Py_XINCREF(python::upcast(p)); - return p; -} - -template -inline void decref(T* p) -{ - Py_DECREF(python::upcast(p)); -} - -template -inline void xdecref(T* p) -{ - Py_XDECREF(python::upcast(p)); -} - -}} // namespace boost::python - -#endif // REFCOUNT_DWA2002615_HPP diff --git a/include/boost/python/reference.hpp b/include/boost/python/reference.hpp deleted file mode 100644 index f070f114..00000000 --- a/include/boost/python/reference.hpp +++ /dev/null @@ -1,236 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef PYPTR_DWA050400_H_ -# define PYPTR_DWA050400_H_ - -# ifdef BOOST_PYTHON_V2 - -# error obsolete - -# else - -# include -# include -# include -# include -# include -# include -# include -# include -# include - -# include - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE - -template -struct py_ptr_conversions : Base -{ - inline friend T from_python(PyObject* x, boost::python::type) - { return T(boost::python::downcast(x).get(), T::increment_count); } - - inline friend T from_python(PyObject* x, boost::python::type) - { return T(boost::python::downcast(x).get(), T::increment_count); } - - inline friend PyObject* to_python(T x) - { return boost::python::as_object(x.release()); } - -}; - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -namespace boost { namespace python { - -BOOST_PYTHON_IMPORT_CONVERSION(py_ptr_conversions); - -template -class reference - : public py_ptr_conversions, T> -{ -public: - typedef T value_type; - - reference(const reference& rhs) - : m_p(rhs.m_p) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XINCREF(m_p); - } - - reference() : m_p(0) {} - - // These are two ways of spelling the same thing, that we need to increment - // the reference count on the pointer when we're initialized. - enum increment_count_t { increment_count }; - - enum allow_null { null_ok }; - - template - explicit reference(T2* x) - : m_p(expect_non_null(x)) - { - assert(m_p->ob_refcnt > 0); - } - - template - reference(T2* x, increment_count_t) - : m_p(expect_non_null(x)) - { - assert(m_p->ob_refcnt > 0); - Py_INCREF(m_p); - } - - template - reference(T2* x, allow_null) - : m_p(x) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - } - - template - reference(T2* x, allow_null, increment_count_t) - : m_p(x) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XINCREF(m_p); - } - - template - reference(T2* x, increment_count_t, allow_null) - : m_p(x) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XINCREF(m_p); - } - - reference& operator=(const reference& rhs) - { - assert(rhs.m_p == 0 || rhs.m_p->ob_refcnt > 0); - Py_XINCREF(static_cast(rhs.m_p)); - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XDECREF(m_p); - m_p = rhs.m_p; - return *this; - } - - ~reference() - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XDECREF(m_p); - } - - T& operator*() const - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - return *m_p; - } - - // MSVC doesn't like boost::dereferencable unless T has a default - // constructor, so operator-> must be defined by hand :( - T* operator->() const - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - return &**this; - } - - T* get() const - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - return m_p; - } - - T* release() - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - T* p = m_p; - m_p = 0; - return p; - } - - void reset() - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XDECREF(m_p); - m_p = 0; - } - - template - void reset(T2* x) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XDECREF(m_p); - m_p = expect_non_null(x); - assert(m_p == 0 || m_p->ob_refcnt > 0); - } - - template - void reset(T2* x, increment_count_t) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XINCREF(x); - Py_XDECREF(m_p); - m_p = expect_non_null(x); - assert(m_p->ob_refcnt > 0); - } - - template - void reset(T2* x, allow_null) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XDECREF(m_p); - m_p = x; - assert(m_p == 0 || m_p->ob_refcnt > 0); - } - - template - void reset(T2* x, allow_null, increment_count_t) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XINCREF(x); - Py_XDECREF(m_p); - m_p = x; - assert(m_p == 0 || m_p->ob_refcnt > 0); - } - - template - void reset(T2* x, increment_count_t, allow_null) - { - assert(m_p == 0 || m_p->ob_refcnt > 0); - Py_XINCREF(x); - Py_XDECREF(m_p); - m_p = x; - assert(m_p == 0 || m_p->ob_refcnt > 0); - } - -#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) -private: - template friend class shared_ptr; -#endif - - inline PyObject* object() const - { - return as_object(m_p); - } - - T* m_p; -}; - -typedef reference ref; - -template -ref make_ref(const T& x) -{ - return ref(to_python(x)); -} - -}} // namespace boost::python - -#endif // BOOST_PYTHON_V2 - -#endif // PYPTR_DWA050400_H_ diff --git a/include/boost/python/reference_existing_object.hpp b/include/boost/python/reference_existing_object.hpp deleted file mode 100644 index e16dcf18..00000000 --- a/include/boost/python/reference_existing_object.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef REFERENCE_EXISTING_OBJECT_DWA200222_HPP -# define REFERENCE_EXISTING_OBJECT_DWA200222_HPP -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct reference_existing_object_requires_a_pointer_or_reference_return_type -# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) - {} -# endif - ; -} - -template struct to_python_value; - -struct reference_existing_object -{ - template - struct apply - { - BOOST_STATIC_CONSTANT( - bool, ok = is_pointer::value || is_reference::value); - - typedef typename mpl::if_c< - ok - , to_python_indirect - , detail::reference_existing_object_requires_a_pointer_or_reference_return_type - >::type type; - }; -}; - -}} // namespace boost::python - -#endif // REFERENCE_EXISTING_OBJECT_DWA200222_HPP diff --git a/include/boost/python/return_internal_reference.hpp b/include/boost/python/return_internal_reference.hpp deleted file mode 100644 index 7e350d77..00000000 --- a/include/boost/python/return_internal_reference.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef RETURN_INTERNAL_REFERENCE_DWA2002131_HPP -# define RETURN_INTERNAL_REFERENCE_DWA2002131_HPP - -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct return_internal_reference_owner_arg_must_be_greater_than_zero -# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) - {} -# endif - ; -} - -template -struct return_internal_reference - : with_custodian_and_ward_postcall<0, owner_arg, BasePolicy_> -{ - private: - BOOST_STATIC_CONSTANT(bool, legal = owner_arg > 0); - public: - typedef typename mpl::if_c< - legal - , reference_existing_object - , detail::return_internal_reference_owner_arg_must_be_greater_than_zero - >::type result_converter; -}; - -}} // namespace boost::python - -#endif // RETURN_INTERNAL_REFERENCE_DWA2002131_HPP diff --git a/include/boost/python/return_value_policy.hpp b/include/boost/python/return_value_policy.hpp deleted file mode 100644 index 0f3c00fe..00000000 --- a/include/boost/python/return_value_policy.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef RETURN_VALUE_POLICY_DWA2002131_HPP -# define RETURN_VALUE_POLICY_DWA2002131_HPP -# include - -namespace boost { namespace python { - -template -struct return_value_policy : BasePolicy_ -{ - typedef ResultConverterGenerator result_converter; -}; - -}} // namespace boost::python - -#endif // RETURN_VALUE_POLICY_DWA2002131_HPP diff --git a/include/boost/python/scope.hpp b/include/boost/python/scope.hpp deleted file mode 100644 index 7262f8da..00000000 --- a/include/boost/python/scope.hpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef SCOPE_DWA2002724_HPP -# define SCOPE_DWA2002724_HPP - -# include -# include -# include - -namespace boost { namespace python { - -class BOOST_PYTHON_DECL scope - : public object, private noncopyable -{ - public: - inline scope(object const&); - inline scope(); - inline ~scope(); - - private: // data members - PyObject* m_previous_scope; - - private: // static members - - // Use a PyObject* to avoid problems with static destruction after Py_Finalize - static PyObject* current_scope; -}; - -inline scope::scope(object const& new_scope) - : object(new_scope) - , m_previous_scope(current_scope) -{ - current_scope = python::incref(new_scope.ptr()); -} - -inline scope::scope() - : object(detail::borrowed_reference( - current_scope ? current_scope : Py_None - )) - , m_previous_scope(python::xincref(current_scope)) -{ -} - -inline scope::~scope() -{ - python::xdecref(current_scope); - current_scope = m_previous_scope; -} - -namespace converter -{ - template <> - struct object_manager_traits - : object_manager_traits - { - }; -} - -}} // namespace boost::python - -#endif // SCOPE_DWA2002724_HPP diff --git a/include/boost/python/self.hpp b/include/boost/python/self.hpp deleted file mode 100755 index c7d3f670..00000000 --- a/include/boost/python/self.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef SELF_DWA2002531_HPP -# define SELF_DWA2002531_HPP - -# include - -namespace boost { namespace python { - -//# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 -# define BOOST_PYTHON_SELF_IS_CLASS -//# endif - -// Sink self_t into its own namespace so that we have a safe place to -// put the completely general operator templates which operate on -// it. It is possible to avoid this, but it turns out to be much more -// complicated and finally GCC 2.95.2 chokes on it. -namespace self_ns -{ -# ifndef BOOST_PYTHON_SELF_IS_CLASS - enum self_t { self }; -# else - struct self_t {}; - extern BOOST_PYTHON_DECL self_t self; -# endif -} - -using self_ns::self_t; -using self_ns::self; - -}} // namespace boost::python - -#endif // SELF_DWA2002531_HPP diff --git a/include/boost/python/signature.hpp b/include/boost/python/signature.hpp deleted file mode 100644 index bd4b26df..00000000 --- a/include/boost/python/signature.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -// -/////////////////////////////////////////////////////////////////////////////// -#if !defined(BOOST_PP_IS_ITERATING) - -# ifndef SIGNATURE_JDG20020813_HPP -# define SIGNATURE_JDG20020813_HPP - -# include -# include -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include - -# define BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(n) \ - BOOST_PP_CAT(mpl::list, BOOST_PP_INC(n)) - -# define BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(n) \ - BOOST_PP_CAT(mpl::list, BOOST_PP_INC(BOOST_PP_INC(n))) - - -/////////////////////////////////////////////////////////////////////////////// -namespace boost { namespace python { namespace detail { - -/////////////////////////////////////////////////////////////////////////////// -// -// The following macros generate expansions for: -// -// template -// inline mpl::list -// get_signature(RT(*)(T0...TN)) -// { -// return mpl::list(); -// } -// -// template -// inline mpl::list -// get_signature(RT(ClassT::*)(T0...TN))) -// { -// return mpl::list(); -// } -// -// template -// inline mpl::list -// get_signature(RT(ClassT::*)(T0...TN) const)) -// { -// return mpl::list(); -// } -// -// These functions extract the return type, class (for member functions) -// and arguments of the input signature and stuffs them in an mpl::list. -// -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -# define BOOST_PP_ITERATION_PARAMS_1 \ - (3, (0, BOOST_PYTHON_MAX_ARITY-1, )) - -# include BOOST_PP_ITERATE() - -} - -}} // namespace boost::python - - -# undef BOOST_PYTHON_FUNCTION_SIGNATURE_LIST -# undef BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST - -/////////////////////////////////////////////////////////////////////////////// -# endif // SIGNATURE_JDG20020813_HPP - -#else // defined(BOOST_PP_IS_ITERATING) - -# define N BOOST_PP_ITERATION() - -template < - class RT BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)> -inline BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(N)< - RT BOOST_PP_ENUM_TRAILING_PARAMS(N, T)> -get_signature(RT(*)(BOOST_PP_ENUM_PARAMS(N, T))) -{ - return BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(N)< - RT BOOST_PP_ENUM_TRAILING_PARAMS(N, T) - >(); -} - -/////////////////////////////////////////////////////////////////////////////// -#if N <= (BOOST_PYTHON_MAX_ARITY - 2) - -template < - class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)> -inline BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< - RT, ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, T)> -get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(N, T))) -{ - return BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< - RT, ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, T)>(); -} - -/////////////////////////////////////// -template < - class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)> -inline BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< - RT, ClassT const BOOST_PP_ENUM_TRAILING_PARAMS(N, T)> -get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(N, T)) const) -{ - return BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< - RT, ClassT const BOOST_PP_ENUM_TRAILING_PARAMS(N, T)>(); -} - -#endif // N < (BOOST_PYTHON_MAX_ARITY - 2) - -#endif // !defined(BOOST_PP_IS_ITERATING) diff --git a/include/boost/python/slice_nil.hpp b/include/boost/python/slice_nil.hpp deleted file mode 100644 index cb169116..00000000 --- a/include/boost/python/slice_nil.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef SLICE_NIL_DWA2002620_HPP -# define SLICE_NIL_DWA2002620_HPP - -namespace boost { namespace python { namespace api { - -class object; - -enum slice_nil -{ -# ifndef _ // Watch out for GNU gettext users, who #define _(x) - _ -# endif -}; - -template -struct slice_bound -{ - typedef object type; -}; - -template <> -struct slice_bound -{ - typedef slice_nil type; -}; - -} - -using api::slice_nil; -# ifndef _ // Watch out for GNU gettext users, who #define _(x) -using api::_; -# endif - -}} // namespace boost::python - -#endif // SLICE_NIL_DWA2002620_HPP diff --git a/include/boost/python/str.hpp b/include/boost/python/str.hpp deleted file mode 100644 index fb8bfe58..00000000 --- a/include/boost/python/str.hpp +++ /dev/null @@ -1,375 +0,0 @@ -#ifndef STR_20020703_HPP -#define STR_20020703_HPP - -#include -#include -#include - -// disable defines in provided by some system libraries -#undef isspace -#undef islower -#undef isalpha -#undef isdigit -#undef isalnum -#undef isupper - -namespace boost { namespace python { - -class str : public object -{ - public: - BOOST_PYTHON_DECL str(); // new str - - BOOST_PYTHON_DECL str(const char* s); // new str - explicit BOOST_PYTHON_DECL str(object_cref other); - - template - explicit str(T const& other) - : object(str::call(object(other))) - { - } - - BOOST_PYTHON_DECL str capitalize() const ; - - BOOST_PYTHON_DECL str center(object_cref width) const ; - - template - str center(T const& width) const - { - return this->center(object(width)); - } - - BOOST_PYTHON_DECL long count(object_cref sub) const; - - template - long count(T const& sub) const - { - return this->count(object(sub)); - } - - BOOST_PYTHON_DECL long count(object_cref sub, object_cref start) const; - - template - long count(T1 const& sub,T2 const& start) const - { - return this->count(object(sub), object(start)); - } - - BOOST_PYTHON_DECL long count(object_cref sub, object_cref start, object_cref end) const; - - template - long count(T1 const& sub,T2 const& start, T3 const& end) const - { - return this->count(object(sub), object(start)); - } - - BOOST_PYTHON_DECL object decode() const; - BOOST_PYTHON_DECL object decode(object_cref encoding) const; - - template - object decode(T const& encoding) const - { - return this->decode(object(encoding)); - } - - BOOST_PYTHON_DECL object decode(object_cref encoding, object_cref errors) const; - - template - object decode(T1 const& encoding, T2 const& errors) const - { - return this->decode(object(encoding),object(errors)); - } - - BOOST_PYTHON_DECL object encode() const; - BOOST_PYTHON_DECL object encode(object_cref encoding) const; - - template - object encode(T const& encoding) const - { - return this->encode(object(encoding)); - } - - BOOST_PYTHON_DECL object encode(object_cref encoding, object_cref errors) const; - - template - object encode(T1 const& encoding, T2 const& errors) const - { - return this->encode(object(encoding),object(errors)); - } - - BOOST_PYTHON_DECL bool endswith(object_cref suffix) const; - - template - bool endswith(T const& suffix) const - { - return this->endswith(object(suffix)); - } - - BOOST_PYTHON_DECL bool endswith(object_cref suffix, object_cref start) const; - - template - bool endswith(T1 const& suffix, T2 const& start) const - { - return this->endswith(object(suffix), object(start)); - } - - BOOST_PYTHON_DECL bool endswith(object_cref suffix, object_cref start, object_cref end) const; - - template - bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const - { - return this->endswith(object(suffix), object(start), object(end)); - } - - BOOST_PYTHON_DECL str expandtabs() const; - BOOST_PYTHON_DECL str expandtabs(object_cref tabsize) const; - - template - str expandtabs(T const& tabsize) const - { - return this->expandtabs(object(tabsize)); - } - - BOOST_PYTHON_DECL long find(object_cref sub) const; - - template - long find(T const& sub) const - { - return this->find(object(sub)); - } - - BOOST_PYTHON_DECL long find(object_cref sub, object_cref start) const; - - template - long find(T1 const& sub, T2 const& start) const - { - return this->find(object(sub), object(start)); - } - - BOOST_PYTHON_DECL long find(object_cref sub, object_cref start, object_cref end) const; - - template - long find(T1 const& sub, T2 const& start, T3 const& end) const - { - return this->find(object(sub), object(start), object(end)); - } - - BOOST_PYTHON_DECL long index(object_cref sub) const; - - template - long index(T const& sub) const - { - return this->index(object(sub)); - } - - BOOST_PYTHON_DECL long index(object_cref sub, object_cref start) const; - - template - long index(T1 const& sub, T2 const& start) const - { - return this->index(object(sub), object(start)); - } - - BOOST_PYTHON_DECL long index(object_cref sub, object_cref start, object_cref end) const; - - template - long index(T1 const& sub, T2 const& start, T3 const& end) const - { - return this->index(object(sub), object(start), object(end)); - } - - BOOST_PYTHON_DECL bool isalnum() const; - BOOST_PYTHON_DECL bool isalpha() const; - BOOST_PYTHON_DECL bool isdigit() const; - BOOST_PYTHON_DECL bool islower() const; - BOOST_PYTHON_DECL bool isspace() const; - BOOST_PYTHON_DECL bool istitle() const; - BOOST_PYTHON_DECL bool isupper() const; - - BOOST_PYTHON_DECL str join(object_cref sequence) const; - - template - str join(T const& sequence) const - { - return this->join(object(sequence)); - } - - BOOST_PYTHON_DECL str ljust(object_cref width) const; - - template - str ljust(T const& width) const - { - return this->ljust(object(width)); - } - - BOOST_PYTHON_DECL str lower() const; - BOOST_PYTHON_DECL str lstrip() const; - - BOOST_PYTHON_DECL str replace(object_cref old, object_cref new_) const ; - - template - str replace(T1 const& old, T2 const& new_) const - { - return this->replace(object(old),object(new_)); - } - - BOOST_PYTHON_DECL str replace(object_cref old, object_cref new_, object_cref maxsplit) const ; - - template - str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const - { - return this->replace(object(old),object(new_),object(maxsplit)); - } - - BOOST_PYTHON_DECL long rfind(object_cref sub) const; - - template - long rfind(T const& sub) const - { - return this->rfind(object(sub)); - } - - BOOST_PYTHON_DECL long rfind(object_cref sub, object_cref start) const; - - template - long rfind(T1 const& sub, T2 const& start) const - { - return this->rfind(object(sub), object(start)); - } - - BOOST_PYTHON_DECL long rfind(object_cref sub, object_cref start, object_cref end) const; - - template - long rfind(T1 const& sub, T2 const& start, T3 const& end) const - { - return this->rfind(object(sub), object(start), object(end)); - } - - BOOST_PYTHON_DECL long rindex(object_cref sub) const; - - template - long rindex(T const& sub) const - { - return this->rindex(object(sub)); - } - - BOOST_PYTHON_DECL long rindex(object_cref sub, object_cref start) const; - - template - long rindex(T1 const& sub, T2 const& start) const - { - return this->rindex(object(sub), object(start)); - } - - BOOST_PYTHON_DECL long rindex(object_cref sub, object_cref start, object_cref end) const; - - template - long rindex(T1 const& sub, T2 const& start, T3 const& end) const - { - return this->rindex(object(sub), object(start), object(end)); - } - - BOOST_PYTHON_DECL str rjust(object_cref width) const; - - template - str rjust(T const& width) const - { - return this->rjust(object(width)); - } - - BOOST_PYTHON_DECL str rstrip() const; - - BOOST_PYTHON_DECL list split() const; - BOOST_PYTHON_DECL list split(object_cref sep) const; - - template - list split(T const& sep) const - { - return this->split(object(sep)); - } - - BOOST_PYTHON_DECL list split(object_cref sep, object_cref maxsplit) const; - - template - list split(T1 const& sep, T2 const& maxsplit) const - { - return this->split(object(sep), object(maxsplit)); - } - - BOOST_PYTHON_DECL list splitlines() const; - BOOST_PYTHON_DECL list splitlines(object_cref keepends) const; - - template - list splitlines(T const& keepends) const - { - return this->splitlines(object(keepends)); - } - - BOOST_PYTHON_DECL bool startswith(object_cref prefix) const ; - - template - bool startswith(T const& prefix) const - { - return this->startswith(object(prefix)); - } - - BOOST_PYTHON_DECL bool startswith(object_cref prefix, object_cref start) const ; - - template - bool startswidth(T1 const& prefix, T2 const& start) const - { - return this->startswidth(object(prefix), object(start)); - } - - BOOST_PYTHON_DECL bool startswith(object_cref prefix, object_cref start, object_cref end) const ; - - template - bool startswidth(T1 const& prefix, T2 const& start, T3 const& end) const - { - return this->startswidth(object(prefix), object(start), object(end)); - } - - BOOST_PYTHON_DECL str strip() const ; - BOOST_PYTHON_DECL str swapcase() const ; - BOOST_PYTHON_DECL str title() const ; - - BOOST_PYTHON_DECL str translate(object_cref table) const; - - template - str translate(T const& table) const - { - return this->translate(object(table)); - } - - BOOST_PYTHON_DECL str translate(object_cref table, object_cref deletechars) const; - - template - str translate(T1 const& table, T2 const& deletechars) const - { - return this->translate(object(table), object(deletechars)); - } - - BOOST_PYTHON_DECL str upper() const; - - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str) - - private: - static BOOST_PYTHON_DECL detail::new_reference call(object const&); -}; - -// -// Converter Specializations -// -namespace converter -{ - template <> - struct object_manager_traits - : pytype_object_manager_traits<&PyString_Type,str> - { - }; -} - -}} // namespace boost::python - -#endif // STR_20020703_HPP diff --git a/include/boost/python/tag.hpp b/include/boost/python/tag.hpp deleted file mode 100644 index c8ce6878..00000000 --- a/include/boost/python/tag.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TAG_DWA2002720_HPP -# define TAG_DWA2002720_HPP - -namespace boost { namespace python { - -// used only to prevent argument-dependent lookup from finding the -// wrong function in some cases. Cheaper than qualification. -enum tag_t { tag }; - -}} // namespace boost::python - -#endif // TAG_DWA2002720_HPP diff --git a/include/boost/python/to_python_converter.hpp b/include/boost/python/to_python_converter.hpp deleted file mode 100644 index 814b9ba7..00000000 --- a/include/boost/python/to_python_converter.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TO_PYTHON_CONVERTER_DWA200221_HPP -# define TO_PYTHON_CONVERTER_DWA200221_HPP - -# include -# include -# include - -namespace boost { namespace python { - -template -struct to_python_converter -{ - to_python_converter(); -}; - -// -// implementation -// - -template -to_python_converter::to_python_converter() -{ - typedef converter::as_to_python_function< - T, Conversion - > normalized; - - converter::registry::insert( - &normalized::convert - , type_id()); -} - -}} // namespace boost::python - -#endif // TO_PYTHON_CONVERTER_DWA200221_HPP diff --git a/include/boost/python/to_python_indirect.hpp b/include/boost/python/to_python_indirect.hpp deleted file mode 100644 index 23ff8594..00000000 --- a/include/boost/python/to_python_indirect.hpp +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TO_PYTHON_INDIRECT_DWA200221_HPP -# define TO_PYTHON_INDIRECT_DWA200221_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -template -struct to_python_indirect -{ - static bool convertible(); - PyObject* operator()(T ptr) const; - private: - static PyTypeObject* type(); -}; - -// -// implementations -// -namespace detail -{ - struct make_owning_holder - { - typedef PyObject* result_type; - template - static result_type execute(T* p) - { - // can't use auto_ptr with Intel 5 for some reason -# if defined(__ICL) && __ICL < 600 - typedef boost::shared_ptr smart_pointer; -# else - typedef std::auto_ptr smart_pointer; -# endif - typedef objects::pointer_holder holder_t; - - smart_pointer ptr(p); - return objects::make_instance::execute(ptr); - } - }; - - struct make_reference_holder - { - typedef PyObject* result_type; - template - static result_type execute(T* p) - { - typedef objects::pointer_holder holder_t; - return objects::make_instance::execute(p); - } - }; - - struct get_pointer_class - { - typedef PyTypeObject* result_type; - template - static result_type execute(T* p) - { - BOOST_STATIC_ASSERT(is_class::value); - return converter::registered::converters.class_object; - } - }; - - // null_pointer_to_none -- return none() for null pointers and 0 for all other types/values - // - // Uses simulated partial ordering - template - inline PyObject* null_pointer_to_none(T&, int) - { - return 0; - } - - // overload for pointers - template - inline PyObject* null_pointer_to_none(T* x, long) - { - return x == 0 ? python::detail::none() : 0; - } -} - -template -inline bool to_python_indirect::convertible() -{ - BOOST_STATIC_ASSERT(is_pointer::value || is_reference::value); - return type() != 0; -} - -template -inline PyObject* to_python_indirect::operator()(T x) const -{ - PyObject* const null_result = detail::null_pointer_to_none(x, 1L); - if (null_result != 0) - return null_result; - - return detail::unwind_type(x); -} - -template -inline PyTypeObject* to_python_indirect::type() -{ - return detail::unwind_type(); -} - -}} // namespace boost::python - -#endif // TO_PYTHON_INDIRECT_DWA200221_HPP diff --git a/include/boost/python/to_python_value.hpp b/include/boost/python/to_python_value.hpp deleted file mode 100644 index 3b9cd76c..00000000 --- a/include/boost/python/to_python_value.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TO_PYTHON_VALUE_DWA200221_HPP -# define TO_PYTHON_VALUE_DWA200221_HPP - -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - template - struct object_manager_to_python_value - { - typedef typename add_reference< - typename add_const::type - >::type argument_type; - - static bool convertible(); - PyObject* operator()(argument_type) const; - }; - - - template - struct registry_to_python_value - { - typedef typename add_reference< - typename add_const::type - >::type argument_type; - - static bool convertible(); - PyObject* operator()(argument_type) const; - }; -} - -template -struct to_python_value - : mpl::if_c< - boost::type_traits::ice_or< - converter::is_object_manager::value - , converter::is_reference_to_object_manager::value - >::value - - , detail::object_manager_to_python_value - , detail::registry_to_python_value - >::type -{ -}; - -// -// implementation -// -namespace detail -{ - template - inline bool registry_to_python_value::convertible() - { - return converter::registered::converters.to_python != 0; - } - - template - inline PyObject* registry_to_python_value::operator()(argument_type x) const - { - return converter::registered::converters.to_python(&x); - } - - template - inline bool object_manager_to_python_value::convertible() - { - return true; - } - - template - inline PyObject* object_manager_to_python_value::operator()(argument_type x) const - { - return python::upcast( - python::xincref( - get_managed_object(x, tag)) - ); - } -} - -}} // namespace boost::python - -#endif // TO_PYTHON_VALUE_DWA200221_HPP diff --git a/include/boost/python/tuple.hpp b/include/boost/python/tuple.hpp deleted file mode 100644 index 38547696..00000000 --- a/include/boost/python/tuple.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef TUPLE_20020706_HPP -#define TUPLE_20020706_HPP - -#include -#include - -namespace boost { namespace python { - -class tuple : public object -{ - public: - // tuple() -> an empty tuple - BOOST_PYTHON_DECL tuple(); - - // tuple(sequence) -> tuple initialized from sequence's items - BOOST_PYTHON_DECL tuple(object_cref sequence); - - template - explicit tuple(T const& sequence) - : object(tuple::call(object(sequence))) - { - } - - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple) - - private: - static BOOST_PYTHON_DECL detail::new_reference call(object const&); -}; - -// -// Converter Specializations // $$$ JDG $$$ moved here to prevent -// // G++ bug complaining specialization - // provided after instantiation -namespace converter -{ - template <> - struct object_manager_traits - : pytype_object_manager_traits<&PyTuple_Type,tuple> - { - }; -} - -// for completeness -inline tuple make_tuple() { return tuple(); } - -# define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -}} // namespace boost::python - -#endif - diff --git a/include/boost/python/type_from_python.hpp b/include/boost/python/type_from_python.hpp deleted file mode 100644 index 38d2ceea..00000000 --- a/include/boost/python/type_from_python.hpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TYPE_FROM_PYTHON_DWA2002130_HPP -# define TYPE_FROM_PYTHON_DWA2002130_HPP - -# include -# include - -namespace boost { namespace python { - -namespace detail -{ - // Given a pointer-to-function of 1 parameter returning a reference - // type, return the type_id of the function's return type. - template - inline converter::undecorated_type_id_t extractor_type_id(T&(*)(U)) - { - return converter::undecorated_type_id(); - } - - // A function generator whose static execute() function is an lvalue - // from_python converter using the given Extractor. U is expected to - // be the actual type of the PyObject instance from which the result - // is being extracted. - template - struct normalized_extractor - { - static inline void* execute(PyObject* op) - { - typedef typename boost::add_reference::type param; - return &Extractor::execute( - boost::python::detail::void_ptr_to_reference( - op, (param(*)())0 ) - ); - } - }; - - // Given an Extractor type and a pointer to its execute function, - // return a new object whose static execute function does the same - // job but is a conforming lvalue from_python conversion function. - // - // usage: normalize(&Extractor::execute) - template - inline normalized_extractor - normalize(T(*)(U), Extractor* = 0) - { - return normalized_extractor(); - } -} - -// An Extractor which extracts the given member from a Python object -// whose instances are stored as InstanceType. -template -struct member_extractor -{ - static MemberType& execute(InstanceType& c) - { - (void)c.ob_type; // static assertion - return c.*member; - } -}; - -// An Extractor which simply extracts the entire python object -// instance of InstanceType. -template -struct identity_extractor -{ - static InstanceType& execute(InstanceType& c) - { - (void)c.ob_type; // static assertion - return c; - } -}; - -// Registers a from_python conversion which extracts lvalues using -// Extractor's static execute function from Python objects whose type -// object is python_type. -template -struct type_from_python -{ - type_from_python() - { - converter::registry::insert( - &extract, detail::extractor_type_id(&Extractor::execute)); - } - - static void* extract(PyObject* op) - { - return PyObject_TypeCheck(op, const_cast(python_type)) - ? const_cast( - static_cast( - detail::normalize(&Extractor::execute).execute(op))) - : 0 - ; - } -}; - -}} // namespace boost::python - -#endif // TYPE_FROM_PYTHON_DWA2002130_HPP diff --git a/include/boost/python/type_id.hpp b/include/boost/python/type_id.hpp deleted file mode 100755 index cf818fe3..00000000 --- a/include/boost/python/type_id.hpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TYPE_ID_DWA2002517_HPP -# define TYPE_ID_DWA2002517_HPP - -# include -# include -# include -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -// for this compiler at least, cross-shared-library type_info -// comparisons don't work, so use typeid(x).name() instead. It's not -// yet clear what the best default strategy is. -# if (defined(__GNUC__) && __GNUC__ >= 3) \ - || defined(_AIX) \ - || ( defined(__sgi) && defined(__host_mips)) -# define BOOST_PYTHON_TYPE_ID_NAME -# endif - -// type ids which represent the same information as std::type_info -// (i.e. the top-level reference and cv-qualifiers are stripped), but -// which works across shared libraries. -struct type_info : private totally_ordered -{ - inline type_info(std::type_info const& = typeid(void)); - - inline bool operator<(type_info const& rhs) const; - inline bool operator==(type_info const& rhs) const; - - char const* name() const; - friend BOOST_PYTHON_DECL std::ostream& operator<<( - std::ostream&, type_info const&); - - private: // data members -# ifdef BOOST_PYTHON_TYPE_ID_NAME - typedef char const* base_id_t; -# else - typedef std::type_info const* base_id_t; -# endif - - base_id_t m_base_type; -}; - -template -inline type_info type_id(boost::type* = 0) -{ - return type_info( -# if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600) - typeid(T) -# else // strip the decoration which msvc and Intel mistakenly leave in - python::detail::msvc_typeid() -# endif - ); -} - -# if defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 -// Older EDG-based compilers seems to mistakenly distinguish "int" from -// "signed int", etc., but only in typeid() expressions. However -// though int == signed int, the "signed" decoration is propagated -// down into template instantiations. Explicit specialization stops -// that from taking hold. - -# define BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(T) \ -template <> \ -inline type_info type_id(boost::type*) \ -{ \ - return type_info(typeid(T)); \ -} - -BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(short) -BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(int) -BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(long) -// using Python's macro instead of Boost's - we don't seem to get the -// config right all the time. -# ifdef HAVE_LONG_LONG -BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(long long) -# endif -# undef BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID -# endif - - -inline type_info::type_info(std::type_info const& id) - : m_base_type( -# ifdef BOOST_PYTHON_TYPE_ID_NAME - id.name() -# else - &id -# endif - ) -{ -} - -inline bool type_info::operator<(type_info const& rhs) const -{ -# ifdef BOOST_PYTHON_TYPE_ID_NAME - return std::strcmp(m_base_type, rhs.m_base_type) < 0; -# else - return m_base_type->before(*rhs.m_base_type); -# endif -} - -inline bool type_info::operator==(type_info const& rhs) const -{ -# ifdef BOOST_PYTHON_TYPE_ID_NAME - return !std::strcmp(m_base_type, rhs.m_base_type); -# else - return *m_base_type == *rhs.m_base_type; -# endif -} - -inline char const* type_info::name() const -{ -# ifdef BOOST_PYTHON_TYPE_ID_NAME - return m_base_type; -# else - return m_base_type->name(); -# endif -} - - -BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_info const&); - -}} // namespace boost::python - -#endif // TYPE_ID_DWA2002517_HPP diff --git a/include/boost/python/with_custodian_and_ward.hpp b/include/boost/python/with_custodian_and_ward.hpp deleted file mode 100644 index 4d022448..00000000 --- a/include/boost/python/with_custodian_and_ward.hpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef WITH_CUSTODIAN_AND_WARD_DWA2002131_HPP -# define WITH_CUSTODIAN_AND_WARD_DWA2002131_HPP - -# include -# include - -namespace boost { namespace python { - -template -struct with_custodian_and_ward : BasePolicy_ -{ - static bool precall(PyObject* args); -}; - -template -struct with_custodian_and_ward_postcall : BasePolicy_ -{ - static PyObject* postcall(PyObject* args, PyObject* result); -}; - -// -// implementations -// -template -bool with_custodian_and_ward::precall(PyObject* args_) -{ - BOOST_STATIC_ASSERT(custodian != ward); - BOOST_STATIC_ASSERT(custodian > 0); - BOOST_STATIC_ASSERT(ward > 0); - - PyObject* patient = PyTuple_GetItem(args_, ward - 1); - if (patient == 0) return false; - PyObject* nurse = PyTuple_GetItem(args_, custodian - 1); - if (nurse == 0) return false; - - PyObject* life_support = python::objects::make_nurse_and_patient(nurse, patient); - if (life_support == 0) - return false; - - bool result = BasePolicy_::precall(args_); - - if (!result) - Py_XDECREF(life_support); - - return result; -} - -template -PyObject* with_custodian_and_ward_postcall::postcall(PyObject* args_, PyObject* result) -{ - BOOST_STATIC_ASSERT(custodian != ward); - - PyObject* patient = ward > 0 ? PyTuple_GetItem(args_, ward - 1) : result; - if (patient == 0) return 0; - - PyObject* nurse = custodian > 0 ? PyTuple_GetItem(args_, custodian - 1) : result; - if (nurse == 0) return 0; - - result = BasePolicy_::postcall(args_, result); - if (result == 0) - return 0; - - if (python::objects::make_nurse_and_patient(nurse, patient) == 0) - { - Py_XDECREF(result); - return 0; - } - return result; -} - -}} // namespace boost::python - -#endif // WITH_CUSTODIAN_AND_WARD_DWA2002131_HPP diff --git a/test/Jamfile b/test/Jamfile deleted file mode 100644 index 511408e8..00000000 --- a/test/Jamfile +++ /dev/null @@ -1,151 +0,0 @@ -subproject libs/python/test ; - -# bring in the rules for python -SEARCH on python.jam = $(BOOST_BUILD_PATH) ; -include python.jam ; -# bring in rules for testing -SEARCH on testing.jam = $(BOOST_BUILD_PATH) ; -include testing.jam ; - -local PYTHON_V1_PROPERTIES = $(PYTHON_PROPERTIES) ; -local PYTHON_PROPERTIES = $(BOOST_PYTHON_V2_PROPERTIES) ; - -# Convenience rule makes declaring tests faster -rule bpl-test ( name ? : files * ) -{ - files ?= $(name).py $(name).cpp ; - - local modules ; - local py ; - for local f in $(files) - { - if $(f:S) = .py - { - if $(py) - { - EXIT too many python drivers specified: "$(py)" "$(f)" ; - } - py = $(f) ; - } - } - - name ?= $(py:S=) ; - - for local f in $(files) - { - if $(f:S) != .py - { - local m = $(f:S=) ; - - if $(m) = $(py:S=) - { - m = $(name) ; - - if $(m) = $(py:S=) - { - m = $(m)_ext ; - } - } - extension $(m) : $(f) ../bpl ; - modules += $(m) ; - } - } - - boost-python-runtest $(name) : $(py) $(modules) ; -} - -bpl-test enum ; -bpl-test minimal ; -bpl-test docstring ; -bpl-test exception_translator ; -bpl-test pearu1 : test_cltree.py cltree.cpp ; -bpl-test try : newtest.py m1.cpp m2.cpp ; -bpl-test builtin_converters : test_builtin_converters.py test_builtin_converters.cpp ; -bpl-test test_pointer_adoption ; -bpl-test operators ; -bpl-test callbacks ; -bpl-test defaults ; - -bpl-test object ; -bpl-test list ; -bpl-test long ; -bpl-test dict ; -bpl-test tuple ; -bpl-test str ; - -bpl-test virtual_functions ; -bpl-test back_reference ; -bpl-test implicit ; -bpl-test data_members ; - -bpl-test bienstman1 ; -bpl-test bienstman2 ; -bpl-test bienstman3 ; -bpl-test multi_arg_constructor ; -bpl-test iterator : iterator.py iterator.cpp input_iterator.cpp ; - -bpl-test extract ; - -bpl-test pickle1 ; -bpl-test pickle2 ; -bpl-test pickle3 ; - -bpl-test nested ; - -if $(TEST_BIENSTMAN_NON_BUGS) -{ - bpl-test bienstman4 ; - bpl-test bienstman5 ; -} - -# --- unit tests of library components --- - -local UNIT_TEST_PROPERTIES = - [ difference $(PYTHON_PROPERTIES) : BOOST_PYTHON_DYNAMIC_LIB ] BOOST_PYTHON_STATIC_LIB ; - -run indirect_traits_test.cpp ; -run destroy_test.cpp ; -run pointer_type_id_test.cpp ../../test/build/test_exec_monitor : : : $(UNIT_TEST_PROPERTIES) ; -run member_function_cast.cpp ; -run bases.cpp ; -run if_else.cpp ; -run pointee.cpp ; -run result.cpp ; - -compile string_literal.cpp ; -compile borrowed.cpp : $(UNIT_TEST_PROPERTIES) ; -compile object_manager.cpp : $(UNIT_TEST_PROPERTIES) ; - -run upcast.cpp ../../test/build/test_exec_monitor - : # command-line args - : # input files - : $(UNIT_TEST_PROPERTIES) - ; - -run select_holder.cpp ../../test/build/test_exec_monitor - : # command-line args - : # input files - : $(UNIT_TEST_PROPERTIES) - ; - - -run select_from_python_test.cpp ../src/converter/type_id.cpp ../../test/build/test_exec_monitor - : # command-line args - : # input files - : $(UNIT_TEST_PROPERTIES) - ; - -run select_arg_to_python_test.cpp ../src/converter/type_id.cpp ../../test/build/test_exec_monitor - : # command-line args - : # input files - : $(UNIT_TEST_PROPERTIES) - ; - -if $(TEST_EXPECTED_FAILURES) -{ - compile-fail ./raw_pyobject_fail1.cpp : $(PYTHON_PROPERTIES) ; - compile-fail ./raw_pyobject_fail2.cpp : $(PYTHON_PROPERTIES) ; - compile-fail ./object_fail1.cpp : $(PYTHON_PROPERTIES) ; -} - - diff --git a/test/back_reference.cpp b/test/back_reference.cpp deleted file mode 100644 index d5ae5ece..00000000 --- a/test/back_reference.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// This test shows that a class can be wrapped "as itself" but also -// acquire a back-reference iff has_back_reference<> is appropriately -// specialized. -using namespace boost::python; - -struct X -{ - explicit X(int x) : x(x), magic(7654321) { ++counter; } - X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } - virtual ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } - - void set(int x) { assert(magic == 7654321); this->x = x; } - int value() const { assert(magic == 7654321); return x; } - static int count() { return counter; } - private: - void operator=(X const&); - private: - int x; - long magic; - static int counter; -}; - -int X::counter; - -struct Y : X -{ - Y(PyObject* self, int x) : X(x) {}; - Y(PyObject* self, Y const& rhs) : X(rhs), self(self) {}; - private: - Y(Y const&); - PyObject* self; -}; - -struct Z : X -{ - Z(PyObject* self, int x) : X(x) {}; - Z(PyObject* self, Z const& rhs) : X(rhs), self(self) {}; - private: - Z(Z const&); - PyObject* self; -}; - -Y const& copy_Y(Y const& y) { return y; } -Z const& copy_Z(Z const& z) { return z; } - -namespace boost { namespace python -{ - template <> - struct has_back_reference - { - BOOST_STATIC_CONSTANT(bool, value = true); - }; - - template <> - struct has_back_reference - { - BOOST_STATIC_CONSTANT(bool, value = true); - }; -}} - -// prove that back_references get initialized with the right PyObject* -object y_identity(back_reference y) -{ - return y.source(); -} - -// prove that back_references contain the right value -bool y_equality(back_reference y1, Y const& y2) -{ - return &y1.get() == &y2; -} - -BOOST_PYTHON_MODULE_INIT(back_reference_ext) -{ - def("copy_Y", copy_Y, return_value_policy()); - def("copy_Z", copy_Z, return_value_policy()); - def("x_instances", &X::count); - - class_("Y", init()) - .def("value", &Y::value) - .def("set", &Y::set) - ; - - class_ >("Z", init()) - .def("value", &Z::value) - .def("set", &Z::set) - ; - - def("y_identity", y_identity); - def("y_equality", y_equality); - -} - -#include "module_tail.cpp" diff --git a/test/back_reference.py b/test/back_reference.py deleted file mode 100644 index 21d5d1c0..00000000 --- a/test/back_reference.py +++ /dev/null @@ -1,30 +0,0 @@ -''' ->>> from back_reference_ext import * ->>> y = Y(3) ->>> z = Z(4) ->>> x_instances() -2 ->>> y2 = copy_Y(y) ->>> x_instances() -3 ->>> z2 = copy_Z(z) ->>> x_instances() -4 ->>> y_identity(y) is y -1 ->>> y_equality(y, y) -1 -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/bases.cpp b/test/bases.cpp deleted file mode 100644 index e4f91990..00000000 --- a/test/bases.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include - -struct A; -struct B; - -template -struct choose_bases - : boost::python::detail::select_bases< - X - , typename boost::python::detail::select_bases< - Y - , typename boost::python::detail::select_bases::type - >::type> -{ - -}; - -int main() -{ - BOOST_STATIC_ASSERT((boost::python::detail::specifies_bases< - boost::python::bases >::value)); - - BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< - boost::python::bases& >::value)); - - BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< - void* >::value)); - - BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< - int >::value)); - - BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< - int[5] >::value)); - - typedef boost::python::detail::select_bases< - int - , boost::python::detail::select_bases::type > collected1; - - BOOST_STATIC_ASSERT((boost::is_same >::value)); - BOOST_STATIC_ASSERT((boost::is_same::type,boost::python::bases<> >::value)); - - typedef boost::python::detail::select_bases< - int - , boost::python::detail::select_bases< - boost::python::bases - , boost::python::detail::select_bases< - A - >::type - >::type - > collected2; - - BOOST_STATIC_ASSERT((boost::is_same >::value)); - BOOST_STATIC_ASSERT((boost::is_same,long>::type,boost::python::bases >::value)); - - return 0; -} diff --git a/test/bienstman1.cpp b/test/bienstman1.cpp deleted file mode 100644 index b4acf059..00000000 --- a/test/bienstman1.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include -#include -#include - -struct A {}; - -struct V -{ - - virtual void f() = 0; - - const A* inside() {return &a;} - - A a; -}; - -const A* outside(const V& v) {return &v.a;} - -BOOST_PYTHON_MODULE_INIT(bienstman1_ext) -{ - using namespace boost::python; - using boost::shared_ptr; - using boost::python::return_value_policy; - using boost::python::reference_existing_object; - - class_ >("A"); - - class_("V", no_init) - .def("inside", &V::inside, - return_value_policy()) - .def("outside", outside, - return_value_policy()) - ; -} - diff --git a/test/bienstman1.py b/test/bienstman1.py deleted file mode 100644 index d5ec22b5..00000000 --- a/test/bienstman1.py +++ /dev/null @@ -1,18 +0,0 @@ -''' -# Try to reproduce a Numeric interaction bug if Numeric is installed. ->>> from bienstman1_ext import * ->>> try: from Numeric import * -... except: pass -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/bienstman2.cpp b/test/bienstman2.cpp deleted file mode 100644 index dd7ba532..00000000 --- a/test/bienstman2.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -struct C {}; - -struct D {}; - -struct E -{ - const D fe (const C&) {return D();} - const D fe2(const C&, const C&) {return D();} -}; - -BOOST_PYTHON_MODULE_INIT(bienstman2_ext) -{ - using namespace boost::python; - - class_("C"); - class_("D"); - class_("E") - .def("fe", &E::fe) // this compiles. - .def("fe2", &E::fe2) // this doesn't... well, now it does ;-) - ; -} diff --git a/test/bienstman2.py b/test/bienstman2.py deleted file mode 100644 index 45ee4134..00000000 --- a/test/bienstman2.py +++ /dev/null @@ -1,15 +0,0 @@ -''' ->>> import bienstman2_ext -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/bienstman3.cpp b/test/bienstman3.cpp deleted file mode 100644 index 22c7638e..00000000 --- a/test/bienstman3.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -struct V -{ - virtual void f() = 0; -}; - -struct B -{ - B(const V&) {} -}; - -BOOST_PYTHON_MODULE_INIT(bienstman3_ext) -{ - using namespace boost::python; - - class_("V", no_init); - class_("B", init()); - -} diff --git a/test/bienstman3.py b/test/bienstman3.py deleted file mode 100644 index 90efdd53..00000000 --- a/test/bienstman3.py +++ /dev/null @@ -1,25 +0,0 @@ -''' ->>> from bienstman3_ext import * - ->>> try: -... V() -... except RuntimeError, x: -... print x -... else: -... print 'expected an exception' -... -This class cannot be instantiated from Python - -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/bienstman4.cpp b/test/bienstman4.cpp deleted file mode 100644 index ee510f2d..00000000 --- a/test/bienstman4.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -#include -#include -#include -#include -#include - -struct Type1 {}; - -struct Term {Term(Type1 const&) {} }; - -struct Expression {void add(Term const&) {} }; - -BOOST_PYTHON_MODULE_INIT(bienstman4_ext) -{ - using namespace boost::python; - using boost::mpl::list; - - implicitly_convertible(); - - class_("Expression") - .def("add", &Expression::add) - ; - - class_("T1") - ; - - class_("Term", init()) - ; - - Type1 t1; - Expression e; - e.add(t1); -} - diff --git a/test/bienstman4.py b/test/bienstman4.py deleted file mode 100644 index 2fede1fc..00000000 --- a/test/bienstman4.py +++ /dev/null @@ -1,18 +0,0 @@ -''' ->>> from bienstman4_ext import * ->>> t1 = T1() ->>> e = Expression() ->>> e.add(t1) -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/bienstman5.cpp b/test/bienstman5.cpp deleted file mode 100644 index 75fbd8da..00000000 --- a/test/bienstman5.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -#include -#include -#include -#include - -#include - -struct M {M(const std::complex&) {} }; - -BOOST_PYTHON_MODULE_INIT(bienstman5_ext) -{ - using namespace boost::python; - - class_("M", init const&>()) - ; -} - - diff --git a/test/bienstman5.py b/test/bienstman5.py deleted file mode 100644 index 10c35ff4..00000000 --- a/test/bienstman5.py +++ /dev/null @@ -1,16 +0,0 @@ -''' ->>> from bienstman5_ext import * ->>> m = M(1j) -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/borrowed.cpp b/test/borrowed.cpp deleted file mode 100755 index 0f8d3112..00000000 --- a/test/borrowed.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include - -using namespace boost::python; - -template -void assert_borrowed_ptr(T const& x) -{ - BOOST_STATIC_ASSERT(boost::python::detail::is_borrowed_ptr::value); -} - -template -void assert_not_borrowed_ptr(T const& x) -{ - BOOST_STATIC_ASSERT(!boost::python::detail::is_borrowed_ptr::value); -} - -int main() -{ - assert_borrowed_ptr(borrowed((PyObject*)0)); - assert_borrowed_ptr(borrowed((PyTypeObject*)0)); - assert_borrowed_ptr((detail::borrowed const*)0); - assert_borrowed_ptr((detail::borrowed volatile*)0); - assert_borrowed_ptr((detail::borrowed const volatile*)0); - assert_not_borrowed_ptr((PyObject*)0); - assert_not_borrowed_ptr(0); - return 0; -} diff --git a/test/callbacks.cpp b/test/callbacks.cpp deleted file mode 100644 index 763dcda8..00000000 --- a/test/callbacks.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -//#include -#include -#include -#include -#include -#include -#include -#include - -using namespace boost::python; -BOOST_STATIC_ASSERT(converter::is_object_manager >::value); - -int apply_int_int(PyObject* f, int x) -{ - return call(f, x); -} - -void apply_void_int(PyObject* f, int x) -{ - call(f, x); -} - -struct X -{ - explicit X(int x) : x(x), magic(7654321) { ++counter; } - X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } - ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } - - void set(int x) { assert(magic == 7654321); this->x = x; } - int value() const { assert(magic == 7654321); return x; } - static int count() { return counter; } - private: - void operator=(X const&); - private: - int x; - long magic; - static int counter; -}; - -X apply_X_X(PyObject* f, X x) -{ - return call(f, x); -} - -void apply_void_X_ref(PyObject* f, X& x) -{ - call(f, boost::ref(x)); -} - -X& apply_X_ref_handle(PyObject* f, handle<> obj) -{ - return call(f, obj); -} - -X* apply_X_ptr_handle_cref(PyObject* f, handle<> const& obj) -{ - return call(f, obj); -} - -void apply_void_X_cref(PyObject* f, X const& x) -{ - call(f, boost::cref(x)); -} - -void apply_void_X_ptr(PyObject* f, X* x) -{ - call(f, ptr(x)); -} - -void apply_void_X_deep_ptr(PyObject* f, X* x) -{ - call(f, x); -} - -char const* apply_cstring_cstring(PyObject* f, char const* s) -{ - return call(f, s); -} - -char const* apply_cstring_pyobject(PyObject* f, PyObject* s) -{ - return call(f, borrowed(s)); -} - -char apply_char_char(PyObject* f, char c) -{ - return call(f, c); -} - -char const* apply_to_string_literal(PyObject* f) -{ - return call(f, "hello, world"); -} - -handle<> apply_to_own_type(handle<> x) -{ - // Tests that we can return handle<> from a callback and that we - // can pass arbitrary handle. - return call >(x.get(), type_handle(borrowed(x->ob_type))); -} - -object apply_object_object(PyObject* f, object x) -{ - return call(f, x); -} - -int X::counter; - -BOOST_PYTHON_MODULE_INIT(callbacks_ext) -{ - def("apply_object_object", apply_object_object); - def("apply_to_own_type", apply_to_own_type); - def("apply_int_int", apply_int_int); - def("apply_void_int", apply_void_int); - def("apply_X_X", apply_X_X); - def("apply_void_X_ref", apply_void_X_ref); - def("apply_void_X_cref", apply_void_X_cref); - def("apply_void_X_ptr", apply_void_X_ptr); - def("apply_void_X_deep_ptr", apply_void_X_deep_ptr); - - def("apply_X_ptr_handle_cref", apply_X_ptr_handle_cref - , return_value_policy()); - - def("apply_X_ref_handle", apply_X_ref_handle - , return_value_policy()); - - def("apply_cstring_cstring", apply_cstring_cstring); - def("apply_cstring_pyobject", apply_cstring_pyobject); - def("apply_char_char", apply_char_char); - def("apply_to_string_literal", apply_to_string_literal); - - - class_("X", init()) - .def(init()) - .def("value", &X::value) - .def("set", &X::set) - ; - - def("x_count", &X::count); -} - -#include "module_tail.cpp" diff --git a/test/callbacks.py b/test/callbacks.py deleted file mode 100644 index 937961fd..00000000 --- a/test/callbacks.py +++ /dev/null @@ -1,133 +0,0 @@ -''' ->>> from callbacks_ext import * - ->>> def double(x): -... return x + x -... ->>> apply_int_int(double, 42) -84 ->>> apply_void_int(double, 42) - ->>> def identity(x): -... return x - -Once we have array conversion support, this test will fail. Er, -succeed: - ->>> try: apply_to_string_literal(identity) -... except: pass # expected -... else: print 'expected an exception!' - ->>> x = apply_X_X(identity, X(42)) ->>> x.value() -42 ->>> x_count() -1 ->>> del x ->>> x_count() -0 - ->>> def increment(x): -... x.set(x.value() + 1) -... ->>> x = X(42) ->>> apply_void_X_ref(increment, x) ->>> x.value() -43 - ->>> apply_void_X_cref(increment, x) ->>> x.value() # const-ness is not respected, sorry! -44 - ->>> last_x = 1 ->>> def decrement(x): -... global last_x -... last_x = x -... if x is not None: -... x.set(x.value() - 1) - ->>> apply_void_X_ptr(decrement, x) ->>> x.value() -43 ->>> last_x.value() -43 ->>> increment(last_x) ->>> x.value() -44 ->>> last_x.value() -44 - ->>> apply_void_X_ptr(decrement, None) ->>> assert last_x is None ->>> x.value() -44 - ->>> last_x = 1 ->>> apply_void_X_deep_ptr(decrement, None) ->>> assert last_x is None ->>> x.value() -44 - ->>> apply_void_X_deep_ptr(decrement, x) ->>> x.value() -44 ->>> last_x.value() -43 - ->>> y = apply_X_ref_handle(identity, x) ->>> assert y.value() == x.value() ->>> increment(x) ->>> assert y.value() == x.value() - ->>> y = apply_X_ptr_handle_cref(identity, x) ->>> assert y.value() == x.value() ->>> increment(x) ->>> assert y.value() == x.value() - ->>> y = apply_X_ptr_handle_cref(identity, None) ->>> y - ->>> def new_x(ignored): -... return X(666) -... ->>> try: apply_X_ref_handle(new_x, 1) -... except ReferenceError: pass -... else: print 'no error' - ->>> try: apply_X_ptr_handle_cref(new_x, 1) -... except ReferenceError: pass -... else: print 'no error' - ->>> try: apply_cstring_cstring(identity, 'hello') -... except ReferenceError: pass -... else: print 'no error' - ->>> apply_char_char(identity, 'x') -'x' - ->>> apply_cstring_pyobject(identity, 'hello') -'hello' - ->>> apply_cstring_pyobject(identity, None) - - ->>> apply_char_char(identity, 'x') -'x' - ->>> assert apply_to_own_type(identity) is type(identity) - ->>> assert apply_object_object(identity, identity) is identity -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/cltree.cpp b/test/cltree.cpp deleted file mode 100755 index f7ea9eeb..00000000 --- a/test/cltree.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include - -/* Non-modifiable definitions */ - -class basic { -public: - basic() { name = "cltree.basic"; } - std::string repr() { return name+"()"; } -protected: - std::string name; -}; - -class constant: public basic { -public: - constant() { name = "cltree.constant"; } -}; - -class symbol: public basic { -public: - symbol() { name = "cltree.symbol"; } -}; - -class variable: public basic { -public: - variable() { name = "cltree.variable"; } -}; - -/* EOF: Non-modifiable definitions */ - -class symbol_wrapper: public symbol { -public: - symbol_wrapper(PyObject* self): symbol() { - name = "cltree.wrapped_symbol"; - } -}; - -class variable_wrapper: public variable { -public: - variable_wrapper(PyObject* self): variable() { - name = "cltree.wrapped_variable"; - } - - // This constructor is introduced only because cannot use - // boost::noncopyable, see below. - variable_wrapper(PyObject* self,variable v): variable(v) {} - -}; - -BOOST_PYTHON_MODULE_INIT(cltree) -{ - boost::python::class_("basic") - .def("__repr__",&basic::repr) - ; - - boost::python::class_, boost::noncopyable>("constant") - ; - - - boost::python::class_("symbol") - ; - - boost::python::class_, variable_wrapper>("variable") - ; -} - -#include "module_tail.cpp" - diff --git a/test/complicated.hpp b/test/complicated.hpp deleted file mode 100644 index 123c53fe..00000000 --- a/test/complicated.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef COMPLICATED_DWA20011215_HPP -# define COMPLICATED_DWA20011215_HPP -# include - -# include "simple_type.hpp" - -struct complicated -{ - complicated(simple const&, int = 0); - ~complicated(); - - int get_n() const; - - char* s; - int n; -}; - -inline complicated::complicated(simple const&s, int n) - : s(s.s), n(n) -{ - std::cout << "constructing complicated: " << this->s << ", " << n << std::endl; -} - -inline complicated::~complicated() -{ - std::cout << "destroying complicated: " << this->s << ", " << n << std::endl; -} - -inline int complicated::get_n() const -{ - return n; -} - -#endif // COMPLICATED_DWA20011215_HPP diff --git a/test/comprehensive.cpp b/test/comprehensive.cpp deleted file mode 100644 index be638066..00000000 --- a/test/comprehensive.cpp +++ /dev/null @@ -1,1265 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -// Revision History: -// 04 Mar 01 Changed name of extension module so it would work with DebugPython, -// eliminated useless test that aggravated MSVC (David Abrahams) -#include "comprehensive.hpp" -#include -#include // used for portability on broken compilers -#include // for pow() -#include - -#if defined(__sgi) \ - && ( (defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730) \ - && !defined(__GNUC__)) -inline double pow(int x, int y) { return pow(static_cast(x), y); } -#endif - -namespace bpl_test { - -FooCallback::FooCallback(PyObject* self, int x) - : Foo(x), m_self(self) -{ -} - -int FooCallback::add_len(const char* x) const -{ - // Try to call the "add_len" method on the corresponding Python object. - return boost::python::callback::call_method(m_self, "add_len", x); -} - -// A function which Python can call in case bar is not overridden from -// Python. In true Python style, we use a free function taking an initial self -// parameter. This function anywhere needn't be a static member of the callback -// class. The only reason to do it this way is that Foo::add_len is private, and -// FooCallback is already a friend of Foo. -int FooCallback::default_add_len(const Foo* self, const char* x) -{ - // Don't forget the Foo:: qualification, or you'll get an infinite - // recursion! - return self->Foo::add_len(x); -} - -// Since Foo::pure() is pure virtual, we don't need a corresponding -// default_pure(). A failure to override it in Python will result in an -// exception at runtime when pure() is called. -std::string FooCallback::pure() const -{ - return boost::python::callback::call_method(m_self, "pure"); -} - -Foo::PythonClass::PythonClass(boost::python::module_builder& m) - : boost::python::class_builder(m, "Foo") -{ - def(boost::python::constructor()); - def(&Foo::mumble, "mumble"); - def(&Foo::set, "set"); - def(&Foo::call_pure, "call_pure"); - def(&Foo::call_add_len, "call_add_len"); - - // This is the way we add a virtual function that has a default implementation. - def(&Foo::add_len, "add_len", &FooCallback::default_add_len); - - // Since pure() is pure virtual, we are leaving it undefined. - - // And the nested classes. - boost::python::class_builder foo_a(*this, "Foo_A"); - foo_a.def(boost::python::constructor<>()); - foo_a.def(&Foo::Foo_A::mumble, "mumble"); - - boost::python::class_builder foo_b(get_extension_class(), - "Foo_B"); - foo_b.def(boost::python::constructor<>()); - foo_b.def(&Foo::Foo_B::mumble, "mumble"); -} - -BarPythonClass::BarPythonClass(boost::python::module_builder& m) - : boost::python::class_builder(m, "Bar") -{ - def(boost::python::constructor()); - def(&Bar::first, "first"); - def(&Bar::second, "second"); - def(&Bar::pass_baz, "pass_baz"); -} - -BazPythonClass::BazPythonClass(boost::python::module_builder& m) - : boost::python::class_builder(m, "Baz") // optional -{ - def(boost::python::constructor<>()); - def(&Baz::pass_bar, "pass_bar"); - def(&Baz::clone, "clone"); - def(&Baz::create_foo, "create_foo"); - def(&Baz::get_foo_value, "get_foo_value"); - def(&Baz::eat_baz, "eat_baz"); -} - -StringMapPythonClass::StringMapPythonClass(boost::python::module_builder& m) - : boost::python::class_builder(m, "StringMap") -{ - def(boost::python::constructor<>()); - // Some compilers make the target of this function - // pointer the same type as the class in which it is defined (some - // standard library class), instead of StringMap. - def((std::size_t (StringMap::*)()const)&StringMap::size, "__len__"); - - def(&get_item, "__getitem__"); - def(&set_item, "__setitem__"); - def(&del_item, "__delitem__"); -} - -int get_first(const IntPair& p) -{ - return p.first; -} - -void set_first(IntPair& p, int value) -{ - p.first = -value; -} - -void del_first(const IntPair&) -{ - PyErr_SetString(PyExc_AttributeError, "first can't be deleted!"); - boost::python::throw_error_already_set(); -} - -IntPairPythonClass::IntPairPythonClass(boost::python::module_builder& m) - : boost::python::class_builder(m, "IntPair") -{ - def(boost::python::constructor()); - def(&getattr, "__getattr__"); - def(&setattr, "__setattr__"); - def(&delattr, "__delattr__"); - def(&get_first, "__getattr__first__"); - def(&set_first, "__setattr__first__"); - def(&del_first, "__delattr__first__"); -} - -void IntPairPythonClass::setattr(IntPair& x, const std::string& name, int value) -{ - if (name == "second") - { - x.second = value; - } - else - { - PyErr_SetString(PyExc_AttributeError, name.c_str()); - boost::python::throw_error_already_set(); - } -} - -void IntPairPythonClass::delattr(IntPair&, const char*) -{ - PyErr_SetString(PyExc_AttributeError, "Attributes can't be deleted!"); - boost::python::throw_error_already_set(); -} - -int IntPairPythonClass::getattr(const IntPair& p, const std::string& s) -{ - if (s == "second") - { - return p.second; - } - else - { - PyErr_SetString(PyExc_AttributeError, s.c_str()); - boost::python::throw_error_already_set(); - } - return 0; -} - -namespace { namespace file_local { -void throw_key_error_if_end(const StringMap& m, StringMap::const_iterator p, std::size_t key) -{ - if (p == m.end()) - { - PyErr_SetObject(PyExc_KeyError, BOOST_PYTHON_CONVERSION::to_python(key)); - boost::python::throw_error_already_set(); - } -} -}} // namespace ::file_local - -const std::string& StringMapPythonClass::get_item(const StringMap& m, std::size_t key) -{ - const StringMap::const_iterator p = m.find(key); - file_local::throw_key_error_if_end(m, p, key); - return p->second; -} - -void StringMapPythonClass::set_item(StringMap& m, std::size_t key, const std::string& value) -{ - m[key] = value; -} - -void StringMapPythonClass::del_item(StringMap& m, std::size_t key) -{ - const StringMap::iterator p = m.find(key); - file_local::throw_key_error_if_end(m, p, key); - m.erase(p); -} - -// -// Show that polymorphism can work. a DerivedFromFoo object will be passed to -// Python in a smart pointer object. -// -class DerivedFromFoo : public Foo -{ -public: - DerivedFromFoo(int x) : Foo(x) {} - -private: - std::string pure() const - { return "this was never pure!"; } - - int add_len(const char*) const - { return 1000; } -}; - -// -// function implementations -// - -IntPair make_pair(int x, int y) -{ - return std::make_pair(x, y); -} - -const char* Foo::mumble() -{ - return "mumble"; -} - -const char* Foo::Foo_A::mumble() -{ - return "mumble a"; -} - -const char* Foo::Foo_B::mumble() -{ - return "mumble b"; -} - -void Foo::set(long x) -{ - m_x = x; -} - -std::string Foo::call_pure() -{ - return this->pure(); -} - -int Foo::call_add_len(const char* s) const -{ - return this->add_len(s); -} - -int Foo::add_len(const char* s) const // sum the held value and the length of s -{ - return BOOST_CSTD_::strlen(s) + static_cast(m_x); -} - -boost::shared_ptr Baz::create_foo() -{ - return boost::shared_ptr(new DerivedFromFoo(0)); -} - -// Used to check conversion to None -boost::shared_ptr foo_factory(bool create) -{ - return boost::shared_ptr(create ? new DerivedFromFoo(0) : 0); -} - -// Used to check conversion from None -bool foo_ptr_is_null(Foo* p) -{ - return p == 0; -} - -bool foo_shared_ptr_is_null(boost::shared_ptr p) -{ - return p.get() == 0; -} - -// We can accept smart pointer parameters -int Baz::get_foo_value(boost::shared_ptr foo) -{ - return foo->call_add_len(""); -} - -// Show what happens in python when we take ownership from an auto_ptr -void Baz::eat_baz(std::auto_ptr baz) -{ - baz->clone(); // just do something to show that it is valid. -} - -Baz Bar::pass_baz(Baz b) -{ - return b; -} - -std::string stringpair_repr(const StringPair& sp) -{ - return "('" + sp.first + "', '" + sp.second + "')"; -} - -int stringpair_compare(const StringPair& sp1, const StringPair& sp2) -{ - return sp1 < sp2 ? -1 : sp2 < sp1 ? 1 : 0; -} - -boost::python::string range_str(const Range& r) -{ - char buf[200]; - sprintf(buf, "(%d, %d)", r.m_start, r.m_finish); - return boost::python::string(buf); -} - -int range_compare(const Range& r1, const Range& r2) -{ - int d = r1.m_start - r2.m_start; - if (d == 0) - d = r1.m_finish - r2.m_finish; - return d; -} - -long range_hash(const Range& r) -{ - return r.m_start * 123 + r.m_finish; -} - -/************************************************************/ -/* */ -/* some functions to test overloading */ -/* */ -/************************************************************/ - -static std::string testVoid() -{ - return std::string("Hello world!"); -} - -static int testInt(int i) -{ - return i; -} - -static std::string testString(std::string i) -{ - return i; -} - -static int test2(int i1, int i2) -{ - return i1+i2; -} - -static int test3(int i1, int i2, int i3) -{ - return i1+i2+i3; -} - -static int test4(int i1, int i2, int i3, int i4) -{ - return i1+i2+i3+i4; -} - -static int test5(int i1, int i2, int i3, int i4, int i5) -{ - return i1+i2+i3+i4+i5; -} - -/************************************************************/ -/* */ -/* a class to test overloading */ -/* */ -/************************************************************/ - -struct OverloadTest -{ - OverloadTest(): x_(1000) {} - OverloadTest(int x): x_(x) {} - OverloadTest(int x,int y): x_(x+y) { } - OverloadTest(int x,int y,int z): x_(x+y+z) {} - OverloadTest(int x,int y,int z, int a): x_(x+y+z+a) {} - OverloadTest(int x,int y,int z, int a, int b): x_(x+y+z+a+b) {} - - int x() const { return x_; } - void setX(int x) { x_ = x; } - - int p1(int x) { return x; } - int p2(int x, int y) { return x + y; } - int p3(int x, int y, int z) { return x + y + z; } - int p4(int x, int y, int z, int a) { return x + y + z + a; } - int p5(int x, int y, int z, int a, int b) { return x + y + z + a + b; } - private: - int x_; -}; - -static int getX(OverloadTest* u) -{ - return u->x(); -} - - -/************************************************************/ -/* */ -/* classes to test base declarations and conversions */ -/* */ -/************************************************************/ - -struct Dummy -{ - virtual ~Dummy() {} - int dummy_; -}; - -struct Base -{ - virtual int x() const { return 999; }; - virtual ~Base() {} -}; - -// inherit Dummy so that the Base part of Concrete starts at an offset -// otherwise, typecast tests wouldn't be very meaningful -struct Derived1 : public Dummy, public Base -{ - Derived1(int x): x_(x) {} - virtual int x() const { return x_; } - - private: - int x_; -}; - -struct Derived2 : public Dummy, public Base -{ - Derived2(int x): x_(x) {} - virtual int x() const { return x_; } - - private: - int x_; -}; - -static int testUpcast(Base* b) -{ - return b->x(); -} - -static std::auto_ptr derived1Factory(int i) -{ - return std::auto_ptr(i < 0 ? 0 : new Derived1(i)); -} - -static std::auto_ptr derived2Factory(int i) -{ - return std::auto_ptr(new Derived2(i)); -} - -static int testDowncast1(Derived1* d) -{ - return d->x(); -} - -static int testDowncast2(Derived2* d) -{ - return d->x(); -} - -/************************************************************/ -/* */ -/* test classes for interaction of overloading, */ -/* base declarations, and callbacks */ -/* */ -/************************************************************/ - -struct CallbackTestBase -{ - virtual int testCallback(int i) { return callback(i); } - virtual int callback(int i) = 0; - virtual ~CallbackTestBase() {} -}; - -struct CallbackTest : public CallbackTestBase -{ - virtual int callback(int i) { return i + 1; } - virtual std::string callbackString(std::string const & i) { return i + " 1"; } -}; - -struct CallbackTestCallback : public CallbackTest -{ - CallbackTestCallback(PyObject* self) - : m_self(self) - {} - - int callback(int x) - { - return boost::python::callback::call_method(m_self, "callback", x); - } - std::string callbackString(std::string const & x) - { - return boost::python::callback::call_method(m_self, "callback", x); - } - - static int default_callback(CallbackTest* self, int x) - { - return self->CallbackTest::callback(x); - } - static std::string default_callbackString(CallbackTest* self, std::string x) - { - return self->CallbackTest::callbackString(x); - } - - PyObject* m_self; -}; - -int testCallback(CallbackTestBase* b, int i) -{ - return b->testCallback(i); -} - -/************************************************************/ -/* */ -/* test classes for interaction of method lookup */ -/* in the context of inheritance */ -/* */ -/************************************************************/ - -struct A1 { - virtual ~A1() {} - virtual std::string overrideA1() const { return "A1::overrideA1"; } - virtual std::string inheritA1() const { return "A1::inheritA1"; } -}; - -struct A2 { - virtual ~A2() {} - virtual std::string inheritA2() const { return "A2::inheritA2"; } -}; - -struct B1 : A1, A2 { - std::string overrideA1() const { return "B1::overrideA1"; } - virtual std::string overrideB1() const { return "B1::overrideB1"; } -}; - -struct B2 : A1, A2 { - std::string overrideA1() const { return "B2::overrideA1"; } - virtual std::string inheritB2() const { return "B2::inheritB2"; } -}; - -struct C : B1 { - std::string overrideB1() const { return "C::overrideB1"; } -}; - -std::string call_overrideA1(const A1& a) { return a.overrideA1(); } -std::string call_overrideB1(const B1& b) { return b.overrideB1(); } -std::string call_inheritA1(const A1& a) { return a.inheritA1(); } - -std::auto_ptr factoryA1asA1() { return std::auto_ptr(new A1); } -std::auto_ptr factoryB1asA1() { return std::auto_ptr(new B1); } -std::auto_ptr factoryB2asA1() { return std::auto_ptr(new B2); } -std::auto_ptr factoryCasA1() { return std::auto_ptr(new C); } -std::auto_ptr factoryA2asA2() { return std::auto_ptr(new A2); } -std::auto_ptr factoryB1asA2() { return std::auto_ptr(new B1); } -std::auto_ptr factoryB1asB1() { return std::auto_ptr(new B1); } -std::auto_ptr factoryCasB1() { return std::auto_ptr(new C); } - -struct B_callback : B1 { - B_callback(PyObject* self) : m_self(self) {} - - std::string overrideA1() const { return boost::python::callback::call_method(m_self, "overrideA1"); } - std::string overrideB1() const { return boost::python::callback::call_method(m_self, "overrideB1"); } - - static std::string default_overrideA1(B1& x) { return x.B1::overrideA1(); } - static std::string default_overrideB1(B1& x) { return x.B1::overrideB1(); } - - PyObject* m_self; -}; - -struct A_callback : A1 { - A_callback(PyObject* self) : m_self(self) {} - - std::string overrideA1() const { return boost::python::callback::call_method(m_self, "overrideA1"); } - std::string inheritA1() const { return boost::python::callback::call_method(m_self, "inheritA1"); } - - static std::string default_overrideA1(A1& x) { return x.A1::overrideA1(); } - static std::string default_inheritA1(A1& x) { return x.A1::inheritA1(); } - - PyObject* m_self; -}; - -/************************************************************/ -/* */ -/* RawTest */ -/* (test passing of raw arguments to C++) */ -/* */ -/************************************************************/ - -struct RawTest -{ - RawTest(int i) : i_(i) {} - - int i_; -}; - -PyObject* raw(boost::python::tuple const & args, boost::python::dictionary const & keywords); - -int raw1(PyObject* args, PyObject* keywords) -{ - return PyTuple_Size(args) + PyDict_Size(keywords); -} - -int raw2(boost::python::ref args, boost::python::ref keywords) -{ - return PyTuple_Size(args.get()) + PyDict_Size(keywords.get()); -} - - - -/************************************************************/ -/* */ -/* Ratio */ -/* */ -/************************************************************/ - -typedef boost::rational Ratio; - -boost::python::string ratio_str(const Ratio& r) -{ - char buf[200]; - - if (r.denominator() == 1) - sprintf(buf, "%d", r.numerator()); - else - sprintf(buf, "%d/%d", r.numerator(), r.denominator()); - - return boost::python::string(buf); -} - -boost::python::string ratio_repr(const Ratio& r) -{ - char buf[200]; - sprintf(buf, "Rational(%d, %d)", r.numerator(), r.denominator()); - return boost::python::string(buf); -} - -boost::python::tuple ratio_coerce(const Ratio& r1, int r2) -{ - return boost::python::tuple(r1, Ratio(r2)); -} - -// The most reliable way, across compilers, to grab the particular abs function -// we're interested in. -Ratio ratio_abs(const Ratio& r) -{ - return boost::abs(r); -} - -// An experiment, to be integrated into the py_cpp library at some point. -template -struct StandardOps -{ - static T add(const T& x, const T& y) { return x + y; } - static T sub(const T& x, const T& y) { return x - y; } - static T mul(const T& x, const T& y) { return x * y; } - static T div(const T& x, const T& y) { return x / y; } - static T cmp(const T& x, const T& y) { return std::less()(x, y) ? -1 : std::less()(y, x) ? 1 : 0; } -}; - -// This helps us prove that we can now pass non-const reference parameters to constructors -struct Fubar { - Fubar(Foo&) {} - Fubar(int) {} -}; - -/************************************************************/ -/* */ -/* Int */ -/* this class tests operator export */ -/* */ -/************************************************************/ - -#ifndef NDEBUG -int total_Ints = 0; -#endif - -struct Int -{ - explicit Int(int i) : i_(i), j_(0) { -#ifndef NDEBUG - ++total_Ints; -#endif - } - -#ifndef NDEBUG - ~Int() { --total_Ints; } - Int(const Int& rhs) : i_(rhs.i_), j_(rhs.j_) { ++total_Ints; } -#endif - - int i() const { return i_; } - int j() const { return j_; } - - int i_; - int j_; - - Int& operator +=(Int const& r) { ++j_; i_ += r.i_; return *this; } - Int& operator -=(Int const& r) { ++j_; i_ -= r.i_; return *this; } - Int& operator *=(Int const& r) { ++j_; i_ *= r.i_; return *this; } - Int& operator /=(Int const& r) { ++j_; i_ /= r.i_; return *this; } - Int& operator %=(Int const& r) { ++j_; i_ %= r.i_; return *this; } - Int& ipow (Int const& r) { ++j_; - int o=i_; - for (int k=1; k>=(Int const& r) { ++j_; i_ >>= r.i_; return *this; } - Int& operator &=(Int const& r) { ++j_; i_ &= r.i_; return *this; } - Int& operator |=(Int const& r) { ++j_; i_ |= r.i_; return *this; } - Int& operator ^=(Int const& r) { ++j_; i_ ^= r.i_; return *this; } -}; - -Int operator+(Int const & l, Int const & r) { return Int(l.i_ + r.i_); } -Int operator+(Int const & l, int const & r) { return Int(l.i_ + r); } -Int operator+(int const & l, Int const & r) { return Int(l + r.i_); } - -Int operator-(Int const & l, Int const & r) { return Int(l.i_ - r.i_); } -Int operator-(Int const & l, int const & r) { return Int(l.i_ - r); } -Int operator-(int const & l, Int const & r) { return Int(l - r.i_); } -Int operator-(Int const & r) { return Int(- r.i_); } - -Int mul(Int const & l, Int const & r) { return Int(l.i_ * r.i_); } -Int imul(Int const & l, int const & r) { return Int(l.i_ * r); } -Int rmul(Int const & r, int const & l) { return Int(l * r.i_); } - -Int operator/(Int const & l, Int const & r) { return Int(l.i_ / r.i_); } - -Int operator%(Int const & l, Int const & r) { return Int(l.i_ % r.i_); } - -bool operator<(Int const & l, Int const & r) { return l.i_ < r.i_; } -bool operator<(Int const & l, int const & r) { return l.i_ < r; } -bool operator<(int const & l, Int const & r) { return l < r.i_; } - -Int pow(Int const & l, Int const & r) { return Int(static_cast(::pow(l.i_, r.i_))); } -Int powmod(Int const & l, Int const & r, Int const & m) { return Int((int)::pow(l.i_, r.i_) % m.i_); } -Int pow(Int const & l, int const & r) { return Int(static_cast(::pow(l.i_, r))); } - -std::ostream & operator<<(std::ostream & o, Int const & r) { return (o << r.i_); } - -/************************************************************/ -/* */ -/* double tests from Mark Evans() */ -/* */ -/************************************************************/ -double sizelist(boost::python::list list) { return list.size(); } -void vd_push_back(std::vector& vd, const double& x) -{ - vd.push_back(x); -} - -/************************************************************/ -/* */ -/* What if I want to return a pointer? */ -/* */ -/************************************************************/ - -// -// This example exposes the pointer by copying its referent -// -struct Record { - Record(int x) : value(x){} - int value; -}; - -const Record* get_record() -{ - static Record v(1234); - return &v; -} - -} // namespace bpl_test - -namespace boost { namespace python { - template class class_builder; // explicitly instantiate -}} // namespace boost::python - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE -inline PyObject* to_python(const bpl_test::Record* p) -{ - return to_python(*p); -} -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -/************************************************************/ -/* */ -/* Enums and non-method class attributes */ -/* */ -/************************************************************/ - -namespace bpl_test { - -struct EnumOwner -{ - public: - enum enum_type { one = 1, two = 2, three = 3 }; - - EnumOwner(enum_type a1, const enum_type& a2) - : m_first(a1), m_second(a2) {} - - void set_first(const enum_type& x) { m_first = x; } - void set_second(const enum_type& x) { m_second = x; } - - enum_type first() { return m_first; } - enum_type second() { return m_second; } - private: - enum_type m_first, m_second; -}; - -} - -namespace boost { namespace python { - template class enum_as_int_converters; - using bpl_test::pow; -}} // namespace boost::python - -// This is just a way of getting the converters instantiated -//struct EnumOwner_enum_type_Converters -// : boost::python::py_enum_as_int_converters -//{ -//}; - -namespace bpl_test { - -/************************************************************/ -/* */ -/* pickling support */ -/* */ -/************************************************************/ - class world - { - private: - std::string country; - int secret_number; - public: - world(const std::string& country) : secret_number(0) { - this->country = country; - } - std::string greet() const { return "Hello from " + country + "!"; } - std::string get_country() const { return country; } - void set_secret_number(int number) { secret_number = number; } - int get_secret_number() const { return secret_number; } - }; - - // Support for pickle. - boost::python::tuple world_getinitargs(const world& w) - { - boost::python::tuple result(1); - result.set_item(0, w.get_country()); - return result; - } - - boost::python::tuple world_getstate(const world& w) - { - boost::python::tuple result(1); - result.set_item(0, w.get_secret_number()); - return result; - } - - void world_setstate(world& w, boost::python::tuple state) - { - if (state.size() != 1) { - PyErr_SetString(PyExc_ValueError, - "Unexpected argument in call to __setstate__."); - boost::python::throw_error_already_set(); - } - - const int number = BOOST_PYTHON_CONVERSION::from_python(state[0].get(), boost::python::type()); - if (number != 42) - w.set_secret_number(number); - } - - // Test plain char converters. - char get_plain_char() { return 'x'; } - std::string use_plain_char(char c) { return std::string(3, c); } - - // This doesn't test anything but the compiler, since it has the same signature as the above. - // Since MSVC is broken and gets the signature wrong, we'll skip it. - std::string use_const_plain_char( -#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 - const -#endif - char c) { return std::string(5, c); } - - // Test std::complex converters. - std::complex dpolar(double rho, double theta) { - return std::polar(rho, theta); - } - double dreal(const std::complex& c) { return c.real(); } - double dimag(std::complex c) { return c.imag(); } - - // Test std::complex converters. - std::complex fpolar(float rho, float theta) { - return std::polar(rho, theta); - } - double freal(const std::complex& c) { return c.real(); } - double fimag(std::complex c) { return c.imag(); } - - // Wrappers for inplace operators. - Int& int_iadd(Int& self, const Int& r) { self += r; return self; } - Int& int_isub(Int& self, const Int& r) { self -= r; return self; } - Int& int_imul(Int& self, const Int& r) { self *= r; return self; } - Int& int_idiv(Int& self, const Int& r) { self /= r; return self; } - Int& int_imod(Int& self, const Int& r) { self %= r; return self; } - Int& int_ipow(Int& self, const Int& r) { self.ipow (r); return self; } - Int& int_ilshift(Int& self, const Int& r) { self <<= r; return self; } - Int& int_irshift(Int& self, const Int& r) { self >>= r; return self; } - Int& int_iand(Int& self, const Int& r) { self &= r; return self; } - Int& int_ior(Int& self, const Int& r) { self |= r; return self; } - Int& int_ixor(Int& self, const Int& r) { self ^= r; return self; } - -/************************************************************/ -/* */ -/* init the module */ -/* */ -/************************************************************/ - -void init_module(boost::python::module_builder& m) -{ - m.def(get_record, "get_record"); - boost::python::class_builder record_class(m, "Record"); - record_class.def_readonly(&Record::value, "value"); - - m.def(sizelist, "sizelist"); - - boost::python::class_builder > vector_double(m, "vector_double"); - vector_double.def(boost::python::constructor<>()); - vector_double.def(vd_push_back, "push_back"); - - boost::python::class_builder fubar(m, "Fubar"); - fubar.def(boost::python::constructor()); - fubar.def(boost::python::constructor()); - - Foo::PythonClass foo(m); - BarPythonClass bar(m); - BazPythonClass baz(m); - StringMapPythonClass string_map(m); - IntPairPythonClass int_pair(m); - m.def(make_pair, "make_pair"); - CompareIntPairPythonClass compare_int_pair(m); - - boost::python::class_builder string_pair(m, "StringPair"); - string_pair.def(boost::python::constructor()); - string_pair.def_readonly(&StringPair::first, "first"); - string_pair.def_read_write(&StringPair::second, "second"); - string_pair.def(&stringpair_repr, "__repr__"); - string_pair.def(&stringpair_compare, "__cmp__"); - m.def(first_string, "first_string"); - m.def(second_string, "second_string"); - - // This shows the wrapping of a 3rd-party numeric type. - boost::python::class_builder > rational(m, "Rational"); - rational.def(boost::python::constructor()); - rational.def(boost::python::constructor()); - rational.def(boost::python::constructor<>()); - rational.def(StandardOps::add, "__add__"); - rational.def(StandardOps::sub, "__sub__"); - rational.def(StandardOps::mul, "__mul__"); - rational.def(StandardOps::div, "__div__"); - rational.def(StandardOps::cmp, "__cmp__"); - rational.def(ratio_coerce, "__coerce__"); - rational.def(ratio_str, "__str__"); - rational.def(ratio_repr, "__repr__"); - rational.def(ratio_abs, "__abs__"); - - boost::python::class_builder range(m, "Range"); - range.def(boost::python::constructor()); - range.def(boost::python::constructor()); - range.def((std::size_t (Range::*)() const)&Range::length, "__len__"); - range.def((void (Range::*)(std::size_t))&Range::length, "__len__"); - range.def(&Range::operator[], "__getitem__"); - range.def(&Range::slice, "__getslice__"); - range.def(&range_str, "__str__"); - range.def(&range_compare, "__cmp__"); - range.def(&range_hash, "__hash__"); - range.def_readonly(&Range::m_start, "start"); - range.def_readonly(&Range::m_finish, "finish"); - - m.def(&testVoid, "overloaded"); - m.def(&testInt, "overloaded"); - m.def(&testString, "overloaded"); - m.def(&test2, "overloaded"); - m.def(&test3, "overloaded"); - m.def(&test4, "overloaded"); - m.def(&test5, "overloaded"); - - boost::python::class_builder over(m, "OverloadTest"); - over.def(boost::python::constructor<>()); - over.def(boost::python::constructor()); - over.def(boost::python::constructor()); - over.def(boost::python::constructor()); - over.def(boost::python::constructor()); - over.def(boost::python::constructor()); - over.def(boost::python::constructor()); - over.def(&getX, "getX"); - over.def(&OverloadTest::setX, "setX"); - over.def(&OverloadTest::x, "overloaded"); - over.def(&OverloadTest::p1, "overloaded"); - over.def(&OverloadTest::p2, "overloaded"); - over.def(&OverloadTest::p3, "overloaded"); - over.def(&OverloadTest::p4, "overloaded"); - over.def(&OverloadTest::p5, "overloaded"); - - boost::python::class_builder base(m, "Base"); - base.def(&Base::x, "x"); - - boost::python::class_builder derived1(m, "Derived1"); - // this enables conversions between Base and Derived1 - // and makes wrapped methods of Base available - derived1.declare_base(base); - derived1.def(boost::python::constructor()); - - boost::python::class_builder derived2(m, "Derived2"); - // don't enable downcast from Base to Derived2 - derived2.declare_base(base, boost::python::without_downcast); - derived2.def(boost::python::constructor()); - - m.def(&testUpcast, "testUpcast"); - m.def(&derived1Factory, "derived1Factory"); - m.def(&derived2Factory, "derived2Factory"); - m.def(&testDowncast1, "testDowncast1"); - m.def(&testDowncast2, "testDowncast2"); - - boost::python::class_builder callbackTestBase(m, "CallbackTestBase"); - callbackTestBase.def(&CallbackTestBase::testCallback, "testCallback"); - m.def(&testCallback, "testCallback"); - - boost::python::class_builder callbackTest(m, "CallbackTest"); - callbackTest.def(boost::python::constructor<>()); - callbackTest.def(&CallbackTest::callback, "callback", - &CallbackTestCallback::default_callback); - callbackTest.def(&CallbackTest::callbackString, "callback", - &CallbackTestCallback::default_callbackString); - - callbackTest.declare_base(callbackTestBase); - - boost::python::class_builder a1_class(m, "A1"); - a1_class.def(boost::python::constructor<>()); - a1_class.def(&A1::overrideA1, "overrideA1", &A_callback::default_overrideA1); - a1_class.def(&A1::inheritA1, "inheritA1", &A_callback::default_inheritA1); - - boost::python::class_builder a2_class(m, "A2"); - a2_class.def(boost::python::constructor<>()); - a2_class.def(&A2::inheritA2, "inheritA2"); - - boost::python::class_builder b1_class(m, "B1"); - b1_class.declare_base(a1_class); - b1_class.declare_base(a2_class); - - b1_class.def(boost::python::constructor<>()); - b1_class.def(&B1::overrideA1, "overrideA1", &B_callback::default_overrideA1); - b1_class.def(&B1::overrideB1, "overrideB1", &B_callback::default_overrideB1); - - boost::python::class_builder b2_class(m, "B2"); - b2_class.declare_base(a1_class); - b2_class.declare_base(a2_class); - - b2_class.def(boost::python::constructor<>()); - b2_class.def(&B2::overrideA1, "overrideA1"); - b2_class.def(&B2::inheritB2, "inheritB2"); - - m.def(call_overrideA1, "call_overrideA1"); - m.def(call_overrideB1, "call_overrideB1"); - m.def(call_inheritA1, "call_inheritA1"); - - m.def(factoryA1asA1, "factoryA1asA1"); - m.def(factoryB1asA1, "factoryB1asA1"); - m.def(factoryB2asA1, "factoryB2asA1"); - m.def(factoryCasA1, "factoryCasA1"); - m.def(factoryA2asA2, "factoryA2asA2"); - m.def(factoryB1asA2, "factoryB1asA2"); - m.def(factoryB1asB1, "factoryB1asB1"); - m.def(factoryCasB1, "factoryCasB1"); - - boost::python::class_builder rawtest_class(m, "RawTest"); - rawtest_class.def(boost::python::constructor()); - rawtest_class.def_raw(&raw, "raw"); - - m.def_raw(&raw, "raw"); - m.def_raw(&raw1, "raw1"); - m.def_raw(&raw2, "raw2"); - - boost::python::class_builder int_class(m, "Int"); - int_class.def(boost::python::constructor()); - int_class.def(&Int::i, "i"); - int_class.def(&Int::j, "j"); - - // wrap homogeneous operators - int_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub | boost::python::op_neg | - boost::python::op_cmp | boost::python::op_str | boost::python::op_divmod | boost::python::op_pow )>()); - // export non-operator functions as homogeneous operators - int_class.def(&mul, "__mul__"); - int_class.def(&powmod, "__pow__"); - - // wrap heterogeneous operators (lhs: Int const &, rhs: int const &) - int_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub | boost::python::op_cmp | boost::python::op_pow)>(), - boost::python::right_operand()); - // export non-operator function as heterogeneous operator - int_class.def(&imul, "__mul__"); - - // wrap heterogeneous operators (lhs: int const &, rhs: Int const &) - int_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub | boost::python::op_cmp)>(), - boost::python::left_operand()); - // export non-operator function as heterogeneous reverse-argument operator - int_class.def(&rmul, "__rmul__"); - -#if PYTHON_API_VERSION >= 1010 - // inplace operators. - int_class.def(&int_iadd, "__iadd__"); - int_class.def(&int_isub, "__isub__"); - int_class.def(&int_imul, "__imul__"); - int_class.def(&int_idiv, "__idiv__"); - int_class.def(&int_imod, "__imod__"); - int_class.def(&int_ipow, "__ipow__"); - int_class.def(&int_ilshift, "__ilshift__"); - int_class.def(&int_irshift, "__irshift__"); - int_class.def(&int_iand, "__iand__"); - int_class.def(&int_ior, "__ior__"); - int_class.def(&int_ixor, "__ixor__"); -#endif - - - boost::python::class_builder enum_owner(m, "EnumOwner"); - enum_owner.def(boost::python::constructor()); - enum_owner.def(&EnumOwner::set_first, "__setattr__first__"); - enum_owner.def(&EnumOwner::set_second, "__setattr__second__"); - enum_owner.def(&EnumOwner::first, "__getattr__first__"); - enum_owner.def(&EnumOwner::second, "__getattr__second__"); - enum_owner.add(PyInt_FromLong(EnumOwner::one), "one"); - enum_owner.add(PyInt_FromLong(EnumOwner::two), "two"); - enum_owner.add(PyInt_FromLong(EnumOwner::three), "three"); - - // pickling support - - // Create the Python type object for our extension class. - boost::python::class_builder world_class(m, "world"); - - // Add the __init__ function. - world_class.def(boost::python::constructor()); - // Add a regular member function. - world_class.def(&world::greet, "greet"); - world_class.def(&world::get_secret_number, "get_secret_number"); - world_class.def(&world::set_secret_number, "set_secret_number"); - - // Support for pickle. - world_class.def(world_getinitargs, "__getinitargs__"); - world_class.def(world_getstate, "__getstate__"); - world_class.def(world_setstate, "__setstate__"); - - // Test plain char converters. - m.def(get_plain_char, "get_plain_char"); - m.def(use_plain_char, "use_plain_char"); - m.def(use_const_plain_char, "use_const_plain_char"); - - // Test std::complex converters. - m.def(dpolar, "dpolar"); - m.def(dreal, "dreal"); - m.def(dimag, "dimag"); - - // Test std::complex converters. - m.def(fpolar, "fpolar"); - m.def(freal, "freal"); - m.def(fimag, "fimag"); - - // Test new null-pointer<->None conversions - m.def(foo_factory, "foo_factory"); - m.def(foo_ptr_is_null, "foo_ptr_is_null"); - m.def(foo_shared_ptr_is_null, "foo_shared_ptr_is_null"); -} - -PyObject* raw(const boost::python::tuple& args, const boost::python::dictionary& keywords) -{ - if(args.size() != 2 || keywords.size() != 2) - { - PyErr_SetString(PyExc_TypeError, "wrong number of arguments"); - boost::python::throw_argument_error(); - } - - RawTest* first = BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()); - int second = BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()); - - int third = BOOST_PYTHON_CONVERSION::from_python(keywords[boost::python::string("third")].get(), boost::python::type()); - int fourth = BOOST_PYTHON_CONVERSION::from_python(keywords[boost::python::string("fourth")].get(), boost::python::type()); - - return BOOST_PYTHON_CONVERSION::to_python(first->i_ + second + third + fourth); -} - -BOOST_PYTHON_MODULE_INIT(boost_python_test) -{ - boost::python::module_builder boost_python_test("boost_python_test"); - init_module(boost_python_test); - - // Just for giggles, add a raw metaclass. - boost_python_test.add(new boost::python::meta_class); -} - -CompareIntPairPythonClass::CompareIntPairPythonClass(boost::python::module_builder& m) - : boost::python::class_builder(m, "CompareIntPair") -{ - def(boost::python::constructor<>()); - def(&CompareIntPair::operator(), "__call__"); -} - -} // namespace bpl_test - - -#if defined(_WIN32) -# ifdef __MWERKS__ -# pragma ANSI_strict off -# endif -# include -# ifdef __MWERKS__ -# pragma ANSI_strict reset -# endif -extern "C" BOOL WINAPI DllMain ( HINSTANCE hInst, DWORD wDataSeg, LPVOID lpvReserved ); - -# ifdef BOOST_MSVC -extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*) -# if BOOST_MSVC > 1200 - throw(...) -# endif -{ - throw; -} -# endif - -#ifndef NDEBUG -namespace boost { namespace python { namespace detail { - extern int total_Dispatchers; -}}} // namespace boost::python::detail -#endif - -BOOL WINAPI DllMain( - HINSTANCE, //hDllInst - DWORD fdwReason, - LPVOID // lpvReserved - ) -{ -# ifdef BOOST_MSVC - _set_se_translator(structured_exception_translator); -#endif - (void)fdwReason; // warning suppression. - -#ifndef NDEBUG - switch(fdwReason) - { - case DLL_PROCESS_DETACH: - assert(bpl_test::total_Ints == 0); - } -#endif - - return 1; -} -#endif // _WIN32 diff --git a/test/comprehensive.hpp b/test/comprehensive.hpp deleted file mode 100644 index 370f7d04..00000000 --- a/test/comprehensive.hpp +++ /dev/null @@ -1,235 +0,0 @@ -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef BPL_TEST_DWA052200_H_ -# define BPL_TEST_DWA052200_H_ -// -// Example code demonstrating extension class usage -// - -# include -# include -# include -# include -# include -# include -# include -# include - -namespace bpl_test { - -// -// example: Foo, Bar, and Baz are C++ classes we want to wrap. -// - -class Foo // prohibit copying, proving that it doesn't choke - : private boost::noncopyable // our generation of to_python(). -{ - public: // constructor/destructor - Foo(int x) : m_x(x) {} - virtual ~Foo() {} - - public: // non-virtual functions - const char* mumble(); // mumble something - void set(long x); // change the held value - - // These two call virtual functions - std::string call_pure(); // call a pure virtual fuction - int call_add_len(const char* s) const; // virtual function with a default implementation - - // A couple nested classs. - struct Foo_A { const char* mumble(); }; - struct Foo_B { const char* mumble(); }; - - private: - // by default, sum the held value and the length of s - virtual int add_len(const char* s) const; - - // Derived classes can do whatever they want here, but they must do something! - virtual std::string pure() const = 0; - - public: // friend declarations - // If you have private virtual functions such as add_len which you want to - // override in Python and have default implementations, they must be - // accessible by the thing making the def() call on the extension_class (in - // this case, the nested PythonClass itself), and by the C++ derived class - // which is used to cause the Python callbacks (in this case, - // FooCallback). See the definition of FooCallback::add_len() - struct PythonClass; - friend struct PythonClass; - friend class FooCallback; - - private: - int m_x; // the held value -}; - -// -// Bar and Baz have mutually-recursive type conversion dependencies (see -// pass_xxx functions). I've done this to prove that it doesn't cause a -// problem for Python class definitions, which happen later. -// -// Bar and Baz functions are only virtual to increase the likelihood of a crash -// if I inadvertently use a pointer to garbage memory (a likely thing to test -// for considering the amount of type casting needed to translate to and from -// Python). -struct Baz; -struct Bar -{ - Bar(int x, int y) : m_first(x), m_second(y) {} - virtual int first() const { return m_first; } - virtual int second() const { return m_second; } - virtual Baz pass_baz(Baz x); - - int m_first, m_second; -}; - -struct Baz -{ - virtual Bar pass_bar(const Bar& x) { return x; } - - // We can return smart pointers - virtual std::auto_ptr clone() { return std::auto_ptr(new Baz(*this)); } - - // This illustrates creating a polymorphic derived class of Foo - virtual boost::shared_ptr create_foo(); - - // We can accept smart pointer parameters - virtual int get_foo_value(boost::shared_ptr); - - // Show what happens in python when we take ownership from an auto_ptr - virtual void eat_baz(std::auto_ptr); -}; - -typedef std::map StringMap; -typedef std::pair IntPair; - -IntPair make_pair(int, int); - -typedef std::less CompareIntPair; -typedef std::pair StringPair; - -inline std::string first_string(const StringPair& x) -{ - return x.first; -} - -inline std::string second_string(const StringPair& x) -{ - return x.second; -} - -struct Range -{ - Range(int x) - : m_start(x), m_finish(x) {} - - Range(int start, int finish) - : m_start(start), m_finish(finish) {} - - std::size_t length() const - { return m_finish < m_start ? 0 : m_finish - m_start; } - - void length(std::size_t new_length) - { m_finish = m_start + new_length; } - - int operator[](std::size_t n) - { return m_start + n; } - - Range slice(std::size_t start, std::size_t end) - { - if (start > length()) - start = length(); - if (end > length()) - end = length(); - return Range(m_start + start, m_start + end); - } - - int m_start, m_finish; -}; - -//////////////////////////////////////////////////////////////////////// -// // -// Begin wrapping code. Usually this would live in a separate header. // -// // -//////////////////////////////////////////////////////////////////////// - -// Since Foo has virtual functions which we want overriden in Python, we must -// derive FooCallback. -class FooCallback : public Foo -{ - public: - // Note the additional constructor parameter "self", which is needed to - // allow function overriding from Python. - FooCallback(PyObject* self, int x); - - friend struct PythonClass; // give it access to the functions below - - private: // implementations of Foo virtual functions that are overridable in python. - int add_len(const char* x) const; - - // A function which Python can call in case bar is not overridden from - // Python. In true Python style, we use a free function taking an initial - // self parameter. You can put this function anywhere; it needn't be a - // static member of the wrapping class. - static int default_add_len(const Foo* self, const char* x); - - // Since Foo::pure() is pure virtual, we don't need a corresponding - // default_pure(). A failure to override it in Python will result in an - // exception at runtime when pure() is called. - std::string pure() const; - - private: // Required boilerplate if functions will be overridden - PyObject* m_self; // No, we don't want a boost::python::ref here, or we'd get an ownership cycle. -}; - -// Define the Python base class -struct Foo::PythonClass : boost::python::class_builder { PythonClass(boost::python::module_builder&); }; - -// No virtual functions on Bar or Baz which are actually supposed to behave -// virtually from C++, so we'll rely on the library to define a wrapper for -// us. Even so, Python class_t types for each type we're wrapping should be -// _defined_ here in a header where they can be seen by other extension class -// definitions, since it is the definition of the boost::python::class_builder<> that -// causes to_python/from_python conversion functions to be generated. -struct BarPythonClass : boost::python::class_builder { BarPythonClass(boost::python::module_builder&); }; -struct BazPythonClass : boost::python::class_builder { BazPythonClass(boost::python::module_builder&); }; - -struct StringMapPythonClass - : boost::python::class_builder -{ - StringMapPythonClass(boost::python::module_builder&); - - // These static functions implement the right argument protocols for - // implementing the Python "special member functions" for mapping on - // StringMap. Could just as easily be global functions. - static const std::string& get_item(const StringMap& m, std::size_t key); - static void set_item(StringMap& m, std::size_t key, const std::string& value); - static void del_item(StringMap& m, std::size_t key); -}; - -struct IntPairPythonClass - : boost::python::class_builder -{ - IntPairPythonClass(boost::python::module_builder&); - - // The following could just as well be a free function; it implements the - // getattr functionality for IntPair. - static int getattr(const IntPair&, const std::string& s); - static void setattr(IntPair&, const std::string& name, int value); - static void delattr(IntPair&, const char* name); -}; - -struct CompareIntPairPythonClass - : boost::python::class_builder -{ - CompareIntPairPythonClass(boost::python::module_builder&); -}; - -} // namespace bpl_test - -#endif // BPL_TEST_DWA052200_H_ diff --git a/test/comprehensive.py b/test/comprehensive.py deleted file mode 100644 index f64ed661..00000000 --- a/test/comprehensive.py +++ /dev/null @@ -1,1281 +0,0 @@ -r''' -// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -// Revision History: -// 2001 Nov 01 Python 2.2 pickle problems fixed (rwgk) -// 04 Mar 01 Changed name of extension module so it would work with DebugPython, -// fixed exception message checking to work with Python 2.0 -// (Dave Abrahams) - -Automatic checking of the number and type of arguments. Foo's constructor takes -a single long parameter. - - >>> try: - ... ext = Foo() - ... except TypeError, err: - ... assert re.match(r'function .* exactly 1 argument;? \(?0 given\)?', - ... str(err)) - ... else: - ... print 'no exception' - - >>> try: ext = Foo('foo') - ... except TypeError, err: - ... assert_integer_expected(err) - ... else: - ... print 'no exception' - - >>> ext = Foo(1) - -Call a virtual function. This call takes a trip into C++ where -FooCallback::add_len() looks up the Python "add_len" attribute and finds the -wrapper for FooCallback::default_add_len(), which in turn calls Foo::add_len(). - - >>> ext.add_len('hello') - 6 - >>> ext.set(3) - >>> ext.add_len('hello') - 8 - -Call a pure virtual function which should have been overridden, but was not. - - >>> ext.call_pure() - Traceback (innermost last): - File "", line 1, in ? - AttributeError: pure - -We can subclass Foo. - - >>> class Subclass(Foo): - ... def __init__(self, seq): - ... Foo.__init__(self, len(seq)) - ... - ... def pure(self): - ... return 'not pure anymore!' - ... - ... def get(self): - ... return Foo.add_len(self, '') - ... - ... def add_len(self, s): - ... print 'called add_len()' - ... return self.get() + len(s) - ... - >>> b = Subclass('yippee') - >>> b.get() - 6 - >>> b.mumble() - 'mumble' - >>> b.call_pure() - 'not pure anymore!' - -None corresponds to a NULL pointer or smart pointer - >>> f = foo_factory(1) - >>> f.add_len('xxx') - 1000 - >>> foo_factory(0) is None - 1 - >>> foo_ptr_is_null(None) - 1 - >>> foo_ptr_is_null(f) - 0 - >>> foo_shared_ptr_is_null(None) - 1 - >>> foo_shared_ptr_is_null(f) - 0 - -If no __init__ function is defined, the one from the base class takes effect, just -like in a Python class. - - >>> class DemonstrateInitPassthru(Foo): pass - ... - >>> q = DemonstrateInitPassthru(1) - >>> q.add_len("x") - 2 - -If we don't initialize the base class, we'll get a RuntimeError when we try to -use its methods. The test illustrates the kind of error to expect. - - >>> class BadSubclass(Foo): - ... def __init__(self): pass - ... - >>> barf = BadSubclass() - >>> barf.set(4) - Traceback (innermost last): - ... - RuntimeError: __init__ function for extension class 'Foo' was never called. - -Here we are tesing that the simple definition procedure used in the C++ demo -file for classes without any virtual functions actually worked. - - >>> bar = Bar(3, 4) - >>> bar.first() - 3 - >>> bar.second() - 4 - >>> baz = Baz() - -We can actually return the wrapped classes by value - - >>> baz.pass_bar(bar).first() - 3 - >>> bar.pass_baz(baz) is baz # A copy of the return value is made. - 0 - >>> type(bar.pass_baz(baz)) is type(baz) - 1 - -And, yes, we can multiply inherit from these classes. - - >>> class MISubclass(Subclass, Bar): - ... def __init__(self, s): - ... Subclass.__init__(self, s) - ... Bar.__init__(self, 0, len(s)) - ... - >>> mi = MISubclass('xx') - >>> mi.first() - 0 - >>> mi.second() - 2 - >>> mi.mumble() - 'mumble' - -We can even mulitply inherit from built-in Python classes, even if they are -first in the list of bases - - >>> class RealPythonClass: - ... def real_python_method(self): - ... print 'RealPythonClass.real_python_method()' - ... def other_first(self, other): - ... return other.first() - - >>> class MISubclass2(RealPythonClass, Bar): - ... def new_method(self): - ... print 'MISubclass2.new_method()' - ... bound_function = RealPythonClass().other_first - ... - >>> mi2 = MISubclass2(7, 8) - >>> mi2.first() # we can call inherited member functions from Bar - 7 - >>> mi2.real_python_method() # we can call inherited member functions from RealPythonClass - RealPythonClass.real_python_method() - - >>> mi2.new_method() # we can call methods on the common derived class - MISubclass2.new_method() - - We can call unbound methods from the base class accessed through the derived class - >>> MISubclass2.real_python_method(mi2) - RealPythonClass.real_python_method() - - We have not interfered with ordinary python bound methods - >>> MISubclass2.bound_function(mi2) - 7 - >>> mi2.bound_function() - 7 - -Any object whose class is derived from Bar can be passed to a function expecting -a Bar parameter: - - >>> baz.pass_bar(mi).first() - 0 - -But objects not derived from Bar cannot: - - >>> baz.pass_bar(baz) - Traceback (innermost last): - ... - TypeError: extension class 'Baz' is not convertible into 'Bar'. - -The clone function on Baz returns a smart pointer; we wrap it into an -extension_instance and make it look just like any other Baz obj. - - >>> baz_clone = baz.clone() - >>> baz_clone.pass_bar(mi).first() - 0 - -Functions expecting an std::auto_ptr parameter will not accept a raw Baz - - >>> try: baz.eat_baz(Baz()) - ... except RuntimeError, err: - ... assert re.match("Object of extension class 'Baz' does not wrap <.*>.", - ... str(err)) - ... else: - ... print 'no exception' - -We can pass std::auto_ptr where it is expected - - >>> baz.eat_baz(baz_clone) - -And if the auto_ptr has given up ownership? - - # MSVC6 ships with an outdated auto_ptr that doesn't get zeroed out when it - # gives up ownership. If you are using MSVC6 without the new Dinkumware - # library, SGI STL or the STLport, expect this test to crash unless you put - # --broken-auto-ptr on the command line. - >>> if not '--broken-auto-ptr' in sys.argv: - ... try: baz_clone.clone() - ... except RuntimeError, err: - ... assert re.match('Converting from python, pointer or smart pointer to <.*> is NULL.', str(err)) - ... else: - ... print 'no exeption' - -Polymorphism also works: - - >>> polymorphic_foo = baz.create_foo() - >>> polymorphic_foo.call_pure() - 'this was never pure!' - >>> baz.get_foo_value(polymorphic_foo) - 1000 - -Simple nested class test: - >>> foo_a = Foo.Foo_A() - >>> foo_a.mumble() - 'mumble a' - >>> foo_b = Foo.Foo_B() - >>> foo_b.mumble() - 'mumble b' - -Pickling tests: - - >>> world.__module__ - 'boost_python_test' - >>> world.__safe_for_unpickling__ - 1 - >>> world.__reduce__() - 'world' - >>> reduced = world('Hello').__reduce__() - >>> reduced[0] == world - 1 - >>> reduced[1:] - (('Hello',), (0,)) - >>> import StringIO - >>> import cPickle - >>> pickle = cPickle - >>> for number in (24, 42): - ... wd = world('California') - ... wd.set_secret_number(number) - ... # Dump it out and read it back in. - ... f = StringIO.StringIO() - ... pickle.dump(wd, f) - ... f = StringIO.StringIO(f.getvalue()) - ... wl = pickle.load(f) - ... # - ... print wd.greet(), wd.get_secret_number() - ... print wl.greet(), wl.get_secret_number() - ... - Hello from California! 24 - Hello from California! 24 - Hello from California! 42 - Hello from California! 0 - -Pickle safety measures: - >>> r=Rational(3, 4) - >>> r - Rational(3, 4) - >>> try: s=pickle.dumps(r) - ... except RuntimeError, err: print err[0] - ... - Incomplete pickle support (__dict_defines_state__ not set) - >>> r=myrational(3, 4) - >>> r - Rational(3, 4) - >>> s=pickle.dumps(r) - >>> u=pickle.loads(s) - - >>> w = myworld() - >>> w.greet() - 'Hello from anywhere!' - >>> w.__dict__ - {'x': 1} - >>> try: s=pickle.dumps(w) - ... except RuntimeError, err: print err[0] - ... - Incomplete pickle support (__getstate_manages_dict__ not set) - - >>> w = myunsafeworld() - >>> w.greet() - 'Hello from anywhere!' - >>> w.__dict__ - {'x': 1} - >>> s=pickle.dumps(w) - -Special member attributes. Tests courtesy of Barry Scott - - >>> class DerivedFromFoo(Foo): - ... def __init__(self): - ... Foo.__init__( self, 1 ) - ... def fred(self): - ... 'Docs for DerivedFromFoo.fred' - ... print 'Barry.fred' - ... def __del__(self): - ... print 'Deleting DerivedFromFoo' - - >>> class Base: - ... i_am_base = 'yes' - ... def fred(self): - ... 'Docs for Base.fred' - ... pass - - - >>> class DerivedFromBase(Base): - ... i_am_derived_from_base = 'yes' - ... def fred(self): - ... 'Docs for DerivedFromBase.fred' - ... pass - - >>> dir(DerivedFromFoo) - ['__del__', '__doc__', '__init__', '__module__', 'fred'] - - >>> df = DerivedFromFoo() - >>> df.__dict__ - {} - >>> df.fred.__doc__ - 'Docs for DerivedFromFoo.fred' - - >>> db = DerivedFromBase() - >>> db.__dict__ - {} - >>> db.fred.__doc__ - 'Docs for DerivedFromBase.fred' - - >>> import sys - >>> if not sys.__dict__.has_key('version_info') or \ - ... sys.version_info[0] < 2 or ( sys.version_info[0] == 2 and - ... sys.version_info[1] < 2 ): - ... assert dir(df) == [] - ... assert dir(db) == [] - ... assert dir(DerivedFromBase) == [ - ... '__doc__', '__module__', 'fred', 'i_am_derived_from_base'] - ... else: - ... assert dir(df) == [ - ... 'Foo_A', 'Foo_B', '__del__', '__doc__', '__init__', '__module__', 'add_len', - ... 'call_add_len', 'call_pure', 'fred', 'mumble', 'set'] - ... assert dir(db) == ['__doc__', '__module__', 'fred' - ... , 'i_am_base', 'i_am_derived_from_base'] - ... assert dir(DerivedFromBase) == [ - ... '__doc__', '__module__', 'fred', 'i_am_base', 'i_am_derived_from_base'] - -Special member functions in action - >>> del df - Deleting DerivedFromFoo - - # force method table sharing - >>> class DerivedFromStringMap(StringMap): pass - ... - - >>> m = StringMap() - -__getitem__() - >>> m[1] - Traceback (innermost last): - File "", line 1, in ? - KeyError: 1 - -__setitem__() - - >>> m[1] = 'hello' - -__getitem__() - >>> m[1] - 'hello' - -__delitem__() - >>> del m[1] - >>> m[1] # prove that it's gone - Traceback (innermost last): - File "", line 1, in ? - KeyError: 1 - -__delitem__() - >>> del m[2] - Traceback (innermost last): - File "", line 1, in ? - KeyError: 2 - -__length__() - >>> len(m) - 0 - >>> m[3] = 'farther' - >>> len(m) - 1 - -Check for sequence/mapping confusion: - >>> for x in m: - ... print x - ... - Traceback (innermost last): - File "", line 1, in ? - KeyError: 0 - -Check for the ability to pass a non-const reference as a constructor parameter - >>> x = Fubar(Foo(1)) - -Some simple overloading tests: - >>> r = Range(3) - >>> print str(r) - (3, 3) - >>> r.start - 3 - >>> r.finish - 3 - >>> r.__len__() - 0 - >>> r.__len__(4) - >>> r.finish - 7 - >>> try: r = Range('yikes') - ... except TypeError, e: - ... assert re.match( - ... 'No overloaded functions match [(]Range, str[a-z]*[)]\. Candidates are:\n.*\n.*', - ... str(e)) - ... else: print 'no exception' - -Sequence tests: - >>> len(Range(3, 10)) - 7 - - >>> map(lambda x:x, Range(3, 10)) - [3, 4, 5, 6, 7, 8, 9] - - >>> map(lambda x:x, Range(3, 10)[-2:]) - [8, 9] - - >>> map(lambda x:x, Range(3, 10)[:-4]) - [3, 4, 5] - - >>> map(lambda x:x, Range(3, 10)[4:]) - [7, 8, 9] - - >>> map(lambda x:x, Range(3, 10)[4:100]) - [7, 8, 9] - - >>> map(lambda x:x, Range(3, 10)[20:]) - [] - - >>> map(lambda x:x, Range(3, 10)[0:4]) - [3, 4, 5, 6] - -Numeric tests: - >>> x = Rational(2,3) - >>> y = Rational(1,4) - >>> print x + y - 11/12 - >>> print x - y - 5/12 - >>> print x * y - 1/6 - >>> print x / y - 8/3 - >>> print x + 1 # testing coercion - 5/3 - >>> print 1 + x # coercion the other way - 5/3 - -delete non-existent attribute: - del m.foobar - Traceback (innermost last): - File "", line 1, in ? - AttributeError: delete non-existing obj attribute - -Testing __getattr__ and __getattr__: - - >>> n = IntPair(1, 2) - >>> n.first - 1 - >>> n.second - 2 - >>> n.third - Traceback (innermost last): - File "", line 1, in ? - AttributeError: third - -Testing __setattr__ and __setattr__: - >>> n.first = 33 # N.B __setattr__first sets first to - >>> n.first # the negative of its argument. - -33 - >>> n.second = 66 - >>> n.second - 66 - -Testing __delattr__ and __delattr__: - >>> del n.first - Traceback (innermost last): - File "", line 1, in ? - AttributeError: first can't be deleted! - >>> del n.second - Traceback (innermost last): - File "", line 1, in ? - AttributeError: Attributes can't be deleted! - >>> del n.third - Traceback (innermost last): - File "", line 1, in ? - AttributeError: Attributes can't be deleted! - - # Now show that we can override it. - - >>> class IntTriple(IntPair): - ... def __getattr__(self, s): - ... if s in ['first', 'second']: - ... return IntPair.__getattr__(self, s) - ... elif s == 'third': - ... return 3 - ... else: - ... raise AttributeError(s) - ... - ... # Also show that __setattr__ is supported - ... def __setattr__(self, name, value): - ... raise AttributeError('no writable attributes') - ... - >>> p = IntTriple(0, 1) - >>> p.first - 0 - >>> p.second - 1 - >>> p.third - 3 - >>> p.bax - Traceback (innermost last): - File "", line 1, in ? - AttributeError: bax - >>> p.third = 'yes' - Traceback (innermost last): - File "", line 1, in ? - AttributeError: no writable attributes - >>> del p.third - Traceback (innermost last): - File "", line 1, in ? - AttributeError: Attributes can't be deleted! - -demonstrate def_readonly, def_read_write: - >>> sp = StringPair("hello", "world") - >>> sp.first # first is read-only - 'hello' - >>> first_string(sp) # prove that we're not just looking in sp's __dict__ - 'hello' - >>> sp.first = 'hi' # we're not allowed to change it - Traceback (innermost last): - File "", line 1, in ? - AttributeError: 'first' attribute is read-only - >>> first_string(sp) # prove that it hasn't changed - 'hello' - - >>> sp.second # second is read/write - 'world' - >>> second_string(sp) - 'world' - >>> sp.second = 'universe' # set the second attribute - >>> sp.second - 'universe' - >>> second_string(sp) # this proves we didn't just set it in sp's __dict__ - 'universe' - -some __str__ and __repr__ tests: - >>> sp - ('hello', 'universe') - >>> repr(sp) - "('hello', 'universe')" - >>> str(sp) - "('hello', 'universe')" - - Range has a __str__ function but not a __repr__ function - >>> range = Range(5, 20) - >>> str(range) - '(5, 20)' - >>> assert re.match('', repr(range)) - -__hash__ and __cmp__ tests: - # Range has both __hash__ and __cmp__, thus is hashable - >>> colors = { Range(3,4): 'blue', Range(7,9): 'red' } - >>> colors[Range(3,4)] - 'blue' - - # StringPair has only __cmp__ - >>> { StringPair('yo', 'eddy'): 1 } - Traceback (innermost last): - File "", line 1, in ? - TypeError: unhashable type - - # But it can be sorted - >>> stringpairs = [ StringPair('yo', 'eddy'), StringPair('yo', 'betty'), sp ] - >>> stringpairs.sort() - >>> stringpairs - [('hello', 'universe'), ('yo', 'betty'), ('yo', 'eddy')] - -make_pair is a global function in the module. - - >>> couple = make_pair(3,12) - >>> couple.first - 3 - >>> couple.second - 12 - -Testing __call__: - >>> couple2 = make_pair(3, 7) - >>> comparator = CompareIntPair() - >>> comparator(couple, couple) - 0 - >>> comparator(couple, couple2) - 0 - >>> comparator(couple2, couple) - 1 - -Testing overloaded free functions - >>> overloaded() - 'Hello world!' - >>> overloaded(1) - 1 - >>> overloaded('foo') - 'foo' - >>> overloaded(1,2) - 3 - >>> overloaded(1,2,3) - 6 - >>> overloaded(1,2,3,4) - 10 - >>> overloaded(1,2,3,4,5) - 15 - >>> try: overloaded(1, 'foo') - ... except TypeError, err: - ... assert re.match("No overloaded functions match \(int, str[a-z]*\)\. Candidates are:", - ... str(err)) - ... else: - ... print 'no exception' - -Testing overloaded constructors - - >>> over = OverloadTest() - >>> over.getX() - 1000 - >>> over = OverloadTest(1) - >>> over.getX() - 1 - >>> over = OverloadTest(1,1) - >>> over.getX() - 2 - >>> over = OverloadTest(1,1,1) - >>> over.getX() - 3 - >>> over = OverloadTest(1,1,1,1) - >>> over.getX() - 4 - >>> over = OverloadTest(1,1,1,1,1) - >>> over.getX() - 5 - >>> over = OverloadTest(over) - >>> over.getX() - 5 - >>> try: over = OverloadTest(1, 'foo') - ... except TypeError, err: - ... assert re.match("No overloaded functions match \(OverloadTest, int, str[a-z]*\)\. Candidates are:", - ... str(err)) - ... else: - ... print 'no exception' - -Testing overloaded methods - - >>> over.setX(3) - >>> over.overloaded() - 3 - >>> over.overloaded(1) - 1 - >>> over.overloaded(1,1) - 2 - >>> over.overloaded(1,1,1) - 3 - >>> over.overloaded(1,1,1,1) - 4 - >>> over.overloaded(1,1,1,1,1) - 5 - >>> try: over.overloaded(1,'foo') - ... except TypeError, err: - ... assert re.match("No overloaded functions match \(OverloadTest, int, str[a-z]*\)\. Candidates are:", - ... str(err)) - ... else: - ... print 'no exception' - -Testing base class conversions - - >>> testUpcast(over) - Traceback (innermost last): - TypeError: extension class 'OverloadTest' is not convertible into 'Base'. - >>> der1 = Derived1(333) - >>> der1.x() - 333 - >>> testUpcast(der1) - 333 - >>> der1 = derived1Factory(1000) - >>> testDowncast1(der1) - 1000 - >>> testDowncast2(der1) - Traceback (innermost last): - TypeError: extension class 'Base' is not convertible into 'Derived2'. - >>> der2 = Derived2(444) - >>> der2.x() - 444 - >>> testUpcast(der2) - 444 - >>> der2 = derived2Factory(1111) - >>> testDowncast2(der2) - Traceback (innermost last): - TypeError: extension class 'Base' is not convertible into 'Derived2'. - -Testing interaction between callbacks, base declarations, and overloading -- testCallback() calls callback() (within C++) -- callback() is overloaded (in the wrapped class CallbackTest) -- callback() is redefined in RedefineCallback (overloading is simulated by type casing) -- testCallback() should use the redefined callback() - - >>> c = CallbackTest() - >>> c.testCallback(1) - 2 - - >>> try: c.testCallback('foo') - ... except TypeError, err: assert_integer_expected(err) - ... else: print 'no exception' - - >>> c.callback(1) - 2 - >>> c.callback('foo') - 'foo 1' - - >>> import types - >>> class RedefineCallback(CallbackTest): - ... def callback(self, x): - ... if type(x) is types.IntType: - ... return x - 2 - ... else: - ... return CallbackTest.callback(self,x) - ... - >>> r = RedefineCallback() - >>> r.callback(1) - -1 - >>> r.callback('foo') - 'foo 1' - - >>> try: r.testCallback('foo') - ... except TypeError, err: assert_integer_expected(err) - ... else: print 'no exception' - - >>> r.testCallback(1) - -1 - >>> testCallback(r, 1) - -1 - -Regression test for a reference-counting bug thanks to Mark Evans -() - >>> sizelist([]) - 0.0 - >>> sizelist([1, 2, 4]) - 3.0 - -And another for doubles - >>> vector_double().push_back(3.0) - -Tests for method lookup in the context of inheritance -Set up the tests - - >>> a1 = A1() - >>> a2 = A2() - >>> b1 = B1() - >>> b2 = B2() - >>> pa1_a1 = factoryA1asA1() - >>> pb1_a1 = factoryB1asA1() - >>> pb2_a1 = factoryB2asA1() - >>> pc_a1 = factoryCasA1() - >>> pa2_a2 = factoryA2asA2() - >>> pb1_a2 = factoryB1asA2() - >>> pb1_b1 = factoryB1asB1() - >>> pc_b1 = factoryCasB1() - >>> class DA1(A1): - ... def overrideA1(self): - ... return 'DA1.overrideA1' - ... - >>> da1 = DA1() - >>> class DB1(B1): - ... def overrideA1(self): - ... return 'DB1.overrideA1' - ... def overrideB1(self): - ... return 'DB1.overrideB1' - ... - >>> db1 = DB1() - >>> class DB2(B2): pass - ... - >>> db2 = DB2() - -test overrideA1 - - >>> a1.overrideA1() - 'A1::overrideA1' - >>> b1.overrideA1() - 'B1::overrideA1' - >>> b2.overrideA1() - 'B2::overrideA1' - >>> da1.overrideA1() - 'DA1.overrideA1' - >>> db1.overrideA1() - 'DB1.overrideA1' - >>> pa1_a1.overrideA1() - 'A1::overrideA1' - >>> pb1_a1.overrideA1() - 'B1::overrideA1' - >>> pb2_a1.overrideA1() - 'B2::overrideA1' - >>> pb1_b1.overrideA1() - 'B1::overrideA1' - >>> pc_a1.overrideA1() - 'B1::overrideA1' - >>> pc_b1.overrideA1() - 'B1::overrideA1' - -test call_overrideA1 - - >>> call_overrideA1(a1) - 'A1::overrideA1' - >>> call_overrideA1(b1) - 'B1::overrideA1' - >>> call_overrideA1(b2) - 'B2::overrideA1' - >>> call_overrideA1(da1) - 'DA1.overrideA1' - >>> call_overrideA1(db1) - 'DB1.overrideA1' - >>> call_overrideA1(pa1_a1) - 'A1::overrideA1' - >>> call_overrideA1(pb1_a1) - 'B1::overrideA1' - >>> call_overrideA1(pb2_a1) - 'B2::overrideA1' - >>> call_overrideA1(pb1_b1) - 'B1::overrideA1' - >>> call_overrideA1(pc_a1) - 'B1::overrideA1' - >>> call_overrideA1(pc_b1) - 'B1::overrideA1' - -test inheritA1 - - >>> a1.inheritA1() - 'A1::inheritA1' - >>> b1.inheritA1() - 'A1::inheritA1' - >>> b2.inheritA1() - 'A1::inheritA1' - >>> da1.inheritA1() - 'A1::inheritA1' - >>> db1.inheritA1() - 'A1::inheritA1' - >>> pa1_a1.inheritA1() - 'A1::inheritA1' - >>> pb1_a1.inheritA1() - 'A1::inheritA1' - >>> pb2_a1.inheritA1() - 'A1::inheritA1' - >>> pb1_b1.inheritA1() - 'A1::inheritA1' - >>> pc_a1.inheritA1() - 'A1::inheritA1' - >>> pc_b1.inheritA1() - 'A1::inheritA1' - -test call_inheritA1 - - >>> call_inheritA1(a1) - 'A1::inheritA1' - >>> call_inheritA1(b1) - 'A1::inheritA1' - >>> call_inheritA1(b2) - 'A1::inheritA1' - >>> call_inheritA1(da1) - 'A1::inheritA1' - >>> call_inheritA1(db1) - 'A1::inheritA1' - >>> call_inheritA1(pa1_a1) - 'A1::inheritA1' - >>> call_inheritA1(pb1_a1) - 'A1::inheritA1' - >>> call_inheritA1(pb2_a1) - 'A1::inheritA1' - >>> call_inheritA1(pb1_b1) - 'A1::inheritA1' - >>> call_inheritA1(pc_a1) - 'A1::inheritA1' - >>> call_inheritA1(pc_b1) - 'A1::inheritA1' - -test inheritA2 - - >>> a2.inheritA2() - 'A2::inheritA2' - >>> b1.inheritA2() - 'A2::inheritA2' - >>> b2.inheritA2() - 'A2::inheritA2' - >>> db1.inheritA2() - 'A2::inheritA2' - >>> pa2_a2.inheritA2() - 'A2::inheritA2' - >>> pb1_a2.inheritA2() - 'A2::inheritA2' - >>> pb1_b1.inheritA2() - 'A2::inheritA2' - -test overrideB1 - - >>> b1.overrideB1() - 'B1::overrideB1' - >>> db1.overrideB1() - 'DB1.overrideB1' - >>> pb1_b1.overrideB1() - 'B1::overrideB1' - >>> pc_b1.overrideB1() - 'C::overrideB1' - -test call_overrideB1 - - >>> call_overrideB1(b1) - 'B1::overrideB1' - >>> call_overrideB1(db1) - 'DB1.overrideB1' - >>> call_overrideB1(pb1_a1) - 'B1::overrideB1' - >>> call_overrideB1(pc_a1) - 'C::overrideB1' - >>> call_overrideB1(pb1_b1) - 'B1::overrideB1' - >>> call_overrideB1(pc_b1) - 'C::overrideB1' - -test inheritB2 - - >>> b2.inheritB2() - 'B2::inheritB2' - >>> db2.inheritB2() - 'B2::inheritB2' - -========= test the new def_raw() feature ========== - - >>> r = RawTest(1) - >>> raw(r,1,third=1,fourth=1) - 4 - >>> r.raw(1,third=1,fourth=1) - 4 - >>> raw(r,1,third=1,f=1) - Traceback (innermost last): - KeyError: fourth - >>> raw(r,1,third=1) - Traceback (innermost last): - TypeError: wrong number of arguments - >>> raw(r,1) - Traceback (innermost last): - TypeError: wrong number of arguments - >>> raw() - Traceback (innermost last): - TypeError: wrong number of arguments - >>> raw1(1,second=1) - 2 - >>> raw1(1) - 1 - >>> raw1(second=1) - 1 - >>> raw1() - 0 - >>> raw2(1,second=1) - 2 - >>> raw2(1) - 1 - >>> raw2(second=1) - 1 - >>> raw2() - 0 - -========= test export of operators ========== - - >>> i = Int(2) - >>> j = i+i - >>> j.i() - 4 - >>> j = i-i - >>> j.i() - 0 - >>> j = i*i - >>> j.i() - 4 - >>> i>> cmp(i,i) - 0 - >>> k = Int(5) - >>> j = divmod(k, i) - >>> j[0].i() - 2 - >>> j[1].i() - 1 - >>> j = pow(i, k) - >>> j.i() - 32 - >>> j = pow(i, k, k) - >>> j.i() - 2 - >>> j = -i - >>> j.i() - -2 - >>> str(i) - '2' - >>> try: j = i/i - ... except TypeError, err: - ... assert re.match(r'(bad|unsupported) operand type\(s\) for /', - ... str(err)) - ... else: print 'no exception' - - >>> j = abs(i) - Traceback (innermost last): - TypeError: bad operand type for abs() - >>> j = i+1 - >>> j.i() - 3 - >>> j = i-1 - >>> j.i() - 1 - >>> j = i*1 - >>> j.i() - 2 - >>> i<1 - 0 - >>> cmp(i,1) - 1 - >>> j = pow(i, 5) - >>> j.i() - 32 - >>> j = pow(i, 5, k) - Traceback (innermost last): - TypeError: bad operand type(s) for pow() - >>> j = pow(i, 5, 5) - Traceback (innermost last): - TypeError: bad operand type(s) for pow() - >>> j = i/1 - Traceback (innermost last): - TypeError: bad operand type(s) for / - >>> j = 1+i - >>> j.i() - 3 - >>> j = 1-i - >>> j.i() - -1 - >>> j = 1*i - >>> j.i() - 2 - >>> 1>> cmp(1,i) - -1 - >>> j = 1/i - Traceback (innermost last): - TypeError: bad operand type(s) for / - >>> pow(1,i) - Traceback (innermost last): - TypeError: bad operand type(s) for pow() - -Test operator export to a subclass - - # force method table sharing - >>> class IntDerived1(Int): pass - ... - - >>> class IntDerived(Int): - ... def __init__(self, i): - ... Int.__init__(self, i) - ... def __str__(self): - ... return 'IntDerived: ' + str(self.i()) - ... - >>> f = IntDerived(3) - >>> str(f) - 'IntDerived: 3' - >>> j = f * f - >>> j.i() - 9 - >>> j = f * i - >>> j.i() - 6 - >>> j = f * 5 - >>> j.i() - 15 - >>> j = i * f - >>> j.i() - 6 - >>> j = 5 * f - >>> j.i() - 15 - - -========= Prove that the "phantom base class" issue is resolved ========== - - >>> assert pa1_a1.__class__ == A1 - >>> assert pb1_a1.__class__ == A1 - >>> assert pb2_a1.__class__ == A1 - >>> assert pc_a1.__class__ == A1 - >>> assert pa2_a2.__class__ == A2 - >>> assert pb1_a2.__class__ == A2 - >>> assert pb1_b1.__class__ == B1 - >>> assert pc_b1.__class__ == B1 - >>> assert A1 in B1.__bases__ - >>> assert A2 in B1.__bases__ - >>> assert A1 in B2.__bases__ - >>> assert A2 in B2.__bases__ - >>> assert A1 in DA1.__bases__ - >>> assert B1 in DB1.__bases__ - >>> assert B2 in DB2.__bases__ - -=============================================================== -test methodologies for wrapping functions that return a pointer - - >>> get_record().value - 1234 - - In this methodology, the referent is copied - >>> get_record() == get_record() - 0 - -======== Enums and non-method class attributes ============== - >>> eo = EnumOwner(EnumOwner.one, EnumOwner.two) - >>> eo.first - 1 - >>> eo.second - 2 - >>> eo.first = EnumOwner.three - >>> eo.second = EnumOwner.one - >>> eo.first - 3 - >>> eo.second - 1 - -======== test [plain] char converters ============== - >>> get_plain_char() - 'x' - >>> use_plain_char('a') - 'aaa' - >>> use_const_plain_char('b') - 'bbbbb' - -======== test std::complex converters ============== - >>> c = dpolar(3, 5) - >>> type(c) - - >>> '%.3g' % (dreal(c)) - '0.851' - >>> '%.3g' % (dimag(c)) - '-2.88' - >>> '%.3g' % (freal(c)) - '0.851' - >>> '%.3g' % (fimag(c)) - '-2.88' - >>> c = fpolar(7, 13) - >>> type(c) - - >>> '%.3g' % (fimag(c)) - '2.94' - >>> '%.3g' % (freal(c)) - '6.35' - >>> '%.3g' % (dimag(c)) - '2.94' - >>> '%.3g' % (dreal(c)) - '6.35' - >>> '%.3g' % (dreal(3)) - '3' - >>> '%.3g' % (dreal(3L)) - '3' - >>> '%.3g' % (dreal(3.)) - '3' - >>> '%.3g' % (freal(3)) - '3' - >>> '%.3g' % (freal(3L)) - '3' - >>> '%.3g' % (freal(3.)) - '3' - -''' -#' - -__test__ = {} -import sys - -# Inplace ops only exist in python 2.1 or later. -if sys.hexversion >= 0x02010000: - __test__['inplacetests'] = r''' - >>> ii = Int(1) - >>> ii += Int(2) - >>> ii.i() - 3 - >>> ii -= Int(1) - >>> ii.i() - 2 - >>> ii *= Int(3) - >>> ii.i() - 6 - >>> ii /= Int(2) - >>> ii.i() - 3 - >>> ii <<= Int(2) - >>> ii.i() - 12 - >>> ii >>= Int(1) - >>> ii.i() - 6 - >>> ii &= Int(5) - >>> ii.i() - 4 - >>> ii |= Int(9) - >>> ii.i() - 13 - >>> ii ^= Int(7) - >>> ii.i() - 10 - >>> ii %= Int(4) - >>> ii.i() - 2 - >>> ii **= Int(3) - >>> ii.i() - 8 - >>> ii.j() - 11 -''' - -from boost_python_test import * - -# pickle requires these derived classes to be -# at the global scope of the module - -class myrational(Rational): - __dict_defines_state__ = 1 # this is a lie but good enough for testing. - -class myworld(world): - def __init__(self): - world.__init__(self, 'anywhere') - self.x = 1 - -class myunsafeworld(myworld): - __getstate_manages_dict__ = 1 # this is a lie but good enough for testing. - - -def assert_integer_expected(err): - """Handle a common error report which appears differently in Python 1.5.x and 2.0""" - assert isinstance(err, TypeError) - message = str(err) - assert (message == "illegal argument type for built-in operation" - or message == "an integer is required") - -import string -import re -import sys - -def run(args = None): - if args is not None: - sys.argv = args - - import doctest, comprehensive - return doctest.testmod(comprehensive) - -if __name__ == '__main__': - sys.exit(run()[0]) diff --git a/test/data_members.cpp b/test/data_members.cpp deleted file mode 100644 index 7a05d359..00000000 --- a/test/data_members.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include "test_class.hpp" - -#if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 -# include // works around a KCC intermediate code generation bug -#endif - - -using namespace boost::python; - -typedef test_class<> X; - -typedef test_class<1> Y; - -double get_fair_value(X const& x) { return x.value(); } - -BOOST_PYTHON_MODULE_INIT(data_members_ext) -{ - class_("X", init()) - .def("value", &X::value) - .def("set", &X::set) - .def_readonly("x", &X::x) - .add_property("fair_value", &get_fair_value) - ; - - class_("Y", init()) - .def("value", &Y::value) - .def("set", &Y::set) - .def_readwrite("x", &Y::x) - ; -} - -#include "module_tail.cpp" diff --git a/test/data_members.py b/test/data_members.py deleted file mode 100644 index ab79a90a..00000000 --- a/test/data_members.py +++ /dev/null @@ -1,32 +0,0 @@ -''' ->>> from data_members_ext import * ->>> x = X(42) ->>> x.x -42 ->>> try: x.x = 77 -... except AttributeError: pass -... else: print 'no error' - ->>> x.fair_value -42.0 - ->>> y = Y(69) ->>> y.x -69 ->>> y.x = 77 ->>> y.x -77 -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/defaults.cpp b/test/defaults.cpp deleted file mode 100644 index 41341e72..00000000 --- a/test/defaults.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -#include -#include -#include -#include -#include -#include -#include - -#if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 -# include // works around a KCC intermediate code generation bug -#endif - -using namespace boost::python; - -char const* const format = "int(%s); char(%s); string(%s); double(%s); "; - -/////////////////////////////////////////////////////////////////////////////// -// -// Overloaded functions -// -/////////////////////////////////////////////////////////////////////////////// -object -bar(int a, char b, std::string c, double d) -{ - return format % make_tuple(a, b, c, d); -} - -object -bar(int a, char b, std::string c) -{ - return format % make_tuple(a, b, c, 0.0); -} - -object -bar(int a, char b) -{ - return format % make_tuple(a, b, "default", 0.0); -} - -object -bar(int a) -{ - return format % make_tuple(a, 'D', "default", 0.0); -} - -BOOST_PYTHON_FUNCTION_OVERLOADS(bar_stubs, bar, 1, 4) - -/////////////////////////////////////////////////////////////////////////////// -// -// Functions with default arguments -// -/////////////////////////////////////////////////////////////////////////////// -object -foo(int a, char b = 'D', std::string c = "default", double d = 0.0) -{ - return format % make_tuple(a, b, c, d); -} - -BOOST_PYTHON_FUNCTION_OVERLOADS(foo_stubs, foo, 1, 4) - -/////////////////////////////////////////////////////////////////////////////// -// -// Overloaded member functions with default arguments -// -/////////////////////////////////////////////////////////////////////////////// -struct Y { - - Y() {} - - object - get_state() const - { - return format % make_tuple(a, b, c, d); - } - - int a; char b; std::string c; double d; -}; - - -struct X { - - X() {} - - X(int a, char b = 'D', std::string c = "constructor", double d = 0.0) - : state(format % make_tuple(a, b, c, d)) - {} - - X(std::string s, bool b) - : state("Got exactly two arguments from constructor: string(%s); bool(%s); " % make_tuple(s, b)) - {} - - object - bar(int a, char b = 'D', std::string c = "default", double d = 0.0) const - { - return format % make_tuple(a, b, c, d); - } - - Y const& - bar2(int a = 0, char b = 'D', std::string c = "default", double d = 0.0) - { - // tests zero arg member function and return_internal_reference policy - y.a = a; - y.b = b; - y.c = c; - y.d = d; - return y; - } - - object - foo(int a, bool b=false) const - { - return "int(%s); bool(%s); " % make_tuple(a, b); - } - - object - foo(std::string a, bool b=false) const - { - return "string(%s); bool(%s); " % make_tuple(a, b); - } - - object - foo(list a, list b, bool c=false) const - { - return "list(%s); list(%s); bool(%s); " % make_tuple(a, b, c); - } - - object - get_state() const - { - return state; - } - - Y y; - object state; -}; - -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_bar_stubs, bar, 1, 4) -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_bar_stubs2, bar2, 0, 4) -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_foo_2_stubs, foo, 1, 2) -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_foo_3_stubs, foo, 2, 3) - -/////////////////////////////////////////////////////////////////////////////// - -BOOST_PYTHON_MODULE_INIT(defaults_ext) -{ - def("foo", foo, foo_stubs()); - def("bar", (object(*)(int, char, std::string, double))0, bar_stubs()); - - // Show that this works with the old obsolete module version of def(). - module("defaults_ext") - .def("foobar", foo, foo_stubs()) - .def("barfoo", (object(*)(int, char, std::string, double))0, bar_stubs()) - ; - - class_("Y", init<>("doc of Y init")) // this should work - .def("get_state", &Y::get_state) - ; - - class_("X") - - .def(init >("doc of init")) - .def(init()[default_call_policies()]) // what's a good policy here? - .def("get_state", &X::get_state) - .def("bar", &X::bar, X_bar_stubs()) - .def("bar2", &X::bar2, X_bar_stubs2("doc of X::bar2")[return_internal_reference<>()]) - .def("foo", (object(X::*)(std::string, bool) const)0, X_foo_2_stubs()) - .def("foo", (object(X::*)(int, bool) const)0, X_foo_2_stubs()) - .def("foo", (object(X::*)(list, list, bool) const)0, X_foo_3_stubs()) - ; -} - -#include "module_tail.cpp" - diff --git a/test/defaults.py b/test/defaults.py deleted file mode 100644 index ee7a6588..00000000 --- a/test/defaults.py +++ /dev/null @@ -1,172 +0,0 @@ -""" - ->>> from defaults_ext import * ->>> bar(1) -'int(1); char(D); string(default); double(0.0); ' - ->>> bar(2, 'X') -'int(2); char(X); string(default); double(0.0); ' - ->>> bar(3, 'Y', "Hello World") -'int(3); char(Y); string(Hello World); double(0.0); ' - ->>> bar(4, 'Z', "Hi There", 3.3) -'int(4); char(Z); string(Hi There); double(3.3); ' - ->>> foo(1) -'int(1); char(D); string(default); double(0.0); ' - ->>> foo(2, 'X') -'int(2); char(X); string(default); double(0.0); ' - ->>> foo(3, 'Y', "Hello World") -'int(3); char(Y); string(Hello World); double(0.0); ' - ->>> foo(4, 'Z', "Hi There", 3.3) -'int(4); char(Z); string(Hi There); double(3.3); ' - ->>> x = X() ->>> x.bar(1) -'int(1); char(D); string(default); double(0.0); ' - ->>> x.bar(2, 'X') -'int(2); char(X); string(default); double(0.0); ' - ->>> x.bar(3, 'Y', "Hello World") -'int(3); char(Y); string(Hello World); double(0.0); ' - ->>> x.bar(4, 'Z', "Hi There", 3.3) -'int(4); char(Z); string(Hi There); double(3.3); ' - ->>> x.foo(5) -'int(5); bool(0); ' - ->>> x.foo(6, 0) -'int(6); bool(0); ' - ->>> x.foo(7, 1) -'int(7); bool(1); ' - ->>> x.foo("A") -'string(A); bool(0); ' - ->>> x.foo("B", False) -'string(B); bool(0); ' - ->>> x.foo("C", True) -'string(C); bool(1); ' - ->>> x.foo([0,1,2], [2,3,4]) -'list([0, 1, 2]); list([2, 3, 4]); bool(0); ' - ->>> x.foo([0,1,2], [2,3,4], False) -'list([0, 1, 2]); list([2, 3, 4]); bool(0); ' - ->>> x.foo([0,1,2], [2,3,4], True) -'list([0, 1, 2]); list([2, 3, 4]); bool(1); ' - ->>> x = X(1) ->>> x.get_state() -'int(1); char(D); string(constructor); double(0.0); ' - ->>> x = X(1, 'X') ->>> x.get_state() -'int(1); char(X); string(constructor); double(0.0); ' - ->>> x = X(1, 'X', "Yabadabadoo") ->>> x.get_state() -'int(1); char(X); string(Yabadabadoo); double(0.0); ' - ->>> x = X(1, 'X', "Phoenix", 3.65) ->>> x.get_state() -'int(1); char(X); string(Phoenix); double(3.65); ' - ->>> x.bar2().get_state() -'int(0); char(D); string(default); double(0.0); ' - ->>> x.bar2(1).get_state() -'int(1); char(D); string(default); double(0.0); ' - ->>> x.bar2(1, 'K').get_state() -'int(1); char(K); string(default); double(0.0); ' - ->>> x.bar2(1, 'K', "Kim").get_state() -'int(1); char(K); string(Kim); double(0.0); ' - ->>> x.bar2(1, 'K', "Kim", 9.9).get_state() -'int(1); char(K); string(Kim); double(9.9); ' - ->>> x = X("Phoenix", 1) ->>> x.get_state() -'Got exactly two arguments from constructor: string(Phoenix); bool(1); ' - ->>> def printdoc(x): -... print x.__doc__ - ->>> printdoc(X.__init__) -doc of init - ->>> printdoc(Y.__init__) -doc of Y init - ->>> printdoc(X.bar2) -doc of X::bar2 - -""" -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/destroy_test.cpp b/test/destroy_test.cpp deleted file mode 100644 index 38d5d1d5..00000000 --- a/test/destroy_test.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include - -struct bar; - -namespace boost -{ - // lie to the library about bar so we can show that its destructor is optimized away. - template <> - struct has_trivial_destructor - { - BOOST_STATIC_CONSTANT(bool, value=true); - }; -} - - -int count; -int marks[] = { - -1 - , -1, -1 - , -1, -1, -1, -1 - , -1 -}; -int* kills = marks; - -struct foo -{ - foo() : n(count++) {} - ~foo() - { - *kills++ = n; - } - int n; -}; - -struct bar : foo {}; - -void assert_destructions(int n) -{ - for (int i = 0; i < n; ++i) - assert(marks[i] == i); - assert(marks[n] == -1); -} - -int main() -{ - assert_destructions(0); - typedef int a[2]; - - foo* f1 = new foo; - boost::python::detail::destroy_referent(f1); - assert_destructions(1); - - foo* f2 = new foo[2]; - typedef foo x[2]; - - boost::python::detail::destroy_referent(f2); - assert_destructions(3); - - typedef foo y[2][2]; - x* f3 = new y; - boost::python::detail::destroy_referent(f3); - assert_destructions(7); - - bar* b1 = new bar; - boost::python::detail::destroy_referent(b1); - assert_destructions(7); - - bar* b2 = new bar[2]; - typedef bar xb[2]; - - boost::python::detail::destroy_referent(b2); - assert_destructions(7); - - typedef bar yb[2][2]; - xb* b3 = new yb; - boost::python::detail::destroy_referent(b3); - assert_destructions(7); - - return 0; -} diff --git a/test/dict.cpp b/test/dict.cpp deleted file mode 100644 index 0850c6be..00000000 --- a/test/dict.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include -#include - -using namespace boost::python; - -object new_dict() -{ - return dict(); -} - -object data_dict() -{ - dict tmp1; - tmp1["key1"] = "value1"; - - dict tmp2; - tmp2["key2"] = "value2"; - tmp1[1] = tmp2; - return tmp1; -} - -object dict_from_sequence(object sequence) -{ - return dict(sequence); -} - -object dict_keys(dict data) -{ - return data.keys(); -} - -object dict_values(dict data) -{ - return data.values(); -} - -object dict_items(dict data) -{ - return data.items(); -} - -void work_with_dict(dict data1, dict data2) -{ - if (!data1.has_key("k1")) { - throw std::runtime_error("dict does not have key 'k1'"); - } - data1.update(data2); -} - -void test_templates(object print) -{ - std::string key = "key"; - - dict tmp; - tmp[1] = "a test string"; - print(tmp.get(1)); - //print(tmp[1]); - tmp[1.5] = 13; - print(tmp.get(1.5)); - print(tmp); - print(tmp.get(2,"default")); - print(tmp.has_key(key)); - print(tmp.setdefault(3,"default")); - //print(tmp[3]); -} - -BOOST_PYTHON_MODULE_INIT(dict_ext) -{ - def("new_dict", new_dict); - def("data_dict", data_dict); - def("dict_keys", dict_keys); - def("dict_values", dict_values); - def("dict_items", dict_items); - def("dict_from_sequence", dict_from_sequence); - def("work_with_dict", work_with_dict); - def("test_templates", test_templates); -} diff --git a/test/dict.py b/test/dict.py deleted file mode 100644 index fdabf2c9..00000000 --- a/test/dict.py +++ /dev/null @@ -1,40 +0,0 @@ -""" ->>> from dict_ext import * ->>> def printer(*args): -... for x in args: print x, -... print -... ->>> print new_dict() -{} ->>> print data_dict() -{1: {'key2': 'value2'}, 'key1': 'value1'} ->>> tmp = data_dict() ->>> print dict_keys(tmp) -[1, 'key1'] ->>> print dict_values(tmp) -[{'key2': 'value2'}, 'value1'] ->>> print dict_items(tmp) -[(1, {'key2': 'value2'}), ('key1', 'value1')] ->>> print dict_from_sequence([(1,1),(2,2),(3,3)]) -{1: 1, 2: 2, 3: 3} ->>> test_templates(printer) -a test string -13 -{1.5: 13, 1: 'a test string'} -default -0 -default -""" - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/docstring.cpp b/test/docstring.cpp deleted file mode 100644 index 417a6635..00000000 --- a/test/docstring.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include -#include -#include "test_class.hpp" - -// Just use math.h here; trying to use std::pow() causes too much -// trouble for non-conforming compilers and libraries. -#include - -using namespace boost::python; - -typedef test_class<> X; - -X* create(int x) -{ - return new X(x); -} - -unsigned long fact(unsigned long n) -{ - return n <= 1 ? n : n * fact(n - 1); -} - -BOOST_PYTHON_MODULE_INIT(docstring_ext) -{ - scope().attr("__doc__") = - "A simple test module for documentation strings\n" - "Exercised by docstring.py" - ; - - class_("X", - "A simple class wrapper around a C++ int\n" - "includes some error-checking" - - , init( - "this is the __init__ function\n" - "its documentation has two lines." - ) - - ) - .def("value", &X::value, - "gets the value of the object") - ; - - def("create", create, return_value_policy(), - "creates a new X object"); - - def("fact", fact, "compute the factorial"); -} - -#include "module_tail.cpp" diff --git a/test/docstring.py b/test/docstring.py deleted file mode 100644 index 15cfdaf1..00000000 --- a/test/docstring.py +++ /dev/null @@ -1,54 +0,0 @@ -''' ->>> from docstring_ext import * - ->>> def printdoc(x): -... print x.__doc__ - ->>> printdoc(X) -A simple class wrapper around a C++ int -includes some error-checking - ->>> printdoc(X.__init__) -this is the __init__ function -its documentation has two lines. - ->>> printdoc(X.value) -gets the value of the object - ->>> printdoc(create) -creates a new X object - ->>> printdoc(fact) -compute the factorial -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - - import docstring_ext - - result = doctest.testmod(sys.modules.get(__name__)) - - import pydoc - import re - docmodule = lambda m: re.sub(".\10", "", pydoc.text.docmodule(m)) - try: - print 'printing module help:' - print docmodule(docstring_ext) - except object, x: - print '********* failed **********' - print x - result = list(result) - result[0] += 1 - return tuple(result) - - return result - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/doctest.py b/test/doctest.py deleted file mode 100644 index 2829f1e6..00000000 --- a/test/doctest.py +++ /dev/null @@ -1,1173 +0,0 @@ -# Module doctest. -# Released to the public domain 16-Jan-2001, -# by Tim Peters (tim.one@home.com). - -# Provided as-is; use at your own risk; no warranty; no promises; enjoy! - -"""Module doctest -- a framework for running examples in docstrings. - -NORMAL USAGE - -In normal use, end each module M with: - -def _test(): - import doctest, M # replace M with your module's name - return doctest.testmod(M) # ditto - -if __name__ == "__main__": - _test() - -Then running the module as a script will cause the examples in the -docstrings to get executed and verified: - -python M.py - -This won't display anything unless an example fails, in which case the -failing example(s) and the cause(s) of the failure(s) are printed to stdout -(why not stderr? because stderr is a lame hack <0.2 wink>), and the final -line of output is "Test failed.". - -Run it with the -v switch instead: - -python M.py -v - -and a detailed report of all examples tried is printed to stdout, along -with assorted summaries at the end. - -You can force verbose mode by passing "verbose=1" to testmod, or prohibit -it by passing "verbose=0". In either of those cases, sys.argv is not -examined by testmod. - -In any case, testmod returns a 2-tuple of ints (f, t), where f is the -number of docstring examples that failed and t is the total number of -docstring examples attempted. - - -WHICH DOCSTRINGS ARE EXAMINED? - -+ M.__doc__. - -+ f.__doc__ for all functions f in M.__dict__.values(), except those - with private names and those defined in other modules. - -+ C.__doc__ for all classes C in M.__dict__.values(), except those with - private names and those defined in other modules. - -+ If M.__test__ exists and "is true", it must be a dict, and - each entry maps a (string) name to a function object, class object, or - string. Function and class object docstrings found from M.__test__ - are searched even if the name is private, and strings are searched - directly as if they were docstrings. In output, a key K in M.__test__ - appears with name - .__test__.K - -Any classes found are recursively searched similarly, to test docstrings in -their contained methods and nested classes. Private names reached from M's -globals are skipped, but all names reached from M.__test__ are searched. - -By default, a name is considered to be private if it begins with an -underscore (like "_my_func") but doesn't both begin and end with (at least) -two underscores (like "__init__"). You can change the default by passing -your own "isprivate" function to testmod. - -If you want to test docstrings in objects with private names too, stuff -them into an M.__test__ dict, or see ADVANCED USAGE below (e.g., pass your -own isprivate function to Tester's constructor, or call the rundoc method -of a Tester instance). - -WHAT'S THE EXECUTION CONTEXT? - -By default, each time testmod finds a docstring to test, it uses a *copy* -of M's globals (so that running tests on a module doesn't change the -module's real globals, and so that one test in M can't leave behind crumbs -that accidentally allow another test to work). This means examples can -freely use any names defined at top-level in M. It also means that sloppy -imports (see above) can cause examples in external docstrings to use -globals inappropriate for them. - -You can force use of your own dict as the execution context by passing -"globs=your_dict" to testmod instead. Presumably this would be a copy of -M.__dict__ merged with the globals from other imported modules. - - -WHAT IF I WANT TO TEST A WHOLE PACKAGE? - -Piece o' cake, provided the modules do their testing from docstrings. -Here's the test.py I use for the world's most elaborate Rational/ -floating-base-conversion pkg (which I'll distribute some day): - -from Rational import Cvt -from Rational import Format -from Rational import machprec -from Rational import Rat -from Rational import Round -from Rational import utils - -modules = (Cvt, - Format, - machprec, - Rat, - Round, - utils) - -def _test(): - import doctest - import sys - verbose = "-v" in sys.argv - for mod in modules: - doctest.testmod(mod, verbose=verbose, report=0) - doctest.master.summarize() - -if __name__ == "__main__": - _test() - -IOW, it just runs testmod on all the pkg modules. testmod remembers the -names and outcomes (# of failures, # of tries) for each item it's seen, and -passing "report=0" prevents it from printing a summary in verbose mode. -Instead, the summary is delayed until all modules have been tested, and -then "doctest.master.summarize()" forces the summary at the end. - -So this is very nice in practice: each module can be tested individually -with almost no work beyond writing up docstring examples, and collections -of modules can be tested too as a unit with no more work than the above. - - -WHAT ABOUT EXCEPTIONS? - -No problem, as long as the only output generated by the example is the -traceback itself. For example: - - >>> [1, 2, 3].remove(42) - Traceback (most recent call last): - File "", line 1, in ? - ValueError: list.remove(x): x not in list - >>> - -Note that only the exception type and value are compared (specifically, -only the last line in the traceback). - - -ADVANCED USAGE - -doctest.testmod() captures the testing policy I find most useful most -often. You may want other policies. - -testmod() actually creates a local instance of class doctest.Tester, runs -appropriate methods of that class, and merges the results into global -Tester instance doctest.master. - -You can create your own instances of doctest.Tester, and so build your own -policies, or even run methods of doctest.master directly. See -doctest.Tester.__doc__ for details. - - -SO WHAT DOES A DOCSTRING EXAMPLE LOOK LIKE ALREADY!? - -Oh ya. It's easy! In most cases a copy-and-paste of an interactive -console session works fine -- just make sure the leading whitespace is -rigidly consistent (you can mix tabs and spaces if you're too lazy to do it -right, but doctest is not in the business of guessing what you think a tab -means). - - >>> # comments are ignored - >>> x = 12 - >>> x - 12 - >>> if x == 13: - ... print "yes" - ... else: - ... print "no" - ... print "NO" - ... print "NO!!!" - ... - no - NO - NO!!! - >>> - -Any expected output must immediately follow the final ">>>" or "..." line -containing the code, and the expected output (if any) extends to the next -">>>" or all-whitespace line. That's it. - -Bummers: - -+ Expected output cannot contain an all-whitespace line, since such a line - is taken to signal the end of expected output. - -+ Output to stdout is captured, but not output to stderr (exception - tracebacks are captured via a different means). - -+ If you continue a line via backslashing in an interactive session, or for - any other reason use a backslash, you need to double the backslash in the - docstring version. This is simply because you're in a string, and so the - backslash must be escaped for it to survive intact. Like: - ->>> if "yes" == \\ -... "y" + \\ -... "es": # in the source code you'll see the doubled backslashes -... print 'yes' -yes - -The starting column doesn't matter: - ->>> assert "Easy!" - >>> import math - >>> math.floor(1.9) - 1.0 - -and as many leading whitespace characters are stripped from the expected -output as appeared in the initial ">>>" line that triggered it. - -If you execute this very file, the examples above will be found and -executed, leading to this output in verbose mode: - -Running doctest.__doc__ -Trying: [1, 2, 3].remove(42) -Expecting: -Traceback (most recent call last): - File "", line 1, in ? -ValueError: list.remove(x): x not in list -ok -Trying: x = 12 -Expecting: nothing -ok -Trying: x -Expecting: 12 -ok -Trying: -if x == 13: - print "yes" -else: - print "no" - print "NO" - print "NO!!!" -Expecting: -no -NO -NO!!! -ok -... and a bunch more like that, with this summary at the end: - -5 items had no tests: - doctest.Tester.__init__ - doctest.Tester.run__test__ - doctest.Tester.summarize - doctest.run_docstring_examples - doctest.testmod -12 items passed all tests: - 8 tests in doctest - 6 tests in doctest.Tester - 10 tests in doctest.Tester.merge - 14 tests in doctest.Tester.rundict - 3 tests in doctest.Tester.rundoc - 3 tests in doctest.Tester.runstring - 2 tests in doctest.__test__._TestClass - 2 tests in doctest.__test__._TestClass.__init__ - 2 tests in doctest.__test__._TestClass.get - 1 tests in doctest.__test__._TestClass.square - 2 tests in doctest.__test__.string - 7 tests in doctest.is_private -60 tests in 17 items. -60 passed and 0 failed. -Test passed. -""" - -__all__ = [ - 'testmod', - 'run_docstring_examples', - 'is_private', - 'Tester', -] - -import __future__ - -import re -PS1 = ">>>" -PS2 = "..." -_isPS1 = re.compile(r"(\s*)" + re.escape(PS1)).match -_isPS2 = re.compile(r"(\s*)" + re.escape(PS2)).match -_isEmpty = re.compile(r"\s*$").match -_isComment = re.compile(r"\s*#").match -del re - -from types import StringTypes as _StringTypes - -from inspect import isclass as _isclass -from inspect import isfunction as _isfunction -from inspect import ismodule as _ismodule -from inspect import classify_class_attrs as _classify_class_attrs - -# Extract interactive examples from a string. Return a list of triples, -# (source, outcome, lineno). "source" is the source code, and ends -# with a newline iff the source spans more than one line. "outcome" is -# the expected output if any, else an empty string. When not empty, -# outcome always ends with a newline. "lineno" is the line number, -# 0-based wrt the start of the string, of the first source line. - -def _extract_examples(s): - isPS1, isPS2 = _isPS1, _isPS2 - isEmpty, isComment = _isEmpty, _isComment - examples = [] - lines = s.split("\n") - i, n = 0, len(lines) - while i < n: - line = lines[i] - i = i + 1 - m = isPS1(line) - if m is None: - continue - j = m.end(0) # beyond the prompt - if isEmpty(line, j) or isComment(line, j): - # a bare prompt or comment -- not interesting - continue - lineno = i - 1 - if line[j] != " ": - raise ValueError("line " + `lineno` + " of docstring lacks " - "blank after " + PS1 + ": " + line) - j = j + 1 - blanks = m.group(1) - nblanks = len(blanks) - # suck up this and following PS2 lines - source = [] - while 1: - source.append(line[j:]) - line = lines[i] - m = isPS2(line) - if m: - if m.group(1) != blanks: - raise ValueError("inconsistent leading whitespace " - "in line " + `i` + " of docstring: " + line) - i = i + 1 - else: - break - if len(source) == 1: - source = source[0] - else: - # get rid of useless null line from trailing empty "..." - if source[-1] == "": - del source[-1] - source = "\n".join(source) + "\n" - # suck up response - if isPS1(line) or isEmpty(line): - expect = "" - else: - expect = [] - while 1: - if line[:nblanks] != blanks: - raise ValueError("inconsistent leading whitespace " - "in line " + `i` + " of docstring: " + line) - expect.append(line[nblanks:]) - i = i + 1 - line = lines[i] - if isPS1(line) or isEmpty(line): - break - expect = "\n".join(expect) + "\n" - examples.append( (source, expect, lineno) ) - return examples - -# Capture stdout when running examples. - -class _SpoofOut: - def __init__(self): - self.clear() - def write(self, s): - self.buf.append(s) - def get(self): - guts = "".join(self.buf) - # If anything at all was written, make sure there's a trailing - # newline. There's no way for the expected output to indicate - # that a trailing newline is missing. - if guts and not guts.endswith("\n"): - guts = guts + "\n" - # Prevent softspace from screwing up the next test case, in - # case they used print with a trailing comma in an example. - if hasattr(self, "softspace"): - del self.softspace - return guts - def clear(self): - self.buf = [] - if hasattr(self, "softspace"): - del self.softspace - def flush(self): - # JPython calls flush - pass - -# Display some tag-and-msg pairs nicely, keeping the tag and its msg -# on the same line when that makes sense. - -def _tag_out(printer, *tag_msg_pairs): - for tag, msg in tag_msg_pairs: - printer(tag + ":") - msg_has_nl = msg[-1:] == "\n" - msg_has_two_nl = msg_has_nl and \ - msg.find("\n") < len(msg) - 1 - if len(tag) + len(msg) < 76 and not msg_has_two_nl: - printer(" ") - else: - printer("\n") - printer(msg) - if not msg_has_nl: - printer("\n") - -# Run list of examples, in context globs. "out" can be used to display -# stuff to "the real" stdout, and fakeout is an instance of _SpoofOut -# that captures the examples' std output. Return (#failures, #tries). - -def _run_examples_inner(out, fakeout, examples, globs, verbose, name, - compileflags): - import sys, traceback - OK, BOOM, FAIL = range(3) - NADA = "nothing" - stderr = _SpoofOut() - failures = 0 - for source, want, lineno in examples: - if verbose: - _tag_out(out, ("Trying", source), - ("Expecting", want or NADA)) - fakeout.clear() - try: - exec compile(source, "", "single", - compileflags, 1) in globs - got = fakeout.get() - state = OK - except: - # See whether the exception was expected. - if want.find("Traceback (innermost last):\n") == 0 or \ - want.find("Traceback (most recent call last):\n") == 0: - # Only compare exception type and value - the rest of - # the traceback isn't necessary. - want = want.split('\n')[-2] + '\n' - exc_type, exc_val = sys.exc_info()[:2] - got = traceback.format_exception_only(exc_type, exc_val)[-1] - state = OK - else: - # unexpected exception - stderr.clear() - traceback.print_exc(file=stderr) - state = BOOM - - if state == OK: - if got == want: - if verbose: - out("ok\n") - continue - state = FAIL - - assert state in (FAIL, BOOM) - failures = failures + 1 - out("*" * 65 + "\n") - _tag_out(out, ("Failure in example", source)) - out("from line #" + `lineno` + " of " + name + "\n") - if state == FAIL: - _tag_out(out, ("Expected", want or NADA), ("Got", got)) - else: - assert state == BOOM - _tag_out(out, ("Exception raised", stderr.get())) - - return failures, len(examples) - -# Get the future-flags associated with the future features that have been -# imported into globs. - -def _extract_future_flags(globs): - flags = 0 - for fname in __future__.all_feature_names: - feature = globs.get(fname, None) - if feature is getattr(__future__, fname): - flags |= feature.compiler_flag - return flags - -# Run list of examples, in a shallow copy of context (dict) globs. -# Return (#failures, #tries). - -def _run_examples(examples, globs, verbose, name, compileflags): - import sys - saveout = sys.stdout - globs = globs.copy() - try: - sys.stdout = fakeout = _SpoofOut() - x = _run_examples_inner(saveout.write, fakeout, examples, - globs, verbose, name, compileflags) - finally: - sys.stdout = saveout - # While Python gc can clean up most cycles on its own, it doesn't - # chase frame objects. This is especially irksome when running - # generator tests that raise exceptions, because a named generator- - # iterator gets an entry in globs, and the generator-iterator - # object's frame's traceback info points back to globs. This is - # easy to break just by clearing the namespace. This can also - # help to break other kinds of cycles, and even for cycles that - # gc can break itself it's better to break them ASAP. - globs.clear() - return x - -def run_docstring_examples(f, globs, verbose=0, name="NoName", - compileflags=None): - """f, globs, verbose=0, name="NoName" -> run examples from f.__doc__. - - Use (a shallow copy of) dict globs as the globals for execution. - Return (#failures, #tries). - - If optional arg verbose is true, print stuff even if there are no - failures. - Use string name in failure msgs. - """ - - try: - doc = f.__doc__ - if not doc: - # docstring empty or None - return 0, 0 - # just in case CT invents a doc object that has to be forced - # to look like a string <0.9 wink> - doc = str(doc) - except: - return 0, 0 - - e = _extract_examples(doc) - if not e: - return 0, 0 - if compileflags is None: - compileflags = _extract_future_flags(globs) - return _run_examples(e, globs, verbose, name, compileflags) - -def is_private(prefix, base): - """prefix, base -> true iff name prefix + "." + base is "private". - - Prefix may be an empty string, and base does not contain a period. - Prefix is ignored (although functions you write conforming to this - protocol may make use of it). - Return true iff base begins with an (at least one) underscore, but - does not both begin and end with (at least) two underscores. - - >>> is_private("a.b", "my_func") - 0 - >>> is_private("____", "_my_func") - 1 - >>> is_private("someclass", "__init__") - 0 - >>> is_private("sometypo", "__init_") - 1 - >>> is_private("x.y.z", "_") - 1 - >>> is_private("_x.y.z", "__") - 0 - >>> is_private("", "") # senseless but consistent - 0 - """ - - return base[:1] == "_" and not base[:2] == "__" == base[-2:] - -# Determine if a class of function was defined in the given module. - -def _from_module(module, object): - if _isfunction(object): - return module.__dict__ is object.func_globals - if _isclass(object): - return module.__name__ == object.__module__ - raise ValueError("object must be a class or function") - -class Tester: - """Class Tester -- runs docstring examples and accumulates stats. - -In normal use, function doctest.testmod() hides all this from you, -so use that if you can. Create your own instances of Tester to do -fancier things. - -Methods: - runstring(s, name) - Search string s for examples to run; use name for logging. - Return (#failures, #tries). - - rundoc(object, name=None) - Search object.__doc__ for examples to run; use name (or - object.__name__) for logging. Return (#failures, #tries). - - rundict(d, name, module=None) - Search for examples in docstrings in all of d.values(); use name - for logging. Exclude functions and classes not defined in module - if specified. Return (#failures, #tries). - - run__test__(d, name) - Treat dict d like module.__test__. Return (#failures, #tries). - - summarize(verbose=None) - Display summary of testing results, to stdout. Return - (#failures, #tries). - - merge(other) - Merge in the test results from Tester instance "other". - ->>> from doctest import Tester ->>> t = Tester(globs={'x': 42}, verbose=0) ->>> t.runstring(r''' -... >>> x = x * 2 -... >>> print x -... 42 -... ''', 'XYZ') -***************************************************************** -Failure in example: print x -from line #2 of XYZ -Expected: 42 -Got: 84 -(1, 2) ->>> t.runstring(">>> x = x * 2\\n>>> print x\\n84\\n", 'example2') -(0, 2) ->>> t.summarize() -***************************************************************** -1 items had failures: - 1 of 2 in XYZ -***Test Failed*** 1 failures. -(1, 4) ->>> t.summarize(verbose=1) -1 items passed all tests: - 2 tests in example2 -***************************************************************** -1 items had failures: - 1 of 2 in XYZ -4 tests in 2 items. -3 passed and 1 failed. -***Test Failed*** 1 failures. -(1, 4) ->>> -""" - - def __init__(self, mod=None, globs=None, verbose=None, - isprivate=None): - """mod=None, globs=None, verbose=None, isprivate=None - -See doctest.__doc__ for an overview. - -Optional keyword arg "mod" is a module, whose globals are used for -executing examples. If not specified, globs must be specified. - -Optional keyword arg "globs" gives a dict to be used as the globals -when executing examples; if not specified, use the globals from -module mod. - -In either case, a copy of the dict is used for each docstring -examined. - -Optional keyword arg "verbose" prints lots of stuff if true, only -failures if false; by default, it's true iff "-v" is in sys.argv. - -Optional keyword arg "isprivate" specifies a function used to determine -whether a name is private. The default function is doctest.is_private; -see its docs for details. -""" - - if mod is None and globs is None: - raise TypeError("Tester.__init__: must specify mod or globs") - if mod is not None and not _ismodule(mod): - raise TypeError("Tester.__init__: mod must be a module; " + - `mod`) - if globs is None: - globs = mod.__dict__ - self.globs = globs - - if verbose is None: - import sys - verbose = "-v" in sys.argv - self.verbose = verbose - - if isprivate is None: - isprivate = is_private - self.isprivate = isprivate - - self.name2ft = {} # map name to (#failures, #trials) pair - - self.compileflags = _extract_future_flags(globs) - - def runstring(self, s, name): - """ - s, name -> search string s for examples to run, logging as name. - - Use string name as the key for logging the outcome. - Return (#failures, #examples). - - >>> t = Tester(globs={}, verbose=1) - >>> test = r''' - ... # just an example - ... >>> x = 1 + 2 - ... >>> x - ... 3 - ... ''' - >>> t.runstring(test, "Example") - Running string Example - Trying: x = 1 + 2 - Expecting: nothing - ok - Trying: x - Expecting: 3 - ok - 0 of 2 examples failed in string Example - (0, 2) - """ - - if self.verbose: - print "Running string", name - f = t = 0 - e = _extract_examples(s) - if e: - f, t = _run_examples(e, self.globs, self.verbose, name, - self.compileflags) - if self.verbose: - print f, "of", t, "examples failed in string", name - self.__record_outcome(name, f, t) - return f, t - - def rundoc(self, object, name=None): - """ - object, name=None -> search object.__doc__ for examples to run. - - Use optional string name as the key for logging the outcome; - by default use object.__name__. - Return (#failures, #examples). - If object is a class object, search recursively for method - docstrings too. - object.__doc__ is examined regardless of name, but if object is - a class, whether private names reached from object are searched - depends on the constructor's "isprivate" argument. - - >>> t = Tester(globs={}, verbose=0) - >>> def _f(): - ... '''Trivial docstring example. - ... >>> assert 2 == 2 - ... ''' - ... return 32 - ... - >>> t.rundoc(_f) # expect 0 failures in 1 example - (0, 1) - """ - - if name is None: - try: - name = object.__name__ - except AttributeError: - raise ValueError("Tester.rundoc: name must be given " - "when object.__name__ doesn't exist; " + `object`) - if self.verbose: - print "Running", name + ".__doc__" - f, t = run_docstring_examples(object, self.globs, self.verbose, name, - self.compileflags) - if self.verbose: - print f, "of", t, "examples failed in", name + ".__doc__" - self.__record_outcome(name, f, t) - if _isclass(object): - # In 2.2, class and static methods complicate life. Build - # a dict "that works", by hook or by crook. - d = {} - for tag, kind, homecls, value in _classify_class_attrs(object): - - if homecls is not object: - # Only look at names defined immediately by the class. - continue - - elif self.isprivate(name, tag): - continue - - elif kind == "method": - # value is already a function - d[tag] = value - - elif kind == "static method": - # value isn't a function, but getattr reveals one - d[tag] = getattr(object, tag) - - elif kind == "class method": - # Hmm. A classmethod object doesn't seem to reveal - # enough. But getattr turns it into a bound method, - # and from there .im_func retrieves the underlying - # function. - d[tag] = getattr(object, tag).im_func - - elif kind == "property": - # The methods implementing the property have their - # own docstrings -- but the property may have one too. - if value.__doc__ is not None: - d[tag] = str(value.__doc__) - - elif kind == "data": - # Grab nested classes. - if _isclass(value): - d[tag] = value - - else: - raise ValueError("teach doctest about %r" % kind) - - f2, t2 = self.run__test__(d, name) - f += f2 - t += t2 - - return f, t - - def rundict(self, d, name, module=None): - """ - d, name, module=None -> search for docstring examples in d.values(). - - For k, v in d.items() such that v is a function or class, - do self.rundoc(v, name + "." + k). Whether this includes - objects with private names depends on the constructor's - "isprivate" argument. If module is specified, functions and - classes that are not defined in module are excluded. - Return aggregate (#failures, #examples). - - Build and populate two modules with sample functions to test that - exclusion of external functions and classes works. - - >>> import new - >>> m1 = new.module('_m1') - >>> m2 = new.module('_m2') - >>> test_data = \""" - ... def _f(): - ... '''>>> assert 1 == 1 - ... ''' - ... def g(): - ... '''>>> assert 2 != 1 - ... ''' - ... class H: - ... '''>>> assert 2 > 1 - ... ''' - ... def bar(self): - ... '''>>> assert 1 < 2 - ... ''' - ... \""" - >>> exec test_data in m1.__dict__ - >>> exec test_data in m2.__dict__ - >>> m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H}) - - Tests that objects outside m1 are excluded: - - >>> t = Tester(globs={}, verbose=0) - >>> t.rundict(m1.__dict__, "rundict_test", m1) # _f, f2 and g2 and h2 skipped - (0, 3) - - Again, but with a custom isprivate function allowing _f: - - >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0) - >>> t.rundict(m1.__dict__, "rundict_test_pvt", m1) # Only f2, g2 and h2 skipped - (0, 4) - - And once more, not excluding stuff outside m1: - - >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0) - >>> t.rundict(m1.__dict__, "rundict_test_pvt") # None are skipped. - (0, 8) - - The exclusion of objects from outside the designated module is - meant to be invoked automagically by testmod. - - >>> testmod(m1) - (0, 3) - - """ - - if not hasattr(d, "items"): - raise TypeError("Tester.rundict: d must support .items(); " + - `d`) - f = t = 0 - # Run the tests by alpha order of names, for consistency in - # verbose-mode output. - names = d.keys() - names.sort() - for thisname in names: - value = d[thisname] - if _isfunction(value) or _isclass(value): - if module and not _from_module(module, value): - continue - f2, t2 = self.__runone(value, name + "." + thisname) - f = f + f2 - t = t + t2 - return f, t - - def run__test__(self, d, name): - """d, name -> Treat dict d like module.__test__. - - Return (#failures, #tries). - See testmod.__doc__ for details. - """ - - failures = tries = 0 - prefix = name + "." - savepvt = self.isprivate - try: - self.isprivate = lambda *args: 0 - # Run the tests by alpha order of names, for consistency in - # verbose-mode output. - keys = d.keys() - keys.sort() - for k in keys: - v = d[k] - thisname = prefix + k - if type(v) in _StringTypes: - f, t = self.runstring(v, thisname) - elif _isfunction(v) or _isclass(v): - f, t = self.rundoc(v, thisname) - else: - raise TypeError("Tester.run__test__: values in " - "dict must be strings, functions " - "or classes; " + `v`) - failures = failures + f - tries = tries + t - finally: - self.isprivate = savepvt - return failures, tries - - def summarize(self, verbose=None): - """ - verbose=None -> summarize results, return (#failures, #tests). - - Print summary of test results to stdout. - Optional arg 'verbose' controls how wordy this is. By - default, use the verbose setting established by the - constructor. - """ - - if verbose is None: - verbose = self.verbose - notests = [] - passed = [] - failed = [] - totalt = totalf = 0 - for x in self.name2ft.items(): - name, (f, t) = x - assert f <= t - totalt = totalt + t - totalf = totalf + f - if t == 0: - notests.append(name) - elif f == 0: - passed.append( (name, t) ) - else: - failed.append(x) - if verbose: - if notests: - print len(notests), "items had no tests:" - notests.sort() - for thing in notests: - print " ", thing - if passed: - print len(passed), "items passed all tests:" - passed.sort() - for thing, count in passed: - print " %3d tests in %s" % (count, thing) - if failed: - print "*" * 65 - print len(failed), "items had failures:" - failed.sort() - for thing, (f, t) in failed: - print " %3d of %3d in %s" % (f, t, thing) - if verbose: - print totalt, "tests in", len(self.name2ft), "items." - print totalt - totalf, "passed and", totalf, "failed." - if totalf: - print "***Test Failed***", totalf, "failures." - elif verbose: - print "Test passed." - return totalf, totalt - - def merge(self, other): - """ - other -> merge in test results from the other Tester instance. - - If self and other both have a test result for something - with the same name, the (#failures, #tests) results are - summed, and a warning is printed to stdout. - - >>> from doctest import Tester - >>> t1 = Tester(globs={}, verbose=0) - >>> t1.runstring(''' - ... >>> x = 12 - ... >>> print x - ... 12 - ... ''', "t1example") - (0, 2) - >>> - >>> t2 = Tester(globs={}, verbose=0) - >>> t2.runstring(''' - ... >>> x = 13 - ... >>> print x - ... 13 - ... ''', "t2example") - (0, 2) - >>> common = ">>> assert 1 + 2 == 3\\n" - >>> t1.runstring(common, "common") - (0, 1) - >>> t2.runstring(common, "common") - (0, 1) - >>> t1.merge(t2) - *** Tester.merge: 'common' in both testers; summing outcomes. - >>> t1.summarize(1) - 3 items passed all tests: - 2 tests in common - 2 tests in t1example - 2 tests in t2example - 6 tests in 3 items. - 6 passed and 0 failed. - Test passed. - (0, 6) - >>> - """ - - d = self.name2ft - for name, (f, t) in other.name2ft.items(): - if d.has_key(name): - print "*** Tester.merge: '" + name + "' in both" \ - " testers; summing outcomes." - f2, t2 = d[name] - f = f + f2 - t = t + t2 - d[name] = f, t - - def __record_outcome(self, name, f, t): - if self.name2ft.has_key(name): - print "*** Warning: '" + name + "' was tested before;", \ - "summing outcomes." - f2, t2 = self.name2ft[name] - f = f + f2 - t = t + t2 - self.name2ft[name] = f, t - - def __runone(self, target, name): - if "." in name: - i = name.rindex(".") - prefix, base = name[:i], name[i+1:] - else: - prefix, base = "", base - if self.isprivate(prefix, base): - return 0, 0 - return self.rundoc(target, name) - -master = None - -def testmod(m, name=None, globs=None, verbose=None, isprivate=None, - report=1): - """m, name=None, globs=None, verbose=None, isprivate=None, report=1 - - Test examples in docstrings in functions and classes reachable from - module m, starting with m.__doc__. Private names are skipped. - - Also test examples reachable from dict m.__test__ if it exists and is - not None. m.__dict__ maps names to functions, classes and strings; - function and class docstrings are tested even if the name is private; - strings are tested directly, as if they were docstrings. - - Return (#failures, #tests). - - See doctest.__doc__ for an overview. - - Optional keyword arg "name" gives the name of the module; by default - use m.__name__. - - Optional keyword arg "globs" gives a dict to be used as the globals - when executing examples; by default, use m.__dict__. A copy of this - dict is actually used for each docstring, so that each docstring's - examples start with a clean slate. - - Optional keyword arg "verbose" prints lots of stuff if true, prints - only failures if false; by default, it's true iff "-v" is in sys.argv. - - Optional keyword arg "isprivate" specifies a function used to - determine whether a name is private. The default function is - doctest.is_private; see its docs for details. - - Optional keyword arg "report" prints a summary at the end when true, - else prints nothing at the end. In verbose mode, the summary is - detailed, else very brief (in fact, empty if all tests passed). - - Advanced tomfoolery: testmod runs methods of a local instance of - class doctest.Tester, then merges the results into (or creates) - global Tester instance doctest.master. Methods of doctest.master - can be called directly too, if you want to do something unusual. - Passing report=0 to testmod is especially useful then, to delay - displaying a summary. Invoke doctest.master.summarize(verbose) - when you're done fiddling. - """ - - global master - - if not _ismodule(m): - raise TypeError("testmod: module required; " + `m`) - if name is None: - name = m.__name__ - tester = Tester(m, globs=globs, verbose=verbose, isprivate=isprivate) - failures, tries = tester.rundoc(m, name) - f, t = tester.rundict(m.__dict__, name, m) - failures = failures + f - tries = tries + t - if hasattr(m, "__test__"): - testdict = m.__test__ - if testdict: - if not hasattr(testdict, "items"): - raise TypeError("testmod: module.__test__ must support " - ".items(); " + `testdict`) - f, t = tester.run__test__(testdict, name + ".__test__") - failures = failures + f - tries = tries + t - if report: - tester.summarize() - if master is None: - master = tester - else: - master.merge(tester) - return failures, tries - -class _TestClass: - """ - A pointless class, for sanity-checking of docstring testing. - - Methods: - square() - get() - - >>> _TestClass(13).get() + _TestClass(-12).get() - 1 - >>> hex(_TestClass(13).square().get()) - '0xa9' - """ - - def __init__(self, val): - """val -> _TestClass object with associated value val. - - >>> t = _TestClass(123) - >>> print t.get() - 123 - """ - - self.val = val - - def square(self): - """square() -> square TestClass's associated value - - >>> _TestClass(13).square().get() - 169 - """ - - self.val = self.val ** 2 - return self - - def get(self): - """get() -> return TestClass's associated value. - - >>> x = _TestClass(-42) - >>> print x.get() - -42 - """ - - return self.val - -__test__ = {"_TestClass": _TestClass, - "string": r""" - Example of a string object, searched as-is. - >>> x = 1; y = 2 - >>> x + y, x * y - (3, 2) - """ - } - -def _test(): - import doctest - return doctest.testmod(doctest) - -if __name__ == "__main__": - _test() diff --git a/test/enum.cpp b/test/enum.cpp deleted file mode 100644 index d6147bc0..00000000 --- a/test/enum.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include - -using namespace boost::python; - -enum color { red = 1, green = 2, blue = 4 }; - -color identity_(color x) { return x; } - -BOOST_PYTHON_MODULE_INIT(enum_ext) -{ - enum_("color") - .value("red", red) - .value("green", green) - .value("blue", blue) - ; - - def("identity", identity_); -} - -#include "module_tail.cpp" diff --git a/test/enum.py b/test/enum.py deleted file mode 100644 index e21f8eb8..00000000 --- a/test/enum.py +++ /dev/null @@ -1,42 +0,0 @@ -''' ->>> from enum_ext import * - ->>> identity(color.red) -enum_ext.color.red - ->>> identity(color.green) -enum_ext.color.green - ->>> identity(color.blue) -enum_ext.color.blue - ->>> identity(color(1)) -enum_ext.color.red - ->>> identity(color(2)) -enum_ext.color.green - ->>> identity(color(3)) -enum_ext.color(3) - ->>> identity(color(4)) -enum_ext.color.blue - ->>> try: identity(1) -... except TypeError: pass -... else: print 'expected a TypeError' - -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/exception_translator.cpp b/test/exception_translator.cpp deleted file mode 100644 index 8a6428fd..00000000 --- a/test/exception_translator.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -struct error {}; - -void translate(error const& e) -{ - PyErr_SetString(PyExc_RuntimeError, "!!!error!!!"); -} - -void throw_error() -{ - throw error(); - -} - -BOOST_PYTHON_MODULE_INIT(exception_translator_ext) -{ - using namespace boost::python; - register_exception_translator(&translate); - - def("throw_error", throw_error); -} - diff --git a/test/exception_translator.py b/test/exception_translator.py deleted file mode 100644 index 78fe3507..00000000 --- a/test/exception_translator.py +++ /dev/null @@ -1,22 +0,0 @@ -''' ->>> from exception_translator_ext import * ->>> try: -... throw_error(); -... except RuntimeError, x: -... print x -... else: -... print 'Expected a RuntimeError!' -!!!error!!! -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/extract.cpp b/test/extract.cpp deleted file mode 100644 index 749f265a..00000000 --- a/test/extract.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -#include "test_class.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace boost::python; - -typedef test_class<> X; - -bool extract_bool(object x) { return extract(x); } - -boost::python::list extract_list(object x) -{ - extract get_list((x)); - - // Make sure we always have the right idea about whether it's a list - bool is_list_1 = get_list.check(); - bool is_list_2 = PyObject_IsInstance(x.ptr(), (PyObject*)&PyList_Type); - assert(is_list_1 == is_list_2); - - return get_list(); -} - -char const* extract_cstring(object x) -{ - return extract(x); -} - -std::string extract_string(object x) -{ - std::string s = extract(x); - return s; -} - -std::string const& extract_string_cref(object x) -{ -#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 -# pragma warning(push) -# pragma warning(disable:4172) // msvc lies about returning a reference to temporary -#elif defined(_MSC_VER) && defined(__ICL) && __ICL <= 600 -# pragma warning(push) -# pragma warning(disable:473) // intel/win32 does too -#endif - - return extract(x); - -#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(_MSC_VER) && defined(__ICL) && __ICL <= 600 -# pragma warning(pop) -#endif -} - -X extract_X(object x) -{ - return extract(x); -} - -X* extract_X_ptr(object x) { return extract(x); } - -X& extract_X_ref(object x) -{ - extract get_x(x); - return get_x; -} - -int double_X(object n) -{ - extract x(n); - return x().value() + x().value(); -} - -bool check_bool(object x) { return extract(x).check(); } -bool check_list(object x) { return extract(x).check(); } -bool check_cstring(object x) { return extract(x).check(); } -bool check_string(object x) { return extract(x).check(); } -bool check_string_cref(object x) { return extract(x).check(); } -bool check_X(object x) { return extract(x).check(); } -bool check_X_ptr(object x) { return extract(x).check(); } -bool check_X_ref(object x) { return extract(x).check(); } - -std::string x_rep(X const& x) -{ - return "X(" + boost::lexical_cast(x.value()) + ")"; -} - -BOOST_PYTHON_MODULE_INIT(extract_ext) -{ - implicitly_convertible(); - - def("extract_bool", extract_bool); - def("extract_list", extract_list); - def("extract_cstring", extract_cstring); - def("extract_string", extract_string); - def("extract_string_cref", extract_string_cref, return_value_policy()); - def("extract_X", extract_X); - def("extract_X_ptr", extract_X_ptr, return_value_policy()); - def("extract_X_ref", extract_X_ref, return_value_policy()); - - def("check_bool", check_bool); - def("check_list", check_list); - def("check_cstring", check_cstring); - def("check_string", check_string); - def("check_string_cref", check_string_cref); - def("check_X", check_X); - def("check_X_ptr", check_X_ptr); - def("check_X_ref", check_X_ref); - - def("double_X", double_X); - - def("count_Xs", &X::count); - ; - - object x_class( - class_("X", init()) - .def( "__repr__", x_rep)); - - // Instantiate an X object through the Python interface - object x_obj = x_class(3); - - // Get the C++ object out of the Python object - X const& x = extract(x_obj); - assert(x.value() == 3); -} - - -#include "module_tail.cpp" - diff --git a/test/extract.py b/test/extract.py deleted file mode 100644 index 328049dd..00000000 --- a/test/extract.py +++ /dev/null @@ -1,102 +0,0 @@ -''' - >>> from extract_ext import * - -Just about anything has a truth value in Python - - >>> assert check_bool(None) - >>> extract_bool(None) - 0 - - >>> assert check_bool(2) - >>> extract_bool(2) - 1 - - >>> assert not check_bool('') - -Check that object manager types work properly. These are a different -case because they wrap Python objects instead of being wrapped by them. - - >>> assert not check_list(2) - >>> try: x = extract_list(2) - ... except TypeError, x: - ... if str(x) != 'Expecting an object of type list; got an object of type int instead': - ... print x - ... else: - ... print 'expected an exception, got', x, 'instead' - -Can't extract a list from a tuple. Use list(x) to convert a sequence -to a list: - - >>> assert not check_list((1, 2, 3)) - >>> assert check_list([1, 2, 3]) - >>> extract_list([1, 2, 3]) - [1, 2, 3] - -Can get a char const* from a Python string: - - >>> assert check_cstring('hello') - >>> extract_cstring('hello') - 'hello' - -Can't get a char const* from a Python int: - - >>> assert not check_cstring(1) - >>> try: x = extract_cstring(1) - ... except TypeError: pass - ... else: - ... print 'expected an exception, got', x, 'instead' - -Extract an std::string (class) rvalue from a native Python type - - >>> assert check_string('hello') - >>> extract_string('hello') - 'hello' - -Constant references are not treated as rvalues for the purposes of -extract: - - >>> assert not check_string_cref('hello') - -We can extract lvalues where appropriate: - - >>> x = X(42) - >>> check_X(x) - 1 - >>> extract_X(x) - X(42) - - >>> check_X_ptr(x) - 1 - >>> extract_X_ptr(x) - X(42) - >>> extract_X_ref(x) - X(42) - -Demonstrate that double-extraction of an rvalue works, and all created -copies of the object are destroyed: - - >>> n = count_Xs() - >>> double_X(333) - 666 - >>> count_Xs() - n - 0 - -General check for cleanliness: - - >>> del x - >>> count_Xs() - 0 -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/if_else.cpp b/test/if_else.cpp deleted file mode 100644 index e2b50f28..00000000 --- a/test/if_else.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include - - typedef char c1; - typedef char c2[2]; - typedef char c3[3]; - typedef char c4[4]; - -template -struct choose -{ - typedef typename boost::python::detail::if_< - (sizeof(c1) == size) - >::template then< - c1 - >::template elif< - (sizeof(c2) == size) - >::template then< - c2 - >::template elif< - (sizeof(c3) == size) - >::template then< - c3 - >::template elif< - (sizeof(c4) == size) - >::template then< - c4 - >::template else_::type type; -}; - -int main() -{ - BOOST_STATIC_ASSERT((boost::is_same::type,c1>::value)); - BOOST_STATIC_ASSERT((boost::is_same::type,c2>::value)); - BOOST_STATIC_ASSERT((boost::is_same::type,c3>::value)); - BOOST_STATIC_ASSERT((boost::is_same::type,c4>::value)); - BOOST_STATIC_ASSERT((boost::is_same::type,void*>::value)); - return 0; -} diff --git a/test/implicit.cpp b/test/implicit.cpp deleted file mode 100644 index 2637f5ca..00000000 --- a/test/implicit.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include "test_class.hpp" - -using namespace boost::python; - -typedef test_class<> X; - -int x_value(X const& x) -{ - return x.value(); -} - -X make_x(int n) { return X(n); } - -BOOST_PYTHON_MODULE_INIT(implicit_ext) -{ - implicitly_convertible(); - - def("x_value", x_value); - def("make_x", make_x); - - class_("X", init()) - .def("value", &X::value) - .def("set", &X::set) - ; - - implicitly_convertible(); -} - -#include "module_tail.cpp" diff --git a/test/implicit.py b/test/implicit.py deleted file mode 100644 index e0d8c067..00000000 --- a/test/implicit.py +++ /dev/null @@ -1,26 +0,0 @@ -''' ->>> from implicit_ext import * ->>> x_value(X(42)) -42 ->>> x_value(42) -42 ->>> x = make_x(X(42)) ->>> x.value() -42 ->>> try: make_x('fool') -... except TypeError: pass -... else: print 'no error' -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/indirect_traits_test.cpp b/test/indirect_traits_test.cpp deleted file mode 100644 index 7160b8eb..00000000 --- a/test/indirect_traits_test.cpp +++ /dev/null @@ -1,80 +0,0 @@ -//#include -#include -#include - -//#define print(expr) printf("%s ==> %s\n", #expr, expr) - -// not all the compilers can handle an incomplete class type here. -struct X {}; - -int main() -{ -using namespace boost::python::detail; - -#if 0 // not yet supported - assert(is_reference_to_function::value); - assert(!is_reference_to_function::value); -#endif - - assert(!is_pointer_to_function::value); - assert(is_pointer_to_function::value); - - assert(is_reference_to_pointer::value); - assert(is_reference_to_pointer::value); - assert(is_reference_to_pointer::value); - assert(is_reference_to_pointer::value); - - assert(!is_reference_to_pointer::value); - assert(!is_reference_to_pointer::value); - assert(!is_reference_to_pointer::value); - - assert(!is_reference_to_const::value); - assert(is_reference_to_const::value); - assert(!is_reference_to_const::value); - assert(is_reference_to_const::value); - - assert(!is_reference_to_const::value); - assert(!is_reference_to_const::value); - assert(!is_reference_to_const::value); - - assert(is_reference_to_non_const::value); - assert(!is_reference_to_non_const::value); - assert(is_reference_to_non_const::value); - assert(!is_reference_to_non_const::value); - - assert(!is_reference_to_non_const::value); - assert(!is_reference_to_non_const::value); - assert(!is_reference_to_non_const::value); - - assert(!is_reference_to_volatile::value); - assert(!is_reference_to_volatile::value); - assert(is_reference_to_volatile::value); - assert(is_reference_to_volatile::value); - - assert(!is_reference_to_volatile::value); - assert(!is_reference_to_volatile::value); - assert(!is_reference_to_volatile::value); - - assert(!is_reference_to_class::value); - assert(!is_reference_to_class::value); - assert(!is_reference_to_class::value); - - assert(!is_reference_to_class::value); - assert(is_reference_to_class::value); - assert(is_reference_to_class::value); - assert(is_reference_to_class::value); - assert(is_reference_to_class::value); - - assert(!is_pointer_to_class::value); - assert(!is_pointer_to_class::value); - assert(!is_pointer_to_class::value); - - assert(!is_pointer_to_class::value); - assert(!is_pointer_to_class::value); - assert(is_pointer_to_class::value); - assert(is_pointer_to_class::value); - assert(is_pointer_to_class::value); - assert(is_pointer_to_class::value); - - return 0; -} diff --git a/test/input_iterator.cpp b/test/input_iterator.cpp deleted file mode 100644 index 19b50f77..00000000 --- a/test/input_iterator.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include - -using namespace boost::python; - -typedef std::list list_int; - -// Prove that we can handle InputIterators which return rvalues. -struct doubler -{ - typedef int result_type; - int operator()(int x) const { return x * 2; } -}; - -typedef boost::transform_iterator_generator::type doubling_iterator; -typedef std::pair list_range2; - -list_range2 range2(list_int& x) -{ - return list_range2( - boost::make_transform_iterator(x.begin(), doubler()) - , boost::make_transform_iterator(x.end(), doubler())); -} - -// We do this in a separate module from iterators_ext (iterators.cpp) -// to work around an MSVC6 linker bug, which causes it to complain -// about a "duplicate comdat" if the input iterator is instantiated in -// the same module with the others. -BOOST_PYTHON_MODULE_INIT(input_iterator) -{ - def("range2", &::range2); - - class_("list_range2") - // We can wrap InputIterators which return by-value - .def("__iter__" - , range(&list_range2::first, &list_range2::second)) - ; -} - -#include "module_tail.cpp" diff --git a/test/iterator.cpp b/test/iterator.cpp deleted file mode 100644 index 7aaae77c..00000000 --- a/test/iterator.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace boost::python; - -typedef std::list list_int; -typedef std::list list_list; - - -void push_back(list_int& x, int y) -{ - x.push_back(y); -} - -void push_list_back(list_list& x, list_int const& y) -{ - x.push_back(y); -} - -int back(list_int& x) -{ - return x.back(); -} - -typedef std::pair list_range; - -list_range range(list_int& x) -{ - return list_range(x.begin(), x.end()); -} - -struct two_lists -{ - two_lists() - { - int primes[] = { 2, 3, 5, 7, 11, 13 }; - std::copy(primes, primes + sizeof(primes)/sizeof(*primes), std::back_inserter(one)); - int evens[] = { 2, 4, 6, 8, 10, 12 }; - std::copy(evens, evens + sizeof(evens)/sizeof(*evens), std::back_inserter(two)); - } - - struct two_start - { - typedef list_int::iterator result_type; - result_type operator()(two_lists& ll) const { return ll.two.begin(); } - }; - friend struct two_start; - - list_int::iterator one_begin() { return one.begin(); } - list_int::iterator two_begin() { return two.begin(); } - - list_int::iterator one_end() { return one.end(); } - list_int::iterator two_end() { return two.end(); } - -private: - list_int one; - list_int two; -}; - -BOOST_PYTHON_MODULE_INIT(iterator_ext) -{ - def("range", &::range); - - class_("list_int") - .def("push_back", push_back) - .def("back", back) - .def("__iter__", iterator()) - ; - - class_("list_range") - - // We can specify data members - .def("__iter__" - , range(&list_range::first, &list_range::second)) - ; - - 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() -# else - &two_lists::two_begin -# endif - , &two_lists::two_end)) - ; - - class_("list_list") - .def("push_back", push_list_back) - .def("__iter__", iterator >()) - ; -} - -#include "module_tail.cpp" diff --git a/test/iterator.py b/test/iterator.py deleted file mode 100644 index 2f2f8e02..00000000 --- a/test/iterator.py +++ /dev/null @@ -1,72 +0,0 @@ -''' ->>> from iterator_ext import * ->>> from input_iterator import * ->>> x = list_int() ->>> x.push_back(1) ->>> x.back() -1 ->>> x.push_back(3) ->>> x.push_back(5) ->>> for y in x: -... print y -1 -3 -5 ->>> z = range(x) ->>> for y in z: -... print y -1 -3 -5 - - Range2 wraps a transform_iterator which doubles the elements it - traverses. This proves we can wrap input iterators - ->>> z2 = range2(x) ->>> for y in z2: -... print y -2 -6 -10 - ->>> l2 = two_lists() ->>> for y in l2.primes: -... print y -2 -3 -5 -7 -11 -13 ->>> for y in l2.evens: -... print y -2 -4 -6 -8 -10 -12 ->>> ll = list_list() ->>> ll.push_back(x) ->>> x.push_back(7) ->>> ll.push_back(x) ->>> for a in ll: -... for b in a: -... print b, -... print -... -1 3 5 -1 3 5 7 -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/list.cpp b/test/list.cpp deleted file mode 100644 index 83ea063b..00000000 --- a/test/list.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -#include -#include -#include -#include -#include -#include -#include "test_class.hpp" - -using namespace boost::python; - -object new_list() -{ - return list(); -} - -list listify(object x) -{ - return list(x); -} - -object listify_string(char const* s) -{ - return list(s); -} - -std::string x_rep(test_class<> const& x) -{ - return "X(" + boost::lexical_cast(x.value()) + ")"; -} - -object apply_object_list(object f, list x) -{ - return f(x); -} - -list apply_list_list(object f, list x) -{ - return call(f.ptr(), x); -} - -void append_object(list& x, object y) -{ - x.append(y); -} - -void append_list(list& x, list const& y) -{ - x.append(y); -} - -typedef test_class<> X; - -int notcmp(object const& x, object const& y) -{ - return y < x ? -1 : y > x ? 1 : 0; -} - -void exercise(list x, object y, object print) -{ - x.append(y); - x.append(5); - x.append(X(3)); - - print("after append:"); - print(x); - - print("number of", y, "instances:", x.count(y)); - - print("number of 5s:", x.count(5)); - - x.extend("xyz"); - print("after extend:"); - print(x); - print("index of", y, "is:", x.index(y)); - print("index of 'l' is:", x.index("l")); - - x.insert(4, 666); - print("after inserting 666:"); - print(x); - print("inserting with object as index:"); - x.insert(x[x.index(5)], "---"); - print(x); - - print("popping..."); - x.pop(); - print(x); - x.pop(x[x.index(5)]); - print(x); - x.pop(x.index(5)); - print(x); - - print("removing", y); - x.remove(y); - print(x); - print("removing", 666); - x.remove(666); - print(x); - - print("reversing..."); - x.reverse(); - print(x); - - print("sorted:"); - x.pop(2); // make sorting predictable - x.sort(); - print(x); - - print("reverse sorted:"); - x.sort(¬cmp); - print(x); - - list w; - w.append(5); - w.append(6); - w += "hi"; - assert(w[0] == 5); - assert(w[1] == 6); - assert(w[2] == 'h'); - assert(w[3] == 'i'); -} - -BOOST_PYTHON_MODULE_INIT(list_ext) -{ - def("new_list", new_list); - def("listify", listify); - def("listify_string", listify_string); - def("apply_object_list", apply_object_list); - def("apply_list_list", apply_list_list); - - def("append_object", append_object); - def("append_list", append_list); - - def("exercise", exercise); - - class_("X", init()) - .def( "__repr__", x_rep) - ; -} - diff --git a/test/list.py b/test/list.py deleted file mode 100644 index 0357b9a2..00000000 --- a/test/list.py +++ /dev/null @@ -1,113 +0,0 @@ -''' ->>> from list_ext import * - ->>> new_list() -[] - ->>> listify((1,2,3)) -[1, 2, 3] - ->>> letters = listify_string('hello') ->>> letters -['h', 'e', 'l', 'l', 'o'] - ->>> X(22) -X(22) - ->>> def identity(x): -... return x ->>> assert apply_object_list(identity, letters) is letters - - 5 is not convertible to a list - ->>> try: result = apply_object_list(identity, 5) -... except TypeError: pass -... else: print 'expected an exception, got', result, 'instead' - ->>> assert apply_list_list(identity, letters) is letters - - 5 is not convertible to a list as a return value - ->>> try: result = apply_list_list(len, letters) -... except TypeError: pass -... else: print 'expected an exception, got', result, 'instead' - ->>> append_object(letters, '.') ->>> letters -['h', 'e', 'l', 'l', 'o', '.'] - - tuples do not automatically convert to lists when passed as arguments - ->>> try: append_list(letters, (1,2)) -... except TypeError: pass -... else: print 'expected an exception' - ->>> append_list(letters, [1,2]) ->>> letters -['h', 'e', 'l', 'l', 'o', '.', [1, 2]] - - Check that subclass functions are properly called - ->>> class mylist(list): -... def append(self, o): -... list.append(self, o) -... if not hasattr(self, 'nappends'): -... self.nappends = 1 -... else: -... self.nappends += 1 -... ->>> l2 = mylist() ->>> append_object(l2, 'hello') ->>> append_object(l2, 'world') ->>> l2 -['hello', 'world'] ->>> l2.nappends -2 - ->>> def printer(*args): -... for x in args: print x, -... print -... - ->>> y = X(42) ->>> exercise(letters, y, printer) -after append: -['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(42), 5, X(3)] -number of X(42) instances: 1 -number of 5s: 1 -after extend: -['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y', 'z'] -index of X(42) is: 7 -index of 'l' is: 2 -after inserting 666: -['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y', 'z'] -inserting with object as index: -['h', 'e', 'l', 'l', 666, '---', 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y', 'z'] -popping... -['h', 'e', 'l', 'l', 666, '---', 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y'] -['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(42), 5, X(3), 'x', 'y'] -['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(42), X(3), 'x', 'y'] -removing X(42) -['h', 'e', 'l', 'l', 666, 'o', '.', [1, 2], X(3), 'x', 'y'] -removing 666 -['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(3), 'x', 'y'] -reversing... -['y', 'x', X(3), [1, 2], '.', 'o', 'l', 'l', 'e', 'h'] -sorted: -[[1, 2], '.', 'e', 'h', 'l', 'l', 'o', 'x', 'y'] -reverse sorted: -['y', 'x', 'o', 'l', 'l', 'h', 'e', '.', [1, 2]] -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/long.cpp b/test/long.cpp deleted file mode 100644 index 32d3164a..00000000 --- a/test/long.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -#include -#include -#include -#include - -using namespace boost::python; - -object new_long() -{ - return long_(); -} - -long_ longify(object x) -{ - return long_(x); -} - -object longify_string(char const* s) -{ - return long_(s); -} - -char const* is_long1(long_& x) -{ - long_ y = x; - x += 50; - assert(x == y + 50); - return "yes"; -} - -int is_long2(char const*) -{ - return 0; -} - -BOOST_PYTHON_MODULE_INIT(long_ext) -{ - def("new_long", new_long); - def("longify", longify); - def("longify_string", longify_string); - def("is_long", is_long1); - def("is_long", is_long2); - ; -} - diff --git a/test/long.py b/test/long.py deleted file mode 100644 index 7d08e9b7..00000000 --- a/test/long.py +++ /dev/null @@ -1,26 +0,0 @@ -''' ->>> from long_ext import * ->>> new_long() -0L ->>> longify(42) -42L ->>> longify_string('300') -300L ->>> is_long(20L) -'yes' ->>> is_long('20') -0 -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/m1.cpp b/test/m1.cpp deleted file mode 100644 index 434ab096..00000000 --- a/test/m1.cpp +++ /dev/null @@ -1,268 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - - -#include "simple_type.hpp" -#include "complicated.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Declare some straightforward extension types -extern "C" void -dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -// Noddy is a type we got from one of the Python sample files -struct NoddyObject : PyObject -{ - int x; -}; - -PyTypeObject NoddyType = { - PyObject_HEAD_INIT(NULL) - 0, - "Noddy", - sizeof(NoddyObject), - 0, - dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ -}; - -// Create a Noddy containing 42 -PyObject* new_noddy() -{ - NoddyObject* noddy = PyObject_New(NoddyObject, &NoddyType); - noddy->x = 42; - return (PyObject*)noddy; -} - -// Simple is a wrapper around a struct simple, which just contains a char* -struct SimpleObject -{ - PyObject_HEAD - simple x; -}; - -struct extract_simple_object -{ - static simple& execute(SimpleObject& o) { return o.x; } -}; - -PyTypeObject SimpleType = { - PyObject_HEAD_INIT(NULL) - 0, - "Simple", - sizeof(SimpleObject), - 0, - dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ -}; - -// Create a Simple containing "hello, world" -PyObject* new_simple() -{ - SimpleObject* simple = PyObject_New(SimpleObject, &SimpleType); - simple->x.s = "hello, world"; - return (PyObject*)simple; -} - -// -// Declare some wrappers/unwrappers to test the low-level conversion -// mechanism. -// -using boost::python::to_python_converter; - -// Wrap a simple by copying it into a Simple -struct simple_to_python - : to_python_converter -{ - static PyObject* convert(simple const& x) - { - SimpleObject* p = PyObject_New(SimpleObject, &SimpleType); - p->x = x; - return (PyObject*)p; - } -}; - -struct int_from_noddy -{ - static int& execute(NoddyObject& p) - { - return p.x; - } -}; - -// -// Some C++ functions to expose to Python -// - -// Returns the length of s's held string -int f(simple const& s) -{ - return strlen(s.s); -} - -int f_mutable_ref(simple& s) -{ - return strlen(s.s); -} - -int f_mutable_ptr(simple* s) -{ - return strlen(s->s); -} - -int f_const_ptr(simple const* s) -{ - return strlen(s->s); -} - -int f2(SimpleObject const& s) -{ - return strlen(s.x.s); -} - -// A trivial passthru function for simple objects -simple const& g(simple const& x) -{ - return x; -} - -struct A -{ - A() : x(0) {} - virtual ~A() {} - char const* name() { return "A"; } - int x; -}; - -struct B : A -{ - B() : x(1) {} - static char const* name(B*) { return "B"; } - int x; -}; - - -struct C : A -{ - C() : x(2) {} - char const* name() { return "C"; } - virtual ~C() {} - int x; -}; - -struct D : B, C -{ - D() : x(3) {} - char const* name() { return "D"; } - int x; -}; - -A take_a(A const& a) { return a; } -B take_b(B& b) { return b; } -C take_c(C* c) { return *c; } -D take_d(D* const& d) { return *d; } - -D take_d_shared_ptr(boost::shared_ptr d) { return *d; } - -boost::shared_ptr d_factory() { return boost::shared_ptr(new D); } - -BOOST_PYTHON_MODULE_INIT(m1) -{ - using namespace boost::python; - using boost::shared_ptr; - - simple_to_python(); - - lvalue_from_pytype(); - - lvalue_from_pytype< -#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 // doesn't support non-type member pointer parameters - extract_member -#else - extract_simple_object -#endif - , &SimpleType - >(); - - lvalue_from_pytype,&SimpleType>(); - - def("new_noddy", new_noddy); - def("new_simple", new_simple); - - // Expose f() in all its variations - def("f", f); - def("f_mutable_ref", f_mutable_ref); - def("f_mutable_ptr", f_mutable_ptr); - def("f_const_ptr", f_const_ptr); - - def("f2", f2); - - // Expose g() - def("g", g , return_value_policy() - ); - - def("take_a", take_a); - def("take_b", take_b); - def("take_c", take_c); - def("take_d", take_d); - - - def("take_d_shared_ptr", take_d_shared_ptr); - def("d_factory", d_factory); - - class_ >("A") - .def("name", &A::name) - ; - - // sequence points don't ensure that "A" is constructed before "B" - // or "C" below if we make them part of the same chain - class_, shared_ptr >("B") - .def("name", &B::name) - ; - - class_, shared_ptr >("C") - .def("name", &C::name) - ; - - class_, bases >("D") - .def("name", &D::name) - ; - - class_("complicated", - init()) - .def(init()) - .def("get_n", &complicated::get_n) - ; -} - -#include "module_tail.cpp" diff --git a/test/m2.cpp b/test/m2.cpp deleted file mode 100644 index 5eee1a89..00000000 --- a/test/m2.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -// This module exercises the converters exposed in m1 at a low level -// by exposing raw Python extension functions that use wrap<> and -// unwrap<> objects. -#include -#include -#include -#include -#include -#include "simple_type.hpp" - -// Get a simple (by value) from the argument, and return the -// string it holds. -PyObject* unwrap_simple(simple x) -{ - return PyString_FromString(x.s); -} - -// Likewise, but demands that its possible to get a non-const -// reference to the simple. -PyObject* unwrap_simple_ref(simple& x) -{ - return PyString_FromString(x.s); -} - -// Likewise, with a const reference to the simple object. -PyObject* unwrap_simple_const_ref(simple const& x) -{ - return PyString_FromString(x.s); -} - -// Get an int (by value) from the argument, and convert it to a -// Python Int. -PyObject* unwrap_int(int x) -{ - return PyInt_FromLong(x); -} - -// Get a non-const reference to an int from the argument -PyObject* unwrap_int_ref(int& x) -{ - return PyInt_FromLong(x); -} - -// Get a const reference to an int from the argument. -PyObject* unwrap_int_const_ref(int const& x) -{ - return PyInt_FromLong(x); -} - -// rewrap extracts a T from the argument, then converts the T back -// to a PyObject* and returns it. -template -struct rewrap -{ - static T f(T x) { return x; } -}; - -BOOST_PYTHON_MODULE_INIT(m2) -{ - using boost::python::return_value_policy; - using boost::python::copy_const_reference; - using boost::python::copy_non_const_reference; - using boost::python::def; - - def("unwrap_int", unwrap_int); - def("unwrap_int_ref", unwrap_int_ref); - def("unwrap_int_const_ref", unwrap_int_const_ref); - def("unwrap_simple", unwrap_simple); - def("unwrap_simple_ref", unwrap_simple_ref); - def("unwrap_simple_const_ref", unwrap_simple_const_ref); - - def("wrap_int", &rewrap::f); - - def("wrap_int_ref", &rewrap::f - , return_value_policy() - ); - - def("wrap_int_const_ref", &rewrap::f - , return_value_policy() - ); - - def("wrap_simple", &rewrap::f); - - def("wrap_simple_ref", &rewrap::f - , return_value_policy() - ); - - def("wrap_simple_const_ref", &rewrap::f - , return_value_policy() - ); -} - -#include "module_tail.cpp" diff --git a/test/member_function_cast.cpp b/test/member_function_cast.cpp deleted file mode 100644 index a754fd36..00000000 --- a/test/member_function_cast.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include - -using namespace boost; - -template -void assert_same(S, type* = 0) -{ - BOOST_STATIC_ASSERT((is_same::value)); -} - -template -void assert_mf_cast(F f, type* = 0, type* = 0) -{ - assert_same( - python::detail::member_function_cast::stage1(f).stage2((Target*)0).stage3(f) - ); -} - -struct X -{ - int f() const { return 0; } - void g(char*) {} -}; - -struct Y : X -{ - -}; - -struct Z : Y -{ - int f() const { return 0; } - void g(char*) {} -}; - -int main() -{ - assert_mf_cast(&X::f); - assert_mf_cast(&X::g); - - assert_mf_cast(&Z::f); - assert_mf_cast(&Z::g); - - assert_mf_cast(3); - assert_mf_cast(X()); - return 0; -} diff --git a/test/minimal.cpp b/test/minimal.cpp deleted file mode 100644 index be0fe6ec..00000000 --- a/test/minimal.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include - -#if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 -# include // works around a KCC intermediate code generation bug -#endif - -BOOST_PYTHON_MODULE_INIT(minimal_ext) -{ -} - -#include "module_tail.cpp" diff --git a/test/minimal.py b/test/minimal.py deleted file mode 100644 index fe5788f5..00000000 --- a/test/minimal.py +++ /dev/null @@ -1,2 +0,0 @@ -import minimal_ext - diff --git a/test/module_tail.cpp b/test/module_tail.cpp deleted file mode 100644 index 763e7dff..00000000 --- a/test/module_tail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -#if defined(_WIN32) -# ifdef __MWERKS__ -# pragma ANSI_strict off -# endif -# include -# ifdef __MWERKS__ -# pragma ANSI_strict reset -# endif - -extern "C" BOOL WINAPI DllMain ( HINSTANCE hInst, DWORD wDataSeg, LPVOID lpvReserved ); - -# ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable:4297) -extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*) -{ - throw; -} -# pragma warning(pop) -# endif - -BOOL WINAPI DllMain( - HINSTANCE, //hDllInst - DWORD fdwReason, - LPVOID // lpvReserved - ) -{ -# ifdef BOOST_MSVC - _set_se_translator(structured_exception_translator); -# endif - (void)fdwReason; // warning suppression. - - return 1; -} -#endif // _WIN32 - diff --git a/test/multi_arg_constructor.cpp b/test/multi_arg_constructor.cpp deleted file mode 100644 index 24bc4d9a..00000000 --- a/test/multi_arg_constructor.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -struct A -{ - A(const double, const double, const double, const double, const double - , const double, const double - , const double, const double - ) {} -}; - -BOOST_PYTHON_MODULE_INIT(multi_arg_constructor_ext) -{ - using namespace boost::python; - using boost::shared_ptr; - - class_ >( - "A" - , init() - ) - ; - -} - diff --git a/test/multi_arg_constructor.py b/test/multi_arg_constructor.py deleted file mode 100644 index fb062e8a..00000000 --- a/test/multi_arg_constructor.py +++ /dev/null @@ -1,16 +0,0 @@ -''' ->>> from multi_arg_constructor_ext import * ->>> a = A(1.0, 2, 3, 4, 5, 6, 7.0, 8.1, 9.3) -''' -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/nested.cpp b/test/nested.cpp deleted file mode 100644 index 8cbe3d79..00000000 --- a/test/nested.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include "test_class.hpp" -#if __GNUC__ != 2 -# include -#else -# include -#endif - -typedef test_class<> X; -typedef test_class<1> Y; - -std::ostream& operator<<(std::ostream& s, X const& x) -{ - return s << x.value(); -} - -std::ostream& operator<<(std::ostream& s, Y const& x) -{ - return s << x.value(); -} - - -BOOST_PYTHON_MODULE_INIT(nested_ext) -{ - using namespace boost::python; - - // Establish X as the current scope. - scope x_class( - class_("X", init()) - .def(str(self)) - ); - - // Y will now be defined in the current scope - class_("Y", init()) - .def(str(self)) - ; -} - - -#include "module_tail.cpp" - - - diff --git a/test/nested.py b/test/nested.py deleted file mode 100644 index 97ac2a33..00000000 --- a/test/nested.py +++ /dev/null @@ -1,35 +0,0 @@ -''' - >>> from nested_ext import * - - >>> X - - - >>> X.__module__ - 'nested_ext' - - >>> X.__name__ - 'X' - - >>> X.Y - - - >>> X.Y.__module__ - 'nested_ext' - - >>> X.Y.__name__ - 'Y' - -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/newtest.py b/test/newtest.py deleted file mode 100644 index 7b68a260..00000000 --- a/test/newtest.py +++ /dev/null @@ -1,184 +0,0 @@ -""" ->>> from m1 import * - ->>> from m2 import * - ->>> n = new_noddy() ->>> s = new_simple() ->>> unwrap_int(n) -42 ->>> unwrap_int_ref(n) -42 ->>> unwrap_int_const_ref(n) -42 ->>> unwrap_simple(s) -'hello, world' ->>> unwrap_simple_ref(s) -'hello, world' ->>> unwrap_simple_const_ref(s) -'hello, world' ->>> unwrap_int(5) -5 - -Can't get a non-const reference to a built-in integer object ->>> try: -... unwrap_int_ref(7) -... except: pass -... else: print 'no exception' - ->>> unwrap_int_const_ref(9) -9 - ->>> wrap_int(n) -42 - -try: wrap_int_ref(n) -... except: pass -... else: print 'no exception' - ->>> wrap_int_const_ref(n) -42 - ->>> unwrap_simple_ref(wrap_simple(s)) -'hello, world' - ->>> unwrap_simple_ref(wrap_simple_ref(s)) -'hello, world' - ->>> unwrap_simple_ref(wrap_simple_const_ref(s)) -'hello, world' - ->>> f(s) -12 - ->>> unwrap_simple(g(s)) -'hello, world' - ->>> f(g(s)) -12 - ->>> f_mutable_ref(g(s)) -12 - ->>> f_const_ptr(g(s)) -12 - ->>> f_mutable_ptr(g(s)) -12 - ->>> f2(g(s)) -12 - -Create an extension class which wraps "complicated" (init1 and get_n) -are a complicated constructor and member function, respectively. - ->>> c1 = complicated(s, 99) ->>> c1.get_n() -99 ->>> c2 = complicated(s) ->>> c2.get_n() -0 - - a quick regression test for a bug where None could be converted - to the target of any member function. To see it, we need to - access the __dict__ directly, to bypass the type check supplied - by the Method property which wraps the method when accessed as an - attribute. - ->>> try: A.__dict__['name'](None) -... except TypeError: pass -... else: print 'expected an exception!' - - ->>> a = A() ->>> b = B() ->>> c = C() ->>> d = D() - - ->>> take_a(a).name() -'A' - ->>> try: -... take_b(a) -... except: pass -... else: print 'no exception' - ->>> try: -... take_c(a) -... except: pass -... else: print 'no exception' - ->>> try: -... take_d(a) -... except: pass -... else: print 'no exception' - ------- ->>> take_a(b).name() -'A' - ->>> take_b(b).name() -'B' - ->>> try: -... take_c(b) -... except: pass -... else: print 'no exception' - ->>> try: -... take_d(b) -... except: pass -... else: print 'no exception' - -------- ->>> take_a(c).name() -'A' - ->>> try: -... take_b(c) -... except: pass -... else: print 'no exception' - ->>> take_c(c).name() -'C' - ->>> try: -... take_d(c) -... except: pass -... else: print 'no exception' - -------- ->>> take_a(d).name() -'A' ->>> take_b(d).name() -'B' ->>> take_c(d).name() -'C' ->>> take_d(d).name() -'D' - ->>> take_d_shared_ptr(d).name() -'D' - ->>> d_as_a = d_factory() ->>> dd = take_d(d_as_a) ->>> dd.name() -'D' - -""" - -def run(args = None): - - import sys - import doctest - - if args is not None: - sys.argv = args - - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/object.cpp b/test/object.cpp deleted file mode 100755 index 6a76aeb3..00000000 --- a/test/object.cpp +++ /dev/null @@ -1,318 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include - -using namespace boost::python; - -object call_object_3(object f) -{ - return f(3); -} - -object message() -{ - return object("hello, world!"); -} - -object number() -{ - return object(42); -} - -object obj_getattr(object x, char const* name) -{ - return x.attr(name); -} - -object obj_const_getattr(object const& x, char const* name) -{ - return x.attr(name); -} - -void obj_setattr(object x, char const* name, object value) -{ - x.attr(name) = value; -} - -void obj_setattr42(object x, char const* name) -{ - x.attr(name) = 42; -} - -void obj_moveattr(object& x, char const* src, char const* dst) -{ - x.attr(dst) = x.attr(src); -} - -object obj_getitem(object x, object key) -{ - return x[key]; -} - -object obj_getitem3(object x) -{ - return x[3]; -} - -object obj_const_getitem(object const& x, object key) -{ - return x[key]; -} - -void obj_setitem(object x, object key, object value) -{ - x[key] = value; -} - -void obj_setitem42(object x, object key) -{ - x[key] = 42; -} - -void obj_moveitem(object& x, object src, object dst) -{ - x[dst] = x[src]; -} - -void obj_moveitem2(object const& x_src, object k_src, object& x_dst, object k_dst) -{ - x_dst[k_dst] = x_src[k_src]; -} - -bool test(object y) -{ - return y; -} - -bool test_not(object y) -{ - return !y; -} - -bool test_attr(object y, char* name) -{ - return y.attr(name); -} - -bool test_not_attr(object y, char* name) -{ - return !y.attr(name); -} - -bool test_item(object y, object key) -{ - return y[key]; -} - -bool test_not_item(object y, object key) -{ - return !y[key]; -} - -bool check_string_slice() -{ - object s("hello, world"); - - if (s.slice(_,-3) != "hello, wo") - return false; - - if (s.slice(-3,_) != "rld") - return false; - - if (", " != s.slice(5,7)) - return false; - - return s.slice(2,-1).slice(1,-1) == "lo, wor"; -} - -bool check_binary_operators() -{ - int y; - - object x(3); - -#define TEST_BINARY(op) \ - for (y = 1; y < 6; ++y) \ - { \ - if ((x op y) != (3 op y)) \ - return false; \ - } \ - for (y = 1; y < 6; ++y) \ - { \ - if ((y op x) != (y op 3)) \ - return false; \ - } \ - for (y = 1; y < 6; ++y) \ - { \ - object oy(y); \ - if ((oy op x) != (oy op 3)) \ - return false; \ - } - TEST_BINARY(>) - TEST_BINARY(>=) - TEST_BINARY(<) - TEST_BINARY(<=) - TEST_BINARY(==) - TEST_BINARY(!=) - - TEST_BINARY(+) - TEST_BINARY(-) - TEST_BINARY(*) - TEST_BINARY(/) - TEST_BINARY(%) - TEST_BINARY(<<) - TEST_BINARY(>>) - TEST_BINARY(&) - TEST_BINARY(^) - TEST_BINARY(|) - return true; -} - -bool check_inplace(object l, object o) -{ - int y; -#define TEST_INPLACE(op) \ - for (y = 1; y < 6; ++y) \ - { \ - object x(666); \ - x op##= y; \ - if (x != (666 op y)) \ - return false; \ - } \ - for (y = 1; y < 6; ++y) \ - { \ - object x(666); \ - x op##= object(y); \ - if (!(x == (666 op y))) \ - return false; \ - } - TEST_INPLACE(+) - TEST_INPLACE(-) - TEST_INPLACE(*) - TEST_INPLACE(/) - TEST_INPLACE(%) - TEST_INPLACE(<<) - TEST_INPLACE(>>) - TEST_INPLACE(&) - TEST_INPLACE(^) - TEST_INPLACE(|) - - l += l; - for (y = 0; y < 6; ++y) - { - if (l[y] != y % 3) - return false; - } - -#define TEST_ITEM_INPLACE(index, op, n, r1, r2) \ - l[index] op##= n; \ - if (l[index] != r1) \ - return false; \ - l[index] op##= object(n); \ - if (!(l[index] == r2)) \ - return false; - - TEST_ITEM_INPLACE(0,+,7,7,14) - TEST_ITEM_INPLACE(1,-,2,-1,-3) - TEST_ITEM_INPLACE(2,*,3,6,18) - TEST_ITEM_INPLACE(2,/,2,9,4) - TEST_ITEM_INPLACE(0,%,4,2,2) - l[0] += 1; - TEST_ITEM_INPLACE(0,<<,2,12,48) - TEST_ITEM_INPLACE(0,>>,1,24,12) - l[4] = 15; - TEST_ITEM_INPLACE(4,&,(16+4+1),5,5) - TEST_ITEM_INPLACE(0,^,1,13,12) - TEST_ITEM_INPLACE(0,|,1,13,13) - - o.attr("x0") = 0; - o.attr("x1") = 1; - o.attr("x2") = 2; - o.attr("x3") = 0; - o.attr("x4") = 1; - -#define TEST_ATTR_INPLACE(index, op, n, r1, r2) \ - o.attr("x" #index) op##= n; \ - if (o.attr("x" #index) != r1) \ - return false; \ - o.attr("x" #index) op##= object(n); \ - if (o.attr("x" #index) != r2) \ - return false; - - TEST_ATTR_INPLACE(0,+,7,7,14) - TEST_ATTR_INPLACE(1,-,2,-1,-3) - TEST_ATTR_INPLACE(2,*,3,6,18) - TEST_ATTR_INPLACE(2,/,2,9,4) - TEST_ATTR_INPLACE(0,%,4,2,2) - o.attr("x0") += 1; - TEST_ATTR_INPLACE(0,<<,2,12,48) - TEST_ATTR_INPLACE(0,>>,1,24,12) - o.attr("x4") = 15; - TEST_ATTR_INPLACE(4,&,(16+4+1),5,5) - TEST_ATTR_INPLACE(0,^,1,13,12) - TEST_ATTR_INPLACE(0,|,1,13,13) - - if (l[0] != o.attr("x0")) - return false; - if (l[1] != o.attr("x1")) - return false; - if (l[2] != o.attr("x2")) - return false; - if (l[3] != o.attr("x3")) - return false; - if (l[4] != o.attr("x4")) - return false; - - // set item 5 to be a list, by calling l.__class__ - l[5] = l.attr("__class__")(); - // append an element - l[5].attr("append")(2); - // Check its value - if (l[5][0] != 2) - return false; - - return true; -} - -BOOST_PYTHON_MODULE_INIT(object_ext) -{ - def("call_object_3", call_object_3); - def("message", message); - def("number", number); - - def("obj_getattr", obj_getattr); - def("obj_const_getattr", obj_const_getattr); - def("obj_setattr", obj_setattr); - def("obj_setattr42", obj_setattr42); - def("obj_moveattr", obj_moveattr); - - - def("obj_getitem", obj_getitem); - def("obj_getitem3", obj_getitem); - def("obj_const_getitem", obj_const_getitem); - def("obj_setitem", obj_setitem); - def("obj_setitem42", obj_setitem42); - def("obj_moveitem", obj_moveitem); - def("obj_moveitem2", obj_moveitem2); - - def("test", test); - def("test_not", test_not); - - def("test_attr", test_attr); - def("test_not_attr", test_not_attr); - - def("test_item", test_item); - def("test_not_item", test_not_item); - - def("check_binary_operators", check_binary_operators); - def("check_inplace", check_inplace); - def("check_string_slice", check_string_slice); - ; -} - -#include "module_tail.cpp" diff --git a/test/object.py b/test/object.py deleted file mode 100644 index 02da5ce8..00000000 --- a/test/object.py +++ /dev/null @@ -1,126 +0,0 @@ -''' ->>> from object_ext import * ->>> def print1(x): -... print x ->>> call_object_3(print1) -3 ->>> message() -'hello, world!' ->>> number() -42 - ->>> test('hi') -1 ->>> test(None) -0 ->>> test_not('hi') -0 ->>> test_not(0) -1 - - Attributes - ->>> class X: pass -... ->>> x = X() - ->>> try: obj_getattr(x, 'foo') -... except AttributeError: pass -... else: print 'expected an exception' - ->>> obj_setattr(x, 'foo', 1) ->>> x.foo -1 ->>> obj_getattr(x, 'foo') -1 ->>> obj_const_getattr(x, 'foo') -1 ->>> obj_setattr42(x, 'foo') ->>> x.foo -42 ->>> obj_moveattr(x, 'foo', 'bar') ->>> x.bar -42 ->>> test_attr(x, 'foo') -1 ->>> test_not_attr(x, 'foo') -0 ->>> x.foo = None ->>> test_attr(x, 'foo') -0 ->>> test_not_attr(x, 'foo') -1 - - Items - ->>> d = {} ->>> obj_setitem(d, 'foo', 1) ->>> d['foo'] -1 ->>> obj_getitem(d, 'foo') -1 ->>> obj_const_getitem(d, 'foo') -1 ->>> obj_setitem42(d, 'foo') ->>> obj_getitem(d, 'foo') -42 ->>> d['foo'] -42 ->>> obj_moveitem(d, 'foo', 'bar') ->>> d['bar'] -42 ->>> obj_moveitem2(d, 'bar', d, 'baz') ->>> d['baz'] -42 ->>> test_item(d, 'foo') -1 ->>> test_not_item(d, 'foo') -0 ->>> d['foo'] = None ->>> test_item(d, 'foo') -0 ->>> test_not_item(d, 'foo') -1 - - Slices - ->>> assert check_string_slice() - - Operators - - ->>> assert check_binary_operators() - ->>> class X: pass -... ->>> assert check_inplace(range(3), X()) - - - Now make sure that object is actually managing reference counts - ->>> import weakref ->>> class Z: pass -... ->>> z = Z() ->>> def death(r): print 'death' -... ->>> r = weakref.ref(z, death) ->>> z.foo = 1 ->>> obj_getattr(z, 'foo') -1 ->>> del z -death -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/object_fail1.cpp b/test/object_fail1.cpp deleted file mode 100755 index 3b09e71d..00000000 --- a/test/object_fail1.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include - -int f(boost::python::object const& x) -{ - x._("hello") = 1; - return 0; -} diff --git a/test/object_manager.cpp b/test/object_manager.cpp deleted file mode 100755 index 44005aeb..00000000 --- a/test/object_manager.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include - -using namespace boost::python; -using namespace boost::python::converter; - -struct X {}; - -int main() -{ - BOOST_STATIC_ASSERT(is_object_manager >::value); - BOOST_STATIC_ASSERT(!is_object_manager::value); - BOOST_STATIC_ASSERT(!is_object_manager::value); - - BOOST_STATIC_ASSERT(is_reference_to_object_manager&>::value); - BOOST_STATIC_ASSERT(is_reference_to_object_manager const&>::value); - BOOST_STATIC_ASSERT(is_reference_to_object_manager volatile&>::value); - BOOST_STATIC_ASSERT(is_reference_to_object_manager const volatile&>::value); - - BOOST_STATIC_ASSERT(!is_reference_to_object_manager >::value); - BOOST_STATIC_ASSERT(!is_reference_to_object_manager::value); - BOOST_STATIC_ASSERT(!is_reference_to_object_manager::value); - BOOST_STATIC_ASSERT(!is_reference_to_object_manager::value); - - return 0; -} - diff --git a/test/operators.cpp b/test/operators.cpp deleted file mode 100755 index dc2313df..00000000 --- a/test/operators.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include "test_class.hpp" -#if __GNUC__ != 2 -# include -#else -# include -#endif - -// Just use math.h here; trying to use std::pow() causes too much -// trouble for non-conforming compilers and libraries. -#include - -using namespace boost::python; - -typedef test_class<> X; - -X operator-(X const& l, X const& r) { return X(l.value() - r.value()); } -X operator-(int l, X const& r) { return X(l - r.value()); } -X operator-(X const& l, int r) { return X(l.value() - r); } - -X operator-(X const& x) { return X(-x.value()); } - -X& operator-=(X& l, X const& r) { l.set(l.value() - r.value()); return l; } - -bool operator<(X const& x, X const& y) { return x.value() < y.value(); } -bool operator<(X const& x, int y) { return x.value() < y; } -bool operator<(int x, X const& y) { return x < y.value(); } - -X abs(X x) { return X(x.value() < 0 ? -x.value() : x.value()); } - -X pow(X x, int y) -{ - return X(int(pow(double(x.value()), y))); -} - -X pow(X x, X y) -{ - return X(int(pow(double(x.value()), y.value()))); -} - -int pow(int x, X y) -{ - return int(pow(double(x), y.value())); -} - -std::ostream& operator<<(std::ostream& s, X const& x) -{ - return s << x.value(); -} - -BOOST_PYTHON_MODULE_INIT(operators_ext) -{ - class_("X", init()) - .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)) - ; - - class_ >("Z", init()) - .def(int_(self)) - .def(float_(self)) - .def(complex_(self)) - ; -} - -#include "module_tail.cpp" diff --git a/test/operators.py b/test/operators.py deleted file mode 100644 index 58ffb5eb..00000000 --- a/test/operators.py +++ /dev/null @@ -1,86 +0,0 @@ -''' ->>> from operators_ext import * ->>> x = X(42) ->>> x.value() -42 ->>> y = x - X(5) ->>> y.value() -37 ->>> y = x - 4 ->>> y.value() -38 ->>> y = 3 - x ->>> y.value() --39 ->>> (-y).value() -39 - ->>> abs(y).value() -39 - ->>> x < 10 -0 ->>> x < 43 -1 - ->>> 10 < x -1 ->>> 43 < x -0 - ->>> x < y -0 ->>> y < x -1 - - ------ ->>> x > 10 -1 ->>> x > 43 -0 - ->>> 10 > x -0 ->>> 43 > x -1 - ->>> x > y -1 ->>> y > x -0 - ->>> y = x - 5 ->>> x -= y ->>> x.value() -5 ->>> str(x) -'5' - ->>> z = Z(10) ->>> int(z) -10 ->>> float(z) -10.0 ->>> complex(z) -(10+0j) - ->>> pow(2,x) -32 ->>> pow(x,2).value() -25 ->>> pow(X(2),x).value() -32 -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/pickle1.cpp b/test/pickle1.cpp deleted file mode 100644 index 1f9e5139..00000000 --- a/test/pickle1.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -/* - This example shows how to make an Extension Class "pickleable". - - The world class below can be fully restored by passing the - appropriate argument to the constructor. Therefore it is sufficient - to define the pickle interface method __getinitargs__. - - For more information refer to boost/libs/python/doc/pickle.html. - */ - -#include -#include -#include -#include - -#include - -namespace { - - // A friendly class. - class world - { - private: - std::string country; - public: - world(const std::string& country) { - this->country = country; - } - std::string greet() const { return "Hello from " + country + "!"; } - std::string get_country() const { return country; } - }; - - struct world_pickle_suite : boost::python::pickle_suite - { - static - boost::python::tuple - getinitargs(const world& w) - { - using namespace boost::python; - return make_tuple(w.get_country()); - } - }; - -} - -BOOST_PYTHON_MODULE_INIT(pickle1_ext) -{ - using namespace boost::python; - class_("world", init()) - .def("greet", &world::greet) - .def_pickle(world_pickle_suite()) - ; -} diff --git a/test/pickle1.py b/test/pickle1.py deleted file mode 100644 index d333919d..00000000 --- a/test/pickle1.py +++ /dev/null @@ -1,31 +0,0 @@ -r'''>>> import pickle1_ext - >>> import pickle - >>> pickle1_ext.world.__module__ - 'pickle1_ext' - >>> pickle1_ext.world.__safe_for_unpickling__ - 1 - >>> pickle1_ext.world.__name__ - 'world' - >>> pickle1_ext.world('Hello').__reduce__() - (, ('Hello',)) - >>> wd = pickle1_ext.world('California') - >>> pstr = pickle.dumps(wd) - >>> wl = pickle.loads(pstr) - >>> print wd.greet() - Hello from California! - >>> print wl.greet() - Hello from California! -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/pickle2.cpp b/test/pickle2.cpp deleted file mode 100644 index b8aacbd7..00000000 --- a/test/pickle2.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -/* - This example shows how to make an Extension Class "pickleable". - - The world class below contains member data (secret_number) that - cannot be restored by any of the constructors. Therefore it is - necessary to provide the __getstate__/__setstate__ pair of pickle - interface methods. - - For simplicity, the __dict__ is not included in the result of - __getstate__. This is not generally recommended, but a valid - approach if it is anticipated that the object's __dict__ will - always be empty. Note that safety guards are provided to catch - the cases where this assumption is not true. - - pickle3.cpp shows how to include the object's __dict__ in the - result of __getstate__. - - For more information refer to boost/libs/python/doc/pickle.html. - */ - -#include - -#include -#include -#include -#include -#include -#include - -namespace { // Avoid cluttering the global namespace. - - // A friendly class. - class world - { - public: - world(const std::string& country) : secret_number(0) { - this->country = country; - } - std::string greet() const { return "Hello from " + country + "!"; } - std::string get_country() const { return country; } - void set_secret_number(int number) { secret_number = number; } - int get_secret_number() const { return secret_number; } - private: - std::string country; - int secret_number; - }; - - struct world_pickle_suite : boost::python::pickle_suite - { - static - boost::python::tuple - getinitargs(const world& w) - { - using namespace boost::python; - return make_tuple(w.get_country()); - } - - static - boost::python::tuple - getstate(const world& w) - { - using namespace boost::python; - return make_tuple(w.get_secret_number()); - } - - static - void - setstate(world& w, boost::python::tuple state) - { - using namespace boost::python; - if (len(state) != 1) - { - PyErr_SetObject(PyExc_ValueError, - ("expected 1-item tuple in call to __setstate__; got %s" - % state).ptr() - ); - throw_error_already_set(); - } - - long number = extract(state[0]); - if (number != 42) - w.set_secret_number(number); - } - }; - -} - -BOOST_PYTHON_MODULE_INIT(pickle2_ext) -{ - boost::python::class_( - "world", boost::python::init()) - .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/pickle2.py b/test/pickle2.py deleted file mode 100644 index ec141bc9..00000000 --- a/test/pickle2.py +++ /dev/null @@ -1,45 +0,0 @@ -r'''>>> import pickle2_ext - >>> import pickle - >>> pickle2_ext.world.__module__ - 'pickle2_ext' - >>> pickle2_ext.world.__safe_for_unpickling__ - 1 - >>> pickle2_ext.world.__name__ - 'world' - >>> pickle2_ext.world('Hello').__reduce__() - (, ('Hello',), (0,)) - >>> for number in (24, 42): - ... wd = pickle2_ext.world('California') - ... wd.set_secret_number(number) - ... pstr = pickle.dumps(wd) - ... wl = pickle.loads(pstr) - ... print wd.greet(), wd.get_secret_number() - ... print wl.greet(), wl.get_secret_number() - Hello from California! 24 - Hello from California! 24 - Hello from California! 42 - Hello from California! 0 - -# Now show that the __dict__ is not taken care of. - >>> wd = pickle2_ext.world('California') - >>> wd.x = 1 - >>> wd.__dict__ - {'x': 1} - >>> try: pstr = pickle.dumps(wd) - ... except RuntimeError, err: print err[0] - ... - Incomplete pickle support (__getstate_manages_dict__ not set) -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/pickle3.cpp b/test/pickle3.cpp deleted file mode 100644 index 5fae9e6c..00000000 --- a/test/pickle3.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -/* - This example shows how to make an Extension Class "pickleable". - - The world class below contains member data (secret_number) that - cannot be restored by any of the constructors. Therefore it is - necessary to provide the __getstate__/__setstate__ pair of pickle - interface methods. - - The object's __dict__ is included in the result of __getstate__. - This requires more code (compare with pickle2.cpp), but is - unavoidable if the object's __dict__ is not always empty. - - For more information refer to boost/libs/python/doc/pickle.html. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { // Avoid cluttering the global namespace. - - // A friendly class. - class world - { - public: - world(const std::string& country) : secret_number(0) { - this->country = country; - } - std::string greet() const { return "Hello from " + country + "!"; } - std::string get_country() const { return country; } - void set_secret_number(int number) { secret_number = number; } - int get_secret_number() const { return secret_number; } - private: - std::string country; - int secret_number; - }; - - struct world_pickle_suite : boost::python::pickle_suite - { - static - boost::python::tuple - getinitargs(const world& w) - { - using namespace boost::python; - return make_tuple(w.get_country()); - } - - static - boost::python::tuple - getstate(boost::python::object w_obj) - { - using namespace boost::python; - world const& w = extract(w_obj)(); - - return make_tuple(w_obj.attr("__dict__"), w.get_secret_number()); - } - - static - void - setstate(boost::python::object w_obj, boost::python::tuple state) - { - using namespace boost::python; - world& w = extract(w_obj)(); - - if (len(state) != 2) - { - PyErr_SetObject(PyExc_ValueError, - ("expected 2-item tuple in call to __setstate__; got %s" - % state).ptr() - ); - throw_error_already_set(); - } - - // restore the object's __dict__ - dict d = extract(w_obj.attr("__dict__"))(); - d.update(state[0]); - - // restore the internal state of the C++ object - long number = extract(state[1]); - if (number != 42) - w.set_secret_number(number); - } - - static bool getstate_manages_dict() { return true; } - }; - -} - -BOOST_PYTHON_MODULE_INIT(pickle3_ext) -{ - boost::python::class_( - "world", boost::python::init()) - .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.py b/test/pickle3.py deleted file mode 100644 index b700c1b0..00000000 --- a/test/pickle3.py +++ /dev/null @@ -1,40 +0,0 @@ -r'''>>> import pickle3_ext - >>> import pickle - >>> pickle3_ext.world.__module__ - 'pickle3_ext' - >>> pickle3_ext.world.__safe_for_unpickling__ - 1 - >>> pickle3_ext.world.__getstate_manages_dict__ - 1 - >>> pickle3_ext.world.__name__ - 'world' - >>> pickle3_ext.world('Hello').__reduce__() - (, ('Hello',), ({}, 0)) - >>> for number in (24, 42): - ... wd = pickle3_ext.world('California') - ... wd.set_secret_number(number) - ... wd.x = 2 * number - ... wd.y = 'y' * number - ... wd.z = 3. * number - ... pstr = pickle.dumps(wd) - ... wl = pickle.loads(pstr) - ... print wd.greet(), wd.get_secret_number(), wd.x, wd.y, wd.z - ... print wl.greet(), wl.get_secret_number(), wl.x, wl.y, wl.z - Hello from California! 24 48 yyyyyyyyyyyyyyyyyyyyyyyy 72.0 - Hello from California! 24 48 yyyyyyyyyyyyyyyyyyyyyyyy 72.0 - Hello from California! 42 84 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 126.0 - Hello from California! 0 84 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 126.0 -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/pointee.cpp b/test/pointee.cpp deleted file mode 100644 index 44836b05..00000000 --- a/test/pointee.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include - -struct A; - -int main() -{ - BOOST_STATIC_ASSERT( - (boost::is_same< - boost::python::pointee >::type - , char** - >::value)); - - BOOST_STATIC_ASSERT( - (boost::is_same< - boost::python::pointee >::type - , A>::value)); - -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - BOOST_STATIC_ASSERT( - (boost::is_same< - boost::python::pointee::type - , char - >::value)); -#endif - return 0; -} diff --git a/test/pointer_type_id_test.cpp b/test/pointer_type_id_test.cpp deleted file mode 100644 index e3314e0b..00000000 --- a/test/pointer_type_id_test.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include - -int main() -{ - using namespace boost::python::converter; - - boost::python::type_info x - = boost::python::type_id(); - - - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - - return 0; -} diff --git a/test/raw_pyobject_fail1.cpp b/test/raw_pyobject_fail1.cpp deleted file mode 100755 index 8fe73d68..00000000 --- a/test/raw_pyobject_fail1.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include - -int main() -{ - boost::python::converter::arg_to_python x(0); - return 0; -} diff --git a/test/raw_pyobject_fail2.cpp b/test/raw_pyobject_fail2.cpp deleted file mode 100755 index 7a0e79d9..00000000 --- a/test/raw_pyobject_fail2.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include - -struct X : PyObject {}; - -int main() -{ - boost::python::converter::arg_to_python x(0); - return 0; -} diff --git a/test/result.cpp b/test/result.cpp deleted file mode 100755 index 19b1cf41..00000000 --- a/test/result.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include - -using boost::python::detail::result; -using boost::type; - -void expect_int(type*) {} -void expect_string(type*) {} - -struct X {}; - -int main() -{ - // Test the usage which works for functions, member functions, and data members - expect_int( - result((int(*)())0) - ); - - expect_int( - result((int(*)(char))0) - ); - - expect_int( - result((int(X::*)())0) - ); - - expect_int( - result((int(X::*)(char))0) - ); - - expect_int( - result((int(X::*))0) - ); - - expect_string( - result((char*(*)())0) - ); - - expect_string( - result((char*(*)(char))0) - ); - - expect_string( - result((char*(X::*)())0) - ); - - expect_string( - result((char*(X::*)(char))0) - ); - - expect_string( - result((char*(X::*))0) - ); - - // Show that we can use the general version that works for - // AdaptableFunctions - expect_int( - result((int(*)())0,0) - ); - - expect_int( - result((int(*)(char))0,0) - ); - - expect_int( - result((int(X::*)())0,0) - ); - - expect_int( - result((int(X::*)(char))0,0) - ); - - expect_int( - result((int(X::*))0,0) - ); - - expect_int( - result(std::plus(),0) - ); - - expect_string( - result((char*(*)())0,0) - ); - - expect_string( - result((char*(*)(char))0,0) - ); - - expect_string( - result((char*(X::*)())0,0) - ); - - expect_string( - result((char*(X::*)(char))0,0) - ); - - expect_string( - result((char*(X::*))0,0) - ); - - expect_string( - result(std::plus(),0) - ); - - return 0; -} diff --git a/test/select_arg_to_python_test.cpp b/test/select_arg_to_python_test.cpp deleted file mode 100644 index df925a54..00000000 --- a/test/select_arg_to_python_test.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include - -// gcc 2.95.x and MIPSpro 7.3.1.3 linker seem to demand this definition -#if ((defined(__GNUC__) && __GNUC__ < 3)) \ - || (defined(__sgi) && defined(__EDG_VERSION__) && (__EDG_VERSION__ == 238)) -namespace boost { namespace python { -BOOST_PYTHON_DECL bool handle_exception_impl(function0) -{ - return true; -} -}} -#endif - -int result; - -#define ASSERT_SAME(T1,T2) \ - if (!is_same< T1, T2 >::value) { \ - std::cout << "*********************\n"; \ - std::cout << python::type_id< T1 >() << " != " << python::type_id< T2 >() << "\n"; \ - std::cout << "*********************\n"; \ - result = 1; \ - } - -int main() -{ - using namespace boost::python::converter::detail; - using namespace boost::python::converter; - using namespace boost::python; - using namespace boost; - - - ASSERT_SAME( - select_arg_to_python::type, value_arg_to_python - ); - - ASSERT_SAME( - select_arg_to_python >::type, reference_arg_to_python - ); - - ASSERT_SAME( - select_arg_to_python >::type, pointer_shallow_arg_to_python - ); - - ASSERT_SAME( - select_arg_to_python::type, pointer_deep_arg_to_python - ); - - ASSERT_SAME( - select_arg_to_python >::type, object_manager_arg_to_python > - ); - - ASSERT_SAME( - select_arg_to_python::type, object_manager_arg_to_python - ); - - ASSERT_SAME( - select_arg_to_python::type, arg_to_python - ); - - return result; -} diff --git a/test/select_from_python_test.cpp b/test/select_from_python_test.cpp deleted file mode 100644 index 34018781..00000000 --- a/test/select_from_python_test.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include -#include -#include - -// gcc 2.95.x and MIPSpro 7.3.1.3 linker seem to demand this definition -#if ((defined(__GNUC__) && __GNUC__ < 3)) \ - || (defined(__sgi) && defined(__EDG_VERSION__) && (__EDG_VERSION__ == 238)) -namespace boost { namespace python { -BOOST_PYTHON_DECL bool handle_exception_impl(function0) -{ - return true; -} -}} -#endif - -int result; - -#define ASSERT_SAME(T1,T2) \ - if (!is_same< T1, T2 >::value) { \ - std::cout << "*********************\n"; \ - std::cout << python::type_id< T1 >() << " != " << python::type_id< T2 >() << "\n"; \ - std::cout << "*********************\n"; \ - result = 1; \ - } - -int main() -{ - using namespace boost::python::converter; - using namespace boost; - - - ASSERT_SAME( - select_arg_from_python::type, arg_rvalue_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, arg_rvalue_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, arg_rvalue_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, arg_rvalue_from_python - ); - - - - ASSERT_SAME( - select_arg_from_python::type, pointer_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, pointer_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, pointer_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, pointer_arg_from_python - ); - - - - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, arg_rvalue_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - - - ASSERT_SAME( - select_arg_from_python::type, pointer_cref_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, pointer_cref_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, pointer_cref_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, pointer_cref_arg_from_python - ); - - - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - - ASSERT_SAME( - select_arg_from_python::type, reference_arg_from_python - ); - return result; -} diff --git a/test/select_holder.cpp b/test/select_holder.cpp deleted file mode 100644 index febbeb2d..00000000 --- a/test/select_holder.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include -#include - -#define BOOST_INCLUDE_MAIN -#include - -struct BR {}; - -struct Base {}; -struct Derived : Base {}; - -namespace boost { namespace python -{ - // specialization - template <> - struct has_back_reference
- { - BOOST_STATIC_CONSTANT(bool, value = true); - }; -}} // namespace boost::python - -template -void assert_same(U* = 0, T* = 0) -{ - BOOST_TEST((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); - -} - -template -void assert_holder(T* = 0, Held* = 0, Holder* = 0) -{ - assert_same(boost::python::objects::select_holder::execute((Held*)0).get()); -} - -int test_main(int, char * []) -{ - using namespace boost::python::detail; - using namespace boost::python::objects; - - assert_holder >(); - - assert_holder >(); - assert_holder >(); - assert_holder >(); - - assert_holder >(); - - assert_holder - ,pointer_holder,Base> >(); - - assert_holder - ,pointer_holder_back_reference,Base> >(); - - assert_holder - ,pointer_holder_back_reference,BR> > (); - - return 0; -} - -#if !defined(_WIN32) || defined(__GNUC__) -// This definition is needed for MinGW 2.95.2 and KCC on OSF for some -// reason, but will break other Win32 compilers. -namespace boost { namespace python -{ - bool handle_exception_impl(boost::function0) { return false; } -}} -#endif diff --git a/test/simple_type.hpp b/test/simple_type.hpp deleted file mode 100644 index 2df97cfd..00000000 --- a/test/simple_type.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright David Abrahams 2001. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef SIMPLE_TYPE_DWA2001128_HPP -# define SIMPLE_TYPE_DWA2001128_HPP - -struct simple -{ - char* s; -}; - -#endif // SIMPLE_TYPE_DWA2001128_HPP diff --git a/test/str.cpp b/test/str.cpp deleted file mode 100644 index 646f8676..00000000 --- a/test/str.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include - -using namespace boost::python; - -object convert_to_string(object data) -{ - return str(data); -} - -void work_with_string(object print) -{ - str data("this is a demo string"); - print(data.split(" ")); - print(data.split(" ",3)); - print(str("<->").join(data.split(" "))); - print(data.capitalize()); - print('[' + data.center(30) + ']'); - print(data.count("t")); - print(data.encode("utf-8")); - print(data.decode("utf-8")); - print(data.endswith("xx")); - print(data.startswith("test")); - print(data.splitlines()); - print(data.strip()); - print(data.swapcase()); - print(data.title()); - - print("find"); - print(data.find("demo")); - print(data.find("demo"),3,5); - print(data.find(std::string("demo"))); - print(data.find(std::string("demo"),9)); - - print("expandtabs"); - str tabstr("\t\ttab\tdemo\t!"); - print(tabstr.expandtabs()); - print(tabstr.expandtabs(4)); - print(tabstr.expandtabs(7.9)); - - print("operators"); - print( str("part1") + str("part2") ); -// print( str("a test string").slice(3,_) ); -// print( str("another test")[5] ); - - print(data.replace("demo",std::string("blabla"))); - print(data.rfind("i",5)); - print(data.rindex("i",5)); - print(data.startswith("asdf")); - print(data.endswith("asdf")); - print(data.translate(str('a')*256)); - - - bool tmp = data.isalnum() || data.isalpha() || data.isdigit() || data.islower() || - data.isspace() || data.istitle() || data.isupper(); - (void)tmp; // ignored. -} - - -BOOST_PYTHON_MODULE_INIT(str_ext) -{ - def("convert_to_string",convert_to_string); - def("work_with_string",work_with_string); -} - diff --git a/test/str.py b/test/str.py deleted file mode 100644 index 666096b1..00000000 --- a/test/str.py +++ /dev/null @@ -1,52 +0,0 @@ -""" ->>> from str_ext import * ->>> def printer(*args): -... for x in args: print x, -... print -... ->>> work_with_string(printer) -['this', 'is', 'a', 'demo', 'string'] -['this', 'is', 'a', 'demo string'] -this<->is<->a<->demo<->string -This is a demo string -[ this is a demo string ] -2 -this is a demo string -this is a demo string -0 -0 -['this is a demo string'] -this is a demo string -THIS IS A DEMO STRING -This Is A Demo String -find -10 -10 3 5 -10 -10 -expandtabs - tab demo ! - tab demo ! - tab demo ! -operators -part1part2 -this is a blabla string -18 -18 -0 -0 -aaaaaaaaaaaaaaaaaaaaa -""" - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/string_literal.cpp b/test/string_literal.cpp deleted file mode 100644 index 882fbd4e..00000000 --- a/test/string_literal.cpp +++ /dev/null @@ -1,38 +0,0 @@ -//#include -#include -#include -#include - -using namespace boost::python::detail; - - -template -void expect_string_literal(T const&) -{ - BOOST_STATIC_ASSERT(is_string_literal::value); -} - -int main() -{ - expect_string_literal("hello"); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(is_string_literal::value); - BOOST_STATIC_ASSERT(is_string_literal::value); - - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - BOOST_STATIC_ASSERT(!is_string_literal::value); - return 0; -} diff --git a/test/submod_subclass_api.cpp b/test/submod_subclass_api.cpp deleted file mode 100644 index b2c5293e..00000000 --- a/test/submod_subclass_api.cpp +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright David Hawkes 2002. -// Permission is hereby granted to copy, use and modify this software -// for any purpose, including commercial distribution, provided this -// copyright notice is not removed. No warranty WHATSOEVER is provided with this -// software. Any user(s) accepts this software "as is" and as such they will not -// bind the author(s) to any claim of suitabilty for any purpose. - -// embed_test.cpp : substantial test of embedding python in c++ using boost - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace boost; -using namespace boost::python; - - -// The following macros are for our convenience and coding expediency... -// There is no particular recomendation that they be used elsewhere -// as they are not feature complete and are just sufficient to suport -// the code here - - -#define DEF(fn) def(#fn, fn) -#define DEF_C(c, fn) def(#fn, &c::fn) -#define DEF_C_CB(c, fn) def(#fn, &c##_callback::base_##fn) - -#define CLASS(c) class_ >(#c) -#define CLASS_CB(c) class_, noncopyable >(#c) - -#define START_CALLBACK_CLASS(c) \ -class c##_callback : public c \ -{ \ - typedef c __base__; \ -public: \ - c##_callback(PyObject* self) : m_self(self) {} \ -private: \ - PyObject* m_self; \ -public: - -#define END_CALLBACK_CLASS }; - - -#define CALLBACK_MEMBER0(fn, rtn) \ -rtn fn() { return call_method(m_self, #fn); } \ -rtn base_##fn() { return __base__::fn(); } - - -#define CALLBACK_MEMBER0C(fn, rtn) \ -rtn fn() const { return call_method(m_self, #fn); } \ -rtn base_##fn() const { return __base__::fn(); } -// End of convenience macros - -// useful support classes -template -struct class_object : public object -{ - typedef object base; - class_object() : m_class_ptr(NULL) {} - class_object(object const& o) : base(o) { init(); } - class_object& operator=(object const& o) - { - base::operator=(o); - init(); - return *this; - } - T* operator->() const { return m_class_ptr; } - T& operator*() const { return *m_class_ptr; } -private: - void init() - { - m_class_ptr = arg_from_python(ptr())(ptr()); - } - T* m_class_ptr; -}; - -template -struct item_object : public object -{ - typedef object base; - item_object() {} - item_object(object const& o) : base(o), m_class(arg_from_python(ptr())(ptr())) {} - item_object& operator=(object const& o) - { - base::operator=(o); - init(); - return *this; - } - operator T() { return m_class; } -private: - void init() - { - m_class = arg_from_python(ptr())(ptr()); - } - T m_class; -}; -// end of useful support classes - -// pass our args in this struct -struct main_args { - main_args(int _argc, char* _argv[]) : argc(_argc), argv(_argv) {} - int argc; - char** argv; -}; -int python_main(main_args const &ma); - -// python module init -BOOST_PYTHON_MODULE_INIT(python_main) -{ - DEF(python_main); - CLASS(main_args); -} - -// sub module tests -namespace sm { - -int test_func() { return 7; } - -BOOST_PYTHON_MODULE_INIT(sm_test) -{ - // define a submodule - boost::python::module(".sm"); - // define a 2nd submodule - boost::python::module(".sm.sm2"); - // define a test function to appear in 2nd submodule - DEF(test_func); -} - -// sub-module tests -int test() -{ - api::run_simple_string("import sm_test"); - if(api::call_statement("_0 = bpl_test('sub modules', sm_test.sm.sm2.test_func, _1)", test_func())) - return 1; - return 0; -} - -} - -// sub class tests -namespace sc { - -class c1 { -public: - c1() {} - class c2 { - public: - c2() : n(2) {} - int n; - }; - c2 t; -}; - -c1::c2 test_func() { - return c1().t; -} - -BOOST_PYTHON_MODULE_INIT(sc_test) -{ - class_("c1.c2") - .def_init() - .def_readwrite("n", &c1::c2::n); - CLASS(c1) - .def_init() - .def_readwrite("t", &c1::t); - DEF(test_func); -} - -// sub-class tests -int test() -{ - api::run_simple_string("import sc_test"); - if(api::call_statement("_0 = bpl_test('sub classes', lambda : sc_test.c1.c2().n, _1.n)", test_func())) - return 1; - if(api::call_statement("_0 = bpl_test('sub classes', lambda : sc_test.c1().t.n, _1.n)", test_func())) - return 1; - return 0; -} - -} - -// new main that will have a python execution frame -int main(int argc, char* argv[]) -{ - // default return value; - int rtn = 0; - // define all the built-in modules used - PyImport_AppendInittab("python_main", initpython_main); - PyImport_AppendInittab("sm_test", sm::initsm_test); - PyImport_AppendInittab("sc_test", sc::initsc_test); - // initialize python - Py_Initialize(); - // start a new block so that any objects are released prior to finalizing - { - // import our main module - this will also initialise boost - api::run_simple_string("import python_main"); - // We call back here so we have a proper python execution frame to work with - item_object o_rtn(api::call_statement("_0 = python_main.python_main(_1)", main_args(argc, argv))); - rtn = o_rtn; - } - // clean up - Py_Finalize(); - return rtn; -} - -char *bpl_test = -"def bpl_test(name, func, result):\n" -" print 'testing %s...' % name\n" -" if func() != result:\n" -" print 'failed'\n" -" return 1\n" -" else:\n" -" print 'OK'\n" -" return 0\n"; - - -int python_main(main_args const &ma) -{ - api::print("running...\n"); - api::call_statement(bpl_test); - if(sm::test()) - return 1; - if(sc::test()) - return 1; - return 0; -} diff --git a/test/test_builtin_converters.cpp b/test/test_builtin_converters.cpp deleted file mode 100644 index 912f2dc5..00000000 --- a/test/test_builtin_converters.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include -#include -#include - -template -struct by_value -{ - static T rewrap(T x) - { - return x; - } -}; - -template -struct by_const_reference -{ - static T rewrap(T const& x) - { - return x; - } -}; - -template -struct by_reference -{ - static T rewrap(T& x) - { - return x; - } -}; - -using boost::python::def; -using boost::python::handle; -using boost::python::object; -using boost::python::borrowed; - -// Used to test that arbitrary handle<>s can be returned -handle get_type(handle<> x) -{ - return handle(borrowed(x->ob_type)); -} - -handle<> return_null_handle() -{ - return handle<>(); -} - -char const* rewrap_value_mutable_cstring(char* x) { return x; } - -BOOST_PYTHON_MODULE_INIT(builtin_converters) -{ - def("get_type", get_type); - def("return_null_handle", return_null_handle); - - def("rewrap_value_bool", by_value::rewrap); - def("rewrap_value_char", by_value::rewrap); - def("rewrap_value_signed_char", by_value::rewrap); - def("rewrap_value_unsigned_char", by_value::rewrap); - def("rewrap_value_int", by_value::rewrap); - def("rewrap_value_unsigned_int", by_value::rewrap); - def("rewrap_value_short", by_value::rewrap); - def("rewrap_value_unsigned_short", by_value::rewrap); - def("rewrap_value_long", by_value::rewrap); - def("rewrap_value_unsigned_long", by_value::rewrap); -// using Python's macro instead of Boost's - we don't seem to get the -// config right all the time. -#ifdef HAVE_LONG_LONG - def("rewrap_value_long_long", by_value::rewrap); - def("rewrap_value_unsigned_long_long", by_value::rewrap); -#endif - def("rewrap_value_float", by_value::rewrap); - def("rewrap_value_double", by_value::rewrap); - def("rewrap_value_long_double", by_value::rewrap); - def("rewrap_value_complex_float", by_value >::rewrap); - def("rewrap_value_complex_double", by_value >::rewrap); - def("rewrap_value_complex_long_double", by_value >::rewrap); - def("rewrap_value_string", by_value::rewrap); - def("rewrap_value_cstring", by_value::rewrap); - def("rewrap_value_handle", by_value >::rewrap); - def("rewrap_value_object", by_value::rewrap); - - // Expose this to illustrate our failings ;-). See test_builtin_converters.py - def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring); - - - def("rewrap_const_reference_bool", by_const_reference::rewrap); - def("rewrap_const_reference_char", by_const_reference::rewrap); - def("rewrap_const_reference_signed_char", by_const_reference::rewrap); - def("rewrap_const_reference_unsigned_char", by_const_reference::rewrap); - def("rewrap_const_reference_int", by_const_reference::rewrap); - def("rewrap_const_reference_unsigned_int", by_const_reference::rewrap); - def("rewrap_const_reference_short", by_const_reference::rewrap); - def("rewrap_const_reference_unsigned_short", by_const_reference::rewrap); - def("rewrap_const_reference_long", by_const_reference::rewrap); - def("rewrap_const_reference_unsigned_long", by_const_reference::rewrap); -// using Python's macro instead of Boost's - we don't seem to get the -// config right all the time. -#ifdef HAVE_LONG_LONG - def("rewrap_const_reference_long_long", by_const_reference::rewrap); - def("rewrap_const_reference_unsigned_long_long", by_const_reference::rewrap); -#endif - def("rewrap_const_reference_float", by_const_reference::rewrap); - def("rewrap_const_reference_double", by_const_reference::rewrap); - def("rewrap_const_reference_long_double", by_const_reference::rewrap); - def("rewrap_const_reference_complex_float", by_const_reference >::rewrap); - def("rewrap_const_reference_complex_double", by_const_reference >::rewrap); - def("rewrap_const_reference_complex_long_double", by_const_reference >::rewrap); - def("rewrap_const_reference_string", by_const_reference::rewrap); - def("rewrap_const_reference_cstring", by_const_reference::rewrap); - def("rewrap_const_reference_handle", by_const_reference >::rewrap); - def("rewrap_const_reference_object", by_const_reference::rewrap); - - - def("rewrap_reference_object", by_reference::rewrap); -} - diff --git a/test/test_builtin_converters.py b/test/test_builtin_converters.py deleted file mode 100644 index f6caf56b..00000000 --- a/test/test_builtin_converters.py +++ /dev/null @@ -1,236 +0,0 @@ -""" ->>> from builtin_converters import * - -# Synthesize idendity functions in case long long not supported ->>> if not 'rewrap_value_long_long' in dir(): -... def rewrap_value_long_long(x): return long(x) -... def rewrap_value_unsigned_long_long(x): return long(x) -... def rewrap_const_reference_long_long(x): return long(x) -... def rewrap_const_reference_unsigned_long_long(x): return long(x) - ->>> rewrap_value_bool(None) -0 ->>> rewrap_value_bool(0) -0 ->>> rewrap_value_bool(33) -1 ->>> rewrap_value_char('x') -'x' - - Note that there's currently silent truncation of strings passed to - char arguments. - ->>> rewrap_value_char('xy') -'x' ->>> rewrap_value_signed_char(42) -42 ->>> rewrap_value_unsigned_char(42) -42 ->>> rewrap_value_int(42) -42 ->>> rewrap_value_unsigned_int(42) -42 ->>> rewrap_value_short(42) -42 ->>> rewrap_value_unsigned_short(42) -42 ->>> rewrap_value_long(42) -42 ->>> rewrap_value_unsigned_long(42) -42 ->>> rewrap_value_long_long(42) -42L ->>> rewrap_value_unsigned_long_long(42) -42L - - show that we have range checking. - ->>> try: rewrap_value_unsigned_short(-42) -... except OverflowError: pass -... else: print 'expected an OverflowError!' - ->>> try: rewrap_value_int(sys.maxint * 2) -... except OverflowError: pass -... else: print 'expected an OverflowError!' - - ->>> abs(rewrap_value_float(4.2) - 4.2) < .000001 -1 ->>> rewrap_value_double(4.2) - 4.2 -0.0 ->>> rewrap_value_long_double(4.2) - 4.2 -0.0 - ->>> abs(rewrap_value_complex_float(4+.2j) - (4+.2j)) < .000001 -1 ->>> abs(rewrap_value_complex_double(4+.2j) - (4+.2j)) < .000001 -1 ->>> abs(rewrap_value_complex_long_double(4+.2j) - (4+.2j)) < .000001 -1 - ->>> rewrap_value_cstring('hello, world') -'hello, world' ->>> rewrap_value_string('yo, wassup?') -'yo, wassup?' - ->>> rewrap_value_handle(1) -1 ->>> x = 'hi' ->>> assert rewrap_value_handle(x) is x ->>> assert rewrap_value_object(x) is x - - Note that we can currently get a mutable pointer into an immutable - Python string: - ->>> rewrap_value_mutable_cstring('hello, world') -'hello, world' - ->>> rewrap_const_reference_bool(None) -0 ->>> rewrap_const_reference_bool(0) -0 - ->>> try: rewrap_const_reference_bool('yes') -... except TypeError: pass -... else: print 'expected a TypeError exception' - ->>> rewrap_const_reference_char('x') -'x' - - Note that there's currently silent truncation of strings passed to - char arguments. - ->>> rewrap_const_reference_char('xy') -'x' ->>> rewrap_const_reference_signed_char(42) -42 ->>> rewrap_const_reference_unsigned_char(42) -42 ->>> rewrap_const_reference_int(42) -42 ->>> rewrap_const_reference_unsigned_int(42) -42 ->>> rewrap_const_reference_short(42) -42 ->>> rewrap_const_reference_unsigned_short(42) -42 ->>> rewrap_const_reference_long(42) -42 ->>> rewrap_const_reference_unsigned_long(42) -42 ->>> rewrap_const_reference_long_long(42) -42L ->>> rewrap_const_reference_unsigned_long_long(42) -42L - - ->>> abs(rewrap_const_reference_float(4.2) - 4.2) < .000001 -1 ->>> rewrap_const_reference_double(4.2) - 4.2 -0.0 ->>> rewrap_const_reference_long_double(4.2) - 4.2 -0.0 - ->>> abs(rewrap_const_reference_complex_float(4+.2j) - (4+.2j)) < .000001 -1 ->>> abs(rewrap_const_reference_complex_double(4+.2j) - (4+.2j)) < .000001 -1 ->>> abs(rewrap_const_reference_complex_long_double(4+.2j) - (4+.2j)) < .000001 -1 - ->>> rewrap_const_reference_cstring('hello, world') -'hello, world' ->>> rewrap_const_reference_string('yo, wassup?') -'yo, wassup?' - ->>> rewrap_const_reference_handle(1) -1 ->>> x = 'hi' ->>> assert rewrap_const_reference_handle(x) is x ->>> assert rewrap_const_reference_object(x) is x ->>> assert rewrap_reference_object(x) is x - - -Check that None <==> NULL - ->>> rewrap_const_reference_cstring(None) - -But None cannot be converted to a string object: - ->>> try: rewrap_const_reference_string(None) -... except TypeError: pass -... else: print 'expected a TypeError exception' - -Now check implicit conversions between floating/integer types - ->>> rewrap_const_reference_float(42) -42.0 - ->>> rewrap_const_reference_float(42L) -42.0 - ->>> try: rewrap_const_reference_int(42.0) -... except TypeError: pass -... else: print 'expected a TypeError exception' - ->>> rewrap_value_float(42) -42.0 - ->>> try: rewrap_value_int(42.0) -... except TypeError: pass -... else: print 'expected a TypeError exception' - -Check that classic classes also work - ->>> class FortyTwo: -... def __int__(self): -... return 42 -... def __float__(self): -... return 42.0 -... def __complex__(self): -... return complex(4+.2j) -... def __str__(self): -... return '42' - ->>> try: rewrap_const_reference_float(FortyTwo()) -... except TypeError: pass -... else: print 'expected a TypeError exception' - ->>> try: rewrap_value_int(FortyTwo()) -... except TypeError: pass -... else: print 'expected a TypeError exception' - ->>> try: rewrap_const_reference_string(FortyTwo()) -... except TypeError: pass -... else: print 'expected a TypeError exception' - ->>> try: rewrap_value_complex_double(FortyTwo()) -... except TypeError: pass -... else: print 'expected a TypeError exception' - -# show that arbitrary handle instantiations can be returned ->>> get_type(1) is type(1) -1 - ->>> return_null_handle() is None -1 -""" - -def run(args = None): - import sys - import doctest - import builtin_converters - - if 'rewrap_value_long_long' in dir(builtin_converters): - print 'LONG_LONG supported, testing...' - else: - print 'LONG_LONG not supported, skipping those tests...' - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/test_class.hpp b/test/test_class.hpp deleted file mode 100644 index 18164102..00000000 --- a/test/test_class.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef TEST_CLASS_DWA2002326_HPP -# define TEST_CLASS_DWA2002326_HPP -# include - -template -struct test_class -{ - explicit test_class(int x) : x(x), magic(7654321 + n) { ++counter; } - test_class(test_class const& rhs) : x(rhs.x), magic(7654321 + n) { ++counter; } - virtual ~test_class() { assert(magic == 7654321 + n); magic = 6666666; x = 9999; --counter; } - - void set(int x) { assert(magic == 7654321 + n); this->x = x; } - int value() const { assert(magic == 7654321 + n); return x; } - operator int() const { return x; } - static int count() { return counter; } - - int x; - long magic; - static int counter; - - private: - void operator=(test_class const&); -}; - -template -int test_class::counter; - -#endif // TEST_CLASS_DWA2002326_HPP diff --git a/test/test_cltree.py b/test/test_cltree.py deleted file mode 100644 index 8408f7f2..00000000 --- a/test/test_cltree.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -from cltree import basic,symbol,constant,variable - -b = basic() -c = constant() -s = symbol() -v = variable() - -assert isinstance(b,basic) -assert not isinstance(b,symbol) -assert not isinstance(b,constant) -assert not isinstance(b,variable) - -assert isinstance(c,basic) -assert isinstance(c,constant) -assert not isinstance(c,symbol) -assert not isinstance(c,variable) - -assert not isinstance(s,basic) -assert isinstance(s,symbol) -assert not isinstance(s,constant) -assert not isinstance(s,variable) - -assert isinstance(v,basic) -assert not isinstance(v,symbol) -assert not isinstance(v,constant) -assert isinstance(v,variable) - -print 'b=',b -assert repr(b)=='cltree.basic()' -print 's=',s -assert repr(s)!='cltree.wrapped_symbol()' # because not isinstance(s,basic) -print 'c=',c -assert repr(c)=='cltree.constant()' -print 'v=',v -assert repr(v)=='cltree.wrapped_variable()' - - -print 'ok' diff --git a/test/test_pointer_adoption.cpp b/test/test_pointer_adoption.cpp deleted file mode 100644 index 90b39ea7..00000000 --- a/test/test_pointer_adoption.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include - -using namespace boost::python; - -int a_instances = 0; - -int num_a_instances() { return a_instances; } - -struct inner -{ - inner(std::string const& s) - : s(s) - {} - - void change(std::string const& new_s) - { - this->s = new_s; - } - - std::string s; -}; - -struct Base -{ - virtual ~Base() {} -}; - -struct A : Base -{ - A(std::string const& s) - : x(s) - { - ++a_instances; - } - - ~A() - { - --a_instances; - } - - std::string content() const - { - return x.s; - } - - inner& get_inner() - { - return x; - } - - inner x; -}; - -struct B -{ - B() : x(0) {} - B(A* x_) : x(x_) {} - - inner const* adopt(A* x) { this->x = x; return &x->get_inner(); } - - std::string a_content() - { - return x ? x->content() : std::string("empty"); - } - - A* x; -}; - - -A* create(std::string const& s) -{ - return new A(s); -} - -A* as_A(Base* b) -{ - return dynamic_cast(b); -} - -BOOST_PYTHON_MODULE_INIT(test_pointer_adoption_ext) -{ - def("num_a_instances", num_a_instances); - - // Specify the manage_new_object return policy to take - // ownership of create's result - def("create", create, return_value_policy()); - - def("as_A", as_A, return_internal_reference<>()); - - class_("Base") - ; - - class_ >("A", no_init) - .def("content", &A::content) - .def("get_inner", &A::get_inner, return_internal_reference<>()) - ; - - class_("inner", no_init) - .def("change", &inner::change) - ; - - class_("B") - .def(init()[with_custodian_and_ward_postcall<1,2>()]) - - .def("adopt", &B::adopt - // Adopt returns a pointer referring to a subobject of its 2nd argument (1st being "self") - , return_internal_reference<2 - // Meanwhile, self holds a reference to the 2nd argument. - , with_custodian_and_ward<1,2> >() - ) - - .def("a_content", &B::a_content) - ; -} - -#include "module_tail.cpp" diff --git a/test/test_pointer_adoption.py b/test/test_pointer_adoption.py deleted file mode 100644 index f684b062..00000000 --- a/test/test_pointer_adoption.py +++ /dev/null @@ -1,90 +0,0 @@ -""" ->>> from test_pointer_adoption_ext import * - ->>> num_a_instances() -0 - ->>> a = create('dynamically allocated') ->>> num_a_instances() -1 - ->>> a.content() -'dynamically allocated' - ->>> innards = a.get_inner() ->>> innards.change('with an exposed reference') ->>> a.content() -'with an exposed reference' - -# The a instance should be kept alive... ->>> a = None ->>> num_a_instances() -1 - -# ...until we're done with its innards ->>> innards = None ->>> num_a_instances() -0 - ->>> b = B() ->>> a = create('another') ->>> b.a_content() -'empty' ->>> innards = b.adopt(a); ->>> b.a_content() -'another' ->>> num_a_instances() -1 ->>> del a # innards and b are both holding a reference ->>> num_a_instances() -1 ->>> innards.change('yet another') ->>> b.a_content() -'yet another' - ->>> del innards ->>> num_a_instances() # b still owns a reference to a -1 ->>> del b ->>> num_a_instances() -0 - -Test call policies for constructors here - ->>> a = create('second a') ->>> num_a_instances() -1 ->>> b = B(a) ->>> num_a_instances() -1 ->>> a.content() -'second a' - ->>> del a ->>> num_a_instances() -1 ->>> b.a_content() -'second a' - ->>> del b ->>> num_a_instances() -0 - ->>> as_A(create('dynalloc')) is None -0 ->>> base = Base() ->>> as_A(base) is None -1 -""" -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/tuple.cpp b/test/tuple.cpp deleted file mode 100644 index d5569185..00000000 --- a/test/tuple.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include - -using namespace boost::python; - -object convert_to_tuple(object data) -{ - return tuple(data); -} - -void test_operators(tuple t1, tuple t2, object print) -{ - print(t1 + t2); -} - -tuple mktuple0() { return make_tuple(); } -tuple mktuple1(int x) { return make_tuple(x); } -tuple mktuple2(char const* a1, int x) { return make_tuple(a1, x); } - -BOOST_PYTHON_MODULE_INIT(tuple_ext) -{ - def("convert_to_tuple",convert_to_tuple); - def("test_operators",test_operators); - def("make_tuple", mktuple0); - def("make_tuple", mktuple1); - def("make_tuple", mktuple2); -} diff --git a/test/tuple.py b/test/tuple.py deleted file mode 100644 index cd899df4..00000000 --- a/test/tuple.py +++ /dev/null @@ -1,32 +0,0 @@ -""" ->>> from tuple_ext import * ->>> def printer(*args): -... for x in args: print x, -... print -... ->>> print convert_to_tuple("this is a test string") -('t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't', ' ', 's', 't', 'r', 'i', 'n', 'g') ->>> t1 = convert_to_tuple("this is") ->>> t2 = (1,2,3,4) ->>> test_operators(t1,t2,printer) -('t', 'h', 'i', 's', ' ', 'i', 's', 1, 2, 3, 4) ->>> make_tuple() -() ->>> make_tuple(42) -(42,) ->>> make_tuple('hello', 42) -('hello', 42) -""" - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0]) diff --git a/test/upcast.cpp b/test/upcast.cpp deleted file mode 100755 index b02d2534..00000000 --- a/test/upcast.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include - -struct X { long x; }; -struct Y : X, PyObject {}; - -int main() -{ - PyTypeObject o; - Y y; - assert(&boost::python::upcast(&o)->ob_refcnt == &o.ob_refcnt); - assert(&boost::python::upcast(&y)->ob_refcnt == &y.ob_refcnt); - return 0; -} - diff --git a/test/virtual_functions.cpp b/test/virtual_functions.cpp deleted file mode 100644 index f0bfd787..00000000 --- a/test/virtual_functions.cpp +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#include -#include -#include -#include -#include -#include - -using namespace boost::python; - -struct X -{ - explicit X(int x) : x(x), magic(7654321) { ++counter; } - X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } - virtual ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } - - void set(int x) { assert(magic == 7654321); this->x = x; } - int value() const { assert(magic == 7654321); return x; } - static int count() { return counter; } - private: - void operator=(X const&); - private: - int x; - long magic; - static int counter; -}; - -struct Y : X -{ - Y(int x) : X(x) {}; -}; - -struct abstract : X -{ - abstract(int x) : X(x) {}; - int call_f(Y const& y) { return f(y); } - virtual int f(Y const& y) = 0; -}; - -struct concrete : X -{ - concrete(int x) : X(x) {}; - int call_f(Y const& y) { return f(y); } - virtual int f(Y const& y) { set(y.value()); return y.value(); } -}; - -struct abstract_callback : abstract -{ - abstract_callback(PyObject* p, int x) - : abstract(x), self(p) - {} - - int f(Y const& y) - { - return call_method(self, "f", boost::ref(y)); - } - - PyObject* self; -}; - -struct concrete_callback : concrete -{ - concrete_callback(PyObject* p, int x) - : concrete(x), self(p) - {} - - concrete_callback(PyObject* p, concrete const& x) - : concrete(x), self(p) - {} - - int f(Y const& y) - { - return call_method(self, "f", boost::ref(y)); - } - - int f_impl(Y const& y) - { - return this->concrete::f(y); - } - - PyObject* self; -}; - -int X::counter; - -BOOST_PYTHON_MODULE_INIT(virtual_functions_ext) -{ - class_("concrete", init()) - .def("value", &concrete::value) - .def("set", &concrete::set) - .def("call_f", &concrete::call_f) - .def("f", &concrete_callback::f_impl) - ; - - class_ - >("abstract", init()) - - .def("value", &abstract::value) - .def("call_f", &abstract::call_f) - .def("set", &abstract::set) - ; - - class_("Y", init()) - .def("value", &Y::value) - .def("set", &Y::set) - ; -} - -#include "module_tail.cpp" diff --git a/test/virtual_functions.py b/test/virtual_functions.py deleted file mode 100644 index 9b074b1a..00000000 --- a/test/virtual_functions.py +++ /dev/null @@ -1,102 +0,0 @@ -''' ->>> from virtual_functions_ext import * - ->>> class C1(concrete): -... def f(self, y): -... return concrete.f(self, Y(-y.value())) - ->>> class C2(concrete): -... pass - ->>> class A1(abstract): -... def f(self, y): -... return y.value() * 2 - ->>> class A2(abstract): -... pass - - ->>> y1 = Y(16) ->>> y2 = Y(17) - - - -# -# Test abstract with f overridden -# ->>> a1 = A1(42) ->>> a1.value() -42 - -# Call f indirectly from C++ ->>> a1.call_f(y1) -32 - -# Call f directly from Python ->>> a1.f(y2) -34 - -# -# Test abstract with f not overridden -# ->>> a2 = A2(42) ->>> a2.value() -42 - -# Call f indirectly from C++ ->>> try: a2.call_f(y1) -... except AttributeError: pass -... else: print 'no exception' - -# Call f directly from Python ->>> try: a2.call_f(y2) -... except AttributeError: pass -... else: print 'no exception' - -############# Concrete Tests ############ - -# -# Test concrete with f overridden -# ->>> c1 = C1(42) ->>> c1.value() -42 - -# Call f indirectly from C++ ->>> c1.call_f(y1) --16 - -# Call f directly from Python ->>> c1.f(y2) --17 - -# -# Test concrete with f not overridden -# ->>> c2 = C2(42) ->>> c2.value() -42 - -# Call f indirectly from C++ ->>> c2.call_f(y1) -16 - -# Call f directly from Python ->>> c2.f(y2) -17 - - -''' - -def run(args = None): - import sys - import doctest - - if args is not None: - sys.argv = args - return doctest.testmod(sys.modules.get(__name__)) - -if __name__ == '__main__': - print "running..." - import sys - sys.exit(run()[0])