diff --git a/todo.txt b/todo.txt index 8a6e3da3..084bce5d 100644 --- a/todo.txt +++ b/todo.txt @@ -5,12 +5,16 @@ use Python generic numeric coercion in from_python() for C++ numeric types Rename PyPtr to Reference. Report Cygwin linker memory issues pickling support -Make abstract classes non-instantiable (?) +__init__ stuff + Make abstract classes non-instantiable (?) + Call default __init__ functions automatically where applicable (?) Support for Python LONG types in Objects.h -Concept checking for to_python() template function (Ullrich did this) Throw TypeError after asserting when objects from objects.cpp detect a type mismatch. Add callback-through-function ability to callback.h -Generate N+1-argument free functions and N-argument member functions from gen_all.py +Figure out how to package everything as a shared library. +Unicode string support +Add read-only wrapper for __dict__ attribute +More template member functions for the elements of objects.h Testing Python 2.0 @@ -25,8 +29,6 @@ Optimizations Documentation: - Alpha support - differences between Python classes and ExtensionClasses additional capabilities of ExtensionClasses slice adjustment @@ -49,9 +51,40 @@ Documentation: >>> C().x 'A.__getattr__' - Multiple inheritance - Smart pointers + #ifndef PY_NO_INLINE_FRIENDS_IN_NAMESPACE + namespace py { + #endif + + template + struct VtkConverters + { + typedef py::PyExtensionClassConverters Converters; + + friend vtk_ptr& from_python(PyObject* p, py::Type&>) + { return Converters::ptr_from_python(p, py::Type >()); } + + friend vtk_ptr& from_python(PyObject* p, py::Type >) + { return Converters::ptr_from_python(p, py::Type >()); } + + friend const vtk_ptr& from_python(PyObject* p, py::Type&>) + { return Converters::ptr_from_python(p, py::Type >()); } + + friend PyObject* to_python(vtk_ptr x) + { return Converters::ptr_to_python(x); } + }; + + #ifndef PY_NO_INLINE_FRIENDS_IN_NAMESPACE + } + #endif + + template + struct VtkWrapper : py::ClassWrapper, py::VtkConverters + { + typedef py::ClassWrapper Base; + VtkWrapper(Module& module, const char* name) + : Base(module, name) {} + }; exception handling @@ -64,33 +97,8 @@ Documentation: dealing with non-const reference/pointer parameters - Private virtual functions with default implementations - extending multiple-argument support using gen_all.py - Calling back into Python: - // caveat: UNTESTED! - #include - #include - #include - #include - int main() - { - try { - py::Ptr module(PyImport_ImportModule("weapons")); - const int strength = 10; - const char* manufacturer = "Vordon Empire"; - py::Ptr a_blaster(py::Callback::call_method( - module.get(), "Blaster", strength, manufacturer)); - py::Callback::call_method(a_blaster.get(), "Fire"); - int old_strength = py::Callback::call_method(a_blaster.get(), "get_strength"); - py::Callback::call_method(a_blaster.get(), "set_strength", 5); - } - catch(...) - { - } - } - Fancy wrapping tricks templates @@ -286,6 +294,18 @@ Documentation: See http://people.ne.mediaone.net/abrahams/downloads/under-the-hood.html for a few details. + raw C++ arrays + You could expose a function like this one to get the desired effect: + + #include + void set_len(UnitCell& x, py::Tuple tuple) + { + double len[3]; + for (std::size_t i =0; i < 3; ++i) + len[i] = py::from_python(tuple[i].get(), py::Type()); + x.set_len(len); + } + Types that are already wrapped by other libraries It's not documented yet, but you should be able to use a raw PyObject* or a @@ -309,46 +329,6 @@ Documentation: then the C++ functions you're wrapping can take a some_NTL_type& parameter directly. - enums - - To handle this case, you need to decide how you want the enum to show up in - Python (since Python doesn't have enums). If you are satisfied with a Python - int as a way to get your enum value, you can write a simple from_python() - function in namespace py:: - - #ifndef PY_NO_INLINE_FRIENDS_IN_NAMESPACE - namespace py { - #endif - - mynamespace::SomeMeasure from_python(PyObject* x, - py::Type) - { - return static_cast( - from_python(x, py::Type())); - } - - #ifndef PY_NO_INLINE_FRIENDS_IN_NAMESPACE - } - #endif - - You may also want to add a bunch of lines like this to your module - initialization: - mymodule.add(PyInt_FromLong(case1), "case1"); - mymodule.add(PyInt_FromLong(case2), "case2"); - ... - - raw C++ arrays - You could expose a function like this one to get the desired effect: - - #include - void set_len(UnitCell& x, py::Tuple tuple) - { - double len[3]; - for (std::size_t i =0; i < 3; ++i) - len[i] = py::from_python(tuple[i].get(), py::Type()); - x.set_len(len); - } - "Thin converting wrappers" for constructors hijack some of the functionality @@ -377,6 +357,29 @@ Documentation: out parameters and non-const pointers + Calling back into Python: + // caveat: UNTESTED! + #include + #include + #include + #include + int main() + { + try { + py::Ptr module(PyImport_ImportModule("weapons")); + const int strength = 10; + const char* manufacturer = "Vordon Empire"; + py::Ptr a_blaster(py::Callback::call_method( + module.get(), "Blaster", strength, manufacturer)); + py::Callback::call_method(a_blaster.get(), "Fire"); + int old_strength = py::Callback::call_method(a_blaster.get(), "get_strength"); + py::Callback::call_method(a_blaster.get(), "set_strength", 5); + } + catch(...) + { + } + } + Miscellaneous About the vc6 project and the debug build About doctest.py