|
|
| PIParseHelper () |
| | Constructs empty parser helper.
|
| |
|
void | assign (Key key, std::function< void()> func) |
| | Assigns key "key" to callback "func" without payload arguments.
|
| |
|
template<typename T > |
| void | assign (Key key, std::function< void(const T &)> func) |
| | Assigns key "key" to callback "func" with one deserialized argument.
|
| |
|
template<typename O > |
| void | assign (Key key, O *obj, void(O::*member_func)()) |
| | Assigns key "key" to zero-argument member function of object "obj".
|
| |
|
template<typename T , typename O > |
| void | assign (Key key, O *obj, void(O::*member_func)(const T &)) |
| | Assigns key "key" to member function of object "obj" with one deserialized argument.
|
| |
|
template<typename L > |
| void | assign (Key key, L func) |
| | Assigns key "key" to functor or lambda with zero or one argument.
|
| |
|
void | parse (Key key, PIByteArray ba) |
| | Deserializes payload "ba" and invokes handlers assigned to "key".
|
| |
template<typename Key>
class PIParseHelper< Key >
Maps packet keys to handlers and deserializes payloads before invocation.
PIParseHelper helps replace manual switch-based packet dispatch with a set of assign() calls. Handlers may be plain callbacks, functors or object member functions. Payload types are restored from PIByteArray by the selected handler signature.
Example:
enum Header {
hInt = 1,
hString,
hVoid
};
PIOBJECT(MyObj);
public:
assign(hInt, std::function<
void(
int)>([
this](
int i){
piCout <<
"lambda type Int" << i;}));
assign(hInt, HANDLER(methodI));
assign(hString, HANDLER(methodS));
assign(hVoid, HANDLER(method));
}
EVENT_HANDLER1(
void, methodI,
int, i) {
piCout <<
"methodI" << i;}
EVENT_HANDLER0(
void, method) {
piCout <<
"method";}
};
int main() {
MyObj o;
data.clear();
data << 11;
o.parse(hInt, data);
data.clear();
o.parse(hString, data);
data.clear();
o.parse(hVoid, data);
}
The PIByteArray class provides an array of bytes with efficient memory management and various manipul...
Definition: pibytearray.h:42
Base class for objects that declare events, event handlers and registered methods.
Definition: piobject.h:56
Maps packet keys to handlers and deserializes payloads before invocation.
Definition: piparsehelper.h:54
void assign(Key key, std::function< void()> func)
Assigns key "key" to callback "func" without payload arguments.
Definition: piparsehelper.h:63
String class.
Definition: pistring.h:42
return s
Store operator.
Definition: pisystemmonitor.h:312
#define piCout
Definition: picout.h:36
enum Header {
hInt = 1,
hString,
hVoid
};
PIOBJECT(MyObj);
public:
EVENT_HANDLER1(
void, methodI,
int, i) {
piCout <<
"methodI" << i;}
EVENT_HANDLER0(
void, method) {
piCout <<
"method";}
};
int main() {
MyObj obj;
parser.assign(hInt, obj.HANDLER(methodI));
parser.assign(hString, obj.HANDLER(methodS));
parser.assign(hVoid, obj.HANDLER(method));
data.clear();
data << 11;
parser.parse(hInt, data);
data.clear();
parser.parse(hString, data);
data.clear();
parser.parse(hVoid, data);
}