How to implement your own visitor (Implementation of your proprietary algorithm) that can easily run inside DataFrame
DataFrame visitors have a very simple interface that you can follow. To see examples of built-in visitors, look at the file DataFrameStatsVisitors.h.
These are the interfaces you must have:
- It is helpful if you include file DataFrameStatsVisitors.h in your new visitor source file. It includes some macros you can use.
- A visitor at its heart is a functor:
- You must declare a struct or class with an appropriate name for your visitor. If your visitor needs parameters, take them in the functor constructor.
- Your functor must publicly declare the operator()(). The number of parameters to the () operator depends on your algorithm and what you are implementing. The first pair of parameters to () operator is always the begin and end iterators of the index vector. After that you have pairs of begin/end iterators to the data vectors. DataFrame supports visitors that operate on 1 to 5 data columns. DataFrame calls this operator to pass the data. Your algorithm should be here.
- Your functor must publicly typedef the following types:
- index_type: This defines the index column type
- value_type: This defines the data column(s) type. If you have multiple data columns of different types, define it for the first one
- result_type: This defines the type of your algorithm result. The result could be an item or a container of items or … If you have multiple result types, define it for the first/main one.
- Your functor must publicly define the following member functions:
- void pre(): This is called by DataFrame before passing data to your visitor. You can initialize the process here. And/or reset the process here for repeated use of the same visitor instance.
- void post(): This is called by DataFrame after it finishes with passing data to your visitor. You can finalize the process here.
- const result_type &get_result() const: This returns the result of your algorithm. If you have multiple results, define this for the first/main result.
- result_type &get_result(): non-const version of above, if applicable.
- Your visitor will be used by DataFrame's visit() or signle_act_visit() methods.