Files
pip/doc/examples/piobject.cpp
2022-03-18 01:28:07 +03:00

37 lines
945 B
C++

#include "pip.h"
//! [main]
class ObjectA: public PIObject {
PIOBJECT(ObjectA)
public:
EVENT_HANDLER1(void, handlerA, const PIString & , str) {piCoutObj << "handler A:" << str;}
EVENT1(eventA1, const PIString & , str);
EVENT2(eventA2, int, i, float, f);
};
class ObjectB: public PIObject {
PIOBJECT(ObjectB)
public:
EVENT_HANDLER2(void, handlerB, int, i, float, f) {piCoutObj << "handler B:" << i << "," << f;}
EVENT1(eventB, PIString, str);
};
int main(int argc, char * argv[]) {
ObjectA obj_a;
ObjectB obj_b;
CONNECT2(void, int, float, &obj_a, eventA2, &obj_b, handlerB);
obj_a.eventA2(2, 0.5);
CONNECT1(void, PIString, &obj_b, eventB, &obj_a, handlerA);
obj_b.eventB("event to handler");
CONNECTU(&obj_a, eventA1, &obj_b, eventB);
obj_a.eventA1("event to event");
obj_a.piDisconnect("eventA1");
CONNECTL(&obj_a, eventA1, ([](const PIString & str){piCout << str;}));
obj_a.eventA1("event to lambda");
};
//! [main]