UserData ClientServiceImpl::getLoggedInUser() const{ ScopeGuard fbCritSectGuard( bind(&CComCriticalSection::Lock, ref(facebookDataCritSect)), bind(&CComCriticalSection::Unlock, ref(facebookDataCritSect))); return _currentData.getLoggedInUser(); }
size_t ClientServiceImpl::getGroupsInvsCount() const{ ScopeGuard fbCritSectGuard( bind(&CComCriticalSection::Lock, ref(facebookDataCritSect)), bind(&CComCriticalSection::Unlock, ref(facebookDataCritSect))); NotificationsData nftnDta = _currentData.getNotificationsData(); return nftnDta.getGroupsInvsCount(); }
size_t ClientServiceImpl::getPokesCount() const{ // lock on construction, unlock on destruction ScopeGuard fbCritSectGuard( bind(&CComCriticalSection::Lock, ref(facebookDataCritSect)), bind(&CComCriticalSection::Unlock, ref(facebookDataCritSect))); NotificationsData nftnDta = _currentData.getNotificationsData(); return nftnDta.getPokesCount(); }
void test_data_members() { using boost::ref; B b(10); BOOST_CHECK(bind(&B::i, ref(b))() == 10); BOOST_CHECK(bind(&B::i, b)() == 10); BOOST_CHECK(bind(&B::i, _1)(b) == 10); BOOST_CHECK(bind(&B::i, _1)(B(11)) == 11); bind(&B::i, ref(b))() = 1; BOOST_CHECK(b.i == 1); }
void ClientServiceImpl::cleanUpCollectedData() { ScopeGuard fbCritSectGuard( bind(&CComCriticalSection::Lock, ref(facebookDataCritSect)), bind(&CComCriticalSection::Unlock, ref(facebookDataCritSect))); _toolbarNotifications.clear(); _friendsChangesPopupNotifications.clear(); _albumsChanges.clear(); _popupSelfNotifications.clear(); ServiceData emptyData; _currentData = emptyData; }
OD grammar_args::options() { namespace po = boost::program_options; using std::string; using boost::bind; using boost::ref; using namespace graehl; OD od("grammar options"); od.add_options() ("grammar-archive,g", defaulted_value(&grammar_archive), "archived translation rules grammar") ( "grammar-format,f" , defaulted_value(&grammar_format), "legal values: brf, archive(default), fat-archive, " "text-archive, fat-text-archive" ) ("weight-file,w" ,po::value<string>()->notifier(bind(&weights_from_file,ref(*this),_1)) ,"file with feature and lm exponents (weights), " "single or multiple lines of: a:-1,b:2.5") ("weight-string" ,po::value<string>()->notifier(bind(&weights_from_string,ref(*this),_1)) ,"same format as weights file; completely overrides any --weight-file") ("verbose-non-numeric", defaulted_value(&verbose), "complain to STDERR about nonnumeric rule attributes") ("final-weights-to", defaulted_value(&final_weights_to), "print weights finally used here (same format as weight-string/file)") ; OD prior_opts("Heuristic (English) per-tag prior probability options"); prior_opts.add_options() ("prior-file", defaulted_value(&prior_file), "file with alternating <tag> <count> e.g. NP 123478. virtual tags ignored") ("prior-floor-prob", defaulted_value(&prior_floor_prob), "minimum probability for missing or low-count tags") ("prior-bonus-count", defaulted_value(&prior_bonus_count), "give every tag that appears in prior-file this many extra counts (before normalization)") ("weight-prior", defaulted_value(&weight_tag_prior), "raise prior prob to this power for rule heuristic") ("tag-prior-bonus", defaulted_value(&grammar.tag_prior_bonus), "constant prior multiplied into (nonvirtual) tag heuristic. greater than 1 <=> favor tags more than virtuals") ; od.add(prior_opts); OD feature_opts("(nonnumeric) feature options"); feature_opts.add_options() ("keep-text-features",defaulted_value(&keep_texts), "Keep the unused nonnumeric features in memory") ("keep-align",defaulted_value(&keep_align), "parse the 'align' attribute for word/variable alignments") ; od.add(feature_opts); return od; }
std::string f(ArgumentPack const& args) { std::string const& s1 = args[_s1]; std::string const& s2 = args[_s2]; #line 1905 "../../../../libs/parameter/doc/index.rst" using boost::bind; using boost::ref; typename parameter::binding< ArgumentPack, tag::s3, std::string >::type s3 = args[_s3 || bind(std::plus<std::string>(), ref(s1), ref(s2)) ]; #line 1931 "../../../../libs/parameter/doc/index.rst" return s3; }
// Run a tweaked sobel convolution void FastSobel::Convolve(const ImageF& input, ImageF& output, const int direction) { if (*gvParallelize) { ParallelPartition(input.GetHeight(), bind(&ConvolveRowRange, ref(input), ref(output), direction, _1, _2)); } else { ConvolveRowRange(input, output, direction, 0, input.GetHeight()-1); } }
static void findOverlap(const Graph& g, ContigID refID, bool rc, const ContigNode& pair, const DistanceEst& est, OverlapGraph& out) { if (refID == pair.id() || (est.distance >= 0 && !opt::scaffold)) return; ContigNode ref(refID, false); const ContigNode& t = rc ? pair : ref; const ContigNode& h = rc ? ref : pair; if (out_degree(t, g) > 0 || in_degree(h, g) > 0 || edge(t, h, out).second) return; bool mask = false; unsigned overlap = est.distance - (int)allowedError(est.stdDev) <= 0 ? findOverlap(g, t, h, mask) : 0; if (mask && !opt::mask) return; if (overlap > 0 || opt::scaffold) add_edge(t, h, Overlap(est, overlap, mask), out); }
void test_member_functions() { using boost::ref; A a(10); int i = 1; BOOST_TEST(bind(&A::add, ref(a), _1)(i) == 11); BOOST_TEST(bind(&A::add, &a, _1)(i) == 11); BOOST_TEST(bind(&A::add, _1, 1)(a) == 11); BOOST_TEST(bind(&A::add, _1, 1)(make_const(&a)) == 11); BOOST_TEST(bind(&A::add2, _1, 1, 1)(a) == 12); BOOST_TEST(bind(&A::add3, _1, 1, 1, 1)(a) == 13); BOOST_TEST(bind(&A::add4, _1, 1, 1, 1, 1)(a) == 14); BOOST_TEST(bind(&A::add5, _1, 1, 1, 1, 1, 1)(a) == 15); BOOST_TEST(bind(&A::add6, _1, 1, 1, 1, 1, 1, 1)(a) == 16); BOOST_TEST(bind(&A::add7, _1, 1, 1, 1, 1, 1, 1, 1)(a) == 17); BOOST_TEST(bind(&A::add8, _1, 1, 1, 1, 1, 1, 1, 1, 1)(a) == 18); // This should fail, as lambda functors store arguments as const // bind(&A::add, a, _1); }
void ClientServiceImpl::FireUpdates(ClientService* clientService) { ScopeGuard fbCritSectGuard( bind(&CComCriticalSection::Lock, ref(facebookDataCritSect)), bind(&CComCriticalSection::Unlock, ref(facebookDataCritSect))); // fire updates about my changes while(!_toolbarNotifications.empty()) { const DataChangeEvents eventID = _toolbarNotifications.front(); _toolbarNotifications.pop_front(); try{ clientService->Fire_dataUpdated(eventID); } catch(...) { } if (!initialUpdate_) { showSelfNotification(eventID, _currentData); } } // fier notifications about self changes while(!_popupSelfNotifications.empty()) { const DataChangeEvents changeID = _popupSelfNotifications.front(); _popupSelfNotifications.pop_front(); showSelfNotification(changeID, _currentData); } // fire updates about my friends while(!_friendsChangesPopupNotifications.empty()) { const EventToFriendIDs eventToFriendIDs = _friendsChangesPopupNotifications.front(); _friendsChangesPopupNotifications.pop_front(); const DataChangeEvents changeID = eventToFriendIDs.first; const FriendsIDs friendsIDs = eventToFriendIDs.second; showFriendsChangePopup(changeID, friendsIDs, _currentData); } // fire updates about albums while(!_albumsChanges.empty()) { const EventsToAlbumsIDs eventToAlbumIDs = _albumsChanges.front(); _albumsChanges.pop_front(); const DataChangeEvents changeID = eventToAlbumIDs.first; const AlbumsIDs albumsIDs = eventToAlbumIDs.second; showAlbumsChangePopup(changeID, albumsIDs, _currentData); } initialUpdate_ = false; }
/** * Retrieve an IEnumIDList to enumerate this directory's contents. * * This function returns an enumerator which can be used to iterate through * the contents of this directory as a series of PIDLs. This listing is a * @b copy of the one obtained from the server and will not update to reflect * changes. In order to obtain an up-to-date listing, this function must be * called again to get a new enumerator. * * @param flags Flags specifying nature of files to fetch. * * @returns Smart pointer to the IEnumIDList. * @throws com_error if an error occurs. */ com_ptr<IEnumIDList> CSftpDirectory::GetEnum(SHCONTF flags) { // Interpret supported SHCONTF flags bool include_folders = (flags & SHCONTF_FOLDERS) != 0; bool include_non_folders = (flags & SHCONTF_NONFOLDERS) != 0; bool include_hidden = (flags & SHCONTF_INCLUDEHIDDEN) != 0; vector<sftp_filesystem_item> directory_enum = m_provider->listing( m_directory); // XXX: PERFORMANCE: // For a link, we look its target details up 3 times! Once to see if it is // a directory, once to see if it isn't a directory and once to see if its // a directory whilst converting to PIDL. This info should be cached in // the sftp_filesystem_item function<bool(const sftp_filesystem_item&)> hidden_filter = include_hidden || !bind(is_dotted, _1); function<bool(const sftp_filesystem_item&)> directory_filter = include_folders || !bind(is_directory, _1, m_directory, ref(*m_provider)); function<bool(const sftp_filesystem_item&)> non_directory_filter = include_non_folders || bind(is_directory, _1, m_directory, ref(*m_provider)); function<cpidl_t(const sftp_filesystem_item&)> pidl_converter = bind( convert_directory_entry_to_pidl, _1, m_directory, ref(*m_provider)); shared_ptr< vector<cpidl_t> > pidls = make_shared< vector<cpidl_t> >(); boost::copy( directory_enum | filtered(hidden_filter) | filtered(directory_filter) | filtered(non_directory_filter) | transformed(pidl_converter), back_inserter(*pidls)); return make_smart_enumeration<IEnumIDList>(pidls); }
void TextWindow::setName(const std::string& utf8name, const std::string& next_char) { if (name_mod_ == 0) { // Display the name in one pass printTextToFunction(bind(&TextWindow::character, ref(*this), _1, _2), utf8name, next_char); setIndentation(); } setNameWithoutDisplay(utf8name); }
int main() { fusion::vector<int,char> lv_vec(1,'\004'); test_func<> f; test_func<noncopyable> f_nc; fusion::result_of::make_fused_procedure< test_func<> >::type fused_func = fusion::make_fused_procedure(f); CHECK_EFFECT(fused_func(lv_vec), 1); CHECK_EFFECT(const_(fused_func)(lv_vec), 0); CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(lv_vec), 1); CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(lv_vec), 1); CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(lv_vec), 0); CHECK_EFFECT(fused_func(fusion::make_vector(2,'\003')), 1); CHECK_EFFECT(const_(fused_func)(fusion::make_vector(2,'\003')), 0); CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(fusion::make_vector(2,'\003')), 1); CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(fusion::make_vector(2,'\003')), 1); CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(fusion::make_vector(2,'\003')), 0); return boost::report_errors(); }
int main(int argc, char* argv[]) { if( argc < 2 ){ printf("%s", usage); return 1; } int len = atoi(argv[1] ); if( len < 3 || len > 12 ){ printf("%s", usage); return 2; } int fact[16]; fact[0] = 1; for(int i = 1; i<len+1; ++i) fact[i] = fact[i-1]*i; unsigned n_cpu = thread::hardware_concurrency(); Fannkuchredux::R r= { 0, 0}; const unsigned max_cpu_limit = 4; Task parts[max_cpu_limit]; unsigned n = min(n_cpu, max_cpu_limit); thread_group tg; int index = 0; int index_max = fact[len]; int index_step = (index_max + n-1)/n; for(unsigned i = 0; i<n; ++i, index += index_step){ Task& p = parts[i]; p.init(fact, len, index, index + index_step); tg.create_thread(ref(p)); } tg.join_all(); for(unsigned i = 0; i<n; ++i){ Task const& p = parts[i]; r.maxflips = max( p.r.maxflips, r.maxflips ); r.checksum += p.r.checksum; } printf("%d\nPfannkuchen(%d) = %d\n", r.checksum, len, r.maxflips); return 0; }
Worker::Worker() : consumer_thread(bind(&Worker::ConsumeLoop, ref(*this))), join_barrier(2), alive(true) { }
void do_write(ip::tcp::socket & sock, char * buff, size_t size) { if ( !started() ) return; sock.async_write_some(buffer(buff,size), MEM_FN3(on_write,ref(sock),_1,_2)); }
void do_read(ip::tcp::socket & sock, char* buff) { async_read(sock, buffer(buff, max_msg), MEM_FN3(read_complete,ref(sock),_1,_2), MEM_FN3(on_read,ref(sock),_1,_2)); }
void Worker::Wait() { Add(bind(&barrier::wait, ref(join_barrier))); // will assert(alive) join_barrier.wait(); }
int run( int argc, char **argv ) { // typedefs typedef typename AdvDiffLatticeModel::Stencil AdvDiffStencil; typedef lbm::PdfField< AdvDiffLatticeModel > AdvDiffPDFField; #ifdef _OPENMP omp_set_num_threads( std::max( omp_get_num_threads()>>1, 4 ) ); #endif // --- physical default values --- // const real_t size[] = { real_t(1), real_t(1), real_t(1) }; const real_t v = real_t(1); real_t time = real_t( 0.2 ); real_t err = real_t( 0 ); real_t d = real_t( 1e-6 ); real_t dx = real_t( 0.01 ); real_t dt = real_t( 0.001 ); real_t dv = real_t( 1.0 ); real_t u_in = real_t( 1 ); uint_t dim = uint_t( 2u ); bool useGui = false; bool useVTK = false; bool quiet = false; // --- read arguments --- // if( argc > 1 ) { std::vector<std::string> args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { if( boost::equals(argv[i], "-d" ) ) d = boost::lexical_cast<real_t>( args[++i] ); else if( boost::equals(argv[i], "-dim" ) ) dim = boost::lexical_cast<uint_t>( args[++i] ); else if( boost::equals(argv[i], "-dx" ) ) dx = boost::lexical_cast<real_t>( args[++i] ); else if( boost::equals(argv[i], "-dt" ) ) dt = boost::lexical_cast<real_t>( args[++i] ); else if( boost::equals(argv[i], "-dv" ) ) dv = boost::lexical_cast<real_t>( args[++i] ); else if( boost::equals(argv[i], "-v" ) ) u_in = boost::lexical_cast<real_t>( args[++i] ); else if( boost::equals(argv[i], "-t" ) ) time = boost::lexical_cast<real_t>( args[++i] ); else if( boost::equals(argv[i], "-err" ) ) err = boost::lexical_cast<real_t>( args[++i] ); else if( boost::equals(argv[i], "--gui" ) ) useGui = true; else if( boost::equals(argv[i], "--quiet" ) ) quiet = true; else if( boost::equals(argv[i], "--vtk" ) ) useVTK = true; else if( boost::equals(argv[i], "-c" ) ) ++i; else if( argv[i][0] != '-' ){ WALBERLA_ABORT( "Usage: -option value" ); } else WALBERLA_LOG_WARNING( "Ignore unknown option " << argv[i++] ); } } // --- make dimensionless --- // const uint_t timesteps = uint_t( time / dt ); uint_t cells[] = { uint_t(1u), uint_t(1u), uint_t(1u) }; cells[dim] = uint_c( size[dim] / dx ); if(!quiet) WALBERLA_LOG_RESULT( "Simulate " << cells[dim] << " cells in " << timesteps << " timesteps " ); const real_t D = d * dt / dx / dx; const real_t tau = real_t(3) * D + real_c(0.5); const real_t omega = real_t(1) / tau; vec3_t u; u[dim] = u_in; u = u / dx * dt; if(!quiet) WALBERLA_LOG_RESULT( " -> u = " << u ); if(!quiet) WALBERLA_LOG_RESULT( " -> tau = " << tau ); const real_t tperiod = real_t(2) * math::PI / real_c( timesteps ); const real_t cperiod = real_t(2) * math::PI / real_c( cells[dim] ); // --- create blockstorage --- // auto blockStorage = blockforest::createUniformBlockGrid( 1, 1, 1, // blocks/processes in x/y/z direction cells[0], cells[1], cells[2], // cells per block in x/y/z direction dx, // cell size true, // one block per process true, true, true, // periodicity false ); // --- create fields --- // BlockDataID oldMomDensity = field::addToStorage<VectorField>( blockStorage, "Old Momentum Density", vec3_t(), field::fzyx, uint_t(0u) ); BlockDataID srcFieldID = createAdvDiffPdfField<AdvDiffLatticeModel>( blockStorage, oldMomDensity, omega ); BlockDataID velFieldID = field::addToStorage<VectorField>( blockStorage, "Velocity field", Vector3<real_t>() ); BlockDataID flagFieldID = blockStorage->template addStructuredBlockData<MyFlagField>( &flagFieldCreationFunction, "Flag field" ); // --- additional sweep variables --- // real_t E_mean_ ( real_t(0) ); uint_t timestep( uint_t(0u) ); real_t cosi(real_t(0)), sisi(real_t(0)), sexp(real_t(0)); // --- data init --- // for( auto block = blockStorage->begin(); block != blockStorage->end(); ++block ){ auto srcField = block->template getData< AdvDiffPDFField >( srcFieldID ); auto oMDField = block->template getData< VectorField >( oldMomDensity ); for( auto it = srcField->beginXYZ(); it != srcField->end(); ++it ){ lbm::setToEquilibrium<AdvDiffLatticeModel>( it, u, v + dv * real_c( cos( ( real_c( it.cell()[dim] ) + real_c(0.5) ) * cperiod ) ) ); oMDField->get(it.x(),it.y(),it.z()) = u * lbm::getDensity( srcField->latticeModel(), it ); } } blockforest::communication::UniformBufferedScheme< AdvDiffStencil > flagScheme( blockStorage ); flagScheme.addPackInfo( make_shared< field::communication::PackInfo< MyFlagField > >( flagFieldID ) ); flagScheme.communicate(); // --- timeloop setup --- // SweepTimeloop timeloop( blockStorage->getBlockStorage(), timesteps ); blockforest::communication::UniformBufferedScheme< AdvDiffStencil > scheme( blockStorage ); scheme.addPackInfo( make_shared< field::communication::PackInfo< AdvDiffPDFField > >( srcFieldID ) ); timeloop.addFuncBeforeTimeStep( scheme, "Communication" ); using boost::ref; timeloop.add() << Sweep( boost::bind( hydroFunc, _1, velFieldID, u, tperiod, ref(timestep) ), "Hydro Func" ); timeloop.add() << Sweep( makeSharedSweep( lbm::makeCellwiseAdvectionDiffusionSweep< AdvDiffLatticeModel, VectorField, MyFlagField >( srcFieldID, velFieldID, flagFieldID, getFluidFlag() ) ), "LBM_SRT" ); timeloop.add() << BeforeFunction( boost::bind( prepFunc, u[dim], dv, D, cperiod, tperiod, ref(timestep), ref(cosi), ref(sisi), ref(sexp) ), "prepare test" ) << Sweep ( boost::bind( testFunc<AdvDiffPDFField>, _1, srcFieldID, dim, v, cperiod, ref(cosi), ref(sisi), ref(sexp), ref(E_mean_) ), "Test Func" ) << AfterFunction ( boost::bind( incTimeFunc, ref(timestep) ), "increment time" ); // --- run timeloop --- // if ( useGui ) { field::addFieldAdaptor< typename lbm::Adaptor<AdvDiffLatticeModel>::Density> ( blockStorage, srcFieldID, "E" ); field::addFieldAdaptor< typename lbm::Adaptor<AdvDiffLatticeModel>::StreamMomentumDensityVector>( blockStorage, srcFieldID, "j" ); GUI gui ( timeloop, blockStorage, argc, argv ); lbm::connectToGui<AdvDiffLatticeModel>( gui ); gui.run(); } else if( !quiet ) { WcTimingPool timeloopTiming; timeloop.run( timeloopTiming ); timeloopTiming.logResultOnRoot(); } else { timeloop.run( ); } if( useVTK ) { auto vtkOut = vtk::createVTKOutput_BlockData( *blockStorage, "fields", 1u, 0u, false, "vtk_out/DiffusionTest" ); auto densityWriter = make_shared<lbm::DensityVTKWriter<AdvDiffLatticeModel>>( srcFieldID, "E" ); vtkOut->addCellDataWriter( densityWriter ); vtkOut->write(); } E_mean_ /= real_c(timesteps) * real_c(cells[dim]); if( err > real_t(0) && E_mean_ > err ){ WALBERLA_ABORT( "E_mean = " << E_mean_ << " > " << err ); } else { if(!quiet) WALBERLA_LOG_RESULT( "E^2 = " << E_mean_ << " E^1 = " << sqrt(E_mean_) ); } return 0; }