int test_main(int, char*[]) { typedef boost::signal1<int, int, max_or_default<int> > sig_type; sig_type s1; // Test auto-disconnection BOOST_CHECK(s1(5) == 0); { short_lived shorty; s1.connect(boost::bind<int>(swallow(), &shorty, _1)); BOOST_CHECK(s1(5) == 5); } BOOST_CHECK(s1(5) == 0); // Test auto-disconnection of slot before signal connection { short_lived* shorty = new short_lived(); sig_type::slot_type slot(boost::bind<int>(swallow(), shorty, _1)); delete shorty; BOOST_CHECK(s1(5) == 0); } return 0; }
// Swallow new GNUPLOT window; search from root window (expensive). static void SwallowTimeOutCB(XtPointer client_data, XtIntervalId *id) { (void) id; PlotWindowInfo *plot = (PlotWindowInfo *)client_data; assert(*id == plot->swallow_timer); plot->swallow_timer = 0; Window root = RootWindowOfScreen(XtScreen(plot->swallower)); Window window = None; Display *display = XtDisplay(plot->swallower); // Try the exact name as given if (window == None) window = findWindow(display, root, plot->window_name.chars()); // Try the capitalized name. Gnuplot does this. if (window == None) { const string s1 = capitalize(plot->window_name); window = findWindow(display, root, s1.chars()); } if (window == None) { // Try again later plot->swallow_timer = XtAppAddTimeOut(XtWidgetToApplicationContext(plot->swallower), app_data.plot_window_delay, SwallowTimeOutCB, XtPointer(plot)); } if (window != None) swallow(plot, window); }
// Swallow new GNUPLOT window; search from window created on root. static void SwallowCB(Widget swallower, XtPointer client_data, XtPointer call_data) { PlotWindowInfo *plot = (PlotWindowInfo *)client_data; assert(plot->swallower == swallower); SwallowerInfo *info = (SwallowerInfo *)call_data; Window root = info->window; Window window = None; Display *display = XtDisplay(swallower); // Try the exact name as given if (window == None) window = findWindow(display, root, plot->window_name.chars()); // Try the capitalized name. Gnuplot does this. if (window == None) { const string s1 = capitalize(plot->window_name); window = findWindow(display, root, s1.chars()); } // Try any `Gnuplot' window just created if (window == None) window = findWindow(display, root, app_data.plot_window_class); if (window != None) swallow(plot, window); }
static int read_rec(FILE *f, TDB_CONTEXT *tdb, int *eof) { int length; TDB_DATA key, data; int ret = -1; key.dptr = NULL; data.dptr = NULL; if (swallow(f, "{\n", eof) == -1) { goto fail; } length = read_linehead(f); if (length == -1) { goto fail; } if (read_data(f, &key, length) == -1) { goto fail; } if (swallow(f, "\"\n", NULL) == -1) { goto fail; } length = read_linehead(f); if (length == -1) { goto fail; } if (read_data(f, &data, length) == -1) { goto fail; } if ((swallow(f, "\"\n", NULL) == -1) || (swallow(f, "}\n", NULL) == -1)) { goto fail; } if (tdb_store(tdb, key, data, TDB_INSERT) != 0) { fprintf(stderr, "TDB error: %s\n", tdb_errorstr(tdb)); goto fail; } ret = 0; fail: free(key.dptr); free(data.dptr); return ret; }
void ProcessMsgSwallow( struct XObj *xobj,unsigned long type,unsigned long *body) { switch(type) { case M_MAP: swallow(xobj,body); break; case M_WINDOW_NAME: case M_RES_NAME: case M_RES_CLASS: CheckForHangon(xobj,body); break; } }
void Animal::collideWith(Environment *environment, Food *food) { if (food->getComposition()[0] == '1' || food->getComposition()[0] == '2' || food->getComposition()[0] == '3' || food->getComposition()[0] == '4') { if (this == environment->getPlayer() && !food->shouldDestroy()) { food->destroy(); printf( "destroy\n"); environment->addPrize(); } } else { swallow(food); food->destroy(); } }
void dbgprint(Args &&... args) { swallow((std::cout << std::forward<Args>(args), 0)...); }
SYMBOL * #endif dofnansi(SYMBOL *currfn, long *addr) { SYMBOL *prevarg; /* ptr to symbol table entry of most recent argument */ SYMBOL *argptr; /* Temporary holder.. */ TAG_SYMBOL *otag ; /* structure tag for structure argument */ struct varid var; char proto; locptr=STARTLOC; prevarg=0; Zsp=0; /* Reset stack pointer */ undeclared=1; proto=YES; swallow("__TD__"); /* kludge to get round typedef problem */ /* Master loop, checking for end of function */ while ( cmatch(')') == 0 ) { if (amatch("...") ) { /* * Found some ellipses, so, add it to the local symbol table and * then return..(after breaking, and checking for ; & , ) */ if (proto == 1 ) warning(W_ELLIP); needchar(')'); argptr=addloc("ellp",0,ELLIPSES,0,0); argptr->offset.p = prevarg; prevarg=argptr; break; } otag=GetVarID(&var,STATIK); if (var.type==STRUCT) { prevarg=getarg(STRUCT, otag,YES,prevarg,0, var.zfar,proto) ; } else if (var.type) { prevarg=getarg(var.type,NULL_TAG,YES,prevarg,var.sign,var.zfar,proto); } else { warning(W_EXPARG); break; } proto++; /* Now check for comma */ if (ch() !=')' && cmatch(',') == 0) { warning(W_EXPCOM); break; } } /* * Check for semicolon - I think this should be enough, just * have to have prototypes on separate lines - good practice * in anycase!! */ if (cmatch('@') ) { constexpr(addr,1); } if (cmatch(';') ) return (prevarg); setlocvar(prevarg,currfn); return (0); }
int test_main(int, char*[]) { typedef boost::signals2::signal<int (int), max_or_default<int> > sig_type; sig_type s1; boost::signals2::connection connection; // Test auto-disconnection BOOST_CHECK(s1(5) == 0); { boost::shared_ptr<int> shorty(new int()); s1.connect(sig_type::slot_type(swallow(), shorty.get(), _1).track(shorty)); BOOST_CHECK(s1(5) == 5); } BOOST_CHECK(s1(5) == 0); // Test auto-disconnection of slot before signal connection { boost::shared_ptr<int> shorty(new int(1)); // doesn't work on gcc 3.3.5, it says: error: type specifier omitted for parameter `shorty' // does work on gcc 4.1.2 // sig_type::slot_type slot(swallow(), shorty.get(), _1); swallow myswallow; sig_type::slot_type slot(myswallow, shorty.get(), _1); slot.track(shorty); shorty.reset(); s1.connect(slot); BOOST_CHECK(s1(5) == 0); } // Test binding of a slot to another slot { boost::shared_ptr<int> shorty(new int(2)); boost::signals2::slot<int (double)> other_slot(&myfunc, boost::cref(*shorty.get()), _1); other_slot.track(shorty); connection = s1.connect(sig_type::slot_type(other_slot, 0.5).track(other_slot)); BOOST_CHECK(s1(3) == 2); } BOOST_CHECK(connection.connected() == false); BOOST_CHECK(s1(3) == 0); // Test binding of a signal as a slot { sig_type s2; s1.connect(s2); s2.connect(sig_type::slot_type(&myfunc, _1, 0.7)); BOOST_CHECK(s1(4) == 4); } BOOST_CHECK(s1(4) == 0); // Test tracking of null but not empty shared_ptr BOOST_CHECK(s1(2) == 0); { boost::shared_ptr<int> shorty((int*)(0)); s1.connect(sig_type::slot_type(swallow(), shorty.get(), _1).track(shorty)); BOOST_CHECK(s1(2) == 2); } BOOST_CHECK(s1(2) == 0); #ifndef BOOST_NO_CXX11_SMART_PTR // Test tracking through std::shared_ptr/weak_ptr BOOST_CHECK(s1(5) == 0); { std::shared_ptr<int> shorty(new int()); s1.connect(sig_type::slot_type(swallow(), shorty.get(), _1).track_foreign(shorty)); BOOST_CHECK(s1(5) == 5); } BOOST_CHECK(s1(5) == 0); { std::shared_ptr<int> shorty(new int()); s1.connect ( sig_type::slot_type ( swallow(), shorty.get(), _1 ).track_foreign ( std::weak_ptr<int>(shorty) ) ); BOOST_CHECK(s1(5) == 5); } BOOST_CHECK(s1(5) == 0); // make sure tracking foreign shared_ptr<const void> works { std::shared_ptr<const void> shorty(new int()); s1.connect(sig_type::slot_type(swallow(), shorty.get(), _1).track_foreign(shorty)); BOOST_CHECK(s1(5) == 5); } { std::shared_ptr<int> shorty(new int()); s1.connect ( sig_type::slot_type ( swallow(), shorty.get(), _1 ).track_foreign ( std::weak_ptr<const void>(shorty) ) ); BOOST_CHECK(s1(5) == 5); } BOOST_CHECK(s1(5) == 0); BOOST_CHECK(s1(5) == 0); #endif return 0; }