// square.cc // Kenneth J. Goldman 12/26/94 // T. Paul McCartney 12/30/96 (converted) // // This module has two integer presentation entries. // in: an input value // out: an output value that is the result of squaring the input value // The module is reactive. It terminates when the input value is negative. #include #include "PG.hh" static int done = 0; PGint out = 0; class squareReactor : public PGreactor { public: virtual void react(PGvariable& v) { PGint& val = (PGint&)v; if (val < 0) done = 1; else out = val * val; }; }; int main() { PGint in = 0; PG::initialize("SQUARE"); out.publish("out", PG::READ); in.publish("in", PG::WRITE); squareReactor r; in.setReactor(&r); while (!done) PG::sleep(0,200); PG::terminate(); }