Calculator object


The calculator object executes C++ code. The code is compiled into a shared object file which is loaded when execution is switched on. An arbitrary number of input and output variables can be created from communication with other vimms objects. The calculator object provides direct access to input and output variables from within the code. Variable definitions are automatically generated and allow writing simple functions within seconds.

For basic documentation read on, otherwise more advanced documents exist:

Basic functionality

Input and output variables are defined using the two list boxes at the top of the property dialog. The C++ code for accessing input and output variables is automatically created and can be viewed by pressing the "Show all code" button. Those variables are derived from classes VflVar and VflVarArray, which are documented here. These classes provide operators so that the I/O variables behave similar to the corresponding basic data type variables. A "Float" output variable can for example be treated like a normal C-style "double" variable.

A single function extern "C" bool run() must be defined which is called when the object is executed. The return value determines whether execution should continue after the object has been evaluated. If the user defined code writes to the standard output, the text is displayed in the message window during run-time if vfl is started with the GUI. Optionally two other functions can be defined: extern "C" bool init() and extern "C" void stop(). The function init is called when the calculator object is initialized and can be used for initializing the user program. When the initialization was successful the function should return true, otherwise the object is disabled. The stop function is called when execution is switched of and all execution threads have terminated.

For creating larger pieces of code an external editor can be specified in the Settings-Dialog which is available via the "Options" menu. This editor is started when pressing the button "Edit externally...". The code is compiled when pressing the "Compile"-button, when the external editor quits, or when the property dialog is close and the code has been changed. Compiler error or warning messages are displayed in the "Compile output" window. The compiler g++ is called with the following command line:

g++ -fpic -shared -O2 -Ivimmspath additional parameters... vimmspath is replaced with the directory containing the vfl binary. Additional compiler parameters like for example include directories can be specified in the settings dialog. If compilation succeeds the resulting shared object binary is stored within the vimms project file. If transporting a vimms project file to another computer it may sometimes be necessary to recompile all code pieces contained in object. This is done using the "Recompile all" function in the "File" menu.

Debugging calculator objects

If debug is enabled in the settings menu, the compiler is called with the following command line: g++ -fpic -shared -g -fno-inline -Ivimmspath additional parameters... The compiler source is written to a file /tmp/calctest.cpp and not deleted after compilation. So it can be used for setting breakpoints using a source code debugger. When debugging if vfl has been started with the GUI, it should be done in the following way: Enable debugging and then load the file containing objects to be debugged. Recompile the object to be debugged. Now start execution. Start a debugger loading the vfl binary and attach it to the running execution process (vfl is called with the parameter --link). Then set the breakpoint in the source file.
After debugging delete all /tmp/calctest*.cpp files.

The Vimms User Manual