Exemple #1
0
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)));
}
Exemple #2
0
void
Nfdc::FaceIdFetcher::startGetFaceId(const ndn::util::FaceUri& faceUri)
{
  faceUri.canonize(bind(&FaceIdFetcher::onCanonizeSuccess, this, _1),
                   bind(&FaceIdFetcher::onCanonizeFailure, this, _1),
                   m_face.getIoService(), ndn::time::seconds(4));
}
Exemple #3
0
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)));
}
Exemple #4
0
void
Nfdc::ribRegisterPrefix()
{
  m_name = m_commandLineArguments[0];
  const std::string& faceName = m_commandLineArguments[1];

  FaceIdFetcher::start(m_face, m_controller, faceName, true,
                       [this] (const uint32_t faceId) {
                         ControlParameters parameters;
                         parameters
                           .setName(m_name)
                           .setCost(m_cost)
                           .setFlags(m_flags)
                           .setOrigin(m_origin)
                           .setFaceId(faceId);

                         if (m_expires != DEFAULT_EXPIRATION_PERIOD)
                           parameters.setExpirationPeriod(m_expires);

                         m_controller
                           .start<RibRegisterCommand>(parameters,
                                                      bind(&Nfdc::onSuccess, this, _1,
                                                           "Successful in name registration"),
                                                      bind(&Nfdc::onError, this, _1, _2,
                                                           "Failed in name registration"));
                       },
                       bind(&Nfdc::onObtainFaceIdFailure, this, _1));
}
// MP setup
TriggerDispatch buildTable(shared_ptr<Engine> engine) {
  TriggerDispatch table = TriggerDispatch();
  table["send_one"] = bind(&K3::send_one, engine, std::placeholders::_1);
  table["receive_one"] = bind(&K3::receive_one, engine, std::placeholders::_1);
  table["finished"] = bind(&K3::finished, engine, std::placeholders::_1);
  return table;
}
double pairInjectionExact(double E, Particle& particle, Particle& photon, fun1 tpf)
{	
	using std::bind; using namespace std::placeholders; // para _1, _2, etc.

	double Erest = electronMass*cLight2;
	
	double cte = 3.0*cLight*thomson*Erest/4.0;  // *Erest^2: de las dos dist de fotones
	                                              // /Erest: de la inyeccion de electrones


	//normalizo todo a me*c^2

	double inf = targetPhotonEmin/Erest; 

	double sup = targetPhotonEmax/Erest;  											

	/*DataInjection data;

	data.E        = E;
	data.mass     = electronMass;
	data.tpf      = tpf;*/

	double integral  = RungeKutta(inf,sup,
		bind(cAnnihilationExact,_1,E,electronMass),
		dAnnihilationExact,
		bind(fAnnihilationExact,_1,_2,E,electronMass,tpf));

	double emissivityA = cte*integral;

	return emissivityA;

}
Exemple #7
0
double pairInjectionFlor(double E, Particle& particle, Particle& photon, fun1 tpf)
{	
	using std::bind; using namespace std::placeholders; // para _1, _2, etc.

	double cte = 3.0*cLight*thomson*pow((particle.mass*cLight2),4)/32.0;

	double sup = 1.0; // 2e9*1.6e-12;  //este es el infinito del limite superior para la integral en Egamma
                                         //como Eph_min =0.15 keV --> Ega_max = 2 GeV 														

	double inf = E;  //Ega_min < Ee_min  --> la condicion esta asegurada
	
	//DataInjection data;

	//data.E        = E;
	//data.mass     = particle.mass;
	//data.tpf      = tpf;

	double integral  = RungeKutta(inf,sup,
		bind(cAnnihilation,_1,E,particle.mass),
		dAnnihilation,
		bind(fAnnihilation,_1,_2,E,tpf));

	double emissivityA = cte*integral;

	return emissivityA;

}
 void
 produce_simple_values()
   {
     using TestFactory = factory::MultiFact<string, theID>;
     
     TestFactory theFact;
     
     // the first "production line" is wired to a free function
     theFact.defineProduction (ONE, buildOne);
     
     // second "production line" uses a explicit partial closure
     theFact.defineProduction (TWO, bind (buildSome<theID>, TWO));
     
     // for the third "production line" we set up a function object
     auto memberFunction = bind (&MultiFact_test::callMe, this, "lalü");
     theFact.defineProduction (THR, memberFunction);
     
     // and the fourth "production line" uses a lambda, closed with a local reference
     string backdoor("backdoor");
     theFact.defineProduction (FOU, [&] {
                                       return backdoor;
                                    });
     
     CHECK (!isnil (theFact));
     CHECK (theFact(ONE) == "1");
     CHECK (theFact(TWO) == "2");
     
     CHECK (theFact(THR) == "lalü");
     CHECK (invocations_ == 1);
     
     CHECK (theFact(FOU) == "backdoor");
     backdoor = "I am " + backdoor.substr(0,4);
     CHECK (theFact(FOU) == "I am back");
     
     
     TestFactory anotherFact;
     CHECK (isnil (anotherFact));
     VERIFY_ERROR (INVALID, anotherFact(ONE) );
     
     anotherFact.defineProduction (ONE, memberFunction);
     CHECK (anotherFact(ONE) == "lalü");
     CHECK (invocations_ == 2);
     
     CHECK (theFact(THR) == "lalü");
     CHECK (invocations_ == 3);
     
     
     CHECK ( theFact.contains (FOU));
     CHECK (!anotherFact.contains (FOU));
     
     anotherFact = theFact;
     CHECK (anotherFact.contains (FOU));
     CHECK (!isSameObject(theFact, anotherFact));
     
     CHECK (anotherFact(ONE) == "1");
     CHECK (anotherFact(TWO) == "2");
     CHECK (anotherFact(THR) == "lalü");
     CHECK (anotherFact(FOU) == "I am back");
     CHECK (invocations_ == 4);
   }
Exemple #9
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)));
}
Exemple #10
0
 ActiveWishesTest()
 : wish_source_(WishSource::factory(&Environment::config()))
 , active_wishes_(Environment::config(), &gesture_source_)
 {
   app_source_.set_initialized_callback(bind(&ActiveWishesTest::app_source_initialized, this));
   app_source_.set_window_opened_callback(bind(&ActiveWishesTest::window_opened, this, _1));
   app_source_.set_window_closed_callback(bind(&ActiveWishesTest::window_closed, this, _1));
   active_wishes_.set_wish_granted_callback(bind(&ActiveWishesTest::callback_counter, this, _1, _2));
   active_wishes_.set_wish_revoked_callback(bind(&ActiveWishesTest::callback_counter, this, _1, _2));
 }
Exemple #11
0
void sqrtSquare() {
	double x = 7;
	double result = sqrt(x * x);

	auto square = getSquare<double>();

	auto func = bind( sqrt, bind(square,_1) );

	ASSERT_EQUAL(func(x), result);
}
Exemple #12
0
void INIT_TILES()
{
	if ( !TILES.empty() ) return;

	using std::bind;
	using std::make_pair;
	using namespace std::placeholders;

	TILES.insert( make_pair( "plains",	bind( CREATE_TILE< tile::Plains >, _1, _2 ) ) );
	TILES.insert( make_pair( "road",	bind( CREATE_TILE< tile::Road >, _1, _2 ) ) );
}
Exemple #13
0
void squareModulo() {
	int x = 7;
	int y = 2;
	int result = (x * x) % y;

	auto square = getSquare<unsigned>();

	auto func = bind(modulus<unsigned>{},  bind(square, _1), _2);

	ASSERT_EQUAL(func(x,y), result);
}
Exemple #14
0
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;
}
Exemple #15
0
void
Nfdc::startFaceCreate(const ndn::util::FaceUri& canonicalUri)
{
  ControlParameters parameters;
  parameters.setUri(canonicalUri.toString());

  m_controller.start<FaceCreateCommand>(parameters,
                                        bind(&Nfdc::onSuccess, this, _1,
                                             "Face creation succeeded"),
                                        bind(&Nfdc::onError, this, _1, _2,
                                             "Face creation failed"));
}
Exemple #16
0
AudioKaraoke::AudioKaraoke(wxWindow *parent, agi::Context *c)
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxBORDER_SUNKEN)
, c(c)
, file_changed(c->ass->AddCommitListener(&AudioKaraoke::OnFileChanged, this))
, audio_opened(c->audioController->AddAudioOpenListener(&AudioKaraoke::OnAudioOpened, this))
, audio_closed(c->audioController->AddAudioCloseListener(&AudioKaraoke::OnAudioClosed, this))
, active_line_changed(c->selectionController->AddActiveLineListener(&AudioKaraoke::OnActiveLineChanged, this))
, active_line(nullptr)
, kara(agi::util::make_unique<AssKaraoke>())
, scroll_x(0)
, scroll_dir(0)
, char_height(0)
, char_width(0)
, mouse_pos(0)
, click_will_remove_split(false)
, enabled(false)
{
	using std::bind;

	cancel_button = new wxBitmapButton(this, -1, GETIMAGE(kara_split_cancel_16));
	cancel_button->SetToolTip(_("Discard all uncommitted splits"));
	cancel_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, bind(&AudioKaraoke::CancelSplit, this));

	accept_button = new wxBitmapButton(this, -1, GETIMAGE(kara_split_accept_16));
	accept_button->SetToolTip(_("Commit splits"));
	accept_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, bind(&AudioKaraoke::AcceptSplit, this));

	split_area = new wxPanel(this);

	wxSizer *main_sizer = new wxBoxSizer(wxHORIZONTAL);
	main_sizer->Add(cancel_button);
	main_sizer->Add(accept_button);
	main_sizer->Add(split_area, wxSizerFlags(1).Expand());
	SetSizerAndFit(main_sizer);

	/// @todo subscribe
	split_font.SetFaceName(to_wx(OPT_GET("Audio/Karaoke/Font Face")->GetString()));
	split_font.SetPointSize(OPT_GET("Audio/Karaoke/Font Size")->GetInt());

	split_area->Bind(wxEVT_SIZE, &AudioKaraoke::OnSize, this);
	split_area->Bind(wxEVT_PAINT, &AudioKaraoke::OnPaint, this);
	split_area->Bind(wxEVT_LEFT_DOWN, &AudioKaraoke::OnMouse, this);
	split_area->Bind(wxEVT_LEFT_UP, &AudioKaraoke::OnMouse, this);
	split_area->Bind(wxEVT_MOTION, &AudioKaraoke::OnMouse, this);
	split_area->Bind(wxEVT_LEAVE_WINDOW, &AudioKaraoke::OnMouse, this);
	split_area->Bind(wxEVT_CONTEXT_MENU, &AudioKaraoke::OnContextMenu, this);
	scroll_timer.Bind(wxEVT_TIMER, &AudioKaraoke::OnScrollTimer, this);

	accept_button->Enable(false);
	cancel_button->Enable(false);
	enabled = false;
}
ArticulationResult<GraphT>
find_articulation_vertices(GraphT& g) {
    g.initializeSearch();

    ArticulationResult<GraphT> result(g);
    auto pEarly = bind(&ArticulationResult<GraphT>::processEarly, ref(result), _1);
    auto pLate = bind(&ArticulationResult<GraphT>::processLate, ref(result), _1);
    auto pEdge = bind(&ArticulationResult<GraphT>::processEdge, ref(result), _1, _2);

    g.dfs("v1", pEarly, pLate, pEdge);

    return result;
}
Exemple #18
0
void multiplyDivide() {
	double x = 1;
	double y = 2;
	double result = (2.0*x)-(y/3.0);

	auto m    = minus<double>{};
	auto mply = multiplies<double>{};
	auto div  = divides<double>{};

	auto func = bind(m, bind(mply, 2, _1), bind(div,_2,3));

	ASSERT_EQUAL(func(x,y), result);
}
Exemple #19
0
void
Nfdc::faceCreate()
{
  boost::regex e("^[a-z0-9]+\\:.*");
  if (!boost::regex_match(m_commandLineArguments[0], e))
    throw Error("invalid uri format");

  ndn::util::FaceUri faceUri;
  faceUri.parse(m_commandLineArguments[0]);

  faceUri.canonize(bind(&Nfdc::startFaceCreate, this, _1),
                   bind(&Nfdc::onCanonizeFailure, this, _1),
                   m_ioService, ndn::time::seconds(4));
}
Exemple #20
0
void
Nfdc::strategyChoiceUnset()
{
  const std::string& name = m_commandLineArguments[0];

  ControlParameters parameters;
  parameters.setName(name);

  m_controller.start<StrategyChoiceUnsetCommand>(parameters,
                                                 bind(&Nfdc::onSuccess, this, _1,
                                                      "Successfully unset strategy choice"),
                                                 bind(&Nfdc::onError, this, _1, _2,
                                                      "Failed to unset strategy choice"));
}
Exemple #21
0
int main() {

	cout << plus<int>()(3,4) << endl; // prints 7
	
	plus<int> intAdd;      // object that can add two int values
	negate<int> intNegate; // object that can negate an int value
	
	// uses intAdd::operator(int, int) to add 10 and 20
	int sum = intAdd(10, 20);         // equivalent to sum = 30
	cout << sum << endl;
	
	sum = intNegate(intAdd(10, 20));  // equivalent to sum = -30
	cout << sum << endl;
	
	// uses intNegate::operator(int) to generate -10 
	// as the second argument to intAdd::operator(int, int)
	sum = intAdd(10, intNegate(10));  // sum = 0
	
	cout << sum << endl;
	
#ifdef LIST_INIT
	vector<int> vec = {0,1,2,3,4,5,16,17,18,19};
#else
	int temp[] = {0,1,2,3,4,5,16,17,18,19};
	vector<int> vec(begin(temp), end(temp));
#endif
	
	// bind second argument to less_equal
	cout << count_if(vec.begin(), vec.end(),
		             bind(less_equal<int>(), _1, 10));  
	cout << endl;
	
	vector<string> svec;
	string in;
	while (cin >> in) 
		svec.push_back(in);

	function<decltype(size_compare)> fp1 = size_compare;

	//decltype(fp1)::result_type ret;
	function<bool(const string&)> fp2 = bind(size_compare, _1, 6);
	cout << count_if(svec.begin(), svec.end(), fp2)
	     << endl;
	cout << count_if(svec.begin(), svec.end(), 
	                 bind(size_compare, _1, 6))
	     << endl;


	return 0;
}
Exemple #22
0
void
start_server(std::string const &cert_uri,
             std::string const &privkey_uri,
             std::string const &address,
             unsigned int port)
{
    using namespace trezord;

    using std::bind;
    using std::placeholders::_1;
    using http_api::handler;

    auto cert = http_client::request_uri_to_string(cert_uri);
    auto privkey = http_client::request_uri_to_string(privkey_uri);

    http_api::handler api_handler{
        std::unique_ptr<core::kernel>{new core::kernel}};
    http_server::route_table api_routes = {
        {{"GET",  "/"},             bind(&handler::handle_index, &api_handler, _1) },
        {{"GET",  "/listen"},       bind(&handler::handle_listen, &api_handler, _1) },
        {{"GET",  "/enumerate"},    bind(&handler::handle_enumerate, &api_handler, _1) },
        {{"POST", "/configure"},    bind(&handler::handle_configure, &api_handler, _1) },
        {{"POST", "/acquire/(.+)"}, bind(&handler::handle_acquire, &api_handler, _1) },
        {{"POST", "/release/(.+)"}, bind(&handler::handle_release, &api_handler, _1) },
        {{"POST", "/call/(.+)"},    bind(&handler::handle_call, &api_handler, _1) },
        {{".*",   ".*"},            bind(&handler::handle_404, &api_handler, _1) }
    };
    http_server::server server{api_routes, [&] (char const *origin) {
            return api_handler.is_origin_allowed(origin);
        }};

    server.start(port, address.c_str(), privkey.c_str(), cert.c_str());
    std::getchar();
    server.stop();
}
Exemple #23
0
int main()
{
	vector<int> ivec{1, 16, 256, 4096, 65536};
	vector<string> svec{"pooh", "pooh", "pooh", "hoop", "pooh"};

	auto cnt = count_if(ivec.cbegin(), ivec.cend(), bind(greater<int>(), _1, 1024));
	cout << cnt << endl;
	auto it = find_if(svec.cbegin(), svec.cend(), bind(not_equal_to<string>(), _1, "pooh"));
	cout << *it << endl;
	transform(ivec.begin(), ivec.end(), ivec.begin(), bind(multiplies<int>(), _1, 2));
	for (const auto &val : ivec)
		cout << val << ' ';

	return 0;
}
Exemple #24
0
 result_type trace() {
     SnifferConfiguration config;
     config.set_promisc_mode(false);
     // ICMPs that aren't sent from us.
     config.set_filter(
         "ip proto \\icmp and not src host " + iface.addresses().ip_addr.to_string());
     Sniffer sniffer(iface.name(), config);
     
     PacketSender sender;
     // Create our handler
     auto handler = bind(
         &Traceroute::sniff_callback, 
         this, 
         std::placeholders::_1
     );
     // We're running
     running = true;
     // Start the sniff thread
     thread sniff_thread(
         [&]() {
             sniffer.sniff_loop(handler);
         }
     );
     send_packets(sender);
     sniff_thread.join();
     // If the final hop responded, add its address at the appropriate ttl
     if (lowest_dest_ttl != numeric_limits<int>::max()) {
         results[lowest_dest_ttl] = addr;
     }
     // Clear our results and return what we've found
     return move(results);
 }
Exemple #25
0
void TcpConnection::do_read_line()
{
	ba::async_read_until(socket_,
			read_buffer,
			'\n',
			bind(&TcpConnection::handle_read_line, shared_from_this(), placeholders::_1, placeholders::_2 ));
}
void MenuSettingBool::initButton()
{
	buttonBox.add(unique_ptr<IconButton>(new IconButton(
			gmenu2x, ts, "skin:imgs/buttons/accept.png",
			gmenu2x->tr["Switch"],
			bind(&MenuSettingBool::toggle, this))));
}
Exemple #27
0
    virtual void
    run (Arg)
    {
        command2::check_.seekp(0);
        uint cnt_defs = Command::definition_count();
        uint cnt_inst = Command::instance_count();

        function<string()> randFun = bind (&CommandUse2_test::randomTxt, this);

        // prepare a command definition (prototype)
        CommandDef ("test.command2")
        .operation (command2::operate)
        .captureUndo (command2::capture)
        .undoOperation (command2::undoIt)
        .bind (randFun, ref(blowUp_));

        //note : blowUp_ is bound via reference_wrapper,
        //        thus we can provoke an exception at will.
        blowUp_ = false;


        check_defaultHandlingPattern();
        check_ThrowOnError();


        Command::remove ("test.command2");
        Command::remove ("test.command2.1");
        CHECK (cnt_defs == Command::definition_count());
        CHECK (cnt_inst == Command::instance_count());
    }
Exemple #28
0
void SDLEventSystem::handleKeyUp(RLMachine& machine, SDL_Event& event) {
  switch (event.key.keysym.sym) {
  case SDLK_LSHIFT:
  case SDLK_RSHIFT: {
    shift_pressed_ = false;
    break;
  }
  case SDLK_LCTRL:
  case SDLK_RCTRL: {
    ctrl_pressed_ = false;
    break;
  }
  case SDLK_F1: {
    machine.system().showSystemInfo(machine);
    break;
  }
  case SDLK_F12: {
    machine.system().dumpRenderTree(machine);
    break;
  }
  default:
    break;
  }

  KeyCode code = KeyCode(event.key.keysym.sym);
  dispatchEvent(machine, bind(&EventListener::keyStateChanged, _1, code,
                              false));
}
std::vector<AssDialogue*> DialogTimingProcessor::SortDialogues() {
	std::set<std::string> styles;
	for (size_t i = 0; i < StyleList->GetCount(); ++i) {
		if (StyleList->IsChecked(i))
			styles.insert(from_wx(StyleList->GetString(i)));
	}

	std::vector<AssDialogue*> sorted;

	if (onlySelection->IsChecked()) {
		SubtitleSelection sel = c->selectionController->GetSelectedSet();
		copy_if(sel.begin(), sel.end(), back_inserter(sorted),
			[&](AssDialogue *d) { return !d->Comment && styles.count(d->Style); });
	}
	else {
		transform(c->ass->Line.begin(), c->ass->Line.end(), back_inserter(sorted), cast<AssDialogue*>());
		sorted.erase(boost::remove_if(sorted, bind(bad_line, &styles, _1)), sorted.end());
	}

	// Check if rows are valid
	for (auto diag : sorted) {
		if (diag->Start > diag->End) {
			int line = count_if(c->ass->Line.begin(), c->ass->Line.iterator_to(*diag), cast<const AssDialogue*>());
			wxMessageBox(
				wxString::Format(_("One of the lines in the file (%i) has negative duration. Aborting."), line),
				_("Invalid script"),
				wxOK | wxICON_ERROR | wxCENTER);
			sorted.clear();
			break;
		}
	}

	boost::sort(sorted, AssFile::CompStart);
	return sorted;
}
Exemple #30
0
void testPlus() {
	double x = 1;
	double y = 2;
	auto func = bind(plus<double>{}, _1, _2);

	ASSERT_EQUAL(func(x,y), x+y);
}