int main(int, char *[]) { hello x(0); hello y(1); more::signal<int(int)> sig; sig.connect(x.method); sig.connect(y.method); // assert(x.method(0) == 1); sig(0); sig.disconnect(y.method); sig(1); return 0; }
QByteArray QtBoostIntegrationBindingObject::buildAdapterSignature (int nrArguments, int argumentMetaTypeList[]) { QByteArray sig("lambda("); for (int i = 0; i < nrArguments; i++) { sig += QMetaType::typeName(argumentMetaTypeList[i]); if (i != nrArguments-1) sig += ","; } sig += ")"; return sig; }
void YardCustomer::OnChange(wxTreeEvent& event) { m_loading = true; custItemData * data = static_cast<custItemData *>(m_tree->GetItemData(event.GetItem())); if (!data) return; try { m_cust = wxGetApp().DB().CustomerGet(data->GetID()); } catch (YardDBException& e) { wxLogDebug(wxT("Error (customer not loaded): %s, %s"),e.what(), e.GetSQL().c_str()); return; } if (m_cust.GetPicLocal() != "") { wxImage pic(m_cust.GetPicLocal().c_str()); if (pic.Ok()) m_pic->SetBitmap(pic); else wxLogDebug(wxT("Bad image data (pic).")); } else m_pic->SetBitmap(wxImage("res/personal.png")); if (m_cust.GetSigLocal() != "") { wxImage sig(m_cust.GetSigLocal().c_str()); if (sig.Ok()) m_sig->SetBitmap(sig); else wxLogDebug(wxT("Bad image data (sig).")); } else m_sig->SetBitmap(wxNullBitmap); m_first->SetValue(m_cust.GetFirstName().c_str()); m_middle->SetValue(m_cust.GetMiddleName().c_str()); m_last->SetValue(m_cust.GetLastName().c_str()); m_address->SetValue(m_cust.GetAddress().c_str()); m_ccNum->SetValue(m_cust.GetCreditCardNumber().c_str()); m_ccName->SetValue(m_cust.GetCreditCardName().c_str()); m_ccExp->SetValue(m_cust.GetCreditCardExpiration().c_str()); m_phone->SetValue(m_cust.GetPhone().c_str()); wxString pos; pos.Printf(wxT("Customer Since: %s"), m_cust.GetSince().c_str()); m_custSince->SetLabel(pos); m_loading = false; }
//! ************************************************************************************************ //! //! ************************************************************************************************ void rdmp::SimpleReturnedValue() { boost::signals2::signal<float(float,float)> sig; sig.connect(3, &RetSumArguments); sig.connect(2, &RetProductArguments); sig.connect(1, &RetDifferenceArguments); sig.connect(0, &RetQuotient); //! @brief The default combiner returns a boost::optional containing the return //! value of the last slot in the slot list, in this case the BRR_LOGI("return %.2f", *sig(3.2, 6.8)); }
PythonQtMethodInfo::PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInfo* classInfo) { #ifdef PYTHONQT_DEBUG #if( QT_VERSION >= QT_VERSION_CHECK(5,0,0) ) QByteArray sig(meta.methodSignature()); #else QByteArray sig(meta.signature()); #endif sig = sig.mid(sig.indexOf('(')); QByteArray fullSig = QByteArray(meta.typeName()) + " " + sig; std::cout << "caching " << fullSig.data() << std::endl; #endif ParameterInfo type; fillParameterInfo(type, QByteArray(meta.typeName()), classInfo); _parameters.append(type); QList<QByteArray> names = meta.parameterTypes(); Q_FOREACH (const QByteArray& name, names) { fillParameterInfo(type, name, classInfo); _parameters.append(type); }
void testSingleSlotConnection() { // Signal with no arguments and a void return value boost::signals2::signal<void ()> sig; // Connect to HelloWorld::operator() HelloWorld hello; sig.connect(hello); // Call all of the slots sig(); }
TEST_F(ThreeIndexTestGF,Operators) { namespace g=alps::gf; for (g::matsubara_index om=g::matsubara_index(0); om<gf.mesh1().extent(); ++om) { for (g::momentum_index ii=g::momentum_index(0); ii<gf.mesh2().extent(); ++ii) { for (g::index sig=g::index(0); sig<gf.mesh3().extent(); ++sig) { std::complex<double> v1(1+om()+ii(), 1+sig()); std::complex<double> v2=1./v1; gf(om,ii,sig)=v1; gf2(om,ii,sig)=v2; } } } gf_type g_plus=gf+gf2; gf_type g_minus=gf-gf2; const double tol=1E-8; for (g::matsubara_index om=g::matsubara_index(0); om<gf.mesh1().extent(); ++om) { for (g::momentum_index ii=g::momentum_index(0); ii<gf.mesh2().extent(); ++ii) { for (g::index sig=g::index(0); sig<gf.mesh3().extent(); ++sig) { std::complex<double> v1(1+om()+ii(), 1+sig()); std::complex<double> v2=1./v1; std::complex<double> r1=v1+v2; std::complex<double> r2=v1-v2; ASSERT_NEAR(r1.real(),g_plus(om,ii,sig).real(),tol); ASSERT_NEAR(r1.imag(),g_plus(om,ii,sig).imag(),tol); ASSERT_NEAR(r2.real(),g_minus(om,ii,sig).real(),tol); ASSERT_NEAR(r2.imag(),g_minus(om,ii,sig).imag(),tol); } } } }
void test_extended_slot() { { typedef boost::signals2::signal1<ResultType, int> signal_type; typedef typename signal_type::extended_slot_type slot_type; signal_type sig; // attempting to work around msvc 7.1 bug by explicitly assigning to a function pointer ResultType (*fp)(const boost::signals2::connection &conn, int) = &disconnecting_slot<ResultType>; slot_type myslot(fp); sig.connect_extended(myslot); BOOST_CHECK(sig.num_slots() == 1); sig(0); BOOST_CHECK(sig.num_slots() == 0); } { // test 0 arg signal typedef boost::signals2::signal0<ResultType> signal_type; typedef typename signal_type::extended_slot_type slot_type; signal_type sig; // attempting to work around msvc 7.1 bug by explicitly assigning to a function pointer ResultType (*fp)(const boost::signals2::connection &conn, int) = &disconnecting_slot<ResultType>; slot_type myslot(fp, _1, 0); sig.connect_extended(myslot); BOOST_CHECK(sig.num_slots() == 1); sig(); BOOST_CHECK(sig.num_slots() == 0); } // test disconnection by slot { typedef boost::signals2::signal1<ResultType, int> signal_type; typedef typename signal_type::extended_slot_type slot_type; signal_type sig; // attempting to work around msvc 7.1 bug by explicitly assigning to a function pointer ResultType (*fp)(const boost::signals2::connection &conn, int) = &disconnecting_slot<ResultType>; slot_type myslot(fp); sig.connect_extended(myslot); BOOST_CHECK(sig.num_slots() == 1); sig.disconnect(fp); BOOST_CHECK(sig.num_slots() == 0); } }
int main() { //[ hello_world_multi_code_snippet boost::signals2::signal<void ()> sig; sig.connect(Hello()); sig.connect(World()); sig(); //] return 0; };
void SMTSolver_eq::merge(int s1, int s2) { assert(settings_s.smtc_s); fprintf(stderr, "Merging %d and %d.\n", s1, s2); if(s1 == s2) return; assert(connectivity_check.find(s1) != nullptr && connectivity_check.find(s2) != nullptr); connectivity_check.make_union(s1,s2); for(int good_term: has_as_arg[s1]) { fprintf(stderr, "%d has %d as arg.\n", good_term, s1); for(auto y : solver->terms_mapping) if(y.first != 0 && sig(good_term, y.first)) { if(connectivity_check.find(y.first) == nullptr) connectivity_check.add(y.first); if(connectivity_check.find(good_term) == nullptr) connectivity_check.add(good_term); merge(connectivity_check.find(good_term)->getValue(), connectivity_check.find(y.first)->getValue()); } } for(int good_term: has_as_arg[s2]) { fprintf(stderr, "%d has %d as arg.\n", good_term, s1); for(auto y : solver->terms_mapping) if(y.first != 0 && sig(good_term, y.first)) { if(connectivity_check.find(y.first) == nullptr) connectivity_check.add(y.first); if(connectivity_check.find(good_term) == nullptr) connectivity_check.add(good_term); merge(connectivity_check.find(good_term)->getValue(), connectivity_check.find(y.first)->getValue()); } } }
void testReturnValuesFromSlotsWithCustomCombiner() { boost::signals2::signal<float (float, float), maximum<float>> sig; sig.connect(&product); sig.connect("ient); sig.connect(&sum); sig.connect(&difference); // Outputs the maximum value returned by the connected slots, // in this case 15 from the product function. std::cout << "maximum: " << sig(5, 3) << std::endl; }
void fixmatrix(transmatrix& T) { if(euclid) { for(int x=0; x<2; x++) for(int y=0; y<=x; y++) { ld dp = 0; for(int z=0; z<2; z++) dp += T[z][x] * T[z][y]; if(y == x) dp = 1 - sqrt(1/dp); for(int z=0; z<2; z++) T[z][x] -= dp * T[z][y]; } for(int x=0; x<2; x++) T[2][x] = 0; T[2][2] = 1; } else for(int x=0; x<3; x++) for(int y=0; y<=x; y++) { ld dp = 0; for(int z=0; z<3; z++) dp += T[z][x] * T[z][y] * sig(z); if(y == x) dp = 1 - sqrt(sig(x)/dp); for(int z=0; z<3; z++) T[z][x] -= dp * T[z][y]; } }
void ObjectSize::updateResolution(const boost::uuids::uuid resolutionId) const { if(this->resolutionId == resolutionId) { return; } this->resolutionId = resolutionId; const std::map<const boost::uuids::uuid, const Size>::const_iterator i = sizeMap.find(resolutionId); BOOST_ASSERT(i != sizeMap.end()); size = i->second; sig(size); }
bool SecRuleRelative::matchSignerName (const Data& data) { try{ SignatureSha256WithRsa sig(data.getSignature()); Name signerName = sig.getKeyLocator().getName (); return m_signerNameRegex.match(signerName); }catch(SignatureSha256WithRsa::Error &e){ return false; }catch(KeyLocator::Error &e){ return false; } }
/** * \brief Generates SignatureSets for e+e- -> n partons. * \param numPartons The number of partons in the final state * \param numFlavors The number of quark flavors to include * \return SignatureSet containing all required Signatures. * * Should generate these with a somewhat more intelligent algorithm. */ SignatureSet SignatureManager::getSignatureseeJets(size_t numPartons, int numFlavors) { // generate recursively for numPartons > 2 if (numPartons > 2) return QCDEmissions(getSignatureseeJets(numPartons - 1, numFlavors), numFlavors); if (numFlavors < 1 || numFlavors > 6) { Logger::globalLogger() << ERROR << "SignatureManager: Number of light flavors should be between 1 and 6!" << std::endl; exit(1); } // signatures for ee -> 2 partons if (numPartons == 2) { SignatureSet sigs; // TODO: code somewhere depends on which is A/B!! Signature justEE; justEE.setInitialA(PdgID::kPositron); justEE.setInitialB(PdgID::kElectron); for (int i = 1; i <= numFlavors; ++i) { Signature sig(justEE); sig.insertFinal(PdgID(i)); sig.insertFinal(PdgID(i).antiPartner()); sigs.insert(sig); } return sigs; } /* // signatures for ee -> 4 partons if (numPartons == 4) { SignatureSet sigs; // TODO: code somewhere depends on which is A/B!! Signature justEE; justEE.setInitialA(PdgID::kPositron); justEE.setInitialB(PdgID::kElectron); for (int i = 1; i <= numFlavors; ++i) { for (int j = 1; j <= numFlavors; ++j) { Signature sig(justEE); sig.insertFinal(PdgID(i)); sig.insertFinal(PdgID(i).antiPartner()); sig.insertFinal(PdgID(j)); sig.insertFinal(PdgID(j).antiPartner()); sigs.insert(sig); } } return sigs; } */ Logger::globalLogger() << ERROR << "SignatureManager: Don't know what to do with " << numPartons << " partons." << std::endl; return SignatureSet(); }
std::string show(const DexDebugInstruction* insn) { if (!insn) return ""; std::ostringstream ss; switch (insn->opcode()) { case DBG_END_SEQUENCE: ss << "DBG_END_SEQUENCE"; break; case DBG_ADVANCE_PC: ss << "DBG_ADVANCE_PC " << insn->uvalue(); break; case DBG_ADVANCE_LINE: ss << "DBG_ADVANCE_LINE " << insn->value(); break; case DBG_START_LOCAL: { auto sl = static_cast<const DexDebugOpcodeStartLocal*>(insn); ss << "DBG_START_LOCAL v" << sl->uvalue() << " " << show(sl->name()) << ":" << show(sl->type()); break; } case DBG_START_LOCAL_EXTENDED: { auto sl = static_cast<const DexDebugOpcodeStartLocal*>(insn); ss << "DBG_START_LOCAL v" << sl->uvalue() << " " << show(sl->name()) << ":" << show(sl->type()) << ";" << show(sl->sig()); break; } case DBG_END_LOCAL: ss << "DBG_END_LOCAL v" << insn->uvalue(); break; case DBG_RESTART_LOCAL: ss << "DBG_RESTART_LOCAL v" << insn->uvalue(); break; case DBG_SET_PROLOGUE_END: ss << "DBG_SET_PROLOGUE_END"; break; case DBG_SET_EPILOGUE_BEGIN: ss << "DBG_SET_EPILOGUE_BEGIN"; break; case DBG_SET_FILE: { auto sf = static_cast<const DexDebugOpcodeSetFile*>(insn); ss << "DBG_SET_FILE " << show(sf->file()); break; } default: { auto adjusted_opcode = insn->opcode() - DBG_FIRST_SPECIAL; auto line = DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE); auto address = (adjusted_opcode / DBG_LINE_RANGE); ss << "DBG_SPECIAL line+=" << line << " addr+=" << address; } } return ss.str(); }
//圆与一般多边形面积交 double CirclePolygon(Point *ps, int n, Point o, double radius) { //保证逆时针 if (area(ps, n) < 0) reverse(ps, ps + n); ps[n] = ps[0]; double res = 0; for (int i = 0; i < n; i++) { int sgn = sig(ps[i].x * ps[i + 1].y - ps[i].y * ps[i + 1].x); if (sgn != 0) { res += sgn * CircleTrianlge(ps[i], ps[i + 1], o, radius); } } return res; }
int unsub() { std::string sig(cmd + UNSUB_LEN); if (subs.count(sig) > 0) { subs.at(sig).erase(socket); if (subs.at(sig).size() == 0) { subs.erase(sig); signals.erase(sig); } } return sig.length(); }
// //////////////////////////////////////////////////////// int main (int argc, char* argv[]) { boost::signals2::signal<void (float, float)> sig; sig.connect (&print_args); sig.connect (&print_sum); sig.connect (&print_product); sig.connect (&print_difference); sig.connect (&print_quotient); sig (5.0, 3.0); return 0; };
SliceMacroParticle::SliceMacroParticle(const PSmoments& S, double z1, double dp1, double q1) : PSmoments4D(),q(q1) { for(int i=0; i<4; i++) { mean(i)=S[i]; for(int j=0; j<=i; j++) { sig(i,j) = S(i,j); } } mean(ps_CT)=z1; mean(ps_DP)=dp1; }
int main() { boost::signal2<void, int, int> sig; sig.connect(print_sum()); sig.connect(print_product()); sig(3, 5); boost::signals::connection print_diff_con = sig.connect(print_difference()); // sig is still connected to print_diff_con assert(print_diff_con.connected()); sig(5, 3); // prints 8, 15, and 2 print_diff_con.disconnect(); // disconnect the print_difference slot sig(5, 3); // now prints 8 and 15, but not the difference assert(!print_diff_con.connected()); // not connected any more return 0; }
// The option's defining parameters SimplePropertySet<string, double> properties() { SimplePropertySet<string, double> result; result.add (Property<string, double> (r.name(), r() ) ); result.add (Property<string, double> (sig.name(), sig() ) ); result.add (Property<string, double> (K.name(), K() ) ); result.add (Property<string, double> (T.name(), T() ) ); result.add (Property<string, double> (U.name(), U() ) ); result.add (Property<string, double> (b.name(), b() ) ); return result; }
bool SecRuleRelative::satisfy (const Data& data) { Name dataName = data.getName(); try{ SignatureSha256WithRsa sig(data.getSignature()); Name signerName = sig.getKeyLocator().getName (); return satisfy (dataName, signerName); }catch(SignatureSha256WithRsa::Error &e){ return false; }catch(KeyLocator::Error &e){ return false; } }
br_status fpa_rewriter::mk_to_fp(func_decl * f, unsigned num_args, expr * const * args, expr_ref & result) { SASSERT(f->get_num_parameters() == 2); SASSERT(f->get_parameter(0).is_int()); SASSERT(f->get_parameter(1).is_int()); bv_util bu(m()); scoped_mpf v(m_fm); mpf_rounding_mode rmv; rational r1, r2, r3; unsigned bvs1, bvs2, bvs3; unsigned ebits = f->get_parameter(0).get_int(); unsigned sbits = f->get_parameter(1).get_int(); if (num_args == 1) { if (bu.is_numeral(args[0], r1, bvs1)) { // BV -> float SASSERT(bvs1 == sbits + ebits); unsynch_mpz_manager & mpzm = m_fm.mpz_manager(); unsynch_mpq_manager & mpqm = m_fm.mpq_manager(); scoped_mpz sig(mpzm), exp(mpzm); const mpz & sm1 = m_fm.m_powers2(sbits - 1); const mpz & em1 = m_fm.m_powers2(ebits); scoped_mpq q(mpqm); mpqm.set(q, r1.to_mpq()); SASSERT(mpzm.is_one(q.get().denominator())); scoped_mpz z(mpzm); z = q.get().numerator(); mpzm.rem(z, sm1, sig); mpzm.div(z, sm1, z); mpzm.rem(z, em1, exp); mpzm.div(z, em1, z); SASSERT(mpzm.is_int64(exp)); mpf_exp_t mpf_exp = mpzm.get_int64(exp); mpf_exp = m_fm.unbias_exp(ebits, mpf_exp); m_fm.set(v, ebits, sbits, !mpzm.is_zero(z), sig, mpf_exp); TRACE("fp_rewriter", tout << "sgn: " << !mpzm.is_zero(z) << std::endl; tout << "sig: " << mpzm.to_string(sig) << std::endl; tout << "exp: " << mpf_exp << std::endl; tout << "v: " << m_fm.to_string(v) << std::endl;); result = m_util.mk_value(v); return BR_DONE; }
void ConstitutiveModel<EvalT, Traits>::computeVolumeAverage( Workset workset, DepFieldMap dep_fields, FieldMap eval_fields) { int const& num_dims = this->num_dims_; int const& num_pts = this->num_pts_; std::string cauchy = (*this->field_name_map_)["Cauchy_Stress"]; PHX::MDField<ScalarT> stress = *eval_fields[cauchy]; minitensor::Tensor<ScalarT> sig(num_dims); minitensor::Tensor<ScalarT> I(minitensor::eye<ScalarT>(num_dims)); ScalarT volume, pbar, p; for (int cell(0); cell < workset.numCells; ++cell) { volume = pbar = 0.0; for (int pt(0); pt < num_pts; ++pt) { sig.fill(stress, cell, pt, 0, 0); pbar += weights_(cell, pt) * (1. / num_dims) * minitensor::trace(sig); volume += weights_(cell, pt); } pbar /= volume; for (int pt(0); pt < num_pts; ++pt) { sig.fill(stress, cell, pt, 0, 0); p = (1. / num_dims) * minitensor::trace(sig); sig += (pbar - p) * I; for (int i = 0; i < num_dims; ++i) { stress(cell, pt, i, i) = sig(i, i); } } } }
int main() { //[ slot_arguments_main_code_snippet boost::signals2::signal<void (float, float)> sig; sig.connect(&print_args); sig.connect(&print_sum); sig.connect(&print_product); sig.connect(&print_difference); sig.connect(&print_quotient); sig(5., 3.); //] return 0; };
int main() { boost::signal<void (const std::string&)> sig; some_slot_type sc1("sc1"); some_slot_type sc2("sc2"); boost::signals::connection c1=sig.connect(sc1); boost::signals::connection c2=sig.connect(sc2); // 比较 std::cout << "c1==c2: " << (c1==c2) << '\n'; std::cout << "c1<c2: " << (c1<c2) << '\n'; // 检查连接 if (c1.connected()) std::cout << "c1 is connected to a signal\n"; // 交换并断开 sig("Hello there"); c1.swap(c2); sig("We've swapped the connections"); c1.disconnect(); sig("Disconnected c1, which referred to sc2 after the swap"); }
int main( int argc, char **argv ) { QApplication app( argc, argv ); ocl::GLWidget *w = new ocl::GLWidget(); ocl::GLData* g = w->addObject(); Cutsim cs; QObject::connect( w, SIGNAL(sig()), &cs, SLOT(cut()) ); cs.setGLData(g); cs.updateGL(); w->show(); return app.exec(); }
int main() { typedef boost::signal2<void, int, int, boost::last_value<void>, std::string, std::less<std::string>, void (*)(int, int)> sig_type; sig_type sig; sig.connect(&print_sum); sig.connect(&print_product); sig(3, 5); // print sum and product of 3 and 5 // should fail // sig.connect(&print_quotient); }
void testCombinerThatSavesAllValuesReturnedFromSlots() { boost::signals2::signal<float (float, float), AggregateValues<std::vector<float>>> sig; sig.connect(&product); sig.connect("ient); sig.connect(&sum); sig.connect(&difference); std::vector<float> results = sig(5, 3); std::cout << "aggregate values: "; std::copy(results.begin(), results.end(), std::ostream_iterator<float>(std::cout, " ")); std::cout << "\n"; }