casadi/casadi — pull request #886 by jgillis (2013-11-09 23:51:28+00:00)
Title: alternative callback mechanism

(passes all unittest, ready to merge)

This is a proposal to replace C Function pointer arguments by Functor objects.

Why?
- Right now, for python, a PyObject is assigned to user_data when registering a callback. But what about jacobianGenerator and sparsityGenerator? Should they start sharing that user_data? This solution was clumsy from the start
- Functors being objects, we can subclass in python to hold also the pointer to the PyObject and do proper reference counting (!)
- Implicit casting from from C Function pointers to Functors is easily achieved -> backwards compatible
- The exra overhead will never be a bottleneck in cpu

see also #878 #879

Renames:
* CFunction -> CustomFunction
- rationale: CFunction was named for C, but it was also used to build a bridge to a host language such as python. C is hence not appropriate in the name
- CustomFunction is initialized with an evaluate Functor
- Jacobian and sparsity generators can be added via the classical options, in other words CustomFunction is composed from several Functors
* ExternalFunction -> CompiledFunction
- rationale: what ExternalFunction really does is reading in and using compiled code from a library. ExternalFunction is too broad a term for this functionality.
- CompiledFunction provides the whole package of init, sparsity, evaluate at once.