![]() |
PIP 5.5.3
Platform-Independent Primitives
|
Helper class to automate structs receive. Подробнее...
#include <piparsehelper.h>
Открытые члены | |
| PIParseHelper () | |
| Construct PIParseHelper. | |
| void | assign (Key key, std::function< void()> func) |
| Assign key "key" to lambda-function "func" without arguments. | |
| template<typename T > | |
| void | assign (Key key, std::function< void(const T &)> func) |
| Assign key "key" to lambda-function "func" with 1 argument. | |
| template<typename O > | |
| void | assign (Key key, O *obj, void(O::*member_func)()) |
| Assign key "key" to member function of object "obj" without arguments. | |
| template<typename T , typename O > | |
| void | assign (Key key, O *obj, void(O::*member_func)(const T &)) |
| Assign key "key" to member function of object "obj" with 1 argument. | |
| template<typename L > | |
| void | assign (Key key, L func) |
| Assign key "key" to functor "func" with 0 or 1 argument. | |
| void | parse (Key key, PIByteArray ba) |
| Deserialize data and invoke assigned to "key" methods. | |
Helper class to automate structs receive.
This class helps to deserialize and invoke neccessarily methods.
Data packets with header and various data types can be automated by this class. Every key value mapped to object member function, lambda-function or functor.
This class can remove switch-case with deserialization code and replace it with several assign() calls, binded to ready-to-use event handlers. Moreover data type automatic takes from event handler or lambda argument. One should only make "PIByteArray & operator <<()" with used types, deserialization will be performed by PIParseHelper.
Create instance of PIParseHelper, or subclass.
In assign() methods you can use object member function, lambda-function or functor with 0 or 1 arguments,
First example describes subclass variant. As one can see, it`s a single place to change type of received data - event handler argument.
Second example show separate variant: