Archived issue #0024202
Support class methods as callbacks for Draw Harness commands
Description
Current Draw_Interpretor interface supports only global functions as command implementation. This results in dirty code in each command which wants to access global variables and group them in some class.
Additional information
New method Draw_Interpretor::Add() accept class method as callback function for tcl-command definition:
Class instance should passed by handle (smart pointer).
template<typename theHandleType>
inline void Add (Standard_CString theCommandName,
Standard_CString theHelp,
Standard_CString theFileName,
const theHandleType& theObjPtr,
typename Draw_Interpretor::CallBackDataMethod<theHandleType>::methodType theMethod,
Standard_CString theGroup)
Class instance should passed by handle (smart pointer).
Public activity
7 archived notes
Participants are labeled by their role within this record.
Patch is ready for review in CR24202 branch.
The patch seems to me potentially dangerous in that new (templated) method Draw_Interpretor::Add() accepts pointer to an object those lifetime must be longer than life of the command, while no protection is made against passing pointer to local variable, or destruction of the pointer while the command still exists. Please consider using smart pointer (Handle) to ensure sufficient life time of the object. If this is not suitable, at least please document this requirement clearly in comments.
Other remarks:
- name of the argument theClassPtr in the above mentioned method Add(), and similar field and argument in class Draw_CallBackDataFunc, is misleading: I suppose it should be rather called theObjectPtr
- classes defined in Draw_CommandFunction.hxx should better be moved to the inside of the Draw_Interpretor class (as private nested classes), as they are made only for internal usage in this class (I do not think inheritance should be supported)
- method Draw_Interpretor::add() should be made private for the same reason
Other remarks:
- name of the argument theClassPtr in the above mentioned method Add(), and similar field and argument in class Draw_CallBackDataFunc, is misleading: I suppose it should be rather called theObjectPtr
- classes defined in Draw_CommandFunction.hxx should better be moved to the inside of the Draw_Interpretor class (as private nested classes), as they are made only for internal usage in this class (I do not think inheritance should be supported)
- method Draw_Interpretor::add() should be made private for the same reason
Updated patch is ready for review in CR24202_3 branch.
Callback now requires Handle rather than object pointer.
Classes moved to Draw_Interpretor.
Callback now requires Handle rather than object pointer.
Classes moved to Draw_Interpretor.
No remarks, please test
Dear kgv,
could you please rebase issue CR24202_3 on current master,
there are conflict files.
could you please rebase issue CR24202_3 on current master,
there are conflict files.
Rebased patch is ready for testing in CR24202_4 branch.
Dear BugMaster,
Branch CR24202_4 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 44 (44 on master)
Windows: 0 (0 on master)
products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 372819988 / 372443488
Total CPU difference: 43232.96 / 43920.73000000019
Testing on Windows:
Total MEMORY difference: 419324916 / 409834624
Total CPU difference: 38269.640625 / 35405.109375
There are not differences in images found by testdiff.
Branch CR24202_4 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 44 (44 on master)
Windows: 0 (0 on master)
products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 372819988 / 372443488
Total CPU difference: 43232.96 / 43920.73000000019
Testing on Windows:
Total MEMORY difference: 419324916 / 409834624
Total CPU difference: 38269.640625 / 35405.109375
There are not differences in images found by testdiff.