#include <FXCodeToPythonCode.h>
I had the idea for this in the shower yesterday and it really does show the power of TnFOX's generic tools. This class lets you create an array of code entry points of your choice of parameters & return which can be attached to code objects within Python. This ability solves one major failing of Boost.Python which prevents GUI list item sorting in FOX - the inability to set python code as the sort function. No doubt there are many other uses too, which is why this class has been made public.
Upon instantiation, this class creates length code entry points attached to length python code objects. You allocate a code entry, set it to its corresponding python code object and pass the returned function pointer to whichever C++ class. All calls made by the C++ class to that function pointer will now call the python code object. Asking to allocate for an already existing code object returns the original function pointer ie; it's a once off allocation. Because the tables must be fixed in size, you must take care not to have more than the maximum total code objects than the table can hold.
FXCodeToPythonCode is a policy-driven class whereby you must provide a policy specifying what kind of code we are vectoring:
template<typename base, int no> struct myVector : public base { typedef Generic::TL::create<returnType, firstParType &firstPar, secondParType &secondPar>::value functionSpec; static returnType function(firstParType &firstPar, secondParType &secondPar) { return call<returnType>(getParent()->lookupVector(no).ptr(), boost::ref(firstPar), boost::ref(secondPar)); } };
Your first reaction will likely be to wonder why the duplication? Unfortunately the current ISO C++ spec does not let you obtain function types except via template argument deduction and while you could wrap the policy creation in such, it gets rapidly very complicated for very little benefit. The above I believe is a good balance.
Definition at line 79 of file FXCodeToPythonCode.h.
Public Member Functions | |
boost::python::object & | lookupVector (int idx) |
FXCodeToPythonCode () | |
vectorSpec | allocate (boost::python::api::object *code) |
bool | deallocate (boost::python::api::object *code) |
bool | deallocate (vectorSpec spec) |