#include "pip.h"

//! [0]
enum Header {
	hInt = 1,
	hString,
	hVoid
};

class MyObj: public PIObject, public PIParseHelper<uchar> {
	PIOBJECT(MyObj);
public:
	MyObj(): PIParseHelper<uchar>(this) {
		// Keys with 1 argument
		assign(hInt, std::function<void(int)>([this](int i){piCout << "lambda type Int" << i;}));
		assign(hInt, HANDLER(methodI));
		assign(hString, HANDLER(methodS));

		// hVoid key, without arguments
		assign(hVoid, [](){piCout << "type void";});
		assign(hVoid, HANDLER(method));
	}
	EVENT_HANDLER1(void, methodI, int, i) {piCout << "methodI" << i;}
	EVENT_HANDLER1(void, methodS, PIString, s) {piCout << "methodS" << s;}
	EVENT_HANDLER0(void, method) {piCout << "method";}
};

int main() {
	MyObj o;

	PIByteArray data;

	data.clear();
	data << 11;
	o.parse(hInt, data);
	// lambda type Int 11
	// methodI 11

	data.clear();
	data << PIString("text");
	o.parse(hString, data);
	// methodS text

	data.clear();
	o.parse(hVoid, data);
	// type void
	// method
}
//! [0]


//! [1]
enum Header {
	hInt = 1,
	hString,
	hVoid
};

class MyObj: public PIObject {
	PIOBJECT(MyObj);
public:
	EVENT_HANDLER1(void, methodI, int, i) {piCout << "methodI" << i;}
	EVENT_HANDLER1(void, methodS, PIString, s) {piCout << "methodS" << s;}
	EVENT_HANDLER0(void, method) {piCout << "method";}
};

int main() {
	MyObj obj;
	PIParseHelper<int> parser(&obj);

	parser.assign(hInt, obj.HANDLER(methodI));
	parser.assign(hString, obj.HANDLER(methodS));
	parser.assign(hVoid, obj.HANDLER(method));

	PIByteArray data;

	data.clear();
	data << 11;
	parser.parse(hInt, data);
	// methodI 11

	data.clear();
	data << PIString("text");
	parser.parse(hString, data);
	// methodS text

	data.clear();
	parser.parse(hVoid, data);
	// method
}
//! [1]
