void Tunnel::stop() { auto d = Tunnel::_instance->d_func(); auto stopDispatcherFunc = [](TunnelPrivate::DispatcherMap::value_type& pair) { winfo("Stopping the " + pair.second->name() + " dispatcher..."); assert(pair.second); pair.second->stop(); winfo("Stopped the " + pair.second->name() + " dispatcher."); }; auto stopReceiverFunc = [](TunnelPrivate::ReceiverMap::value_type& pair) { winfo("Stopping the " + pair.second->name() + " receiver..."); assert(pair.second); pair.second->stop(); winfo("Stopped the " + pair.second->name() + " receiver."); }; wdebug("Stopping the Tunnel..."); for_each(begin(d->receivers), end(d->receivers), stopReceiverFunc); for_each(begin(d->dispatchers), end(d->dispatchers), stopDispatcherFunc); instance()->emitEvent(make_shared<Events::Event>(W_EVENT_TUNNEL_STOP)); wdebug("Stopped the Tunnel."); }
void Tunnel::start() { W_SPRV(Tunnel); auto startDispatcherFunc = [](std::pair<const string, Tunnel::Dispatcher::Ptr> pair) { winfo("Starting the " + pair.second->name() + " dispatcher..."); assert(pair.second); pair.second->start(); winfo("Started the " + pair.second->name() + " dispatcher."); }; auto startReceiverFunc = [](std::pair<const string, Tunnel::Receiver::Ptr> pair) { winfo("Starting the " + pair.second->name() + " receiver..."); assert(pair.second); pair.second->start(); winfo("Started the " + pair.second->name() + " receiver."); }; wdebug("Starting the Tunnel..."); for_each(begin(d->receivers), end(d->receivers), startReceiverFunc); for_each(begin(d->dispatchers), end(d->dispatchers), startDispatcherFunc); auto eventPtr = make_shared<Events::Event>(W_EVENT_TUNNEL_START); assert(instance()->emitter()); instance()->emitEvent(eventPtr); wdebug("Started the Tunnel."); }
int main(int argc, char* argv[]) { /// /// Command line arguments processing /// if (argc < 5) { usage(); return 0; } vector<string> prev_trans_directory; prev_trans_directory.push_back(argv[1]); string dir_of_project_folder = argv[2]; string libname = argv[3]; vector<string> dlls; for (int i = 4; i < argc; i++) { dlls.push_back(argv[i]); } /// /// If there are any other directories that contain libraries we've previously translated, /// pick up all the previously translated things from there /// LibraryConverterDriver driver; for_each(prev_trans_directory.begin(), prev_trans_directory.end(), [&driver] (const string &s) { driver.add_converted_info(s);}); /// /// Ok, now specify the list of libraries we want translated /// for_each(dlls.begin(), dlls.end(), [&driver] (const string &s) { driver.translate_classes_in_library(s); }); /// /// The specifics (output location, etc.) /// driver.set_output_solution_directory(dir_of_project_folder); driver.write_solution(false); driver.use_class_header_locations(true); driver.write_all_in_single_library(libname); driver.print_error_report(false); driver.set_template_files_location (prev_trans_directory[0] + "\\bin"); /// /// Now, do the translation and write out the final project solutoin /// try { driver.translate(); } catch (exception &e) { cout << "ERROR translating: " << e.what() << endl; return 100; } }
int main() { using boost::phoenix::arg_names::arg1; using boost::phoenix::construct; using boost::phoenix::delete_; using boost::phoenix::new_; using std::for_each; using std::vector; { vector<X*> v(10); for_each(v.begin(), v.end(), arg1 = new_<X>()); for_each(v.begin(), v.end(), delete_(arg1)); for_each(v.begin(), v.end(), arg1 = new_<X>(1, 2, 3)); for_each(v.begin(), v.end(), delete_(arg1)); } { using boost::shared_ptr; vector<shared_ptr<X> > v(10); for_each(v.begin(), v.end(), arg1 = boost::phoenix::construct<shared_ptr<X> >(new_<X>()) ); } BOOST_TEST(n == 0); return boost::report_errors(); }
// adds one CDataFile to another CDataFile CDataFile& CDataFile::operator+=(const CDataFile& df) { for_each ( df.m_vstrVariableNames.begin(), df.m_vstrVariableNames.end(), AddTo(m_vstrVariableNames) ); for_each ( df.m_vstrSourceFilenames.begin(), df.m_vstrSourceFilenames.end(), AddTo(m_vstrSourceFilenames) ); for_each ( df.m_v2dData.begin(), df.m_v2dData.end(), AddTo(m_v2dData) ); for_each ( df.m_v2dStrData.begin(), df.m_v2dStrData.end(), AddTo(m_v2dStrData) ); return *this; }
// tell all objects to describe themselves to the console void Model::describe() const { for_each(m_sim_objs.begin(), m_sim_objs.end(), [](const Sim_objs_t::value_type& p){ p.second->describe(); }); for_each(m_groups.begin(), m_groups.end(), [](const shared_ptr<Group>& p){ p->describe(); }); }
void demo_savem() { ofstream out_file("output.txt"); // open a file for output list<Thing *> thing_ptrs; // tell each thing to save its data to the out_file stream for_each(thing_ptrs.begin(), thing_ptrs.end(), Savem(out_file)); // using a lambda for_each(thing_ptrs.begin(), thing_ptrs.end(), [&out_file](Thing * ptr){ptr->save(out_file);} ); }
bool KEY6Parser::parseSlideList(const unsigned id) { const ObjectMessage msg(*this, id, KEY6ObjectType::SlideList); if (!msg) return false; const deque<unsigned> &slideListRefs = readRefs(get(msg), 1); for_each(slideListRefs.begin(), slideListRefs.end(), bind(&KEY6Parser::parseSlideList, this, _1)); const deque<unsigned> &slideRefs = readRefs(get(msg), 2); for_each(slideRefs.begin(), slideRefs.end(), bind(&KEY6Parser::parseSlide, this, _1, false)); return true; }
void LocationMap::initTiles() { bool hi = false; for_each(tiles.begin(), tiles.end(), [&hi](vector<TileShared>& col) { for_each(col.begin(), col.end(), [&hi](TileShared& tile) { // Closures. Neat! hi is fed in as a reference. tile.reset(new Tile()); hi = !hi; tile->setDerp(hi); } ); } ); }
END_EASYSIZE_MAP ///////////////////////////////////////////////////////////////////////////// BOOL CMainDialog::OnInitDialog() { CDialog::OnInitDialog(); ////////////////////////////////////////////////////////////////////////// CMenu *pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } ////////////////////////////////////////////////////////////////////////// SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE); ////////////////////////////////////////////////////////////////////////// GetWindowRect(&m_rtMinSize); INIT_EASYSIZE; InitControl(); GetImageSize(m_dwWidth, m_dwHeight); m_dwFrameStart = 0; m_dwFrameFinish= 0; for_each(nIDGroupPlay, nIDGroupPlay + ItemCount(nIDGroupPlay), bind1st(EnableWnd<FALSE>(), this)); ////////////////////////////////////////////////////////////////////////// if (PathFileExists(m_szSrcFilePath)) { SetTimer(0, 1000 / GetDlgItemInt(IDC_EDT_FPS, NULL, FALSE), NULL); SetDlgItemText(IDC_EDT_SRC_PATH, m_szSrcFilePath); for_each(nIDGroupPlay, nIDGroupPlay + ItemCount(nIDGroupPlay), bind1st(EnableWnd<TRUE>(), this)); m_fileSrc.Create(m_szSrcFilePath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); m_fileSrc.GetSize(m_dwFileLength); Update(TRUE); } Update(FALSE); return TRUE; }
void biggies(vector<string> & words, vector<string>::size_type sz) { elimDups(words); auto iter = stable_partition(words.begin( ), words.end( ), [sz](const string & s) {return sz > s.size( ); }); for_each(iter, words.end( ), [ ](const string & s) {cout << s << ' '; }); cout << endl; }
void biggies(vector<string> &words, vector<string>::size_type sz) { elimDups(words); // put words in alphabetical order and remove duplicates // resort by length, maintaining alphabetical order among words of the same // length stable_sort(words.begin(), words.end(), [](const string &s1, const string &s2) { return s1.size() < s2.size(); }); // get an iterator to the first element whose size() is >= sz auto wc = find_if(words.begin(), words.end(), [sz] (const string &s) { return s.size() >= sz; }); // compute the number of elements with size >= sz auto count = words.end() - wc; cout << count << " " << make_plural(count, "word", "s") << " of length " << sz << " or longer" << endl; // print words of the given size or longer, each one followed by space for_each(wc, words.end(), [] (const string &s) { cout << s << " "; }); cout << endl; }
void PlayListWidget::sort(const QStringList &list) { static QString first; static QString second; static QStringList tmp; static auto comp = [](QString::value_type it) {return it.isDigit();}; for_each(list.begin(), list.end(), [&](const QStringList::value_type & item) { second.clear(); tmp = item.split("$$"); first = tmp[0]; auto digit_begin = find_if(first.begin(), first.end(), comp); auto digit_end = find_if_not(digit_begin, first.end(), comp); std::copy(digit_begin, digit_end, std::back_inserter(second)); play_list.append(list_map {std::make_tuple<QString, QString, QString>( QString("%1").arg(second.toInt(), 10, 10, QChar('0')), std::move(first), std::move(tmp[1])) }); }); std::sort(play_list.begin(), play_list.end(), [](list_map::const_iterator::value_type lvalue, list_map::const_iterator::value_type rvalue) { return std::get<0>(lvalue) < std::get<0>(rvalue); }); }
void Model::update() { ++time; for_each(object_container.begin(), object_container.end(), bind(&Sim_object::update, bind(& map<string, shared_ptr<Sim_object> >::value_type::second, _1))); }
// returns the number of ints greater than criterion int get_count_over_criterion() { count = 0; for_each(ints.begin(), ints.end(), [this](int i) {if (i > criterion) count++;} ); return count; }
void Model::attach(shared_ptr<View> view) { view_container.insert(view); for_each(object_container.begin(), object_container.end(), bind(&Sim_object::broadcast_current_state, bind(& map<string, shared_ptr<Sim_object> >::value_type::second, _1))); }
string join(vector<string>& s, string sep="") { string joined=""; if (! s.size()) return joined; for_each(s.begin(), s.end()-1, [&joined, sep](string tojoin) {joined+=tojoin + sep;}); joined+=s.back(); return joined; }
int main(int argc, char* argv[]) { /// /// Start up ROOT /// int nargs = 2; char *myargv[2]; myargv[0] = "ROOT.NET Library Converter.exe"; myargv[1] = "-b"; TApplication *app = new TApplication ("ROOT.NET Library Converter", &nargs, myargv); // // Get all headers... // auto &headers = ROOTHelpers::GetAllHeaders(); /// /// Now, for each header, try it out. When we are done we'll have a list of bad ones! :-) /// set<string> bad_headers = for_each(headers.begin(), headers.end(), find_bad_headers()).Headers(); /// /// Finally, write these bad boys out! /// ofstream bad_header_list ("bad_headers.txt"); copy (bad_headers.begin(), bad_headers.end(), ostream_iterator<string>(bad_header_list, "\n")); bad_header_list.close(); /// Done! return 0; }
void GraphicsSystem::executeGraphicsSystem(RLMachine& machine) { // Check to see if any of the graphics objects are reporting that // they want to force a redraw for_each(foregroundObjects().allocated_begin(), foregroundObjects().allocated_end(), [&](GraphicsObject& obj) { obj.execute(machine); }); if (mouse_cursor_) mouse_cursor_->execute(system()); if (hik_renderer_ && background_type_ == BACKGROUND_HIK) hik_renderer_->execute(machine); // Possibly update the screen shaking state if (!screen_shake_queue_.empty()) { unsigned int now = system().event().getTicks(); unsigned int accumulated_ticks = now - time_at_last_queue_change_; while (!screen_shake_queue_.empty() && accumulated_ticks > screen_shake_queue_.front().second) { int frame_ticks = screen_shake_queue_.front().second; accumulated_ticks -= frame_ticks; time_at_last_queue_change_ += frame_ticks; screen_shake_queue_.pop(); forceRefresh(); } } }
bool KEY6Parser::parsePresentation(const unsigned id) { const ObjectMessage msg(*this, id, KEY6ObjectType::Presentation); if (!msg) return false; m_collector.startDocument(); const optional<IWAMessage> size = get(msg).message(4).optional(); if (size && get(size).float_(1) && get(size).float_(2)) m_collector.collectPresentationSize(IWORKSize(get(size).float_(1).get(), get(size).float_(2).get())); m_collector.startSlides(); bool success = true; if (get(msg).message(3)) { optional<unsigned> slideListRef; slideListRef = readRef(get(msg).message(3).get(), 1); if (slideListRef) { success = parseSlideList(get(slideListRef)); } else { const deque<unsigned> &slideListRefs = readRefs(get(get(msg).message(3)), 2); for_each(slideListRefs.begin(), slideListRefs.end(), bind(&KEY6Parser::parseSlideList, this, _1)); } } m_collector.endSlides(); m_collector.sendSlides(m_slides); m_collector.endDocument(); return success; }
/// Converts to lowercase. string StringManip::toLowerCase(const string &str) { string tmp = str; for_each(tmp.begin(), tmp.end(), ToLower()); return tmp; }
void logstream::flushStreams() { using std::for_each; // free all pointers in streams recursively std::auto_ptr<StreamMap> tmp(new StreamMap); tmp->swap(*streams); for_each(tmp->begin(), tmp->end(), deleter<StreamMapKey,logstream>()); }
void SingleLinkedList::cleanUp(){ for_each( processedEvents->begin(), processedEvents->end(), DeleteEvent() ); processedEvents->resize(0); }
void Model::attach_view(View_ptr_t view_ptr) { views.insert(view_ptr); // add bind for_each(boards.begin(), boards.end(), bind(&Board::broadcast_state, bind(&Board_map_t::value_type::second, _1))); }
SpikingConnection::SpikingConnection(int S, int T, synapse_vec synapses, bool stdp_enabled) : s(S), t(T), synapses(synapses), stdp_enabled(stdp_enabled) { // compute average float w_sum = 0; for_each(synapses.begin(), synapses.end(), [&](SpikingSynapse *syn) { w_sum += syn->w; }); target_w_avg = w_sum/synapses.size(); // target average calculated from initial conditions }
void biggies( vector<string> &words, vector<string>::size_type sz ) { elimDups(words); stable_sort(words.begin(), words.end(), ShorterString()); auto wc = find_if(words.begin(), words.end(), BiggerEqual(sz)); auto count = words.end() - wc; cout << count << " " << make_plural(count, "word", "s") << " of length " << sz << " or longer" << endl; for_each(wc, words.end(), Print()); cout << endl; }
void biggies_bind(vector<string> &words, vector<string>::size_type sz) { elimDups(words); stable_sort(words.begin(), words.end(), [] (const string &s1, const string &s2) { return s1.size() < s2.size(); }); auto wc = find_if(words.begin(), words.end(), bind(check_size, _1, sz)); auto count = words.end() - wc; cout << count << ' ' << make_plural(count, "word", "s") << " of length " << sz << " or longer" << endl; for_each(wc, words.end(), [] (const string &s) { cout << s << ' '; }); cout << endl; }
void Group::describe() { cout << "Group " << name << ": " << endl; cout << " size is " << members.size() << endl; for_each(members.begin(), members.end(), [](const shared_ptr<Unit> member_ptr) { cout << " " << member_ptr->get_name() << endl; }); }
// ex 10.18 : using partition instead of find_if // ex 10.19 : using stable_partition instead of partition void biggies_ptn(vector<string> &words, vector<string>::size_type sz) { elimDups(words); stable_sort(words.begin(), words.end(), [] (const string &s1, const string &s2) { return s1.size() < s2.size(); }); auto wc = stable_partition(words.begin(), words.end(), [sz] (const string &s) { return s.size() >= sz; }); auto count = wc - words.begin(); cout << count << ' ' << make_plural(count, "word", "s") << " of length " << sz << " or longer" << endl; for_each(words.begin(), wc, [] (const string &s) { cout << s << ' '; }); cout << endl; }
KEYSlidePtr_t KEY6Parser::parseSlide(const unsigned id, const bool master) { const ObjectMessage msg(*this, id, KEY6ObjectType::Slide); if (!msg) return KEYSlidePtr_t(); const optional<unsigned> &masterRef = readRef(get(msg), 17); KEYSlidePtr_t masterSlide; if (!master && masterRef) { if (m_masterSlides.find(get(masterRef))!=m_masterSlides.end()) masterSlide=m_masterSlides.find(get(masterRef))->second; else masterSlide=parseSlide(get(masterRef), true); } m_collector.startPage(); m_collector.startLayer(); IWORKStylePtr_t style; const optional<unsigned> &styleRef = readRef(get(msg), 1); if (styleRef) style = querySlideStyle(get(styleRef)); m_collector.setSlideStyle(style); if (!master) { const optional<unsigned> &titlePlaceholderRef = readRef(get(msg), 5); if (titlePlaceholderRef) parsePlaceholder(get(titlePlaceholderRef)); const optional<unsigned> &bodyPlaceholderRef = readRef(get(msg), 6); if (bodyPlaceholderRef) parsePlaceholder(get(bodyPlaceholderRef)); } const deque<unsigned> &shapeRefs = readRefs(get(msg), 7); for_each(shapeRefs.begin(), shapeRefs.end(), bind(&KEY6Parser::dispatchShape, this, _1)); const optional<unsigned> ¬esRef = readRef(get(msg), 27); if (notesRef) parseNotes(get(notesRef)); const KEYLayerPtr_t layer = m_collector.collectLayer(); m_collector.endLayer(); m_collector.insertLayer(layer); KEYSlidePtr_t slide=m_collector.collectSlide(); m_collector.endPage(); if (slide) { slide->m_masterSlide=masterSlide; if (!master) m_slides.push_back(slide); else m_masterSlides[id]=slide; } return slide; }